Skip to content

Commit

Permalink
Merge pull request #17753 from ChinthakaJ98/is-metadata-test-fix
Browse files Browse the repository at this point in the history
Fixing integration test failure
  • Loading branch information
janakamarasena authored Nov 13, 2023
2 parents 8221030 + a58519e commit 8d7c0da
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@

import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
Expand Down Expand Up @@ -142,32 +141,22 @@ public void testGetAllInboundProtocols() throws IOException {
"Response of the get all inbound protocols doesn't match.");
}

/* This test is being temporarily commented out because the order of the elements change in the json
response payload which fails the test. But this has been manually verified. */
// @Test
// public void testGetOIDCMetadata() throws IOException {

// Response response = getResponseOfGet(METADATA_API_BASE_PATH +
// PATH_SEPARATOR + INBOUND_PROTOCOLS_PATH +
// PATH_SEPARATOR + OIDC_PATH);
// response.then()
// .log()
// .ifValidationFails()
// .assertThat()
// .statusCode(HttpStatus.SC_OK);
// ObjectMapper jsonWriter = new ObjectMapper(new JsonFactory());
// OIDCMetaData responseFound = jsonWriter.readValue(response.asString(), OIDCMetaData.class);
// Assert.assertEquals(sortScopeValidators(responseFound).toString(), oidcMetaData.toString(),
// "OIDC Metadata returned from the API doesn't match.");
// }

private OIDCMetaData sortScopeValidators(OIDCMetaData oidcMetaData) {

List<String> scopeValidators = oidcMetaData.getScopeValidators().getOptions();
Collections.sort(scopeValidators);
oidcMetaData.getScopeValidators().setOptions(scopeValidators);
return oidcMetaData;
}
@Test
public void testGetOIDCMetadata() throws IOException {

Response response = getResponseOfGet(METADATA_API_BASE_PATH +
PATH_SEPARATOR + INBOUND_PROTOCOLS_PATH +
PATH_SEPARATOR + OIDC_PATH);
response.then()
.log()
.ifValidationFails()
.assertThat()
.statusCode(HttpStatus.SC_OK);
ObjectMapper jsonWriter = new ObjectMapper(new JsonFactory());
OIDCMetaData responseFound = jsonWriter.readValue(response.asString(), OIDCMetaData.class);
Assert.assertEquals(responseFound.toString(), oidcMetaData.toString(),
"OIDC Metadata returned from the API doesn't match.");
}

@Test
public void testGetSAMLMetadata() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModelProperty;

import java.util.Collections;
import java.util.Comparator;
import java.util.Objects;
import javax.validation.Valid;

Expand Down Expand Up @@ -395,8 +397,8 @@ public boolean equals(java.lang.Object o) {
Objects.equals(this.tokenEndpointSignatureAlgorithm, oiDCMetaData.requestObjectSignatureAlgorithm) &&
Objects.equals(this.tokenEndpointSignatureAlgorithm, oiDCMetaData.requestObjectEncryptionAlgorithm) &&
Objects.equals(this.tokenEndpointSignatureAlgorithm, oiDCMetaData.requestObjectEncryptionMethod) &&
Objects.equals(this.subjectType, oiDCMetaData.subjectType) &&
Objects.equals(this.fapiMetadata, oiDCMetaData.fapiMetadata);
Objects.equals(this.subjectType, oiDCMetaData.subjectType) &&
Objects.equals(this.fapiMetadata, oiDCMetaData.fapiMetadata);
}

@Override
Expand All @@ -412,6 +414,7 @@ public int hashCode() {
@Override
public String toString() {

sort();
StringBuilder sb = new StringBuilder();
sb.append("class OIDCMetaData {\n");

Expand All @@ -432,6 +435,7 @@ public String toString() {
sb.append(" requestObjectEncryptionAlgorithm: ").append(toIndentedString(requestObjectEncryptionAlgorithm)).append("\n");
sb.append(" requestObjectEncryptionMethod: ").append(toIndentedString(requestObjectEncryptionMethod)).append("\n");
sb.append(" subjectType: ").append(toIndentedString(subjectType)).append("\n");
sb.append(" fapiMetadata: ").append(toIndentedString(fapiMetadata)).append("\n");
sb.append("}");
return sb.toString();
}
Expand All @@ -447,4 +451,27 @@ private String toIndentedString(java.lang.Object o) {
}
return o.toString().replace("\n", "\n");
}

private void sort() {

Comparator<ClientAuthenticationMethod> authMethodByName = Comparator
.comparing(ClientAuthenticationMethod::getName);
Comparator<GrantType> grantByName = Comparator.comparing(GrantType::getName);
allowedGrantTypes.getOptions().sort(grantByName);
tokenEndpointAuthMethod.getOptions().sort(authMethodByName);
fapiMetadata.getTokenEndpointAuthMethod().getOptions().sort(authMethodByName);
Collections.sort(idTokenEncryptionAlgorithm.getOptions());
Collections.sort(idTokenEncryptionMethod.getOptions());
Collections.sort(scopeValidators.getOptions());
Collections.sort(accessTokenType.getOptions());
Collections.sort(accessTokenBindingType.getOptions());
Collections.sort(tokenEndpointSignatureAlgorithm.getOptions());
Collections.sort(idTokenSignatureAlgorithm.getOptions());
Collections.sort(requestObjectSignatureAlgorithm.getOptions());
Collections.sort(requestObjectEncryptionAlgorithm.getOptions());
Collections.sort(requestObjectEncryptionMethod.getOptions());
Collections.sort(subjectType.getOptions());
Collections.sort(fapiMetadata.getAllowedSignatureAlgorithms().getOptions());
Collections.sort(fapiMetadata.getAllowedEncryptionAlgorithms().getOptions());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@
"None",
"cookie",
"sso-session",
"device-flow"
"device-flow",
"certificate"
],
"defaultValue": "None"
},
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2435,7 +2435,7 @@
<!-- Identity REST API feature -->
<identity.api.dispatcher.version>2.0.13</identity.api.dispatcher.version>
<identity.user.api.version>1.3.25</identity.user.api.version>
<identity.server.api.version>1.2.118</identity.server.api.version>
<identity.server.api.version>1.2.119</identity.server.api.version>

<identity.agent.sso.version>5.5.9</identity.agent.sso.version>
<identity.tool.samlsso.validator.version>5.5.7</identity.tool.samlsso.validator.version>
Expand Down

0 comments on commit 8d7c0da

Please sign in to comment.