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

Refactor OIDCUtilTest #22269

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
Expand Up @@ -190,8 +190,8 @@ private UserObject initUser() {
UserObject user = new UserObject();
user.setUserName(TEST_USER_NAME);
user.setPassword(TEST_PASSWORD);
user.setName(new Name().givenName(OIDCUtilTest.firstName).familyName(OIDCUtilTest.lastName));
user.addEmail(new Email().value(OIDCUtilTest.email));
user.setName(new Name().givenName(OIDCUtilTest.FIRST_NAME).familyName(OIDCUtilTest.LAST_NAME));
user.addEmail(new Email().value(OIDCUtilTest.EMAIL));
return user;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ protected UserObject initUser() {
UserObject user = new UserObject();
user.setUserName(USERNAME);
user.setPassword(PASSWORD);
user.setName(new Name().givenName(OIDCUtilTest.firstName).familyName(OIDCUtilTest.lastName));
user.setName(new Name().givenName(OIDCUtilTest.FIRST_NAME).familyName(OIDCUtilTest.LAST_NAME));
user.addPhoneNumbers(new PhoneNumbers().value(MOBILE).type("mobile"));
return user;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,9 @@ private void checkAuthorizationCode(String sessionDataKeyConsent) throws Excepti
private void createAndRegisterPlaygroundApplication() throws Exception {

playgroundApp = new OIDCApplication(PLAYGROUND_APP_NAME, PLAYGROUND_APP_CALLBACK_URI);
playgroundApp.addRequiredClaim(OIDCUtilTest.emailClaimUri);
playgroundApp.addRequiredClaim(OIDCUtilTest.firstNameClaimUri);
playgroundApp.addRequiredClaim(OIDCUtilTest.lastNameClaimUri);
playgroundApp.addRequiredClaim(OIDCUtilTest.EMAIL_CLAIM_URI);
playgroundApp.addRequiredClaim(OIDCUtilTest.FIRST_NAME_CLAIM_URI);
playgroundApp.addRequiredClaim(OIDCUtilTest.LAST_NAME_CLAIM_URI);

createApplication(playgroundApp);
clientID = playgroundApp.getClientId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.ApplicationModel;
import org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.InboundProtocols;
import org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.OpenIDConnectConfiguration;
import org.wso2.identity.integration.test.rest.api.user.common.model.UserObject;
import org.wso2.identity.integration.test.utils.OAuth2Constant;

import java.util.ArrayList;
Expand All @@ -49,6 +50,7 @@ public class OIDCAccessTokenAttributesTestCase extends OIDCAbstractIntegrationTe
private static final String SERVICES = "/services";
private OIDCApplication application;
private OpenIDConnectConfiguration oidcInboundConfig;
private UserObject user;
protected String refreshToken;
protected String sessionDataKey;

Expand All @@ -60,19 +62,19 @@ public void testInit() throws Exception {
RestAssured.baseURI = backendURL.replace(SERVICES, "");

// Create a user
OIDCUtilTest.initUser();
createUser(OIDCUtilTest.user);
user = OIDCUtilTest.initUser();
createUser(user);

// Create application
OIDCUtilTest.initApplications();
application = OIDCUtilTest.applications.get(OIDCUtilTest.playgroundAppTwoAppName);
OIDCUtilTest.initApplicationOne();
application = OIDCUtilTest.initApplicationOne();
createApplication(application);
}

@AfterClass(alwaysRun = true)
public void testClear() throws Exception {

deleteUser(OIDCUtilTest.user);
deleteUser(user);
deleteApplication(application);
clear();
}
Expand All @@ -83,8 +85,8 @@ public void testValidateAccessTokenAttributesWithPasswordGrant() throws Exceptio
Map<String, String> params = new HashMap<>();
params.put("grant_type", OAuth2Constant.OAUTH2_GRANT_TYPE_RESOURCE_OWNER);
params.put("scope", "");
params.put("username", OIDCUtilTest.user.getUserName());
params.put("password", OIDCUtilTest.user.getPassword());
params.put("username", user.getUserName());
params.put("password", user.getPassword());

Response response = getResponseOfFormPostWithAuth(OAUTH2_TOKEN_ENDPOINT_URI, params, new HashMap<>(),
application.getClientId(), application.getClientSecret());
Expand Down Expand Up @@ -156,8 +158,8 @@ public void testValidateAccessTokenAttributesForEmptyAllowedAttributes() throws
Map<String, String> params = new HashMap<>();
params.put("grant_type", OAuth2Constant.OAUTH2_GRANT_TYPE_RESOURCE_OWNER);
params.put("scope", "");
params.put("username", OIDCUtilTest.user.getUserName());
params.put("password", OIDCUtilTest.user.getPassword());
params.put("username", user.getUserName());
params.put("password", user.getPassword());

Response response = getResponseOfFormPostWithAuth(OAUTH2_TOKEN_ENDPOINT_URI, params, new HashMap<>(),
application.getClientId(), application.getClientSecret());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ protected void initApplications() throws Exception {

super.initApplications();

applications.get(OIDCUtilTest.playgroundAppOneAppName).setSubjectClaimURI(OIDCUtilTest.emailClaimUri);
applications.get(OIDCUtilTest.playgroundAppTwoAppName).setSubjectClaimURI(OIDCUtilTest.lastNameClaimUri);
applications.get(OIDCUtilTest.PLAYGROUND_APP_ONE_APP_NAME).setSubjectClaimURI(OIDCUtilTest.EMAIL_CLAIM_URI);
applications.get(OIDCUtilTest.PLAYGROUND_APP_TWO_APP_NAME).setSubjectClaimURI(OIDCUtilTest.LAST_NAME_CLAIM_URI);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public void testClear() throws Exception {
public void testAuthzRequestWithoutValidSessionForIDENTITY5581() throws Exception {

//When accessing the below endpoint from with invalid session it should provide a message with login_required
OIDCApplication application = applications.get(OIDCUtilTest.playgroundAppOneAppName);
OIDCApplication application = applications.get(OIDCUtilTest.PLAYGROUND_APP_ONE_APP_NAME);
URI uri = new URIBuilder(OAuth2Constant.APPROVAL_URL)
.addParameter("client_id", application.getClientId())
.addParameter("scope", "openid")
Expand All @@ -142,28 +142,28 @@ public void testAuthzRequestWithoutValidSessionForIDENTITY5581() throws Exceptio
dependsOnMethods = "testAuthzRequestWithoutValidSessionForIDENTITY5581")
public void testSendAuthenticationRequestFromRP1() throws Exception {

testSendAuthenticationRequest(applications.get(OIDCUtilTest.playgroundAppOneAppName), true, client, cookieStore);
testSendAuthenticationRequest(applications.get(OIDCUtilTest.PLAYGROUND_APP_ONE_APP_NAME), true, client, cookieStore);
}

@Test(groups = "wso2.is", description = "Authenticate for playground.appone", dependsOnMethods =
"testSendAuthenticationRequestFromRP1")
public void testAuthenticationFromRP1() throws Exception {

testAuthentication(applications.get(OIDCUtilTest.playgroundAppOneAppName));
testAuthentication(applications.get(OIDCUtilTest.PLAYGROUND_APP_ONE_APP_NAME));
}

@Test(groups = "wso2.is", description = "Approve consent for playground.appone", dependsOnMethods =
"testAuthenticationFromRP1")
public void testConsentApprovalFromRP1() throws Exception {

testConsentApproval(applications.get(OIDCUtilTest.playgroundAppOneAppName));
testConsentApproval(applications.get(OIDCUtilTest.PLAYGROUND_APP_ONE_APP_NAME));
}

@Test(groups = "wso2.is", description = "Get access token for playground.appone", dependsOnMethods =
"testConsentApprovalFromRP1")
public void testGetAccessTokenFromRP1() throws Exception {

testGetAccessToken(applications.get(OIDCUtilTest.playgroundAppOneAppName));
testGetAccessToken(applications.get(OIDCUtilTest.PLAYGROUND_APP_ONE_APP_NAME));
}

@Test(groups = "wso2.is", description = "Get user claim values for playground.appone", dependsOnMethods =
Expand All @@ -176,22 +176,22 @@ public void testUserClaimsFromRP1() throws Exception {
@Test(groups = "wso2.is", description = "Initiate authentication request from playground.apptwo")
public void testSendAuthenticationRequestFromRP2() throws Exception {

testSendAuthenticationRequest(applications.get(OIDCUtilTest.playgroundAppTwoAppName), false, client,
testSendAuthenticationRequest(applications.get(OIDCUtilTest.PLAYGROUND_APP_TWO_APP_NAME), false, client,
cookieStore);
}

@Test(groups = "wso2.is", description = "Approve consent for playground.apptwo", dependsOnMethods =
"testSendAuthenticationRequestFromRP2")
public void testConsentApprovalFromRP2() throws Exception {

testConsentApproval(applications.get(OIDCUtilTest.playgroundAppTwoAppName));
testConsentApproval(applications.get(OIDCUtilTest.PLAYGROUND_APP_TWO_APP_NAME));
}

@Test(groups = "wso2.is", description = "Get access token for playground.apptwo", dependsOnMethods =
"testConsentApprovalFromRP2")
public void testGetAccessTokenFromRP2() throws Exception {

testGetAccessToken(applications.get(OIDCUtilTest.playgroundAppTwoAppName));
testGetAccessToken(applications.get(OIDCUtilTest.PLAYGROUND_APP_TWO_APP_NAME));
}

@Test(groups = "wso2.is", description = "Get user claim values for playground.apptwo", dependsOnMethods =
Expand Down Expand Up @@ -366,33 +366,33 @@ private void testUserClaims() throws Exception {
String email = ((org.json.simple.JSONObject) obj).get("email").toString();

EntityUtils.consume(response.getEntity());
Assert.assertEquals(OIDCUtilTest.email, email, "Incorrect email claim value");
Assert.assertEquals(OIDCUtilTest.EMAIL, email, "Incorrect email claim value");
}

protected void initUser() throws Exception {

user = new UserObject();
user.setUserName(OIDCUtilTest.username);
user.setPassword(OIDCUtilTest.password);
user.setName(new Name().givenName(OIDCUtilTest.firstName).familyName(OIDCUtilTest.lastName));
user.addEmail(new Email().value(OIDCUtilTest.email));
user.setUserName(OIDCUtilTest.USERNAME);
user.setPassword(OIDCUtilTest.PASSWORD);
user.setName(new Name().givenName(OIDCUtilTest.FIRST_NAME).familyName(OIDCUtilTest.LAST_NAME));
user.addEmail(new Email().value(OIDCUtilTest.EMAIL));
}

protected void initApplications() throws Exception {

OIDCApplication playgroundApp = new OIDCApplication(OIDCUtilTest.playgroundAppOneAppName,
OIDCUtilTest.playgroundAppOneAppCallBackUri);
playgroundApp.addRequiredClaim(OIDCUtilTest.emailClaimUri);
playgroundApp.addRequiredClaim(OIDCUtilTest.firstNameClaimUri);
playgroundApp.addRequiredClaim(OIDCUtilTest.lastNameClaimUri);
applications.put(OIDCUtilTest.playgroundAppOneAppName, playgroundApp);

playgroundApp = new OIDCApplication(OIDCUtilTest.playgroundAppTwoAppName,
OIDCUtilTest.playgroundAppTwoAppCallBackUri);
playgroundApp.addRequiredClaim(OIDCUtilTest.emailClaimUri);
playgroundApp.addRequiredClaim(OIDCUtilTest.firstNameClaimUri);
playgroundApp.addRequiredClaim(OIDCUtilTest.lastNameClaimUri);
applications.put(OIDCUtilTest.playgroundAppTwoAppName, playgroundApp);
OIDCApplication playgroundApp = new OIDCApplication(OIDCUtilTest.PLAYGROUND_APP_ONE_APP_NAME,
OIDCUtilTest.PLAYGROUND_APP_ONE_APP_CALL_BACK_URI);
playgroundApp.addRequiredClaim(OIDCUtilTest.EMAIL_CLAIM_URI);
playgroundApp.addRequiredClaim(OIDCUtilTest.FIRST_NAME_CLAIM_URI);
playgroundApp.addRequiredClaim(OIDCUtilTest.LAST_NAME_CLAIM_URI);
applications.put(OIDCUtilTest.PLAYGROUND_APP_ONE_APP_NAME, playgroundApp);

playgroundApp = new OIDCApplication(OIDCUtilTest.PLAYGROUND_APP_TWO_APP_NAME,
OIDCUtilTest.PLAYGROUND_APP_TWO_APP_CALL_BACK_URI);
playgroundApp.addRequiredClaim(OIDCUtilTest.EMAIL_CLAIM_URI);
playgroundApp.addRequiredClaim(OIDCUtilTest.FIRST_NAME_CLAIM_URI);
playgroundApp.addRequiredClaim(OIDCUtilTest.LAST_NAME_CLAIM_URI);
applications.put(OIDCUtilTest.PLAYGROUND_APP_TWO_APP_NAME, playgroundApp);
}

protected void createApplications() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.wso2.carbon.integration.common.utils.exceptions.AutomationUtilException;
import org.wso2.carbon.integration.common.utils.mgt.ServerConfigurationManager;
import org.wso2.identity.integration.test.oidc.bean.OIDCApplication;
import org.wso2.identity.integration.test.rest.api.user.common.model.UserObject;
import org.wso2.identity.integration.test.util.Utils;

import java.io.File;
Expand All @@ -49,6 +50,8 @@ public class OIDCFileBasedSkipLoginConsentTestCase extends OIDCAbstractIntegrati
protected Log log = LogFactory.getLog(getClass());
protected HttpClient client;
private CookieStore cookieStore = new BasicCookieStore();
private Map<String, OIDCApplication> applications;
private UserObject user;
protected String sessionDataKey;
protected String sessionDataKeyConsent;

Expand All @@ -59,10 +62,10 @@ public void testInit() throws Exception {
changeISConfiguration(SKIP_CONSENT_ENABLED_TOML);
// Re-initiating after the restart.
super.init(TestUserMode.SUPER_TENANT_ADMIN);
OIDCUtilTest.initUser();
createUser(OIDCUtilTest.user);
OIDCUtilTest.initApplications();
createApplications();
user = OIDCUtilTest.initUser();
createUser(user);
applications = OIDCUtilTest.initApplications();
createApplications(applications);
client = HttpClientBuilder.create().setDefaultCookieStore(cookieStore).build();
}

Expand All @@ -88,22 +91,22 @@ private void changeISConfiguration(String fileName) throws IOException,

private void deleteObjects() throws Exception {

deleteUser(OIDCUtilTest.user);
deleteApplications();
deleteUser(user);
deleteApplications(applications);
}

@Test(groups = "wso2.is", description = "Test authz endpoint before creating a valid session")
public void testCreateUserSession() throws Exception {

testSendAuthenticationRequest(OIDCUtilTest.applications.get(OIDCUtilTest.playgroundAppOneAppName), true, client,
testSendAuthenticationRequest(applications.get(OIDCUtilTest.PLAYGROUND_APP_ONE_APP_NAME), true, client,
cookieStore);
testAuthentication(OIDCUtilTest.applications.get(OIDCUtilTest.playgroundAppOneAppName));
testAuthentication(applications.get(OIDCUtilTest.PLAYGROUND_APP_ONE_APP_NAME));
}

@Test(groups = "wso2.is", description = "Initiate authentication request from playground.apptwo")
public void testIntiateLoginRequestForAlreadyLoggedUser() throws Exception {

testSendAuthenticationRequest(OIDCUtilTest.applications.get(OIDCUtilTest.playgroundAppTwoAppName), false, client,
testSendAuthenticationRequest(applications.get(OIDCUtilTest.PLAYGROUND_APP_TWO_APP_NAME), false, client,
cookieStore);
}

Expand All @@ -113,16 +116,16 @@ private void testAuthentication(OIDCApplication application) throws Exception {
EntityUtils.consume(response.getEntity());
}

private void createApplications() throws Exception {
private void createApplications(Map<String, OIDCApplication> applications) throws Exception {

for (Map.Entry<String, OIDCApplication> entry : OIDCUtilTest.applications.entrySet()) {
for (Map.Entry<String, OIDCApplication> entry : applications.entrySet()) {
createApplication(entry.getValue());
}
}

private void deleteApplications() throws Exception {
private void deleteApplications(Map<String, OIDCApplication> applications) throws Exception {

for (Map.Entry<String, OIDCApplication> entry : OIDCUtilTest.applications.entrySet()) {
for (Map.Entry<String, OIDCApplication> entry : applications.entrySet()) {
deleteApplication(entry.getValue());
}
}
Expand Down
Loading