diff --git a/openid-connect-common/src/test/java/org/mitre/oauth2/model/ClientDetailsEntityTest.java b/openid-connect-common/src/test/java/org/mitre/oauth2/model/ClientDetailsEntityTest.java new file mode 100644 index 000000000..122a2ad58 --- /dev/null +++ b/openid-connect-common/src/test/java/org/mitre/oauth2/model/ClientDetailsEntityTest.java @@ -0,0 +1,69 @@ +/** + * + */ +package org.mitre.oauth2.model; + +import java.util.Date; + +import org.junit.Test; +import org.mitre.jose.JWEAlgorithmEmbed; +import org.mitre.jose.JWEEncryptionMethodEmbed; + +import com.google.common.collect.ImmutableSet; +import com.nimbusds.jose.EncryptionMethod; +import com.nimbusds.jose.JWEAlgorithm; + +import static org.junit.Assert.*; + +/** + * @author jricher + * + */ +public class ClientDetailsEntityTest { + + /** + * Test method for {@link org.mitre.oauth2.model.ClientDetailsEntity#ClientDetailsEntity()}. + */ + @Test + public void testClientDetailsEntity() { + Date now = new Date(); + + ClientDetailsEntity c = new ClientDetailsEntity(); + + c.setClientId("s6BhdRkqt3"); + c.setClientSecret("ZJYCqe3GGRvdrudKyZS0XhGv_Z45DuKhCUk0gBR1vZk"); + c.setApplicationType(ClientDetailsEntity.AppType.WEB); + c.setRedirectUris(ImmutableSet.of("https://client.example.org/callback", "https://client.example.org/callback2")); + c.setClientName("My Example"); + c.setLogoUri("https://client.example.org/logo.png"); + c.setSubjectType(ClientDetailsEntity.SubjectType.PAIRWISE); + c.setSectorIdentifierUri("https://other.example.net/file_of_redirect_uris.json"); + c.setTokenEndpointAuthMethod(ClientDetailsEntity.AuthMethod.SECRET_BASIC); + c.setJwksUri("https://client.example.org/my_public_keys.jwks"); + c.setUserInfoEncryptedResponseAlg(new JWEAlgorithmEmbed(JWEAlgorithm.RSA1_5)); + c.setUserInfoEncryptedResponseEnc(new JWEEncryptionMethodEmbed(EncryptionMethod.A128CBC_HS256)); + c.setContacts(ImmutableSet.of("ve7jtb@example.org", "mary@example.org")); + c.setRequestUris(ImmutableSet.of("https://client.example.org/rf.txt#qpXaRLh_n93TTR9F252ValdatUQvQiJi5BDub2BeznA")); + c.setCreatedAt(now); + c.setAccessTokenValiditySeconds(600); + + assertEquals("s6BhdRkqt3", c.getClientId()); + assertEquals("ZJYCqe3GGRvdrudKyZS0XhGv_Z45DuKhCUk0gBR1vZk", c.getClientSecret()); + assertEquals(ClientDetailsEntity.AppType.WEB, c.getApplicationType()); + assertEquals(ImmutableSet.of("https://client.example.org/callback", "https://client.example.org/callback2"), c.getRedirectUris()); + assertEquals("My Example", c.getClientName()); + assertEquals("https://client.example.org/logo.png", c.getLogoUri()); + assertEquals(ClientDetailsEntity.SubjectType.PAIRWISE, c.getSubjectType()); + assertEquals("https://other.example.net/file_of_redirect_uris.json", c.getSectorIdentifierUri()); + assertEquals(ClientDetailsEntity.AuthMethod.SECRET_BASIC, c.getTokenEndpointAuthMethod()); + assertEquals("https://client.example.org/my_public_keys.jwks", c.getJwksUri()); + assertEquals(JWEAlgorithm.RSA1_5, c.getUserInfoEncryptedResponseAlg().getAlgorithm()); + assertEquals(EncryptionMethod.A128CBC_HS256, c.getUserInfoEncryptedResponseEnc().getAlgorithm()); + assertEquals(ImmutableSet.of("ve7jtb@example.org", "mary@example.org"), c.getContacts()); + assertEquals(ImmutableSet.of("https://client.example.org/rf.txt#qpXaRLh_n93TTR9F252ValdatUQvQiJi5BDub2BeznA"), c.getRequestUris()); + assertEquals(now, c.getCreatedAt()); + assertEquals(600, c.getAccessTokenValiditySeconds().intValue()); + + } + +} diff --git a/openid-connect-common/src/test/java/org/mitre/oauth2/model/RegisteredClientTest.java b/openid-connect-common/src/test/java/org/mitre/oauth2/model/RegisteredClientTest.java new file mode 100644 index 000000000..376e85f6b --- /dev/null +++ b/openid-connect-common/src/test/java/org/mitre/oauth2/model/RegisteredClientTest.java @@ -0,0 +1,156 @@ +/** + * + */ +package org.mitre.oauth2.model; + +import java.sql.Date; + +import org.junit.Test; +import org.mitre.jose.JWEAlgorithmEmbed; +import org.mitre.jose.JWEEncryptionMethodEmbed; + +import com.google.common.collect.ImmutableSet; +import com.nimbusds.jose.EncryptionMethod; +import com.nimbusds.jose.JWEAlgorithm; + +import static org.junit.Assert.*; + +/** + * @author jricher + * + */ +public class RegisteredClientTest { + + /** + * Test method for {@link org.mitre.oauth2.model.RegisteredClient#RegisteredClient()}. + */ + @Test + public void testRegisteredClient() { + RegisteredClient c = new RegisteredClient(); + + c.setClientId("s6BhdRkqt3"); + c.setClientSecret("ZJYCqe3GGRvdrudKyZS0XhGv_Z45DuKhCUk0gBR1vZk"); + c.setClientSecretExpiresAt(new Date(1577858400L * 1000L)); + c.setRegistrationAccessToken("this.is.an.access.token.value.ffx83"); + c.setRegistrationClientUri("https://server.example.com/connect/register?client_id=s6BhdRkqt3"); + c.setApplicationType(ClientDetailsEntity.AppType.WEB); + c.setRedirectUris(ImmutableSet.of("https://client.example.org/callback", "https://client.example.org/callback2")); + c.setClientName("My Example"); + c.setLogoUri("https://client.example.org/logo.png"); + c.setSubjectType(ClientDetailsEntity.SubjectType.PAIRWISE); + c.setSectorIdentifierUri("https://other.example.net/file_of_redirect_uris.json"); + c.setTokenEndpointAuthMethod(ClientDetailsEntity.AuthMethod.SECRET_BASIC); + c.setJwksUri("https://client.example.org/my_public_keys.jwks"); + c.setUserInfoEncryptedResponseAlg(new JWEAlgorithmEmbed(JWEAlgorithm.RSA1_5)); + c.setUserInfoEncryptedResponseEnc(new JWEEncryptionMethodEmbed(EncryptionMethod.A128CBC_HS256)); + c.setContacts(ImmutableSet.of("ve7jtb@example.org", "mary@example.org")); + c.setRequestUris(ImmutableSet.of("https://client.example.org/rf.txt#qpXaRLh_n93TTR9F252ValdatUQvQiJi5BDub2BeznA")); + + assertEquals("s6BhdRkqt3", c.getClientId()); + assertEquals("ZJYCqe3GGRvdrudKyZS0XhGv_Z45DuKhCUk0gBR1vZk", c.getClientSecret()); + assertEquals(new Date(1577858400L * 1000L), c.getClientSecretExpiresAt()); + assertEquals("this.is.an.access.token.value.ffx83", c.getRegistrationAccessToken()); + assertEquals("https://server.example.com/connect/register?client_id=s6BhdRkqt3", c.getRegistrationClientUri()); + assertEquals(ClientDetailsEntity.AppType.WEB, c.getApplicationType()); + assertEquals(ImmutableSet.of("https://client.example.org/callback", "https://client.example.org/callback2"), c.getRedirectUris()); + assertEquals("My Example", c.getClientName()); + assertEquals("https://client.example.org/logo.png", c.getLogoUri()); + assertEquals(ClientDetailsEntity.SubjectType.PAIRWISE, c.getSubjectType()); + assertEquals("https://other.example.net/file_of_redirect_uris.json", c.getSectorIdentifierUri()); + assertEquals(ClientDetailsEntity.AuthMethod.SECRET_BASIC, c.getTokenEndpointAuthMethod()); + assertEquals("https://client.example.org/my_public_keys.jwks", c.getJwksUri()); + assertEquals(JWEAlgorithm.RSA1_5, c.getUserInfoEncryptedResponseAlg().getAlgorithm()); + assertEquals(EncryptionMethod.A128CBC_HS256, c.getUserInfoEncryptedResponseEnc().getAlgorithm()); + assertEquals(ImmutableSet.of("ve7jtb@example.org", "mary@example.org"), c.getContacts()); + assertEquals(ImmutableSet.of("https://client.example.org/rf.txt#qpXaRLh_n93TTR9F252ValdatUQvQiJi5BDub2BeznA"), c.getRequestUris()); + } + + /** + * Test method for {@link org.mitre.oauth2.model.RegisteredClient#RegisteredClient(org.mitre.oauth2.model.ClientDetailsEntity)}. + */ + @Test + public void testRegisteredClientClientDetailsEntity() { + ClientDetailsEntity c = new ClientDetailsEntity(); + + c.setClientId("s6BhdRkqt3"); + c.setClientSecret("ZJYCqe3GGRvdrudKyZS0XhGv_Z45DuKhCUk0gBR1vZk"); + c.setApplicationType(ClientDetailsEntity.AppType.WEB); + c.setRedirectUris(ImmutableSet.of("https://client.example.org/callback", "https://client.example.org/callback2")); + c.setClientName("My Example"); + c.setLogoUri("https://client.example.org/logo.png"); + c.setSubjectType(ClientDetailsEntity.SubjectType.PAIRWISE); + c.setSectorIdentifierUri("https://other.example.net/file_of_redirect_uris.json"); + c.setTokenEndpointAuthMethod(ClientDetailsEntity.AuthMethod.SECRET_BASIC); + c.setJwksUri("https://client.example.org/my_public_keys.jwks"); + c.setUserInfoEncryptedResponseAlg(new JWEAlgorithmEmbed(JWEAlgorithm.RSA1_5)); + c.setUserInfoEncryptedResponseEnc(new JWEEncryptionMethodEmbed(EncryptionMethod.A128CBC_HS256)); + c.setContacts(ImmutableSet.of("ve7jtb@example.org", "mary@example.org")); + c.setRequestUris(ImmutableSet.of("https://client.example.org/rf.txt#qpXaRLh_n93TTR9F252ValdatUQvQiJi5BDub2BeznA")); + + RegisteredClient rc = new RegisteredClient(c); + rc.setClientSecretExpiresAt(new Date(1577858400L * 1000L)); + rc.setRegistrationAccessToken("this.is.an.access.token.value.ffx83"); + rc.setRegistrationClientUri("https://server.example.com/connect/register?client_id=s6BhdRkqt3"); + + assertEquals("s6BhdRkqt3", rc.getClientId()); + assertEquals("ZJYCqe3GGRvdrudKyZS0XhGv_Z45DuKhCUk0gBR1vZk", rc.getClientSecret()); + assertEquals(new Date(1577858400L * 1000L), rc.getClientSecretExpiresAt()); + assertEquals("this.is.an.access.token.value.ffx83", rc.getRegistrationAccessToken()); + assertEquals("https://server.example.com/connect/register?client_id=s6BhdRkqt3", rc.getRegistrationClientUri()); + assertEquals(ClientDetailsEntity.AppType.WEB, rc.getApplicationType()); + assertEquals(ImmutableSet.of("https://client.example.org/callback", "https://client.example.org/callback2"), rc.getRedirectUris()); + assertEquals("My Example", rc.getClientName()); + assertEquals("https://client.example.org/logo.png", rc.getLogoUri()); + assertEquals(ClientDetailsEntity.SubjectType.PAIRWISE, rc.getSubjectType()); + assertEquals("https://other.example.net/file_of_redirect_uris.json", rc.getSectorIdentifierUri()); + assertEquals(ClientDetailsEntity.AuthMethod.SECRET_BASIC, rc.getTokenEndpointAuthMethod()); + assertEquals("https://client.example.org/my_public_keys.jwks", rc.getJwksUri()); + assertEquals(JWEAlgorithm.RSA1_5, rc.getUserInfoEncryptedResponseAlg().getAlgorithm()); + assertEquals(EncryptionMethod.A128CBC_HS256, rc.getUserInfoEncryptedResponseEnc().getAlgorithm()); + assertEquals(ImmutableSet.of("ve7jtb@example.org", "mary@example.org"), rc.getContacts()); + assertEquals(ImmutableSet.of("https://client.example.org/rf.txt#qpXaRLh_n93TTR9F252ValdatUQvQiJi5BDub2BeznA"), rc.getRequestUris()); + } + + /** + * Test method for {@link org.mitre.oauth2.model.RegisteredClient#RegisteredClient(org.mitre.oauth2.model.ClientDetailsEntity, java.lang.String, java.lang.String)}. + */ + @Test + public void testRegisteredClientClientDetailsEntityStringString() { + ClientDetailsEntity c = new ClientDetailsEntity(); + + c.setClientId("s6BhdRkqt3"); + c.setClientSecret("ZJYCqe3GGRvdrudKyZS0XhGv_Z45DuKhCUk0gBR1vZk"); + c.setApplicationType(ClientDetailsEntity.AppType.WEB); + c.setRedirectUris(ImmutableSet.of("https://client.example.org/callback", "https://client.example.org/callback2")); + c.setClientName("My Example"); + c.setLogoUri("https://client.example.org/logo.png"); + c.setSubjectType(ClientDetailsEntity.SubjectType.PAIRWISE); + c.setSectorIdentifierUri("https://other.example.net/file_of_redirect_uris.json"); + c.setTokenEndpointAuthMethod(ClientDetailsEntity.AuthMethod.SECRET_BASIC); + c.setJwksUri("https://client.example.org/my_public_keys.jwks"); + c.setUserInfoEncryptedResponseAlg(new JWEAlgorithmEmbed(JWEAlgorithm.RSA1_5)); + c.setUserInfoEncryptedResponseEnc(new JWEEncryptionMethodEmbed(EncryptionMethod.A128CBC_HS256)); + c.setContacts(ImmutableSet.of("ve7jtb@example.org", "mary@example.org")); + c.setRequestUris(ImmutableSet.of("https://client.example.org/rf.txt#qpXaRLh_n93TTR9F252ValdatUQvQiJi5BDub2BeznA")); + + RegisteredClient rc = new RegisteredClient(c, "this.is.an.access.token.value.ffx83", "https://server.example.com/connect/register?client_id=s6BhdRkqt3"); + + assertEquals("s6BhdRkqt3", rc.getClientId()); + assertEquals("ZJYCqe3GGRvdrudKyZS0XhGv_Z45DuKhCUk0gBR1vZk", rc.getClientSecret()); + assertEquals("this.is.an.access.token.value.ffx83", rc.getRegistrationAccessToken()); + assertEquals("https://server.example.com/connect/register?client_id=s6BhdRkqt3", rc.getRegistrationClientUri()); + assertEquals(ClientDetailsEntity.AppType.WEB, rc.getApplicationType()); + assertEquals(ImmutableSet.of("https://client.example.org/callback", "https://client.example.org/callback2"), rc.getRedirectUris()); + assertEquals("My Example", rc.getClientName()); + assertEquals("https://client.example.org/logo.png", rc.getLogoUri()); + assertEquals(ClientDetailsEntity.SubjectType.PAIRWISE, rc.getSubjectType()); + assertEquals("https://other.example.net/file_of_redirect_uris.json", rc.getSectorIdentifierUri()); + assertEquals(ClientDetailsEntity.AuthMethod.SECRET_BASIC, rc.getTokenEndpointAuthMethod()); + assertEquals("https://client.example.org/my_public_keys.jwks", rc.getJwksUri()); + assertEquals(JWEAlgorithm.RSA1_5, rc.getUserInfoEncryptedResponseAlg().getAlgorithm()); + assertEquals(EncryptionMethod.A128CBC_HS256, rc.getUserInfoEncryptedResponseEnc().getAlgorithm()); + assertEquals(ImmutableSet.of("ve7jtb@example.org", "mary@example.org"), rc.getContacts()); + assertEquals(ImmutableSet.of("https://client.example.org/rf.txt#qpXaRLh_n93TTR9F252ValdatUQvQiJi5BDub2BeznA"), rc.getRequestUris()); + } + +} diff --git a/openid-connect-common/src/test/java/org/mitre/openid/connect/ClientDetailsEntityJsonProcessorTest.java b/openid-connect-common/src/test/java/org/mitre/openid/connect/ClientDetailsEntityJsonProcessorTest.java index d408deb7a..b7c20a533 100644 --- a/openid-connect-common/src/test/java/org/mitre/openid/connect/ClientDetailsEntityJsonProcessorTest.java +++ b/openid-connect-common/src/test/java/org/mitre/openid/connect/ClientDetailsEntityJsonProcessorTest.java @@ -18,7 +18,6 @@ import com.nimbusds.jose.EncryptionMethod; import com.nimbusds.jose.JWEAlgorithm; import static org.junit.Assert.*; -import static org.junit.Assert.assertEquals; /** * @author jricher @@ -77,7 +76,7 @@ public class ClientDetailsEntityJsonProcessorTest { " \"client_id\": \"s6BhdRkqt3\",\n" + " \"client_secret\":\n" + " \"ZJYCqe3GGRvdrudKyZS0XhGv_Z45DuKhCUk0gBR1vZk\",\n" + - " \"expires_at\": 1577858400,\n" + + " \"client_secret_expires_at\": 1577858400,\n" + " \"registration_access_token\":\n" + " \"this.is.an.access.token.value.ffx83\",\n" + " \"registration_client_uri\":\n" + @@ -108,7 +107,7 @@ public class ClientDetailsEntityJsonProcessorTest { assertEquals("s6BhdRkqt3", c.getClientId()); assertEquals("ZJYCqe3GGRvdrudKyZS0XhGv_Z45DuKhCUk0gBR1vZk", c.getClientSecret()); - assertEquals(new Date(1577858400L * 1000L), c.getExpiresAt()); + assertEquals(new Date(1577858400L * 1000L), c.getClientSecretExpiresAt()); assertEquals("this.is.an.access.token.value.ffx83", c.getRegistrationAccessToken()); assertEquals("https://server.example.com/connect/register?client_id=s6BhdRkqt3", c.getRegistrationClientUri()); assertEquals(ClientDetailsEntity.AppType.WEB, c.getApplicationType()); @@ -135,7 +134,7 @@ public class ClientDetailsEntityJsonProcessorTest { c.setClientId("s6BhdRkqt3"); c.setClientSecret("ZJYCqe3GGRvdrudKyZS0XhGv_Z45DuKhCUk0gBR1vZk"); - c.setExpiresAt(new Date(1577858400L * 1000L)); + c.setClientSecretExpiresAt(new Date(1577858400L * 1000L)); c.setRegistrationAccessToken("this.is.an.access.token.value.ffx83"); c.setRegistrationClientUri("https://server.example.com/connect/register?client_id=s6BhdRkqt3"); c.setApplicationType(ClientDetailsEntity.AppType.WEB); @@ -155,7 +154,7 @@ public class ClientDetailsEntityJsonProcessorTest { assertEquals("s6BhdRkqt3", j.get("client_id").getAsString()); assertEquals("ZJYCqe3GGRvdrudKyZS0XhGv_Z45DuKhCUk0gBR1vZk", j.get("client_secret").getAsString()); - assertEquals(1577858400L, j.get("expires_at").getAsNumber()); + assertEquals(1577858400L, j.get("client_secret_expires_at").getAsNumber()); assertEquals("this.is.an.access.token.value.ffx83", j.get("registration_access_token").getAsString()); assertEquals("https://server.example.com/connect/register?client_id=s6BhdRkqt3", j.get("registration_client_uri").getAsString()); assertEquals(ClientDetailsEntity.AppType.WEB.getValue(), j.get("application_type").getAsString());