-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #96 from imesh94/fix/toolkit-build-failure
[OB3] Fix toolkit build failures due to updated package naming
- Loading branch information
Showing
9 changed files
with
432 additions
and
9 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
108 changes: 108 additions & 0 deletions
108
...java/com/wso2/openbanking/accelerator/identity/dcr/validation/AlgorithmValidatorTest.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,108 @@ | ||
/** | ||
* Copyright (c) 2024, WSO2 LLC. (https://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 com.wso2.openbanking.accelerator.identity.dcr.validation; | ||
|
||
import com.wso2.openbanking.accelerator.common.constant.OpenBankingConstants; | ||
import com.wso2.openbanking.accelerator.identity.dcr.validation.annotation.ValidateAlgorithm; | ||
import com.wso2.openbanking.accelerator.identity.internal.IdentityExtensionsDataHolder; | ||
import org.apache.commons.beanutils.BeanUtils; | ||
import org.mockito.Mock; | ||
import org.powermock.api.mockito.PowerMockito; | ||
import org.powermock.core.classloader.annotations.PowerMockIgnore; | ||
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.Test; | ||
|
||
import java.util.Arrays; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import javax.validation.ConstraintValidatorContext; | ||
|
||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
@PowerMockIgnore("jdk.internal.reflect.*") | ||
@PrepareForTest({BeanUtils.class, IdentityExtensionsDataHolder.class}) | ||
public class AlgorithmValidatorTest extends PowerMockTestCase { | ||
|
||
private AlgorithmValidator validator; | ||
|
||
@Mock | ||
private ValidateAlgorithm validateAlgorithm; | ||
|
||
@BeforeMethod | ||
public void setUp() { | ||
validator = new AlgorithmValidator(); | ||
|
||
when(validateAlgorithm.idTokenAlg()).thenReturn("idTokenAlg"); | ||
when(validateAlgorithm.reqObjAlg()).thenReturn("reqObjAlg"); | ||
when(validateAlgorithm.tokenAuthAlg()).thenReturn("tokenAuthAlg"); | ||
|
||
validator.initialize(validateAlgorithm); | ||
} | ||
|
||
@Test | ||
public void testIsValid_ReturnsTrue_WhenAlgorithmsAreAllowed() throws Exception { | ||
Object requestObject = mock(Object.class); | ||
ConstraintValidatorContext context = mock(ConstraintValidatorContext.class); | ||
|
||
PowerMockito.mockStatic(BeanUtils.class); | ||
PowerMockito.when(BeanUtils.getProperty(requestObject, "idTokenAlg")).thenReturn("RS256"); | ||
PowerMockito.when(BeanUtils.getProperty(requestObject, "reqObjAlg")).thenReturn("RS256"); | ||
PowerMockito.when(BeanUtils.getProperty(requestObject, "tokenAuthAlg")).thenReturn("RS256"); | ||
|
||
List<String> allowedAlgorithms = Arrays.asList("RS256", "HS256"); | ||
|
||
PowerMockito.mockStatic(IdentityExtensionsDataHolder.class); | ||
IdentityExtensionsDataHolder dataHolder = PowerMockito.mock(IdentityExtensionsDataHolder.class); | ||
Map<String, Object> configMap = new HashMap<>(); | ||
configMap.put(OpenBankingConstants.SIGNATURE_ALGORITHMS, allowedAlgorithms); | ||
when(dataHolder.getConfigurationMap()).thenReturn(configMap); | ||
PowerMockito.when(IdentityExtensionsDataHolder.getInstance()).thenReturn(dataHolder); | ||
|
||
boolean result = validator.isValid(requestObject, context); | ||
Assert.assertTrue(result); | ||
} | ||
|
||
@Test | ||
public void testIsValid_ReturnsFalse_WhenAlgorithmsAreNotAllowed() throws Exception { | ||
Object requestObject = mock(Object.class); | ||
ConstraintValidatorContext context = mock(ConstraintValidatorContext.class); | ||
|
||
PowerMockito.mockStatic(BeanUtils.class); | ||
PowerMockito.when(BeanUtils.getProperty(requestObject, "idTokenAlg")).thenReturn("RS512"); | ||
PowerMockito.when(BeanUtils.getProperty(requestObject, "reqObjAlg")).thenReturn("RS512"); | ||
PowerMockito.when(BeanUtils.getProperty(requestObject, "tokenAuthAlg")).thenReturn("RS512"); | ||
|
||
List<String> allowedAlgorithms = Arrays.asList("RS256", "HS256"); | ||
|
||
PowerMockito.mockStatic(IdentityExtensionsDataHolder.class); | ||
IdentityExtensionsDataHolder dataHolder = PowerMockito.mock(IdentityExtensionsDataHolder.class); | ||
Map<String, Object> configMap = new HashMap<>(); | ||
configMap.put(OpenBankingConstants.SIGNATURE_ALGORITHMS, allowedAlgorithms); | ||
when(dataHolder.getConfigurationMap()).thenReturn(configMap); | ||
PowerMockito.when(IdentityExtensionsDataHolder.getInstance()).thenReturn(dataHolder); | ||
|
||
boolean result = validator.isValid(requestObject, context); | ||
Assert.assertFalse(result); | ||
} | ||
} |
81 changes: 81 additions & 0 deletions
81
...st/java/com/wso2/openbanking/accelerator/identity/dcr/validation/IssuerValidatorTest.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,81 @@ | ||
/** | ||
* Copyright (c) 2024, WSO2 LLC. (https://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 com.wso2.openbanking.accelerator.identity.dcr.validation; | ||
|
||
import com.wso2.openbanking.accelerator.common.util.JWTUtils; | ||
import com.wso2.openbanking.accelerator.identity.dcr.validation.annotation.ValidateIssuer; | ||
import org.apache.commons.beanutils.BeanUtils; | ||
import org.mockito.Mock; | ||
import org.powermock.api.mockito.PowerMockito; | ||
import org.powermock.core.classloader.annotations.PowerMockIgnore; | ||
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.Test; | ||
|
||
import javax.validation.ConstraintValidatorContext; | ||
|
||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
@PowerMockIgnore("jdk.internal.reflect.*") | ||
@PrepareForTest({JWTUtils.class, BeanUtils.class}) | ||
public class IssuerValidatorTest extends PowerMockTestCase { | ||
|
||
private IssuerValidator validator; | ||
|
||
@Mock | ||
private ValidateIssuer validateIssuer; | ||
|
||
@BeforeMethod | ||
public void setUp() { | ||
validator = new IssuerValidator(); | ||
|
||
when(validateIssuer.issuerProperty()).thenReturn("issuer"); | ||
when(validateIssuer.ssa()).thenReturn("ssa"); | ||
|
||
validator.initialize(validateIssuer); | ||
} | ||
|
||
@Test | ||
public void testIsValid_ReturnsTrue_WhenIssuerOrSoftwareStatementIsNull() throws Exception { | ||
Object registrationRequest = mock(Object.class); | ||
ConstraintValidatorContext context = mock(ConstraintValidatorContext.class); | ||
|
||
PowerMockito.mockStatic(BeanUtils.class); | ||
PowerMockito.when(BeanUtils.getProperty(registrationRequest, "issuer")).thenReturn(null); | ||
PowerMockito.when(BeanUtils.getProperty(registrationRequest, "ssa")).thenReturn(null); | ||
|
||
boolean result = validator.isValid(registrationRequest, context); | ||
Assert.assertTrue(result); | ||
} | ||
|
||
@Test | ||
public void testIsValid_ReturnsFalse_OnException() throws Exception { | ||
Object registrationRequest = mock(Object.class); | ||
ConstraintValidatorContext context = mock(ConstraintValidatorContext.class); | ||
|
||
PowerMockito.mockStatic(BeanUtils.class); | ||
PowerMockito.when(BeanUtils.getProperty(registrationRequest, "issuer")).thenThrow(new NoSuchMethodException()); | ||
PowerMockito.when(BeanUtils.getProperty(registrationRequest, "ssa")).thenReturn("dummy-ssa"); | ||
|
||
boolean result = validator.isValid(registrationRequest, context); | ||
Assert.assertFalse(result); | ||
} | ||
} |
Oops, something went wrong.