Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Unit Tests #178

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, WSO2 LLC. (http://www.wso2.com).
* Copyright (c) 2017-2024, 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
Expand Down Expand Up @@ -43,7 +43,9 @@
import org.testng.annotations.DataProvider;
import org.testng.annotations.ObjectFactory;
import org.testng.annotations.Test;
import org.wso2.carbon.identity.application.authentication.framework.config.model.ApplicationConfig;
import org.wso2.carbon.identity.application.authentication.framework.config.model.ExternalIdPConfig;
import org.wso2.carbon.identity.application.authentication.framework.config.model.SequenceConfig;
import org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext;
import org.wso2.carbon.identity.application.authentication.framework.exception.AuthenticationFailedException;
import org.wso2.carbon.identity.application.authentication.framework.exception.FrameworkException;
Expand All @@ -57,6 +59,7 @@
import org.wso2.carbon.identity.application.common.model.ClaimMapping;
import org.wso2.carbon.identity.application.common.model.IdentityProvider;
import org.wso2.carbon.identity.application.common.model.IdentityProviderProperty;
import org.wso2.carbon.identity.application.common.model.ServiceProvider;
import org.wso2.carbon.identity.application.common.util.IdentityApplicationConstants;
import org.wso2.carbon.identity.central.log.mgt.utils.LoggerUtils;
import org.wso2.carbon.identity.claim.metadata.mgt.ClaimMetadataManagementService;
Expand Down Expand Up @@ -1161,6 +1164,25 @@ public Object[][] shareFederatedTokenParamsForAdaptiveScriptConfigs() {
};
}

/**
* This method generates test criteria on extracting scopes from given URL query parameters.
*
* @return Object[][] The test criteria.
*/
@DataProvider(name = "authorizeUrls")
public Object[][] authorizeUrls() {

return new Object[][]{
{"https://localhost:9443/oauth2/authorize?scope=openid+profile+email&clientID=aishf784hwbf947gfo",
"openid profile email"},
{"https://localhost:9443/oauth2/authorize?scope=openid+profile+email", "openid profile email"},
{"https://localhost:9443/oauth2/authorize?scope=openid", "openid"},
{"https://localhost:9443/oauth2/authorize?clientID=aishf784hwbf947gfo", ""},
{"https://localhost:9443/oauth2/authorize", ""},
{"", ""}
};
}

@Test(dataProvider = "shareFederatedTokenParamsForAdaptiveScriptConfigs")
public void testShareFederatedTokenParamsForAdaptiveScriptConfigs(String errorMessage,
String enableShareTokenIDPConfig,
Expand Down Expand Up @@ -1213,6 +1235,35 @@ public void testShareFederatedTokenForIDPConfigAndQueryParameter(String errorMes
}
}

@Test
public void testGetApplicationDetails() throws Exception {

AuthenticationContext mockedAuthenticationContext = mock(AuthenticationContext.class);
when(mockedAuthenticationContext.getServiceProviderName()).thenReturn("Test App");

SequenceConfig mockedSequenceConfig = mock(SequenceConfig.class);
ApplicationConfig mockedApplicationConfig = mock(ApplicationConfig.class);
ServiceProvider mockedServiceProvider = mock(ServiceProvider.class);
when(mockedAuthenticationContext.getSequenceConfig()).thenReturn(mockedSequenceConfig);
when(mockedSequenceConfig.getApplicationConfig()).thenReturn(mockedApplicationConfig);
when(mockedApplicationConfig.getServiceProvider()).thenReturn(mockedServiceProvider);
when(mockedServiceProvider.getApplicationResourceId()).thenReturn("test-app-resource-id");

Map<String, String> applicationDetails =
openIDConnectAuthenticator.getApplicationDetails(mockedAuthenticationContext);
assertEquals(applicationDetails.get("application name"), "Test App",
"Application name is not set properly.");
assertEquals(applicationDetails.get("app id"), "test-app-resource-id",
"Application id is not set properly.");
}

@Test(dataProvider = "authorizeUrls")
public void testExtractScopesFromURL(String url, String expectedScopes) throws Exception {

String scopes = openIDConnectAuthenticator.extractScopesFromURL(url);
assertEquals(scopes, expectedScopes, "Scopes are not extracted properly.");
}

/**
* This method generates an authentication instance for the federated token sharing.
*
Expand Down
Loading