Skip to content

Commit

Permalink
Fix web finger test failure
Browse files Browse the repository at this point in the history
  • Loading branch information
madurangasiriwardena committed Sep 9, 2024
1 parent ba3cf21 commit 953bc97
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 532 deletions.
6 changes: 1 addition & 5 deletions components/org.wso2.carbon.identity.webfinger/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
<dependency>
<groupId>org.wso2.carbon.identity.framework</groupId>
<artifactId>org.wso2.carbon.identity.testutil</artifactId>
<scope>test</scope>
</dependency>

<dependency>
Expand Down Expand Up @@ -83,11 +84,6 @@
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.wso2.carbon.identity.framework</groupId>
<artifactId>org.wso2.carbon.identity.testutil</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-testng</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,17 @@
import org.testng.annotations.Test;
import org.wso2.carbon.base.ServerConfigurationException;
import org.wso2.carbon.identity.base.IdentityException;
import org.wso2.carbon.identity.common.testng.WithCarbonHome;
import org.wso2.carbon.identity.core.util.IdentityConfigParser;
import org.wso2.carbon.identity.oauth2.IdentityOAuth2Exception;
import org.wso2.carbon.identity.oauth2.util.OAuth2Util;
import org.wso2.carbon.identity.webfinger.WebFingerEndpointException;
import org.wso2.carbon.identity.webfinger.WebFingerRequest;
import org.wso2.carbon.identity.webfinger.WebFingerResponse;
import org.wso2.carbon.utils.CarbonUtils;

import java.io.File;
import java.lang.reflect.Field;

import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mockStatic;
Expand All @@ -36,6 +42,7 @@
/**
* Unit test coverage for WebFingerOIDCResponseBuilder class.
*/
@WithCarbonHome
public class WebFingerOIDCResponseBuilderTest {

private WebFingerOIDCResponseBuilder webFingerOIDCResponseBuilder;
Expand Down Expand Up @@ -63,6 +70,9 @@ public void setUp() throws Exception {
webFingerRequest.setRel(rel);
webFingerRequest.setTenant(tenant);

setPrivateStaticField(IdentityConfigParser.class, "configFilePath", System.getProperty("carbon.home")
+ File.separator + "repository" + File.separator + "conf" + File.separator + "identity"
+ File.separator + "identity.xml");
oAuth2Util = mockStatic(OAuth2Util.class);
}

Expand All @@ -72,6 +82,14 @@ public void tearDown() {
oAuth2Util.close();
}

private void setPrivateStaticField(Class<?> clazz, String fieldName, Object newValue)
throws NoSuchFieldException, IllegalAccessException {

Field field = clazz.getDeclaredField(fieldName);
field.setAccessible(true);
field.set(null, newValue);
}

@Test
public void testBuildWebFingerResponse() throws Exception {

Expand Down
Loading

0 comments on commit 953bc97

Please sign in to comment.