rishabhdaim commented on code in PR #2983:
URL: https://github.com/apache/jackrabbit-oak/pull/2983#discussion_r3498948935
##########
oak-http/src/test/java/org/apache/jackrabbit/oak/http/AuthorizationFieldTest.java:
##########
@@ -64,9 +64,71 @@ public void testNoScheme() throws LoginException {
@Test
public void testColonInPassword() throws LoginException {
String b64 = "Basic " +
Base64.getEncoder().encodeToString("foo:bar:qux".getBytes(StandardCharsets.UTF_8));
- SimpleCredentials credentials
=AuthorizationField.valueOf(Collections.enumeration(List.of(b64)));
+ SimpleCredentials credentials =
AuthorizationField.valueOf(Collections.enumeration(List.of(b64)));
+ assertEquals("foo", credentials.getUserID());
+ assertEquals("bar:qux", new String(credentials.getPassword()));
+ }
+
+ @Test(expected = LoginException.class)
+ public void testMissingColon() throws LoginException {
+ String b64 = "Basic " +
Base64.getEncoder().encodeToString("foobarqux".getBytes(StandardCharsets.UTF_8));
+ AuthorizationField.valueOf(Collections.enumeration(List.of(b64)));
+ }
+
+ @Test
+ public void testSchemeCase() throws LoginException {
+ String b64 =
Base64.getEncoder().encodeToString("foo:bar".getBytes(StandardCharsets.UTF_8));
+ SimpleCredentials credentials =
AuthorizationField.valueOf(Collections.enumeration(List.of("BaSiC " + b64)));
+ assertEquals("foo", credentials.getUserID());
+ assertEquals("bar", new String(credentials.getPassword()));
+ }
+
+ @Test
+ public void testMoreWhitespace() throws LoginException {
+ String b64 =
Base64.getEncoder().encodeToString("foo:bar".getBytes(StandardCharsets.UTF_8));
+ SimpleCredentials credentials =
AuthorizationField.valueOf(Collections.enumeration(List.of("Basic " + b64)));
+ assertEquals("foo", credentials.getUserID());
+ assertEquals("bar", new String(credentials.getPassword()));
+ }
+
+ @Test(expected = LoginException.class)
+ public void testNonSpWhitespace() throws LoginException {
+ String b64 =
Base64.getEncoder().encodeToString("foo:bar".getBytes(StandardCharsets.UTF_8));
+ SimpleCredentials credentials =
AuthorizationField.valueOf(Collections.enumeration(List.of("Basic \t " + b64)));
+ assertEquals("foo", credentials.getUserID());
+ assertEquals("bar", new String(credentials.getPassword()));
+ }
+
+ @Test(expected = LoginException.class)
+ public void testBrokenBase64() throws LoginException {
+ String b64 =
Base64.getEncoder().encodeToString("foo:bar".getBytes(StandardCharsets.UTF_8));
+ // insert a single SP into the base64 sequence
+ b64 = b64.substring(0,5) + " " + b64.substring(5);
+ AuthorizationField.valueOf(Collections.enumeration(List.of("Basic " +
b64)));
+ }
+
+ @Test(expected = LoginException.class)
+ public void testMoreBrokenBase64() throws LoginException {
+ String b64 =
Base64.getEncoder().encodeToString("foo:bar".getBytes(StandardCharsets.UTF_8));
+ b64 = b64.substring(0,5) + "=" + b64.substring(5);
+ SimpleCredentials credentials =
AuthorizationField.valueOf(Collections.enumeration(List.of("Basic " + b64)));
+ assertEquals("foo", credentials.getUserID());
+ assertEquals("bar", new String(credentials.getPassword()));
+ }
+
+ @Test
+ public void testMoreNonAscii() throws LoginException {
+ String b64 =
Base64.getEncoder().encodeToString("test:123\u00a3".getBytes(StandardCharsets.UTF_8));
+ SimpleCredentials credentials =
AuthorizationField.valueOf(Collections.enumeration(List.of("Basic " + b64)));
+ assertEquals("test", credentials.getUserID());
+ assertEquals("123\u00a3", new String(credentials.getPassword()));
+ }
+
+ @Test
+ public void Basic64NoPadding() throws LoginException {
Review Comment:
```suggestion
public void testBasic64NoPadding() throws LoginException {
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]