Author: markt
Date: Wed May 30 10:07:30 2018
New Revision: 1832527
URL: http://svn.apache.org/viewvc?rev=1832527&view=rev
Log:
Improve code coverage
Modified:
tomcat/trunk/test/org/apache/tomcat/util/http/parser/TestAuthorizationDigest.java
tomcat/trunk/test/org/apache/tomcat/util/http/parser/TestHttpParser.java
tomcat/trunk/test/org/apache/tomcat/util/http/parser/TestMediaType.java
Modified:
tomcat/trunk/test/org/apache/tomcat/util/http/parser/TestAuthorizationDigest.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/tomcat/util/http/parser/TestAuthorizationDigest.java?rev=1832527&r1=1832526&r2=1832527&view=diff
==============================================================================
---
tomcat/trunk/test/org/apache/tomcat/util/http/parser/TestAuthorizationDigest.java
(original)
+++
tomcat/trunk/test/org/apache/tomcat/util/http/parser/TestAuthorizationDigest.java
Wed May 30 10:07:30 2018
@@ -219,6 +219,16 @@ public class TestAuthorizationDigest {
}
@Test
+ public void testEmptyQop() throws Exception {
+ String header = "Digest qop=";
+
+ StringReader input = new StringReader(header);
+
+ Map<String,String> result =
Authorization.parseAuthorizationDigest(input);
+ Assert.assertNull(result);
+ }
+
+ @Test
public void testNonTokenQop() throws Exception {
String header = "Digest qop=au{th";
@@ -333,6 +343,28 @@ public class TestAuthorizationDigest {
}
@Test
+ public void testParseAuthParamBEscaped() throws Exception {
+ // Test for HttpParser.readTokenOrQuotedString()
+ // auth-param = token "=" ( token | quoted-string )
+ String header = "Digest a=\"b\\\"b\"";
+
+ StringReader input = new StringReader(header);
+
+ Map<String,String> result =
Authorization.parseAuthorizationDigest(input);
+ Assert.assertEquals("b\"b", result.get("a"));
+ }
+
+ @Test
+ public void testQuotedStringNoQuotes() throws Exception {
+ String header = "Digest username=a";
+
+ StringReader input = new StringReader(header);
+
+ Map<String,String> result =
Authorization.parseAuthorizationDigest(input);
+ Assert.assertNull(result);
+ }
+
+ @Test
public void testNotDigest() throws Exception {
String header = "SomethingElse a=b";
@@ -341,4 +373,6 @@ public class TestAuthorizationDigest {
Map<String,String> result =
Authorization.parseAuthorizationDigest(input);
Assert.assertNull(result);
}
+
+
}
Modified:
tomcat/trunk/test/org/apache/tomcat/util/http/parser/TestHttpParser.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/tomcat/util/http/parser/TestHttpParser.java?rev=1832527&r1=1832526&r2=1832527&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/tomcat/util/http/parser/TestHttpParser.java
(original)
+++ tomcat/trunk/test/org/apache/tomcat/util/http/parser/TestHttpParser.java
Wed May 30 10:07:30 2018
@@ -25,4 +25,121 @@ public class TestHttpParser {
public void testTokenDel() {
Assert.assertFalse("DEL is not a token", HttpParser.isToken(127));
}
+
+
+ @Test
+ public void testAbsolutePathRelaxedLargeInvalid() {
+ HttpParser httpParser = new HttpParser(null, null);
+
Assert.assertFalse(httpParser.isAbsolutePathRelaxed(Integer.MAX_VALUE));
+ }
+
+
+ @Test
+ public void testAbsolutePathRelaxed01() {
+ HttpParser httpParser = new HttpParser(null, null);
+ Assert.assertFalse(httpParser.isAbsolutePathRelaxed('{'));
+ }
+
+
+ @Test
+ public void testAbsolutePathRelaxed02() {
+ HttpParser httpParser = new HttpParser("{", null);
+ Assert.assertTrue(httpParser.isAbsolutePathRelaxed('{'));
+ }
+
+
+ @Test
+ public void testAbsolutePathRelaxed03() {
+ HttpParser httpParser = new HttpParser(null, "{");
+ Assert.assertFalse(httpParser.isAbsolutePathRelaxed('{'));
+ }
+
+
+ @Test
+ public void testAbsolutePathRelaxed04() {
+ HttpParser httpParser = new HttpParser("\u1000", null);
+ Assert.assertFalse(httpParser.isAbsolutePathRelaxed('{'));
+ }
+
+
+ @Test
+ public void testAbsolutePathRelaxed05() {
+ HttpParser httpParser = new HttpParser("", null);
+ Assert.assertFalse(httpParser.isAbsolutePathRelaxed('{'));
+ }
+
+
+ @Test
+ public void testQueryRelaxedLargeInvalid() {
+ HttpParser httpParser = new HttpParser(null, null);
+ Assert.assertFalse(httpParser.isQueryRelaxed(Integer.MAX_VALUE));
+ }
+
+
+ @Test
+ public void testRequestTargetLargeInvalid() {
+ Assert.assertTrue(HttpParser.isNotRequestTarget(Integer.MAX_VALUE));
+ }
+
+
+ @Test
+ public void testHttpProtocolLargeInvalid() {
+ Assert.assertFalse(HttpParser.isHttpProtocol(Integer.MAX_VALUE));
+ }
+
+
+ @Test
+ public void testUserInfoLargeInvalid() {
+ Assert.assertFalse(HttpParser.isUserInfo(Integer.MAX_VALUE));
+ }
+
+
+ @Test
+ public void testAbsolutePathLargeInvalid() {
+ Assert.assertFalse(HttpParser.isAbsolutePath(Integer.MAX_VALUE));
+ }
+
+
+ @Test
+ public void testQueryLargeInvalid() {
+ Assert.assertFalse(HttpParser.isQuery(Integer.MAX_VALUE));
+ }
+
+
+ @Test
+ public void testUnquoteNull() {
+ Assert.assertNull(HttpParser.unquote(null));
+ }
+
+
+ @Test
+ public void testUnquoteShort() {
+ String shortText = "a";
+ Assert.assertEquals(shortText, HttpParser.unquote(shortText));
+ }
+
+
+ @Test
+ public void testUnquoteUnquoted() {
+ String shortText = "abcde";
+ Assert.assertEquals(shortText, HttpParser.unquote(shortText));
+ }
+
+
+ @Test
+ public void testUnquoteEscaped() {
+ // Note: Test string is also Java escaped
+ String shortText = "\"ab\\\"ab\"";
+ String result = "ab\"ab";
+ Assert.assertEquals(result, HttpParser.unquote(shortText));
+ }
+
+
+ @Test
+ public void testUnquoteUnquotedEscaped() {
+ // Note: Test string is also Java escaped
+ String shortText = "ab\\\"ab";
+ String result = "ab\"ab";
+ Assert.assertEquals(result, HttpParser.unquote(shortText));
+ }
}
Modified:
tomcat/trunk/test/org/apache/tomcat/util/http/parser/TestMediaType.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/tomcat/util/http/parser/TestMediaType.java?rev=1832527&r1=1832526&r2=1832527&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/tomcat/util/http/parser/TestMediaType.java
(original)
+++ tomcat/trunk/test/org/apache/tomcat/util/http/parser/TestMediaType.java Wed
May 30 10:07:30 2018
@@ -36,6 +36,8 @@ public class TestMediaType {
private static final Parameter PARAM_TOKEN =
new Parameter("a", "b");
+ private static final Parameter PARAM_ESCAPED =
+ new Parameter("v", "\"w\\\"w\"");
private static final Parameter PARAM_QUOTED =
new Parameter("x", "\"y\"");
private static final Parameter PARAM_EMPTY_QUOTED =
@@ -75,6 +77,12 @@ public class TestMediaType {
}
+ @Test
+ public void testSimpleWithEscapedString() throws IOException {
+ doTest(PARAM_ESCAPED);
+ }
+
+
@Test
public void testSimpleWithQuotedString() throws IOException {
doTest(PARAM_QUOTED);
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]