forked from wso2/carbon-identity-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1533048
commit 6eefa53
Showing
3 changed files
with
142 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 126 additions & 0 deletions
126
...plication/authentication/framework/internal/core/ApplicationAuthenticatorManagerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
/* | ||
* Copyright (c) 2025, WSO2 LLC. (http://www.wso2.com). | ||
* | ||
* WSO2 LLC. licenses this file to you under the Apache License, | ||
* Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.wso2.carbon.identity.application.authentication.framework.internal.core; | ||
|
||
import org.mockito.MockedStatic; | ||
import org.testng.annotations.BeforeClass; | ||
import org.testng.annotations.Test; | ||
import org.wso2.carbon.identity.action.execution.model.ActionType; | ||
import org.wso2.carbon.identity.action.execution.util.ActionExecutorConfig; | ||
import org.wso2.carbon.identity.application.authentication.framework.ApplicationAuthenticator; | ||
import org.wso2.carbon.identity.application.authentication.framework.FederatedApplicationAuthenticator; | ||
import org.wso2.carbon.identity.application.authentication.framework.LocalApplicationAuthenticator; | ||
import org.wso2.carbon.identity.application.authentication.framework.MockAuthenticator; | ||
import org.wso2.carbon.identity.application.authentication.framework.UserDefinedAuthenticatorService; | ||
import org.wso2.carbon.identity.application.authentication.framework.internal.FrameworkServiceDataHolder; | ||
import org.wso2.carbon.identity.application.common.ApplicationAuthenticatorService; | ||
import org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig; | ||
import org.wso2.carbon.identity.application.common.model.UserDefinedFederatedAuthenticatorConfig; | ||
import org.wso2.carbon.identity.application.common.model.UserDefinedLocalAuthenticatorConfig; | ||
import org.wso2.carbon.identity.base.AuthenticatorPropertyConstants; | ||
import org.wso2.carbon.idp.mgt.IdentityProviderManager; | ||
|
||
import java.util.List; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.mockStatic; | ||
import static org.mockito.Mockito.when; | ||
|
||
@Test | ||
public class ApplicationAuthenticatorManagerTest { | ||
|
||
private final ApplicationAuthenticatorManager applicationAuthenticatorService = | ||
ApplicationAuthenticatorManager.getInstance(); | ||
|
||
private static final String SYSTEM_DEFINED_AUTHENTICATOR_NAME = "BasicAuthenticator"; | ||
private static final String USER_DEFINED_LOCAL_AUTHENTICATOR_NAME = "UserDefinedLocalMockAuthenticator"; | ||
private static final String USER_DEFINED_FEDERATED_AUTHENTICATOR_NAME = "UserDefinedFederatedMockAuthenticator"; | ||
private static final String TENANT_DOMAIN = "carbon.super"; | ||
|
||
private static final ApplicationAuthenticator systemDefinedAuthenticator = | ||
new MockAuthenticator(SYSTEM_DEFINED_AUTHENTICATOR_NAME); | ||
private static final LocalApplicationAuthenticator userDefinedLocalAuthenticator = | ||
new MockAuthenticator.MockLocalAuthenticator(USER_DEFINED_LOCAL_AUTHENTICATOR_NAME); | ||
private static final FederatedApplicationAuthenticator userDefinedFederatedAuthenticator = | ||
new MockAuthenticator.MockFederatedAuthenticator(USER_DEFINED_FEDERATED_AUTHENTICATOR_NAME); | ||
|
||
private static UserDefinedAuthenticatorService userDefinedAuthenticatorService = | ||
mock(UserDefinedAuthenticatorService.class); | ||
|
||
private final MockedStatic<ActionExecutorConfig> mockedActionExecutorConfig = | ||
mockStatic(ActionExecutorConfig.class); | ||
private final ActionExecutorConfig actionExecutorConfig = mock(ActionExecutorConfig.class); | ||
|
||
private final MockedStatic<ApplicationAuthenticatorService> mockedAuthenticationService = | ||
mockStatic(ApplicationAuthenticatorService.class); | ||
private final ApplicationAuthenticatorService authenticatorService = mock(ApplicationAuthenticatorService.class); | ||
|
||
private final MockedStatic<IdentityProviderManager> mockedIdentityProviderManager = | ||
mockStatic(IdentityProviderManager.class); | ||
private final IdentityProviderManager identityProviderManager = mock(IdentityProviderManager.class); | ||
|
||
@BeforeClass | ||
public void setUp() throws Exception { | ||
|
||
applicationAuthenticatorService.addSystemDefinedAuthenticator(systemDefinedAuthenticator); | ||
when(userDefinedAuthenticatorService.getUserDefinedLocalAuthenticator(any())).thenReturn( | ||
userDefinedLocalAuthenticator); | ||
when(userDefinedAuthenticatorService.getUserDefinedFederatedAuthenticator(any())).thenReturn( | ||
userDefinedFederatedAuthenticator); | ||
FrameworkServiceDataHolder.getInstance().setUserDefinedAuthenticatorService(userDefinedAuthenticatorService); | ||
|
||
mockedActionExecutorConfig.when(ActionExecutorConfig::getInstance).thenReturn(actionExecutorConfig); | ||
|
||
mockedAuthenticationService.when(ApplicationAuthenticatorService::getInstance).thenReturn(authenticatorService); | ||
when(authenticatorService.getAllUserDefinedLocalAuthenticators(TENANT_DOMAIN)).thenReturn( | ||
List.of(new UserDefinedLocalAuthenticatorConfig( | ||
AuthenticatorPropertyConstants.AuthenticationType.IDENTIFICATION))); | ||
|
||
mockedIdentityProviderManager.when(IdentityProviderManager::getInstance).thenReturn(identityProviderManager); | ||
when(identityProviderManager.getAllFederatedAuthenticators(TENANT_DOMAIN)).thenReturn(new | ||
FederatedAuthenticatorConfig[]{new UserDefinedFederatedAuthenticatorConfig()}); | ||
} | ||
|
||
@Test | ||
public void testGetAllAuthenticatorsWithAuthActionTypeEnabledAndNotNullUserDefinedAuthenticatorService() { | ||
|
||
when(actionExecutorConfig.isExecutionForActionTypeEnabled(ActionType.AUTHENTICATION)).thenReturn(true); | ||
List<ApplicationAuthenticator> result = applicationAuthenticatorService.getAllAuthenticators(TENANT_DOMAIN); | ||
assertEquals(3, result.size()); | ||
} | ||
|
||
@Test | ||
public void testGetAllAuthenticatorsWithAuthActionTypeEnabledAndNullUserDefinedAuthenticatorService() { | ||
|
||
FrameworkServiceDataHolder.getInstance().setUserDefinedAuthenticatorService(null); | ||
when(actionExecutorConfig.isExecutionForActionTypeEnabled(ActionType.AUTHENTICATION)).thenReturn(true); | ||
List<ApplicationAuthenticator> result = applicationAuthenticatorService.getAllAuthenticators(TENANT_DOMAIN); | ||
assertEquals(1, result.size()); | ||
} | ||
|
||
@Test | ||
public void testGetAllAuthenticatorsWithAuthenticationActionTypeDisabled() throws Exception { | ||
|
||
when(actionExecutorConfig.isExecutionForActionTypeEnabled(ActionType.AUTHENTICATION)).thenReturn(false); | ||
List<ApplicationAuthenticator> result = applicationAuthenticatorService.getAllAuthenticators(TENANT_DOMAIN); | ||
assertEquals(1, result.size()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters