-
Notifications
You must be signed in to change notification settings - Fork 96
Expand file tree
/
Copy pathXMLExceptionParserTests.kt
More file actions
75 lines (62 loc) · 2.74 KB
/
XMLExceptionParserTests.kt
File metadata and controls
75 lines (62 loc) · 2.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
* Nextcloud Android Library
*
* SPDX-FileCopyrightText: 2025 Alper Ozturk <alper.ozturk@nextcloud.com>
* SPDX-License-Identifier: MIT
*/
package com.owncloud.android
import com.owncloud.android.lib.common.operations.XMLExceptionParser
import org.junit.Assert
import org.junit.Test
import java.io.ByteArrayInputStream
class XMLExceptionParserTests {
@Test
fun testVirusException() {
val virusException =
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
"<d:error xmlns:d=\"DAV:\" xmlns:s=\"http://sabredav.org/ns\">\n" +
" <s:exception>OCA\\DAV\\Connector\\Sabre\\Exception\\UnsupportedMediaType" +
"</s:exception>\n" +
" <s:message>Virus Eicar-Test-Signature is detected in the file. " +
"Upload cannot be completed.</s:message>\n" +
"</d:error>"
val inputStream = ByteArrayInputStream(virusException.toByteArray())
val xmlParser = XMLExceptionParser(inputStream)
Assert.assertTrue(xmlParser.isVirusException)
Assert.assertFalse(xmlParser.isInvalidCharacterException)
}
@Test
fun testInvalidCharacterException() {
val virusException =
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
"<d:error xmlns:d=\"DAV:\" xmlns:s=\"http://sabredav.org/ns\">\n" +
" <s:exception>OC\\Connector\\Sabre\\Exception\\InvalidPath</s:exception>\n" +
" <s:message>Wrong Path</s:message>\n" +
"</d:error>"
val inputStream = ByteArrayInputStream(virusException.toByteArray())
val xmlParser = XMLExceptionParser(inputStream)
Assert.assertTrue(xmlParser.isInvalidCharacterException)
Assert.assertFalse(xmlParser.isVirusException)
}
@Test
fun testInvalidCharacterUploadException() {
val virusException =
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
"<d:error xmlns:d=\"DAV:\" xmlns:s=\"http://sabredav.org/ns\">\n" +
" <s:exception>OCP\\Files\\InvalidPathException</s:exception>\n" +
" <s:message>Wrong Path</s:message>\n" +
"</d:error>"
val inputStream = ByteArrayInputStream(virusException.toByteArray())
val xmlParser = XMLExceptionParser(inputStream)
Assert.assertTrue(xmlParser.isInvalidCharacterException)
Assert.assertFalse(xmlParser.isVirusException)
}
@Test
fun testEmptyString() {
val emptyString = ""
val inputStream = ByteArrayInputStream(emptyString.toByteArray())
val xmlParser = XMLExceptionParser(inputStream)
Assert.assertFalse(xmlParser.isVirusException)
Assert.assertFalse(xmlParser.isInvalidCharacterException)
}
}