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