Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ELY-2797] check for null Boolean and return boolean #2187

Conversation

rsearls
Copy link
Contributor

@rsearls rsearls commented Aug 26, 2024

https://issues.redhat.com/browse/ELY-2797 NullPointerException in
OidcClientConfiguration.resolveUrls if parameter "request_parameter_supported"
is not present in openid-configuration

* Test OIDC json config class properly returns boolean values.
*/
public class OidcProviderMetadataTest {
private OidcProviderMetadata oidcSecRealm;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just minor, but since this represents the provider metadata, I think oidcProviderMetadata would be better than oidcSecRealm.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


@Test
public void testClaimsParameterSupported() throws Exception {
assertFalse(oidcSecRealm.getClaimsParameterSupported());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The OIDC provider metadata gets created by sending a request to the OIDC provider's /.well-known endpoint and then using JsonSerialization#readValue (as seen here https://github.com/wildfly-security/wildfly-elytron/blob/2.x/http/oidc/src/main/java/org/wildfly/security/http/oidc/OidcClientConfiguration.java#L273) to parse what we get back from the well-known endpoint into the OidcProviderMetadata object.

I'm wondering if we can update these tests to make use of JsonSerialization#readValue to more closely mimic what happens in the code.

To do that, I'm wondering if we can call JsonSerialization#readValue directly with a string value for the metadata and that way we can control what options are specified/not specified in our string.

To get a sample string value to work with, you could try setting up a Keycloak OpenID provider locally (following the steps from one of the OIDC blog posts), try to hit the well-known endpoint, e.g., http://localhost:<KEYCLOAK_PORT>/realms/myrealm/.well-known/openid-configuration to get sample OIDC provider metadata.

We can then create hardcoded provider metadata strings to be used for these tests to test the case where these boolean options are present and not present.

Does that make sense?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@rsearls rsearls force-pushed the ELY-2797-NullPointerException-request_parameter_supported branch from 3c56fcc to fbbdf77 Compare August 26, 2024 21:33
@@ -0,0 +1,330 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright 2020 Red Hat, Inc., and individual contributors
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2024 :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -330,7 +330,7 @@ public void setClaimTypesSupported(List<String> claimTypesSupported) {
}

public Boolean getClaimsParameterSupported() {
Copy link
Contributor

@fjuma fjuma Aug 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since OidcProviderMetadata is currently private API, let's go ahead and change the return values from Boolean to boolean as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@rsearls rsearls force-pushed the ELY-2797-NullPointerException-request_parameter_supported branch from fbbdf77 to 8362c43 Compare August 27, 2024 17:56
@Test
public void testIssuer() throws Exception {
assertTrue("http://localhost:8080/realms/myrealm".equals(oidcProviderMetadata.getIssuer()));
assertNull(emptyOidcProviderMetadata.getIssuer());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to add an assertion here for withoutBooleansProviderMetaData? That way, we are testing the expected values for all three cases (control data, empty, control data modified to leave out some options) in each test case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

",\"id_token_encryption_alg_values_supported\":[\"RSA-OAEP\",\"RSA-OAEP-256\",\"RSA1_5\"]\n" +
",\"id_token_encryption_enc_values_supported\":[\"A256GCM\"]\n" +
",\"userinfo_signing_alg_values_supported\":[\"PS384\",\"none\"]\n" +
",\"request_object_signing_alg_values_supported\":[\"PS384\",\"none\"]\n" +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's also remove the other options that were introduced in ELY-2584 since it's also optional for the provider to include these in the metadata:

  • request_object_signing_alg_values_supported
  • request_object_encryption_enc_values_supported
  • request_object_encryption_alg_values_supported
  • pushed_authorization_request_endpoint

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@rsearls rsearls force-pushed the ELY-2797-NullPointerException-request_parameter_supported branch from 8362c43 to b4f6712 Compare August 27, 2024 18:47
public void testRequestObjectEncryptionAlgValuesSupported() throws Exception {
List<String> l = oidcProviderMetadata.getRequestObjectEncryptionAlgValuesSupported();
assertTrue(l.contains("RSA1_5"));
assertNull(emptyOidcProviderMetadata.getRequestObjectEncryptionAlgValuesSupported());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this needs an assertNull for withoutBooleansProviderMetaData.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

public void testRequestObjectEncryptionEncValuesSupported() throws Exception {
List<String> l = oidcProviderMetadata.getRequestObjectEncryptionEncValuesSupported();
assertTrue(l.contains("A192GCM"));
assertNull(emptyOidcProviderMetadata.getRequestObjectEncryptionEncValuesSupported());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this needs an assertNull for withoutBooleansProviderMetaData.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@Test
public void testPushedAuthorizationRequestEndpoint() throws Exception {
assertTrue("http://localhost:8080/realms/myrealm/protocol/openid-connect/ext/par/request".equals(oidcProviderMetadata.getPushedAuthorizationRequestEndpoint()));
assertNull(emptyOidcProviderMetadata.getPushedAuthorizationRequestEndpoint());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this needs an assertNull for withoutBooleansProviderMetaData.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

public void testRequestObjectSigningAlgValuesSupported() throws Exception {
List<String> l = oidcProviderMetadata.getRequestObjectSigningAlgValuesSupported();
assertTrue(l.contains("RS384"));
assertNull(emptyOidcProviderMetadata.getRequestObjectSigningAlgValuesSupported());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this needs an assertNull for withoutBooleansProviderMetaData.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

public class OidcProviderMetadataTest {
private static OidcProviderMetadata oidcProviderMetadata;
private static OidcProviderMetadata emptyOidcProviderMetadata;
private static OidcProviderMetadata withoutBooleansOidcProviderMetadata;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe just to make it more clear, we could rename withoutBooleansOidcProviderMetatdata withoutOptionalsOidcProviderMetadata (since some of the values that are optional aren't booleans).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@rsearls rsearls force-pushed the ELY-2797-NullPointerException-request_parameter_supported branch from b4f6712 to 882fae7 Compare August 27, 2024 19:34
Copy link
Contributor

@fjuma fjuma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks very much @rsearls!

@fjuma fjuma requested a review from darranl August 27, 2024 19:45
@fjuma fjuma merged commit d78b28d into wildfly-security:2.x Aug 28, 2024
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants