8000 Add core unit tests for utility edge cases by cr7yash · Pull Request #49327 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@ public void nullValueArray() throws IOException {
assertNull(foo.get(2));
}

@Test
public void nonStringValues() throws IOException {
Map<String, List<String>> attributes = deserialize("\"enabled\": true, \"count\": 5");

assertEquals("true", attributes.get("enabled").get(0));
assertEquals("5", attributes.get("count").get(0));
}

private Map<String, List<String>> deserialize(String attributeKeyValueString) throws IOException {
TestObject testObject = mapper.readValue("{ \"attributes\": {" + attributeKeyValueString + " } }", TestObject.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,13 @@ public void testSetAddressMethodWorks() {
Assert.assertEquals(addressClaimSet.getRegion(), addressClaimsSet.get("region"));
Assert.assertEquals(addressClaimSet.getPostalCode(), addressClaimsSet.get("postal_code"));
}

@Test
@SuppressWarnings("deprecation")
public void testSessionStateUsesSessionId() {
IDToken idToken = new IDToken();
idToken.setSessionId("session-123");

Assert.assertEquals("session-123", idToken.getSessionState());
}
}
11 changes: 11 additions & 0 deletions core/src/test/java/org/keycloak/util/BasicAuthHelperTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@ public void parseHeader() {
assertArrayEquals(new String[] {username, password}, actual);
}

@Test
public void parseHeaderWithColonInPassword() {
String username = "client";
String password = "secret:with:colons";

String header = BasicAuthHelper.createHeader(username, password);
String[] actual = BasicAuthHelper.parseHeader(header);

assertArrayEquals(new String[] {username, password}, actual);
}

@Test
public void rfc6749_createHeader() {
String username = "user";
Expand Down
9 changes: 9 additions & 0 deletions core/src/test/java/org/keycloak/util/UriUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.Arrays;

import org.keycloak.common.util.MultivaluedHashMap;
import org.keycloak.common.util.MultivaluedMap;
import org.keycloak.common.util.UriUtils;

import org.junit.Test;
Expand Down Expand Up @@ -144,6 +145,14 @@ public void testStripQueryParam(){
assertEquals("http://localhost?pre=test&param=test",UriUtils.stripQueryParam("http://localhost?pre=test&login_hint=michael@me.com&param=test","login_hint"));
}

@Test
public void testDecodeQueryString() {
MultivaluedMap<String, String> actual = UriUtils.decodeQueryString("first%20name=Jane+Doe&empty=");

assertEquals("Jane Doe", actual.getFirst("first name"));
assertEquals("", actual.getFirst("empty"));
}

@Test
public void testParseQueryParametersDecodesNamesOnly() {
MultivaluedHashMap<String, String> params = UriUtils.parseQueryParameters(
Expand Down
0