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
Showing
15 changed files
with
241 additions
and
50 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
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
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
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
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
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
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
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
133 changes: 133 additions & 0 deletions
133
...ava/org/wso2/carbon/identity/client/attestation/mgt/ClientAttestationServiceImplTest.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,133 @@ | ||
/* | ||
* Copyright (c) 2023, 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.client.attestation.mgt; | ||
|
||
import org.powermock.core.classloader.annotations.PrepareForTest; | ||
import org.powermock.modules.testng.PowerMockTestCase; | ||
import org.testng.Assert; | ||
import org.testng.annotations.BeforeMethod; | ||
import org.testng.annotations.DataProvider; | ||
import org.testng.annotations.Test; | ||
import org.wso2.carbon.identity.application.common.IdentityApplicationManagementException; | ||
import org.wso2.carbon.identity.application.common.model.ClientAttestationMetaData; | ||
import org.wso2.carbon.identity.application.common.model.ServiceProvider; | ||
import org.wso2.carbon.identity.application.mgt.ApplicationManagementService; | ||
import org.wso2.carbon.identity.client.attestation.mgt.internal.ClientAttestationMgtDataHolder; | ||
import org.wso2.carbon.identity.client.attestation.mgt.model.ClientAttestationContext; | ||
import org.wso2.carbon.identity.client.attestation.mgt.services.ClientAttestationService; | ||
import org.wso2.carbon.identity.client.attestation.mgt.services.ClientAttestationServiceImpl; | ||
|
||
import static org.mockito.ArgumentMatchers.anyString; | ||
import static org.mockito.ArgumentMatchers.eq; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
import static org.powermock.api.mockito.PowerMockito.mockStatic; | ||
import static org.wso2.carbon.identity.client.attestation.mgt.utils.Constants.OAUTH2; | ||
|
||
/** | ||
* Testing the ClientAttestationServiceImpl class | ||
*/ | ||
@PrepareForTest({ ClientAttestationServiceImpl.class, ClientAttestationMgtDataHolder.class, | ||
ApplicationManagementService.class}) | ||
public class ClientAttestationServiceImplTest extends PowerMockTestCase { | ||
|
||
private ClientAttestationService clientAttestationService; | ||
private ApplicationManagementService applicationManagementService; | ||
|
||
@BeforeMethod | ||
public void setup() { | ||
|
||
clientAttestationService = new ClientAttestationServiceImpl(); | ||
|
||
ClientAttestationMgtDataHolder clientAttestationMgtDataHolder = mock(ClientAttestationMgtDataHolder.class); | ||
mockStatic(ClientAttestationMgtDataHolder.class); | ||
applicationManagementService = mock(ApplicationManagementService.class); | ||
mockStatic(ApplicationManagementService.class); | ||
when(ClientAttestationMgtDataHolder.getInstance()) | ||
.thenReturn(clientAttestationMgtDataHolder); | ||
when(ClientAttestationMgtDataHolder.getInstance().getApplicationManagementService()) | ||
.thenReturn(applicationManagementService); | ||
} | ||
|
||
@DataProvider(name = "validateAttestationDataProvider") | ||
public Object[][] dataValidateAttestationMethod() { | ||
|
||
return new Object[][]{ | ||
{ | ||
"", "tyHuiopdtQdlriM4df5mqCJZEa", "carbon.super", false, false, false, | ||
"App is not subscribed to API-Based Authentication." | ||
}, | ||
{ | ||
"", "tyHuiopdtQdlriM4df5mqCJZEa", "carbon.super", true, false, true, | ||
null | ||
}, | ||
{ | ||
"", "tyHuiopdtQdlriM4df5mqCJZEa", "carbon.super", true, true, false, | ||
"App is configured to validate attestation but attestation object is empty." | ||
}, | ||
{ | ||
"DUMMY OBJECT", "tyHuiopdtQdlriM4df5mqCJZEa", "carbon.super", true, true, false, | ||
"Requested attestation object is not in valid format." | ||
} | ||
}; | ||
} | ||
|
||
@Test(dataProvider = "validateAttestationDataProvider") | ||
public void validateAttestationTest(String attestationObject, | ||
String clientId, | ||
String tenantDomain, | ||
boolean isAPIBasedAuthenticationEnabled, | ||
boolean isAttestationEnabled, | ||
boolean isAttested, | ||
String errorMessage) throws IdentityApplicationManagementException { | ||
|
||
ServiceProvider testSp1 = new ServiceProvider(); | ||
testSp1.setAPIBasedAuthenticationEnabled(isAPIBasedAuthenticationEnabled); | ||
ClientAttestationMetaData clientAttestationMetaData = new ClientAttestationMetaData(); | ||
clientAttestationMetaData.setAttestationEnabled(isAttestationEnabled); | ||
testSp1.setClientAttestationMetaData(clientAttestationMetaData); | ||
|
||
when(applicationManagementService.getServiceProviderByClientId(anyString(), eq(OAUTH2), anyString())) | ||
.thenReturn(testSp1); | ||
ClientAttestationContext clientAttestationContext = | ||
clientAttestationService.validateAttestation(attestationObject, | ||
clientId, tenantDomain); | ||
Assert.assertEquals(isAttested, clientAttestationContext.isAttested(), | ||
"False Client Attestation Validation"); | ||
if (errorMessage != null) { | ||
Assert.assertEquals(errorMessage, clientAttestationContext.getErrorMessage(), | ||
"Wrong Error message."); | ||
} | ||
} | ||
|
||
@Test | ||
public void validateAttestationTestForNullSP() throws IdentityApplicationManagementException { | ||
|
||
when(applicationManagementService.getServiceProviderByClientId(anyString(), eq(OAUTH2), anyString())) | ||
.thenReturn(null); | ||
ClientAttestationContext clientAttestationContext = | ||
clientAttestationService.validateAttestation(" ", | ||
"tyHuiopdtQdlriM4df5mqCJZEa", "carbon.super"); | ||
Assert.assertFalse(clientAttestationContext.isAttested(), | ||
"Client Attestation Validation should be false for null SP."); | ||
Assert.assertEquals(clientAttestationContext.getErrorMessage(), | ||
"Service Provider not found."); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...station-mgt/org.wso2.carbon.identity.client.attestation.mgt/src/test/resources/testng.xml
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,25 @@ | ||
<!-- | ||
~ Copyright (c) 2019, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. | ||
~ | ||
~ Licensed 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. | ||
--> | ||
|
||
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" > | ||
|
||
<suite name="org.wso2.carbon.identity.client.attestation.mgt.test"> | ||
<test name="org.wso2.carbon.identity.client.attestation.mgt.test" preserve-order="false" parallel="false"> | ||
<classes> | ||
<class name="org.wso2.carbon.identity.client.attestation.mgt.ClientAttestationServiceImplTest"/> | ||
</classes> | ||
</test> | ||
</suite> |
Oops, something went wrong.