public RemoteOperationResult(boolean success, String bodyResponse, int httpCode) { mSuccess = success; mHttpCode = httpCode; if (success) { mCode = ResultCode.OK; } else if (httpCode > 0) { switch (httpCode) { case HttpStatus.SC_BAD_REQUEST: try { InputStream is = new ByteArrayInputStream(bodyResponse.getBytes()); ExceptionParser xmlParser = new ExceptionParser(is); if (xmlParser.isInvalidCharacterException()) { mCode = ResultCode.INVALID_CHARACTER_DETECT_IN_SERVER; } } catch (Exception e) { mCode = ResultCode.UNHANDLED_HTTP_CODE; Log_OC.e(TAG, "Exception reading exception from server", e); } break; default: mCode = ResultCode.UNHANDLED_HTTP_CODE; Log_OC.d(TAG, "RemoteOperationResult has processed UNHANDLED_HTTP_CODE: " + httpCode); } } }
ExceptionParser xmlParser = new ExceptionParser(is); if (xmlParser.isInvalidCharacterException()) { mCode = ResultCode.INVALID_CHARACTER_DETECT_IN_SERVER;
@Test public void testEmptyString() throws IOException, XmlPullParserException { String emptyString = ""; InputStream is = new ByteArrayInputStream(emptyString.getBytes()); ExceptionParser xmlParser = new ExceptionParser(is); Assert.assertFalse(xmlParser.isVirusException()); Assert.assertFalse(xmlParser.isInvalidCharacterException()); }
@Test public void testString() throws IOException, XmlPullParserException { String emptyString = ""; InputStream is = new ByteArrayInputStream(emptyString.getBytes()); ExceptionParser xmlParser = new ExceptionParser(is); Assert.assertFalse(xmlParser.isVirusException()); Assert.assertFalse(xmlParser.isInvalidCharacterException()); } }
@Test public void testInvalidCharacterUploadException() throws IOException, XmlPullParserException { String 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>"; InputStream is = new ByteArrayInputStream(virusException.getBytes()); ExceptionParser xmlParser = new ExceptionParser(is); Assert.assertTrue(xmlParser.isInvalidCharacterException()); Assert.assertFalse(xmlParser.isVirusException()); }
@Test public void testInvalidCharacterException() throws IOException, XmlPullParserException { String 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>"; InputStream is = new ByteArrayInputStream(virusException.getBytes()); ExceptionParser xmlParser = new ExceptionParser(is); Assert.assertTrue(xmlParser.isInvalidCharacterException()); Assert.assertFalse(xmlParser.isVirusException()); }
@Test public void testVirusException() throws IOException, XmlPullParserException { String 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>"; InputStream is = new ByteArrayInputStream(virusException.getBytes()); ExceptionParser xmlParser = new ExceptionParser(is); Assert.assertTrue(xmlParser.isVirusException()); Assert.assertFalse(xmlParser.isInvalidCharacterException()); }