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));
}
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);
}
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);
}
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);
}
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);
}
Aggregations