unit tests for basic data classes

pull/341/merge
Justin Richer 2013-05-29 17:47:04 -04:00
parent cc1da67639
commit 317526b1ad
3 changed files with 299 additions and 0 deletions

View File

@ -0,0 +1,182 @@
/**
*
*/
package org.mitre.openid.connect;
import java.sql.Date;
import org.junit.Test;
import org.mitre.jose.JWEAlgorithmEmbed;
import org.mitre.jose.JWEEncryptionMethodEmbed;
import org.mitre.oauth2.model.ClientDetailsEntity;
import org.mitre.oauth2.model.RegisteredClient;
import com.google.common.collect.ImmutableSet;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.nimbusds.jose.EncryptionMethod;
import com.nimbusds.jose.JWEAlgorithm;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
/**
* @author jricher
*
*/
public class ClientDetailsEntityJsonProcessorTest {
/**
* Test method for {@link org.mitre.openid.connect.ClientDetailsEntityJsonProcessor#parse(java.lang.String)}.
*/
@Test
public void testParse() {
String json = " {\n" +
" \"application_type\": \"web\",\n" +
" \"redirect_uris\":\n" +
" [\"https://client.example.org/callback\",\n" +
" \"https://client.example.org/callback2\"],\n" +
" \"client_name\": \"My Example\",\n" +
" \"client_name#ja-Jpan-JP\":\n" +
" \"クライアント名\",\n" +
" \"logo_uri\": \"https://client.example.org/logo.png\",\n" +
" \"subject_type\": \"pairwise\",\n" +
" \"sector_identifier_uri\":\n" +
" \"https://other.example.net/file_of_redirect_uris.json\",\n" +
" \"token_endpoint_auth_method\": \"client_secret_basic\",\n" +
" \"jwks_uri\": \"https://client.example.org/my_public_keys.jwks\",\n" +
" \"userinfo_encrypted_response_alg\": \"RSA1_5\",\n" +
" \"userinfo_encrypted_response_enc\": \"A128CBC-HS256\",\n" +
" \"contacts\": [\"ve7jtb@example.org\", \"mary@example.org\"],\n" +
" \"request_uris\":\n" +
" [\"https://client.example.org/rf.txt#qpXaRLh_n93TTR9F252ValdatUQvQiJi5BDub2BeznA\"]\n" +
" }";
ClientDetailsEntity c = ClientDetailsEntityJsonProcessor.parse(json);
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.openid.connect.ClientDetailsEntityJsonProcessor#parseRegistered(java.lang.String)}.
*/
@Test
public void testParseRegistered() {
String json = " {\n" +
" \"client_id\": \"s6BhdRkqt3\",\n" +
" \"client_secret\":\n" +
" \"ZJYCqe3GGRvdrudKyZS0XhGv_Z45DuKhCUk0gBR1vZk\",\n" +
" \"expires_at\": 1577858400,\n" +
" \"registration_access_token\":\n" +
" \"this.is.an.access.token.value.ffx83\",\n" +
" \"registration_client_uri\":\n" +
" \"https://server.example.com/connect/register?client_id=s6BhdRkqt3\",\n" +
" \"token_endpoint_auth_method\":\n" +
" \"client_secret_basic\",\n" +
" \"application_type\": \"web\",\n" +
" \"redirect_uris\":\n" +
" [\"https://client.example.org/callback\",\n" +
" \"https://client.example.org/callback2\"],\n" +
" \"client_name\": \"My Example\",\n" +
" \"client_name#ja-Jpan-JP\":\n" +
" \"クライアント名\",\n" +
" \"logo_uri\": \"https://client.example.org/logo.png\",\n" +
" \"subject_type\": \"pairwise\",\n" +
" \"sector_identifier_uri\":\n" +
" \"https://other.example.net/file_of_redirect_uris.json\",\n" +
" \"jwks_uri\": \"https://client.example.org/my_public_keys.jwks\",\n" +
" \"userinfo_encrypted_response_alg\": \"RSA1_5\",\n" +
" \"userinfo_encrypted_response_enc\": \"A128CBC-HS256\",\n" +
" \"contacts\": [\"ve7jtb@example.org\", \"mary@example.org\"],\n" +
" \"request_uris\":\n" +
" [\"https://client.example.org/rf.txt#qpXaRLh_n93TTR9F252ValdatUQvQiJi5BDub2BeznA\"]\n" +
" }";
RegisteredClient c = ClientDetailsEntityJsonProcessor.parseRegistered(json);
assertEquals("s6BhdRkqt3", c.getClientId());
assertEquals("ZJYCqe3GGRvdrudKyZS0XhGv_Z45DuKhCUk0gBR1vZk", c.getClientSecret());
assertEquals(new Date(1577858400L * 1000L), c.getExpiresAt());
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.openid.connect.ClientDetailsEntityJsonProcessor#serialize(org.mitre.oauth2.model.RegisteredClient)}.
*/
@Test
public void testSerialize() {
RegisteredClient c = new RegisteredClient();
c.setClientId("s6BhdRkqt3");
c.setClientSecret("ZJYCqe3GGRvdrudKyZS0XhGv_Z45DuKhCUk0gBR1vZk");
c.setExpiresAt(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"));
JsonObject j = ClientDetailsEntityJsonProcessor.serialize(c);
assertEquals("s6BhdRkqt3", j.get("client_id").getAsString());
assertEquals("ZJYCqe3GGRvdrudKyZS0XhGv_Z45DuKhCUk0gBR1vZk", j.get("client_secret").getAsString());
assertEquals(1577858400L, j.get("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());
for (JsonElement e : j.get("redirect_uris").getAsJsonArray()) {
assertTrue(ImmutableSet.of("https://client.example.org/callback", "https://client.example.org/callback2").contains(e.getAsString()));
}
assertEquals("My Example", j.get("client_name").getAsString());
assertEquals("https://client.example.org/logo.png", j.get("logo_uri").getAsString());
assertEquals(ClientDetailsEntity.SubjectType.PAIRWISE.getValue(), j.get("subject_type").getAsString());
assertEquals("https://other.example.net/file_of_redirect_uris.json", j.get("sector_identifier_uri").getAsString());
assertEquals(ClientDetailsEntity.AuthMethod.SECRET_BASIC.getValue(), j.get("token_endpoint_auth_method").getAsString());
assertEquals("https://client.example.org/my_public_keys.jwks", j.get("jwks_uri").getAsString());
assertEquals(JWEAlgorithm.RSA1_5.getName(), j.get("userinfo_encrypted_response_alg").getAsString());
assertEquals(EncryptionMethod.A128CBC_HS256.getName(), j.get("userinfo_encrypted_response_enc").getAsString());
for (JsonElement e : j.get("contacts").getAsJsonArray()) {
assertTrue(ImmutableSet.of("ve7jtb@example.org", "mary@example.org").contains(e.getAsString()));
}
for (JsonElement e : j.get("request_uris").getAsJsonArray()) {
assertTrue(ImmutableSet.of("https://client.example.org/rf.txt#qpXaRLh_n93TTR9F252ValdatUQvQiJi5BDub2BeznA").contains(e.getAsString()));
}
}
}

View File

@ -0,0 +1,39 @@
/**
*
*/
package org.mitre.openid.connect.config;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* @author jricher
*
*/
public class ConfigurationPropertiesBeanTest {
/**
* Test getters and setters for configuration object.
*/
@Test
public void testConfigurationPropertiesBean() {
// make sure the values that go in come back out unchanged
ConfigurationPropertiesBean bean = new ConfigurationPropertiesBean();
String iss = "http://localhost:8080/openid-connect-server/";
String title = "OpenID Connect Server";
String logoUrl = "/images/logo.png";
bean.setIssuer(iss);
bean.setTopbarTitle(title);
bean.setLogoImageUrl(logoUrl);
assertEquals(iss, bean.getIssuer());
assertEquals(title, bean.getTopbarTitle());
assertEquals(logoUrl, bean.getLogoImageUrl());
}
}

View File

@ -0,0 +1,78 @@
/**
*
*/
package org.mitre.openid.connect.config;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* @author jricher
*
*/
public class ServerConfigurationTest {
/**
* Test getters and setters for server configuration bean
*/
@Test
public void testServerConfiguration() {
String authorizationEndpointUri = "http://localhost:8080/openid-connect-server/authorize";
String tokenEndpointUri = "http://localhost:8080/openid-connect-server/token";
String registrationEndpointUri = "http://localhost:8080/openid-connect-server/register";
String issuer = "http://localhost:8080/openid-connect-server/";
String jwksUri = "http://localhost:8080/openid-connect-server/jwk";
String userInfoUri = "http://localhost:8080/openid-connect-server/userinfo";
ServerConfiguration sc = new ServerConfiguration();
sc.setAuthorizationEndpointUri(authorizationEndpointUri);
sc.setTokenEndpointUri(tokenEndpointUri);
sc.setRegistrationEndpointUri(registrationEndpointUri);
sc.setIssuer(issuer);
sc.setJwksUri(jwksUri);
sc.setUserInfoUri(userInfoUri);
assertEquals(authorizationEndpointUri, sc.getAuthorizationEndpointUri());
assertEquals(tokenEndpointUri, sc.getTokenEndpointUri());
assertEquals(registrationEndpointUri, sc.getRegistrationEndpointUri());
assertEquals(issuer, sc.getIssuer());
assertEquals(jwksUri, sc.getJwksUri());
assertEquals(userInfoUri, sc.getUserInfoUri());
}
/**
* Test method for {@link org.mitre.openid.connect.config.ServerConfiguration#equals(java.lang.Object)}.
*/
@Test
public void testEqualsObject() {
String authorizationEndpointUri = "http://localhost:8080/openid-connect-server/authorize";
String tokenEndpointUri = "http://localhost:8080/openid-connect-server/token";
String registrationEndpointUri = "http://localhost:8080/openid-connect-server/register";
String issuer = "http://localhost:8080/openid-connect-server/";
String jwksUri = "http://localhost:8080/openid-connect-server/jwk";
String userInfoUri = "http://localhost:8080/openid-connect-server/userinfo";
ServerConfiguration sc1 = new ServerConfiguration();
sc1.setAuthorizationEndpointUri(authorizationEndpointUri);
sc1.setTokenEndpointUri(tokenEndpointUri);
sc1.setRegistrationEndpointUri(registrationEndpointUri);
sc1.setIssuer(issuer);
sc1.setJwksUri(jwksUri);
sc1.setUserInfoUri(userInfoUri);
ServerConfiguration sc2 = new ServerConfiguration();
sc2.setAuthorizationEndpointUri(authorizationEndpointUri);
sc2.setTokenEndpointUri(tokenEndpointUri);
sc2.setRegistrationEndpointUri(registrationEndpointUri);
sc2.setIssuer(issuer);
sc2.setJwksUri(jwksUri);
sc2.setUserInfoUri(userInfoUri);
assertTrue(sc1.equals(sc2));
}
}