Guest User

Untitled

a guest
Dec 18th, 2018
340
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.51 KB | None | 0 0
  1. package com.godaddy.common.auth;
  2.  
  3. import com.godaddy.sso.auth.JsonMapper;
  4. import com.godaddy.sso.auth.Jwt;
  5. import com.godaddy.sso.auth.KeyStoreType;
  6. import com.godaddy.sso.auth.SsoClient;
  7. import com.godaddy.sso.auth.config.KeyStoreConfiguration;
  8. import com.godaddy.sso.auth.config.SsoConfiguration;
  9. import com.google.common.base.Charsets;
  10. import com.google.common.io.Resources;
  11. import org.junit.Test;
  12. import retrofit2.Call;
  13. import retrofit2.Response;
  14.  
  15. import java.net.URL;
  16. import java.security.KeyStore;
  17. import java.security.KeyStoreException;
  18.  
  19. import static org.assertj.core.api.Assertions.assertThat;
  20.  
  21. public class SsoClientTests {
  22. @Test
  23. public void ssoClientTest() throws Exception {
  24.  
  25. final KeyStoreConfiguration keyStoreConfiguration =
  26. KeyStoreConfiguration.builder()
  27. .path("sso-client.tests.journals.test-godaddy.com.pfx")
  28. .password("Putter")
  29. .type(KeyStoreType.PKCS12)
  30. .build();
  31. final SsoConfiguration ssoConfig = SsoConfiguration.builder()
  32. .ssoHostname("sso.godaddy.com")
  33. .keyStoreConfiguration(keyStoreConfiguration)
  34. .build();
  35.  
  36. runTest(ssoConfig);
  37. }
  38.  
  39. @Test
  40. public void ssoClientConfigTest() throws Exception {
  41. final URL resourceUrl = Resources.getResource("test-config.json");
  42. final SsoConfiguration config = JsonMapper.current().readValue(resourceUrl, SsoConfiguration.class);
  43. runTest(config);
  44. }
  45.  
  46. @Test
  47. public void ssoClientDelegationTest() throws Exception {
  48. final KeyStoreConfiguration keyStoreConfiguration =
  49. KeyStoreConfiguration.builder()
  50. .path("sso-client.tests.journals.test-godaddy.com.pfx")
  51. .password("Putter")
  52. .type(KeyStoreType.PKCS12)
  53. .build();
  54. final SsoConfiguration ssoConfig = SsoConfiguration.builder()
  55. .ssoHostname("sso.test-godaddy.com")
  56. .keyStoreConfiguration(keyStoreConfiguration)
  57. .build();
  58.  
  59. runDelegationTest(ssoConfig);
  60. }
  61.  
  62. @Test
  63. public void ensure_default_keystore_exists() {
  64. final KeyStoreType keyStoreType = KeyStoreType.fromName(KeyStore.getDefaultType());
  65.  
  66. assertThat(keyStoreType).isNotNull();
  67. }
  68.  
  69.  
  70. @Test
  71. public void ensure_all_keystore_types_exist() throws KeyStoreException {
  72. for (final KeyStoreType keyStoreType : KeyStoreType.values()) {
  73. final KeyStore instance = KeyStore.getInstance(keyStoreType.name());
  74. assertThat(instance).withFailMessage("Keystore of type '%s' not found", keyStoreType).isNotNull();
  75. }
  76. }
  77.  
  78. private void runTest(final SsoConfiguration ssoConfig) throws java.io.IOException {
  79. final SsoClient putter = SsoClient.createClient(ssoConfig);
  80.  
  81. final Call<Jwt> cert = putter.getJwt("cert");
  82.  
  83. final Response<Jwt> execute = cert.execute();
  84. assertThat(execute.isSuccessful()).isTrue();
  85. final Jwt body = execute.body();
  86. assertThat(body).isNotNull();
  87. assertThat(body.data()).isNotNull();
  88. }
  89.  
  90. private void runDelegationTest(final SsoConfiguration ssoConfiguration) throws java.io.IOException {
  91. final SsoClient putter = SsoClient.createClient(ssoConfiguration);
  92.  
  93. final Call<Jwt> cert = putter.getDelegatedShopperJwt("idp", "234624");
  94.  
  95. final Response<Jwt> execute = cert.execute();
  96. assertThat(execute.isSuccessful()).isTrue();
  97. final Jwt body = execute.body();
  98. assertThat(body).isNotNull();
  99. assertThat(body.data()).isNotNull();
  100. }
  101. }
Add Comment
Please, Sign In to add comment