Skip to content

Commit

Permalink
KEYCLOAK-7977 Release failing due the NPE during swagger2markup-maven…
Browse files Browse the repository at this point in the history
…-plugin execution
  • Loading branch information
mposolda committed Jul 31, 2018
1 parent f32e258 commit a2afe7c
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ public void setDisplayName(String displayName) {
}

@Deprecated
@JsonSetter("uri")
public void setUri(String uri) {
if (uri != null && !"".equalsIgnoreCase(uri.trim())) {
this.uris = Collections.singleton(uri);
Expand All @@ -201,15 +202,6 @@ public void setUris(Set<String> uris) {
}
}

@JsonProperty("uri")
public void addUri(String uri) {
if (this.uris == null) {
this.uris = new HashSet<>();
}

uris.add(uri);
}

public void setType(String type) {
if (type != null && !"".equalsIgnoreCase(type.trim())) {
this.type = type;
Expand Down
33 changes: 33 additions & 0 deletions core/src/test/java/org/keycloak/JsonParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@
import org.keycloak.representations.IDToken;
import org.keycloak.representations.JsonWebToken;
import org.keycloak.representations.adapters.config.AdapterConfig;
import org.keycloak.representations.idm.authorization.ResourceRepresentation;
import org.keycloak.representations.oidc.OIDCClientRepresentation;
import org.keycloak.util.JsonSerialization;

import java.io.IOException;
import java.io.InputStream;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
Expand Down Expand Up @@ -153,4 +155,35 @@ public void testReadOIDCClientRepWithJWKS() throws IOException {
Assert.assertNotNull(clientRep.getJwks());
}


@Test
public void testResourceRepresentationParsing() throws Exception {
Map<String, Object> resource = parseResourceRepresentation("{ \"_id\": \"123\", \"name\": \"foo\" }");
Assert.assertFalse(resource.containsKey("uri"));
Assert.assertFalse(resource.containsKey("uris"));

resource = parseResourceRepresentation("{ \"_id\": \"123\", \"name\": \"foo\", \"uris\": [ \"uri1\", \"uri2\" ] }");
Assert.assertFalse(resource.containsKey("uri"));
Assert.assertTrue(resource.containsKey("uris"));
Collection<String> uris = (Collection) resource.get("uris");
Assert.assertEquals(2, uris.size());
Assert.assertTrue(uris.contains("uri1"));
Assert.assertTrue(uris.contains("uri2"));

// Backwards compatibility (using old property "uri")
resource = parseResourceRepresentation("{ \"_id\": \"123\", \"name\": \"foo\", \"uri\": \"uri1\" }");
Assert.assertFalse(resource.containsKey("uri"));
Assert.assertTrue(resource.containsKey("uris"));
uris = (Collection) resource.get("uris");
Assert.assertEquals(1, uris.size());
Assert.assertTrue(uris.contains("uri1"));
}

private Map<String, Object> parseResourceRepresentation(String resourceJson) throws Exception {
ResourceRepresentation rep = JsonSerialization.readValue(resourceJson, ResourceRepresentation.class);
String repp = JsonSerialization.writeValueAsString(rep);
return JsonSerialization.readValue(repp, Map.class);
}


}
2 changes: 2 additions & 0 deletions travis-run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ fi

if [ $1 == "unit" ]; then
mvn -B test -DskipTestsuite
# Generate documentation to catch potential issues earlier than during the release
mvn test -B -nsu -f services -Pjboss-release
fi

if [ $1 == "server-group1" ]; then
Expand Down

0 comments on commit a2afe7c

Please sign in to comment.