Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.godaddy.common.auth;
- import com.godaddy.sso.auth.JsonMapper;
- import com.godaddy.sso.auth.Jwt;
- import com.godaddy.sso.auth.KeyStoreType;
- import com.godaddy.sso.auth.SsoClient;
- import com.godaddy.sso.auth.config.KeyStoreConfiguration;
- import com.godaddy.sso.auth.config.SsoConfiguration;
- import com.google.common.base.Charsets;
- import com.google.common.io.Resources;
- import org.junit.Test;
- import retrofit2.Call;
- import retrofit2.Response;
- import java.net.URL;
- import java.security.KeyStore;
- import java.security.KeyStoreException;
- import static org.assertj.core.api.Assertions.assertThat;
- public class SsoClientTests {
- @Test
- public void ssoClientTest() throws Exception {
- final KeyStoreConfiguration keyStoreConfiguration =
- KeyStoreConfiguration.builder()
- .path("sso-client.tests.journals.test-godaddy.com.pfx")
- .password("Putter")
- .type(KeyStoreType.PKCS12)
- .build();
- final SsoConfiguration ssoConfig = SsoConfiguration.builder()
- .ssoHostname("sso.godaddy.com")
- .keyStoreConfiguration(keyStoreConfiguration)
- .build();
- runTest(ssoConfig);
- }
- @Test
- public void ssoClientConfigTest() throws Exception {
- final URL resourceUrl = Resources.getResource("test-config.json");
- final SsoConfiguration config = JsonMapper.current().readValue(resourceUrl, SsoConfiguration.class);
- runTest(config);
- }
- @Test
- public void ssoClientDelegationTest() throws Exception {
- final KeyStoreConfiguration keyStoreConfiguration =
- KeyStoreConfiguration.builder()
- .path("sso-client.tests.journals.test-godaddy.com.pfx")
- .password("Putter")
- .type(KeyStoreType.PKCS12)
- .build();
- final SsoConfiguration ssoConfig = SsoConfiguration.builder()
- .ssoHostname("sso.test-godaddy.com")
- .keyStoreConfiguration(keyStoreConfiguration)
- .build();
- runDelegationTest(ssoConfig);
- }
- @Test
- public void ensure_default_keystore_exists() {
- final KeyStoreType keyStoreType = KeyStoreType.fromName(KeyStore.getDefaultType());
- assertThat(keyStoreType).isNotNull();
- }
- @Test
- public void ensure_all_keystore_types_exist() throws KeyStoreException {
- for (final KeyStoreType keyStoreType : KeyStoreType.values()) {
- final KeyStore instance = KeyStore.getInstance(keyStoreType.name());
- assertThat(instance).withFailMessage("Keystore of type '%s' not found", keyStoreType).isNotNull();
- }
- }
- private void runTest(final SsoConfiguration ssoConfig) throws java.io.IOException {
- final SsoClient putter = SsoClient.createClient(ssoConfig);
- final Call<Jwt> cert = putter.getJwt("cert");
- final Response<Jwt> execute = cert.execute();
- assertThat(execute.isSuccessful()).isTrue();
- final Jwt body = execute.body();
- assertThat(body).isNotNull();
- assertThat(body.data()).isNotNull();
- }
- private void runDelegationTest(final SsoConfiguration ssoConfiguration) throws java.io.IOException {
- final SsoClient putter = SsoClient.createClient(ssoConfiguration);
- final Call<Jwt> cert = putter.getDelegatedShopperJwt("idp", "234624");
- final Response<Jwt> execute = cert.execute();
- assertThat(execute.isSuccessful()).isTrue();
- final Jwt body = execute.body();
- assertThat(body).isNotNull();
- assertThat(body.data()).isNotNull();
- }
- }
Add Comment
Please, Sign In to add comment