Search in sources :

Example 1 with OIDCDiscoveryDataHolder

use of org.wso2.carbon.identity.discovery.internal.OIDCDiscoveryDataHolder in project identity-inbound-auth-oauth by wso2-extensions.

the class ProviderConfigBuilderTest method testBuildOIDProviderConfig.

@Test
public void testBuildOIDProviderConfig() throws Exception {
    OAuthServerConfiguration mockOAuthServerConfiguration = mock(OAuthServerConfiguration.class);
    mockStatic(OAuthServerConfiguration.class);
    when(OAuthServerConfiguration.getInstance()).thenReturn(mockOAuthServerConfiguration);
    OIDCDiscoveryDataHolder mockOidcDiscoveryDataHolder = spy(new OIDCDiscoveryDataHolder());
    mockStatic(OIDCDiscoveryDataHolder.class);
    mockOidcDiscoveryDataHolder.setClaimManagementService(mockClaimMetadataManagementService);
    when(OIDCDiscoveryDataHolder.getInstance()).thenReturn(mockOidcDiscoveryDataHolder);
    mockStatic(OAuth2Util.class);
    mockStatic(OAuth2Util.OAuthURL.class);
    List<ExternalClaim> claims = new ArrayList<>();
    ExternalClaim externalClaim = new ExternalClaim("aaa", "bbb", "ccc");
    claims.add(externalClaim);
    when(mockClaimMetadataManagementService.getExternalClaims(anyString(), anyString())).thenReturn(claims);
    when(mockOAuthServerConfiguration.getIdTokenSignatureAlgorithm()).thenReturn(idTokenSignatureAlgorithm);
    when(OAuth2Util.mapSignatureAlgorithmForJWSAlgorithm(idTokenSignatureAlgorithm)).thenReturn(JWSAlgorithm.RS256);
    when(OAuth2Util.mapSignatureAlgorithmForJWSAlgorithm(anyString())).thenReturn(JWSAlgorithm.RS256);
    assertNotNull(providerConfigBuilder.buildOIDProviderConfig(mockOidProviderRequest));
}
Also used : ExternalClaim(org.wso2.carbon.identity.claim.metadata.mgt.model.ExternalClaim) OAuthServerConfiguration(org.wso2.carbon.identity.oauth.config.OAuthServerConfiguration) ArrayList(java.util.ArrayList) OAuth2Util(org.wso2.carbon.identity.oauth2.util.OAuth2Util) OIDCDiscoveryDataHolder(org.wso2.carbon.identity.discovery.internal.OIDCDiscoveryDataHolder) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 2 with OIDCDiscoveryDataHolder

use of org.wso2.carbon.identity.discovery.internal.OIDCDiscoveryDataHolder in project identity-inbound-auth-oauth by wso2-extensions.

the class ProviderConfigBuilderTest method testBuildOIDProviderConfig4.

@Test
public void testBuildOIDProviderConfig4() throws Exception {
    OAuthServerConfiguration mockOAuthServerConfiguration = mock(OAuthServerConfiguration.class);
    mockStatic(OAuthServerConfiguration.class);
    when(OAuthServerConfiguration.getInstance()).thenReturn(mockOAuthServerConfiguration);
    OIDCDiscoveryDataHolder mockOidcDiscoveryDataHolder = spy(new OIDCDiscoveryDataHolder());
    mockStatic(OIDCDiscoveryDataHolder.class);
    mockOidcDiscoveryDataHolder.setClaimManagementService(mockClaimMetadataManagementService);
    when(OIDCDiscoveryDataHolder.getInstance()).thenReturn(mockOidcDiscoveryDataHolder);
    mockStatic(OAuth2Util.class);
    mockStatic(OAuth2Util.OAuthURL.class);
    when(OAuth2Util.mapSignatureAlgorithmForJWSAlgorithm(idTokenSignatureAlgorithm)).thenReturn(JWSAlgorithm.RS256);
    when(OAuth2Util.mapSignatureAlgorithmForJWSAlgorithm(anyString())).thenReturn(JWSAlgorithm.RS256);
    String dummyIdIssuer = "http://domain:0000/oauth2/token";
    when(OAuth2Util.getIDTokenIssuer()).thenReturn(dummyIdIssuer);
    List<ExternalClaim> claims = new ArrayList<>();
    ExternalClaim externalClaim = new ExternalClaim("aaa", "bbb", "ccc");
    claims.add(externalClaim);
    when(mockClaimMetadataManagementService.getExternalClaims(anyString(), anyString())).thenReturn(claims);
    when(mockOAuthServerConfiguration.getIdTokenSignatureAlgorithm()).thenReturn(idTokenSignatureAlgorithm);
    mockStatic(DiscoveryUtil.class);
    when(DiscoveryUtil.isUseEntityIdAsIssuerInOidcDiscovery()).thenReturn(Boolean.FALSE);
    OIDProviderConfigResponse response = providerConfigBuilder.buildOIDProviderConfig(mockOidProviderRequest);
    assertNotNull(response);
    assertEquals(response.getIssuer(), dummyIdIssuer);
}
Also used : OIDProviderConfigResponse(org.wso2.carbon.identity.discovery.OIDProviderConfigResponse) ExternalClaim(org.wso2.carbon.identity.claim.metadata.mgt.model.ExternalClaim) OAuthServerConfiguration(org.wso2.carbon.identity.oauth.config.OAuthServerConfiguration) ArrayList(java.util.ArrayList) OAuth2Util(org.wso2.carbon.identity.oauth2.util.OAuth2Util) Matchers.anyString(org.mockito.Matchers.anyString) OIDCDiscoveryDataHolder(org.wso2.carbon.identity.discovery.internal.OIDCDiscoveryDataHolder) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with OIDCDiscoveryDataHolder

use of org.wso2.carbon.identity.discovery.internal.OIDCDiscoveryDataHolder in project identity-inbound-auth-oauth by wso2-extensions.

the class ProviderConfigBuilderTest method testBuildOIDProviderConfig3.

@Test(expectedExceptions = ServerConfigurationException.class)
public void testBuildOIDProviderConfig3() throws Exception {
    OAuthServerConfiguration mockOAuthServerConfiguration = mock(OAuthServerConfiguration.class);
    mockStatic(OAuthServerConfiguration.class);
    when(OAuthServerConfiguration.getInstance()).thenReturn(mockOAuthServerConfiguration);
    OIDCDiscoveryDataHolder mockOidcDiscoveryDataHolder = spy(new OIDCDiscoveryDataHolder());
    mockStatic(OIDCDiscoveryDataHolder.class);
    mockOidcDiscoveryDataHolder.setClaimManagementService(mockClaimMetadataManagementService);
    when(OIDCDiscoveryDataHolder.getInstance()).thenReturn(mockOidcDiscoveryDataHolder);
    mockStatic(OAuth2Util.class);
    mockStatic(OAuth2Util.OAuthURL.class);
    List<ExternalClaim> claims = new ArrayList<>();
    ExternalClaim mockExternalClaim = new ExternalClaim("aaa", "bbb", "ccc");
    claims.add(mockExternalClaim);
    when(mockClaimMetadataManagementService.getExternalClaims(anyString(), anyString())).thenReturn(claims);
    when(mockOAuthServerConfiguration.getIdTokenSignatureAlgorithm()).thenReturn(idTokenSignatureAlgorithm);
    when(OAuth2Util.mapSignatureAlgorithmForJWSAlgorithm(idTokenSignatureAlgorithm)).thenThrow(new IdentityOAuth2Exception("IdentityOAuth2Exception"));
    providerConfigBuilder.buildOIDProviderConfig(mockOidProviderRequest);
}
Also used : IdentityOAuth2Exception(org.wso2.carbon.identity.oauth2.IdentityOAuth2Exception) ExternalClaim(org.wso2.carbon.identity.claim.metadata.mgt.model.ExternalClaim) OAuthServerConfiguration(org.wso2.carbon.identity.oauth.config.OAuthServerConfiguration) ArrayList(java.util.ArrayList) OAuth2Util(org.wso2.carbon.identity.oauth2.util.OAuth2Util) OIDCDiscoveryDataHolder(org.wso2.carbon.identity.discovery.internal.OIDCDiscoveryDataHolder) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 4 with OIDCDiscoveryDataHolder

use of org.wso2.carbon.identity.discovery.internal.OIDCDiscoveryDataHolder in project identity-inbound-auth-oauth by wso2-extensions.

the class ProviderConfigBuilderTest method testBuildOIDProviderConfig5.

@Test(expectedExceptions = ServerConfigurationException.class)
public void testBuildOIDProviderConfig5() throws Exception {
    OAuthServerConfiguration mockOAuthServerConfiguration = mock(OAuthServerConfiguration.class);
    mockStatic(OAuthServerConfiguration.class);
    when(OAuthServerConfiguration.getInstance()).thenReturn(mockOAuthServerConfiguration);
    OIDCDiscoveryDataHolder mockOidcDiscoveryDataHolder = spy(new OIDCDiscoveryDataHolder());
    mockStatic(OIDCDiscoveryDataHolder.class);
    mockOidcDiscoveryDataHolder.setClaimManagementService(mockClaimMetadataManagementService);
    when(OIDCDiscoveryDataHolder.getInstance()).thenReturn(mockOidcDiscoveryDataHolder);
    mockStatic(OAuth2Util.class);
    mockStatic(OAuth2Util.OAuthURL.class);
    List<ExternalClaim> claims = new ArrayList<>();
    ExternalClaim externalClaim = new ExternalClaim("aaa", "bbb", "ccc");
    claims.add(externalClaim);
    when(mockClaimMetadataManagementService.getExternalClaims(anyString(), anyString())).thenReturn(claims);
    when(mockOAuthServerConfiguration.getIdTokenSignatureAlgorithm()).thenReturn(idTokenSignatureAlgorithm);
    String wrongAlgo = "SHA150withRSA";
    when(mockOAuthServerConfiguration.getUserInfoJWTSignatureAlgorithm()).thenReturn(wrongAlgo);
    when(OAuth2Util.mapSignatureAlgorithmForJWSAlgorithm(idTokenSignatureAlgorithm)).thenReturn(JWSAlgorithm.RS256);
    when(OAuth2Util.mapSignatureAlgorithmForJWSAlgorithm(wrongAlgo)).thenThrow(new IdentityOAuth2Exception("IdentityOAuth2Exception"));
    providerConfigBuilder.buildOIDProviderConfig(mockOidProviderRequest);
}
Also used : IdentityOAuth2Exception(org.wso2.carbon.identity.oauth2.IdentityOAuth2Exception) ExternalClaim(org.wso2.carbon.identity.claim.metadata.mgt.model.ExternalClaim) OAuthServerConfiguration(org.wso2.carbon.identity.oauth.config.OAuthServerConfiguration) ArrayList(java.util.ArrayList) OAuth2Util(org.wso2.carbon.identity.oauth2.util.OAuth2Util) Matchers.anyString(org.mockito.Matchers.anyString) OIDCDiscoveryDataHolder(org.wso2.carbon.identity.discovery.internal.OIDCDiscoveryDataHolder) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 5 with OIDCDiscoveryDataHolder

use of org.wso2.carbon.identity.discovery.internal.OIDCDiscoveryDataHolder in project identity-inbound-auth-oauth by wso2-extensions.

the class ProviderConfigBuilderTest method testBuildOIDProviderConfig2.

@Test(expectedExceptions = ServerConfigurationException.class)
public void testBuildOIDProviderConfig2() throws Exception {
    OAuthServerConfiguration mockOAuthServerConfiguration = mock(OAuthServerConfiguration.class);
    mockStatic(OAuthServerConfiguration.class);
    when(OAuthServerConfiguration.getInstance()).thenReturn(mockOAuthServerConfiguration);
    OIDCDiscoveryDataHolder mockOidcDiscoveryDataHolder = spy(new OIDCDiscoveryDataHolder());
    mockStatic(OIDCDiscoveryDataHolder.class);
    mockOidcDiscoveryDataHolder.setClaimManagementService(mockClaimMetadataManagementService);
    when(OIDCDiscoveryDataHolder.getInstance()).thenReturn(mockOidcDiscoveryDataHolder);
    mockStatic(OAuth2Util.class);
    mockStatic(OAuth2Util.OAuthURL.class);
    when(mockClaimMetadataManagementService.getExternalClaims(anyString(), anyString())).thenThrow(new ClaimMetadataException("ClaimMetadataException"));
    providerConfigBuilder.buildOIDProviderConfig(mockOidProviderRequest);
}
Also used : ClaimMetadataException(org.wso2.carbon.identity.claim.metadata.mgt.exception.ClaimMetadataException) OAuthServerConfiguration(org.wso2.carbon.identity.oauth.config.OAuthServerConfiguration) OAuth2Util(org.wso2.carbon.identity.oauth2.util.OAuth2Util) OIDCDiscoveryDataHolder(org.wso2.carbon.identity.discovery.internal.OIDCDiscoveryDataHolder) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 Test (org.testng.annotations.Test)5 OIDCDiscoveryDataHolder (org.wso2.carbon.identity.discovery.internal.OIDCDiscoveryDataHolder)5 OAuthServerConfiguration (org.wso2.carbon.identity.oauth.config.OAuthServerConfiguration)5 OAuth2Util (org.wso2.carbon.identity.oauth2.util.OAuth2Util)5 ArrayList (java.util.ArrayList)4 ExternalClaim (org.wso2.carbon.identity.claim.metadata.mgt.model.ExternalClaim)4 Matchers.anyString (org.mockito.Matchers.anyString)2 IdentityOAuth2Exception (org.wso2.carbon.identity.oauth2.IdentityOAuth2Exception)2 ClaimMetadataException (org.wso2.carbon.identity.claim.metadata.mgt.exception.ClaimMetadataException)1 OIDProviderConfigResponse (org.wso2.carbon.identity.discovery.OIDProviderConfigResponse)1