From e0b51e41120f4f311747aa54666e8c67b9ea09d2 Mon Sep 17 00:00:00 2001 From: Arnab Dutta Date: Mon, 25 Mar 2024 23:05:27 +0530 Subject: [PATCH 1/4] fix: correcting test-cases involving selenium Signed-off-by: Arnab Dutta --- oxd-common/pom.xml | 34 +-- .../gluu/oxd/common/SeleniumTestUtils.java | 75 ++--- .../common/model/AuthenticationDetails.java | 110 ++++++++ .../client/api/DifferentAuthServerTest.java | 12 +- .../client/api/GetTokensByCodeTest.java | 45 ++- .../swagger/client/api/GetUserInfoTest.java | 16 +- .../java/io/swagger/client/api/TestUtils.java | 20 ++ oxd-server/pom.xml | 22 +- .../gluu/oxd/server/CheckAccessTokenTest.java | 8 +- .../org/gluu/oxd/server/CheckIdTokenTest.java | 8 +- .../oxd/server/DifferentAuthServerTest.java | 12 +- .../gluu/oxd/server/GetTokensByCodeTest.java | 145 +++++----- .../org/gluu/oxd/server/GetUserInfoTest.java | 13 +- .../org/gluu/oxd/server/RegisterSiteTest.java | 8 +- .../oxd/server/SpontaneousScopeAuthTest.java | 15 +- .../java/org/gluu/oxd/server/TestUtils.java | 16 ++ .../test/java/org/gluu/oxd/server/Tester.java | 6 +- oxd-server/src/test/resources/testng.xml | 257 +----------------- pom.xml | 35 +-- 19 files changed, 379 insertions(+), 478 deletions(-) create mode 100644 oxd-common/src/test/java/org/gluu/oxd/common/model/AuthenticationDetails.java create mode 100644 oxd-gen-client/src/test/java/io/swagger/client/api/TestUtils.java diff --git a/oxd-common/pom.xml b/oxd-common/pom.xml index a6545548d..98d098f34 100644 --- a/oxd-common/pom.xml +++ b/oxd-common/pom.xml @@ -161,32 +161,28 @@ org.seleniumhq.selenium selenium-java - - - org.seleniumhq.selenium - selenium-remote-driver + test + + + org.seleniumhq.selenium + selenium-api + + org.seleniumhq.selenium selenium-support - - - org.seleniumhq.selenium - selenium-common - 2.0b1 - - - org.seleniumhq.selenium - htmlunit-driver - - - net.sourceforge.htmlunit - htmlunit test + + + org.seleniumhq.selenium + selenium-api + + - net.sourceforge.htmlunit - htmlunit-cssparser + org.seleniumhq.selenium + htmlunit3-driver test diff --git a/oxd-common/src/test/java/org/gluu/oxd/common/SeleniumTestUtils.java b/oxd-common/src/test/java/org/gluu/oxd/common/SeleniumTestUtils.java index 81c967e28..6b0f42402 100644 --- a/oxd-common/src/test/java/org/gluu/oxd/common/SeleniumTestUtils.java +++ b/oxd-common/src/test/java/org/gluu/oxd/common/SeleniumTestUtils.java @@ -3,9 +3,12 @@ import org.apache.commons.collections.CollectionUtils; import org.gluu.oxauth.client.AuthorizationRequest; import org.gluu.oxauth.client.AuthorizationResponse; +import org.gluu.oxauth.model.common.AuthorizationMethod; import org.gluu.oxauth.model.common.Holder; +import org.gluu.oxauth.model.common.Prompt; import org.gluu.oxauth.model.common.ResponseType; import org.gluu.oxauth.model.util.Util; +import org.gluu.oxd.common.model.AuthenticationDetails; import org.openqa.selenium.*; import org.openqa.selenium.htmlunit.HtmlUnitDriver; import org.openqa.selenium.interactions.Actions; @@ -31,50 +34,57 @@ public class SeleniumTestUtils { private static int WAIT_OPERATION_TIMEOUT = 30; private static final Logger LOG = LoggerFactory.getLogger(SeleniumTestUtils.class); - public static AuthorizationResponse authorizeClient( - String opHost, String userId, String userSecret, String clientId, String redirectUrls, String state, String nonce, List responseTypes, List scopes) { + public static AuthorizationResponse authorizeClient(AuthenticationDetails authenticationDetails, List responseTypes, List scopes) { WebDriver driver = initWebDriver(true, true); - loginGluuServer(driver, opHost, userId, userSecret, clientId, redirectUrls, state, nonce, responseTypes, scopes); - AuthorizationResponse authorizationResponse = acceptAuthorization(driver); + AuthorizationResponse authorizationResponse = loginGluuServer(driver, authenticationDetails, responseTypes, scopes); + //AuthorizationResponse authorizationResponse = acceptAuthorization(driver); driver.quit(); return authorizationResponse; } - private static void loginGluuServer( - WebDriver driver, String opHost, String userId, String userSecret, String clientId, String redirectUrls, String state, String nonce, List responseTypes, List scopes) { + private static AuthorizationResponse loginGluuServer( + WebDriver driver, AuthenticationDetails authenticationDetails, List responseTypes, List scopes) { //navigate to opHost - driver.navigate().to(getAuthorizationUrl(opHost, clientId, redirectUrls, state, nonce, responseTypes, scopes)); + + String authzUrl = getAuthorizationUrl(authenticationDetails, responseTypes, scopes); + System.out.println(authzUrl); + driver.navigate().to(authzUrl); + //driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); Wait wait = new FluentWait(driver) .withTimeout(Duration.ofSeconds(WAIT_OPERATION_TIMEOUT)) .pollingEvery(Duration.ofMillis(500)) .ignoring(NoSuchElementException.class); - WebElement loginButton = wait.until(new Function() { + + WebElement allowButton = wait.until(new Function() { public WebElement apply(WebDriver d) { //System.out.println(d.getCurrentUrl()); //System.out.println(d.getPageSource()); - return d.findElement(By.id("loginButton")); + return d.findElement(By.id("authorizeForm:allowButton")); } }); + String authorizationResponseStr = driver.getCurrentUrl(); + // We have to use JavaScript because target is link with onclick + JavascriptExecutor jse = (JavascriptExecutor) driver; + jse.executeScript("scroll(0, 1000)"); - LOG.info("Login page loaded. The current url is: " + driver.getCurrentUrl()); - //username field - WebElement usernameElement = driver.findElement(By.id("username")); - usernameElement.sendKeys(userId); - //password field - WebElement passwordElement = driver.findElement(By.id("password")); - passwordElement.sendKeys(userSecret); - //click on login button + String previousURL = driver.getCurrentUrl(); - loginButton.click(); + Actions actions = new Actions(driver); + actions.click(allowButton).perform(); - driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); + authorizationResponseStr = driver.getCurrentUrl(); + AuthorizationResponse authorizationResponse = new AuthorizationResponse(authorizationResponseStr); + + LOG.info("Authorization Response url is: " + driver.getCurrentUrl()); + + return authorizationResponse; } - private static AuthorizationResponse acceptAuthorization(WebDriver driver) { + /*private static AuthorizationResponse acceptAuthorization(WebDriver driver) { String authorizationResponseStr = driver.getCurrentUrl(); AuthorizationResponse authorizationResponse = null; // Check for authorization form if client has no persistent authorization @@ -109,7 +119,7 @@ public WebElement apply(WebDriver d) { fail("The authorization form was expected to be shown."); } return authorizationResponse; - } + }*/ private static WebDriver initWebDriver(boolean enableJavascript, boolean cleanupCookies) { WebDriver currentDriver = new HtmlUnitDriver(); @@ -125,29 +135,26 @@ private static WebDriver initWebDriver(boolean enableJavascript, boolean cleanup return currentDriver; } - private static String getAuthorizationUrl(String opHost, String clientId, String redirectUrls, String state, String nonce, List responseTypes, List scopes) { + private static String getAuthorizationUrl(AuthenticationDetails authenticationDetails, List responseTypes, List scopes) { try { - if(CollectionUtils.isEmpty(responseTypes)) { + if (CollectionUtils.isEmpty(responseTypes)) { responseTypes = Lists.newArrayList("code", "id_token", "token"); } - if(CollectionUtils.isEmpty(scopes)) { + if (CollectionUtils.isEmpty(scopes)) { scopes = Lists.newArrayList("openid", "profile", "oxd", "uma_protection"); } List resTypes = responseTypes.stream().map(item -> ResponseType.fromString(item)).collect(Collectors.toList()); - AuthorizationRequest authorizationRequest = new AuthorizationRequest(resTypes, clientId, scopes, redirectUrls.split(" ")[0], nonce); + AuthorizationRequest authorizationRequest = new AuthorizationRequest(resTypes, authenticationDetails.getClientId(), scopes, authenticationDetails.getRedirectUrls().split(" ")[0], authenticationDetails.getNonce()); authorizationRequest.setResponseTypes(responseTypes.stream().map(item -> ResponseType.fromString(item)).collect(Collectors.toList())); - authorizationRequest.setState(state); + authorizationRequest.setState(authenticationDetails.getState()); + authorizationRequest.addCustomParameter("mail", authenticationDetails.getUserEmail()); + authorizationRequest.addCustomParameter("inum", authenticationDetails.getUserInum()); + authorizationRequest.getPrompts().add(Prompt.NONE); + authorizationRequest.setAuthorizationMethod(AuthorizationMethod.FORM_ENCODED_BODY_PARAMETER); - return URLDecoder.decode(opHost + "/oxauth/restv1/authorize?" +authorizationRequest.getQueryString(), Util.UTF8_STRING_ENCODING); + return URLDecoder.decode(authenticationDetails.getOpHost() + "/oxauth/restv1/authorize?" + authorizationRequest.getQueryString(), Util.UTF8_STRING_ENCODING); - /*return URLDecoder.decode(opHost + "/oxauth/restv1/authorize?" + - "response_type=code+id_token+token" + - "&state=" + state + - "&nonce=" + nonce + - "&client_id=" + clientId + - "&redirect_uri=" + redirectUrls.split(" ")[0] + - "&scope=openid+profile+oxd+uma_protection", Util.UTF8_STRING_ENCODING);*/ } catch (UnsupportedEncodingException ex) { fail("Failed to decode the authorization URL."); return null; diff --git a/oxd-common/src/test/java/org/gluu/oxd/common/model/AuthenticationDetails.java b/oxd-common/src/test/java/org/gluu/oxd/common/model/AuthenticationDetails.java new file mode 100644 index 000000000..24baae926 --- /dev/null +++ b/oxd-common/src/test/java/org/gluu/oxd/common/model/AuthenticationDetails.java @@ -0,0 +1,110 @@ +package org.gluu.oxd.common.model; + +public class AuthenticationDetails { + private String host; + private String opHost; + private String redirectUrls; + private String userId; + private String userSecret; + private String userInum; + private String userEmail; + private String state; + private String nonce; + private String clientId; + + public String getClientId() { + return clientId; + } + + public void setClientId(String clientId) { + this.clientId = clientId; + } + + public String getHost() { + return host; + } + + public void setHost(String host) { + this.host = host; + } + + public String getOpHost() { + return opHost; + } + + public void setOpHost(String opHost) { + this.opHost = opHost; + } + + public String getRedirectUrls() { + return redirectUrls; + } + + public void setRedirectUrls(String redirectUrls) { + this.redirectUrls = redirectUrls; + } + + public String getUserId() { + return userId; + } + + public void setUserId(String userId) { + this.userId = userId; + } + + public String getUserSecret() { + return userSecret; + } + + public void setUserSecret(String userSecret) { + this.userSecret = userSecret; + } + + public String getUserInum() { + return userInum; + } + + public void setUserInum(String userInum) { + this.userInum = userInum; + } + + public String getUserEmail() { + return userEmail; + } + + public void setUserEmail(String userEmail) { + this.userEmail = userEmail; + } + + public String getState() { + return state; + } + + public void setState(String state) { + this.state = state; + } + + public String getNonce() { + return nonce; + } + + public void setNonce(String nonce) { + this.nonce = nonce; + } + + @Override + public String toString() { + return "AuthenticationDetails{" + + "host='" + host + '\'' + + ", opHost='" + opHost + '\'' + + ", redirectUrls='" + redirectUrls + '\'' + + ", userId='" + userId + '\'' + + ", userSecret='" + userSecret + '\'' + + ", userInum='" + userInum + '\'' + + ", userEmail='" + userEmail + '\'' + + ", state='" + state + '\'' + + ", nonce='" + nonce + '\'' + + ", clientId='" + clientId + '\'' + + '}'; + } +} diff --git a/oxd-gen-client/src/test/java/io/swagger/client/api/DifferentAuthServerTest.java b/oxd-gen-client/src/test/java/io/swagger/client/api/DifferentAuthServerTest.java index 45754b969..12a86ed9f 100644 --- a/oxd-gen-client/src/test/java/io/swagger/client/api/DifferentAuthServerTest.java +++ b/oxd-gen-client/src/test/java/io/swagger/client/api/DifferentAuthServerTest.java @@ -4,6 +4,7 @@ import io.swagger.client.model.*; import org.apache.commons.lang.StringUtils; import org.gluu.oxd.common.CoreUtils; +import org.gluu.oxd.common.model.AuthenticationDetails; import org.testng.Assert; import org.testng.annotations.Parameters; import org.testng.annotations.Test; @@ -20,14 +21,15 @@ //Set `protect_commands_with_access_token` field to true in oxd-server.yml file public class DifferentAuthServerTest { - @Parameters({"opHost", "redirectUrls", "authServer", "userId", "userSecret"}) + @Parameters({"opHost", "redirectUrls", "authServer", "userId", "userSecret", "userInum", "userEmail"}) @Test(enabled = false) - public void getUserInfo_withDifferentAuthServer(String opHost, String redirectUrls, String authServer, String userId, String userSecret) throws Exception { + public void getUserInfo_withDifferentAuthServer(String opHost, String redirectUrls, String authServer, String userId, String userSecret, String userInum, String userEmail) throws Exception { final DevelopersApi client = api(); final io.swagger.client.model.RegisterSiteResponse site = RegisterSiteTest.registerSite(client, opHost, redirectUrls); final io.swagger.client.model.RegisterSiteResponse authServerResp = RegisterSiteTest.registerSite(client, authServer, redirectUrls); - final GetTokensByCodeResponse tokens = requestTokens(client, opHost, site, authServerResp, userId, userSecret, site.getClientId(), redirectUrls); + AuthenticationDetails authenticationDetails = TestUtils.setAuthenticationDetails(null, opHost, userId, userSecret, site.getClientId(), redirectUrls, CoreUtils.secureRandomString(), CoreUtils.secureRandomString(), userInum, userEmail); + final GetTokensByCodeResponse tokens = requestTokens(client, site, authServerResp, authenticationDetails); final io.swagger.client.model.GetUserInfoParams params = new GetUserInfoParams(); params.setOxdId(site.getOxdId()); @@ -92,14 +94,14 @@ public static UmaRsCheckAccessResponse checkAccess(DevelopersApi client, Registe return apiResp.getData(); } - private GetTokensByCodeResponse requestTokens(DevelopersApi client, String opHost, io.swagger.client.model.RegisterSiteResponse site, io.swagger.client.model.RegisterSiteResponse authServer, String userId, String userSecret, String clientId, String redirectUrls) throws Exception { + private GetTokensByCodeResponse requestTokens(DevelopersApi client, io.swagger.client.model.RegisterSiteResponse site, io.swagger.client.model.RegisterSiteResponse authServer, AuthenticationDetails authenticationDetails) throws Exception { final String state = CoreUtils.secureRandomString(); final String nonce = CoreUtils.secureRandomString(); final io.swagger.client.model.GetTokensByCodeParams params = new GetTokensByCodeParams(); params.setOxdId(site.getOxdId()); - params.setCode(GetTokensByCodeTest.codeRequest(client, opHost, site.getOxdId(), userId, userSecret, clientId, redirectUrls, state, nonce, getAuthorization(site))); + params.setCode(GetTokensByCodeTest.codeRequest(client, authenticationDetails, site.getOxdId(), getAuthorization(site))); params.setState(state); final GetTokensByCodeResponse resp = client.getTokensByCode(params, getAuthorization(authServer), authServer.getOxdId()); diff --git a/oxd-gen-client/src/test/java/io/swagger/client/api/GetTokensByCodeTest.java b/oxd-gen-client/src/test/java/io/swagger/client/api/GetTokensByCodeTest.java index 68d5f97a5..8c1405bb0 100644 --- a/oxd-gen-client/src/test/java/io/swagger/client/api/GetTokensByCodeTest.java +++ b/oxd-gen-client/src/test/java/io/swagger/client/api/GetTokensByCodeTest.java @@ -11,6 +11,7 @@ import org.gluu.oxauth.model.common.AuthenticationMethod; import org.gluu.oxd.common.CoreUtils; import org.gluu.oxd.common.SeleniumTestUtils; +import org.gluu.oxd.common.model.AuthenticationDetails; import org.testng.annotations.Parameters; import org.testng.annotations.Test; import org.testng.util.Strings; @@ -29,28 +30,28 @@ public class GetTokensByCodeTest { private static final String AUTH_CODE_ENDPOINT = "/get-authorization-code"; - @Parameters({"opHost", "redirectUrls", "userId", "userSecret"}) + @Parameters({"opHost", "redirectUrls", "userId", "userSecret", "userInum", "userEmail"}) @Test - public void test(String opHost, String redirectUrls, String userId, String userSecret) throws Exception { + public void test(String opHost, String redirectUrls, String userId, String userSecret, String userInum, String userEmail) throws Exception { DevelopersApi client = Tester.api(); final RegisterSiteResponse site = RegisterSiteTest.registerSite(client, opHost, redirectUrls); - - GetTokensByCodeResponse tokensResponse = tokenByCode(client, site, opHost, userId, userSecret, site.getClientId(), redirectUrls, CoreUtils.secureRandomString()); + AuthenticationDetails authenticationDetails = TestUtils.setAuthenticationDetails(null, opHost, userId, userSecret, site.getClientId(), redirectUrls, CoreUtils.secureRandomString(), CoreUtils.secureRandomString(), userInum, userEmail); + GetTokensByCodeResponse tokensResponse = tokenByCode(client, site, authenticationDetails); refreshToken(tokensResponse, client, site); } - @Parameters({"opHost", "redirectUrls", "userId", "userSecret"}) + @Parameters({"opHost", "redirectUrls", "userId", "userSecret", "userInum", "userEmail"}) @Test - public void withAuthenticationMethod_shouldGetTokenInResponse(String opHost, String redirectUrls, String userId, String userSecret) throws Exception { + public void withAuthenticationMethod_shouldGetTokenInResponse(String opHost, String redirectUrls, String userId, String userSecret, String userInum, String userEmail) throws Exception { DevelopersApi client = Tester.api(); final RegisterSiteResponse site = RegisterSiteTest.registerSite_withAuthenticationMethod(client, opHost, redirectUrls, redirectUrls, redirectUrls, "PS256", AuthenticationMethod.PRIVATE_KEY_JWT.toString()); - - GetTokensByCodeResponse tokensResponse = tokenByCode(client, site, opHost, userId, userSecret, site.getClientId(), redirectUrls, CoreUtils.secureRandomString(), AuthenticationMethod.PRIVATE_KEY_JWT.toString(), "PS256"); + AuthenticationDetails authenticationDetails = TestUtils.setAuthenticationDetails(null, opHost, userId, userSecret, site.getClientId(), redirectUrls, CoreUtils.secureRandomString(), CoreUtils.secureRandomString(), userInum, userEmail); + GetTokensByCodeResponse tokensResponse = tokenByCode(client, site, authenticationDetails, AuthenticationMethod.PRIVATE_KEY_JWT.toString(), "PS256"); } @@ -72,17 +73,17 @@ private static void refreshToken(GetTokensByCodeResponse resp, DevelopersApi cli notEmpty(refreshResponse.getRefreshToken()); } - private static GetTokensByCodeResponse tokenByCode(DevelopersApi client, RegisterSiteResponse site, String opHost, String userId, String userSecret, String clientId, String redirectUrls, String nonce) throws Exception { - return tokenByCode(client, site, opHost, userId, userSecret, clientId, redirectUrls, nonce, null, null); + private static GetTokensByCodeResponse tokenByCode(DevelopersApi client, RegisterSiteResponse site, AuthenticationDetails authenticationDetails) throws Exception { + return tokenByCode(client, site, authenticationDetails, null, null); } - private static GetTokensByCodeResponse tokenByCode(DevelopersApi client, RegisterSiteResponse site, String opHost, String userId, String userSecret, String clientId, String redirectUrls, String nonce, String authenticationMethod, String algorithm) throws Exception { + private static GetTokensByCodeResponse tokenByCode(DevelopersApi client, RegisterSiteResponse site, AuthenticationDetails authenticationDetails, String authenticationMethod, String algorithm) throws Exception { final String state = CoreUtils.secureRandomString(); - final RegisterSiteResponse authServer = RegisterSiteTest.registerSite(client, opHost, redirectUrls); + final RegisterSiteResponse authServer = RegisterSiteTest.registerSite(client, authenticationDetails.getOpHost(), authenticationDetails.getRedirectUrls()); final String authorizationStr = Tester.getAuthorization(authServer); - final String code = codeRequest(client, opHost, site.getOxdId(), userId, userSecret, clientId, redirectUrls, state, nonce, authorizationStr, authServer.getOxdId()); + final String code = codeRequest(client, authenticationDetails, site.getOxdId(), authorizationStr, authServer.getOxdId()); notEmpty(code); @@ -101,16 +102,14 @@ private static GetTokensByCodeResponse tokenByCode(DevelopersApi client, Registe return resp; } - public static String codeRequest(DevelopersApi client, String opHost, String oxdId, String userId, String userSecret, String clientId, String redirectUrls, String state, - String nonce, String authorization) throws Exception { - return codeRequest(client, opHost, oxdId, userId, userSecret, clientId, redirectUrls, state, nonce, authorization, null); + public static String codeRequest(DevelopersApi client, AuthenticationDetails authenticationDetails, String oxdId, String authorization) throws Exception { + return codeRequest(client, authenticationDetails, oxdId, authorization, null); } - public static String codeRequest(DevelopersApi client, String opHost, String oxdId, String userId, String userSecret, String clientId, String redirectUrls, String state, - String nonce, String authorization, String authorizationOxdId) throws Exception { - SeleniumTestUtils.authorizeClient(opHost, userId, userSecret, clientId, redirectUrls, state, nonce, null, null); + public static String codeRequest(DevelopersApi client, AuthenticationDetails authenticationDetails, String oxdId, String authorization, String authorizationOxdId) throws Exception { + SeleniumTestUtils.authorizeClient(authenticationDetails, null, null); - final Request request = buildRequest(authorization, authorizationOxdId, oxdId, userId, userSecret, state, nonce, client); + final Request request = buildRequest(authorization, authorizationOxdId, oxdId, authenticationDetails, client); final Response response = client.getApiClient().getHttpClient().newCall(request).execute(); @@ -120,10 +119,10 @@ public static String codeRequest(DevelopersApi client, String opHost, String oxd } - private static Request buildRequest(String authorization, String authorizationOxdId, String oxdId, String userId, String userSecret, String state, String nonce, DevelopersApi client) { + private static Request buildRequest(String authorization, String authorizationOxdId, String oxdId, AuthenticationDetails authenticationDetails, DevelopersApi client) { - final String json = "{\"oxd_id\":\"" + oxdId + "\",\"username\":\"" + userId + "\",\"password\":\"" + userSecret - + "\",\"state\":\"" + state + "\",\"nonce\":\"" + nonce + "\"}"; + final String json = "{\"oxd_id\":\"" + oxdId + "\",\"username\":\"" + authenticationDetails.getUserId() + "\",\"password\":\"" + authenticationDetails.getUserSecret() + + "\",\"state\":\"" + authenticationDetails.getState() + "\",\"nonce\":\"" + authenticationDetails.getNonce() + "\"}"; final RequestBody reqBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), json); diff --git a/oxd-gen-client/src/test/java/io/swagger/client/api/GetUserInfoTest.java b/oxd-gen-client/src/test/java/io/swagger/client/api/GetUserInfoTest.java index 3b9a9d214..0244b190d 100644 --- a/oxd-gen-client/src/test/java/io/swagger/client/api/GetUserInfoTest.java +++ b/oxd-gen-client/src/test/java/io/swagger/client/api/GetUserInfoTest.java @@ -6,6 +6,7 @@ import io.swagger.client.model.GetUserInfoParams; import io.swagger.client.model.RegisterSiteResponse; import org.gluu.oxd.common.CoreUtils; +import org.gluu.oxd.common.model.AuthenticationDetails; import org.testng.annotations.Parameters; import org.testng.annotations.Test; @@ -23,13 +24,14 @@ public class GetUserInfoTest { - @Parameters({"opHost", "redirectUrls", "userId", "userSecret"}) + @Parameters({"opHost", "redirectUrls", "userId", "userSecret", "userInum", "userEmail"}) @Test - public void test(String opHost, String redirectUrls, String userId, String userSecret) throws Exception { + public void test(String opHost, String redirectUrls, String userId, String userSecret, String userInum, String userEmail) throws Exception { final DevelopersApi client = api(); final RegisterSiteResponse site = RegisterSiteTest.registerSite(client, opHost, redirectUrls); - final GetTokensByCodeResponse tokens = requestTokens(client, opHost, site, userId, userSecret, site.getClientId(), redirectUrls); + AuthenticationDetails authenticationDetails = TestUtils.setAuthenticationDetails(null, opHost, userId, userSecret, site.getClientId(), redirectUrls, CoreUtils.secureRandomString(), CoreUtils.secureRandomString(), userInum, userEmail); + final GetTokensByCodeResponse tokens = requestTokens(client, site, authenticationDetails); final GetUserInfoParams params = new GetUserInfoParams(); params.setOxdId(site.getOxdId()); @@ -42,9 +44,9 @@ public void test(String opHost, String redirectUrls, String userId, String userS assertNotNull(resp.get("sub")); } - @Parameters({"opHost", "redirectUrls"}) + @Parameters({"opHost", "redirectUrls", "userInum", "userEmail"}) @Test - public void testWithInvalidToken(String opHost, String redirectUrls) throws Exception { + public void testWithInvalidToken(String opHost, String redirectUrls, String userInum, String userEmail) throws Exception { final DevelopersApi client = api(); final RegisterSiteResponse site = RegisterSiteTest.registerSite(client, opHost, redirectUrls); @@ -60,14 +62,14 @@ public void testWithInvalidToken(String opHost, String redirectUrls) throws Exce assertNull(apiResponse.getData().get("sub")); } - private GetTokensByCodeResponse requestTokens(DevelopersApi client, String opHost, RegisterSiteResponse site, String userId, String userSecret, String clientId, String redirectUrls) throws Exception { + private GetTokensByCodeResponse requestTokens(DevelopersApi client, RegisterSiteResponse site, AuthenticationDetails authenticationDetails) throws Exception { final String state = CoreUtils.secureRandomString(); final String nonce = CoreUtils.secureRandomString(); final GetTokensByCodeParams params = new GetTokensByCodeParams(); params.setOxdId(site.getOxdId()); - params.setCode(GetTokensByCodeTest.codeRequest(client, opHost, site.getOxdId(), userId, userSecret, clientId, redirectUrls, state, nonce, getAuthorization(site))); + params.setCode(GetTokensByCodeTest.codeRequest(client, authenticationDetails, site.getOxdId(), getAuthorization(site))); params.setState(state); final GetTokensByCodeResponse resp = client.getTokensByCode(params, getAuthorization(site), null); diff --git a/oxd-gen-client/src/test/java/io/swagger/client/api/TestUtils.java b/oxd-gen-client/src/test/java/io/swagger/client/api/TestUtils.java new file mode 100644 index 000000000..1db931be2 --- /dev/null +++ b/oxd-gen-client/src/test/java/io/swagger/client/api/TestUtils.java @@ -0,0 +1,20 @@ +package io.swagger.client.api; + +import org.gluu.oxd.common.model.AuthenticationDetails; + +public class TestUtils { + public static AuthenticationDetails setAuthenticationDetails(String host, String opHost, String userId, String userSecret, String clientId, String redirectUrls, String nonce, String state, String userInum, String userEmail) { + AuthenticationDetails authenticationDetails = new AuthenticationDetails(); + authenticationDetails.setHost(host); + authenticationDetails.setNonce(nonce); + authenticationDetails.setOpHost(opHost); + authenticationDetails.setRedirectUrls(redirectUrls); + authenticationDetails.setState(state); + authenticationDetails.setUserId(userId); + authenticationDetails.setUserInum(userInum); + authenticationDetails.setClientId(clientId); + authenticationDetails.setUserSecret(userSecret); + authenticationDetails.setUserEmail(userEmail); + return authenticationDetails; + } +} diff --git a/oxd-server/pom.xml b/oxd-server/pom.xml index 4f5f05139..363bfb495 100644 --- a/oxd-server/pom.xml +++ b/oxd-server/pom.xml @@ -639,12 +639,12 @@ org.seleniumhq.selenium - selenium-remote-driver + selenium-java test - com.squareup.okio - okio + org.seleniumhq.selenium + selenium-api @@ -654,24 +654,14 @@ test - com.squareup.okio - okio + org.seleniumhq.selenium + selenium-api org.seleniumhq.selenium - htmlunit-driver - test - - - net.sourceforge.htmlunit - htmlunit - test - - - net.sourceforge.htmlunit - htmlunit-cssparser + htmlunit3-driver test diff --git a/oxd-server/src/test/java/org/gluu/oxd/server/CheckAccessTokenTest.java b/oxd-server/src/test/java/org/gluu/oxd/server/CheckAccessTokenTest.java index 3388529c0..83697deaf 100644 --- a/oxd-server/src/test/java/org/gluu/oxd/server/CheckAccessTokenTest.java +++ b/oxd-server/src/test/java/org/gluu/oxd/server/CheckAccessTokenTest.java @@ -3,6 +3,7 @@ import org.gluu.oxd.client.ClientInterface; import org.gluu.oxd.client.GetTokensByCodeResponse2; import org.gluu.oxd.common.CoreUtils; +import org.gluu.oxd.common.model.AuthenticationDetails; import org.gluu.oxd.common.params.CheckAccessTokenParams; import org.gluu.oxd.common.response.CheckAccessTokenResponse; import org.gluu.oxd.common.response.RegisterSiteResponse; @@ -18,15 +19,16 @@ */ public class CheckAccessTokenTest { - @Parameters({"host", "redirectUrls", "userId", "userSecret", "opHost"}) + @Parameters({"host", "redirectUrls", "userId", "userSecret", "opHost", "userInum", "userEmail"}) @Test - public void test(String host, String redirectUrls, String userId, String userSecret, String opHost) { + public void test(String host, String redirectUrls, String userId, String userSecret, String opHost, String userInum, String userEmail) { ClientInterface client = Tester.newClient(host); String nonce = CoreUtils.secureRandomString(); String state = CoreUtils.secureRandomString(); RegisterSiteResponse site = RegisterSiteTest.registerSite(client, opHost, redirectUrls); - GetTokensByCodeResponse2 response = GetTokensByCodeTest.tokenByCode(client, site, opHost, userId, userSecret, site.getClientId(), redirectUrls, nonce, state); + AuthenticationDetails authenticationDetails = TestUtils.setAuthenticationDetails(host, opHost, userId, userSecret, site.getClientId(), redirectUrls, nonce, state, userInum, userEmail); + GetTokensByCodeResponse2 response = GetTokensByCodeTest.tokenByCode(client, site, authenticationDetails); final CheckAccessTokenParams params = new CheckAccessTokenParams(); params.setAccessToken(response.getAccessToken()); diff --git a/oxd-server/src/test/java/org/gluu/oxd/server/CheckIdTokenTest.java b/oxd-server/src/test/java/org/gluu/oxd/server/CheckIdTokenTest.java index 69a921e57..489b91c6e 100644 --- a/oxd-server/src/test/java/org/gluu/oxd/server/CheckIdTokenTest.java +++ b/oxd-server/src/test/java/org/gluu/oxd/server/CheckIdTokenTest.java @@ -3,6 +3,7 @@ import org.gluu.oxd.client.ClientInterface; import org.gluu.oxd.client.GetTokensByCodeResponse2; import org.gluu.oxd.common.CoreUtils; +import org.gluu.oxd.common.model.AuthenticationDetails; import org.gluu.oxd.common.params.CheckIdTokenParams; import org.gluu.oxd.common.response.CheckIdTokenResponse; import org.gluu.oxd.common.response.RegisterSiteResponse; @@ -22,15 +23,16 @@ public class CheckIdTokenTest { - @Parameters({"host", "opHost", "redirectUrls", "userId", "userSecret"}) + @Parameters({"host", "opHost", "redirectUrls", "userId", "userSecret", "userInum", "userEmail"}) @Test - public void test(String host, String opHost, String redirectUrls, String userId, String userSecret) { + public void test(String host, String opHost, String redirectUrls, String userId, String userSecret, String userInum, String userEmail) { ClientInterface client = Tester.newClient(host); RegisterSiteResponse site = RegisterSiteTest.registerSite(client, opHost, redirectUrls); String state = CoreUtils.secureRandomString(); String nonce = CoreUtils.secureRandomString(); - GetTokensByCodeResponse2 response = GetTokensByCodeTest.tokenByCode(client, site, opHost, userId, userSecret, site.getClientId(), redirectUrls, nonce, state); + AuthenticationDetails authenticationDetails = TestUtils.setAuthenticationDetails(host, opHost, userId, userSecret, site.getClientId(), redirectUrls, nonce, state, userInum, userEmail); + GetTokensByCodeResponse2 response = GetTokensByCodeTest.tokenByCode(client, site, authenticationDetails); final CheckIdTokenParams params = new CheckIdTokenParams(); params.setOxdId(site.getOxdId()); diff --git a/oxd-server/src/test/java/org/gluu/oxd/server/DifferentAuthServerTest.java b/oxd-server/src/test/java/org/gluu/oxd/server/DifferentAuthServerTest.java index cbc2a9925..66282cec2 100644 --- a/oxd-server/src/test/java/org/gluu/oxd/server/DifferentAuthServerTest.java +++ b/oxd-server/src/test/java/org/gluu/oxd/server/DifferentAuthServerTest.java @@ -5,6 +5,7 @@ import org.gluu.oxd.client.ClientInterface; import org.gluu.oxd.client.GetTokensByCodeResponse2; import org.gluu.oxd.common.CoreUtils; +import org.gluu.oxd.common.model.AuthenticationDetails; import org.gluu.oxd.common.params.GetTokensByCodeParams; import org.gluu.oxd.common.params.GetUserInfoParams; import org.gluu.oxd.common.params.RpGetRptParams; @@ -22,15 +23,16 @@ //Set `protect_commands_with_access_token` field to true in oxd-server.yml file public class DifferentAuthServerTest { - @Parameters({"host", "opHost", "authServer", "redirectUrls", "clientId", "clientSecret", "userId", "userSecret"}) + @Parameters({"host", "opHost", "authServer", "redirectUrls", "clientId", "clientSecret", "userId", "userSecret", "userInum", "userEmail"}) @Test - public void getUserInfo_withDifferentAuthServer(String host, String opHost, String authServer, String redirectUrls, String clientId, String clientSecret, String userId, String userSecret) { + public void getUserInfo_withDifferentAuthServer(String host, String opHost, String authServer, String redirectUrls, String clientId, String clientSecret, String userId, String userSecret, String userInum, String userEmail) { ClientInterface client = org.gluu.oxd.server.Tester.newClient(host); RegisterSiteResponse site = RegisterSiteTest.registerSite(client, opHost, redirectUrls); + AuthenticationDetails authenticationDetails = io.swagger.client.api.TestUtils.setAuthenticationDetails(null, opHost, userId, userSecret, site.getClientId(), redirectUrls, CoreUtils.secureRandomString(), CoreUtils.secureRandomString(), userInum, userEmail); RegisterSiteResponse authServerResp = RegisterSiteTest.registerSite(client, authServer, redirectUrls); - final GetTokensByCodeResponse2 tokens = requestTokens(client, opHost, site, authServerResp, userId, userSecret, site.getClientId(), redirectUrls); + final GetTokensByCodeResponse2 tokens = requestTokens(client, site, authServerResp, authenticationDetails); GetUserInfoParams params = new GetUserInfoParams(); params.setOxdId(site.getOxdId()); @@ -66,13 +68,13 @@ public void umaFullTest_withDifferentAuthServer(String host, String authServer, assertTrue(StringUtils.isNotBlank(response.getPct())); } - private GetTokensByCodeResponse2 requestTokens(ClientInterface client, String opHost, RegisterSiteResponse site, RegisterSiteResponse authServer, String userId, String userSecret, String clientId, String redirectUrls) { + private GetTokensByCodeResponse2 requestTokens(ClientInterface client, RegisterSiteResponse site, RegisterSiteResponse authServer, AuthenticationDetails authServerResp) { final String state = CoreUtils.secureRandomString(); final String nonce = CoreUtils.secureRandomString(); final GetTokensByCodeParams params = new GetTokensByCodeParams(); params.setOxdId(site.getOxdId()); - params.setCode(GetTokensByCodeTest.codeRequest(client, opHost, site, userId, userSecret, clientId, redirectUrls, state, nonce)); + params.setCode(GetTokensByCodeTest.codeRequest(client, site, authServerResp)); params.setState(state); final GetTokensByCodeResponse2 resp = client.getTokenByCode(Tester.getAuthorization(authServer), authServer.getOxdId(), params); diff --git a/oxd-server/src/test/java/org/gluu/oxd/server/GetTokensByCodeTest.java b/oxd-server/src/test/java/org/gluu/oxd/server/GetTokensByCodeTest.java index cb6919070..1bb080052 100644 --- a/oxd-server/src/test/java/org/gluu/oxd/server/GetTokensByCodeTest.java +++ b/oxd-server/src/test/java/org/gluu/oxd/server/GetTokensByCodeTest.java @@ -9,6 +9,7 @@ import org.gluu.oxd.client.GetTokensByCodeResponse2; import org.gluu.oxd.common.CoreUtils; import org.gluu.oxd.common.SeleniumTestUtils; +import org.gluu.oxd.common.model.AuthenticationDetails; import org.gluu.oxd.common.params.GetAccessTokenByRefreshTokenParams; import org.gluu.oxd.common.params.GetAuthorizationCodeParams; import org.gluu.oxd.common.params.GetTokensByCodeParams; @@ -30,140 +31,156 @@ public class GetTokensByCodeTest { - @Parameters({"host", "opHost", "redirectUrls", "userId", "userSecret"}) + @Parameters({"host", "opHost", "redirectUrls", "userId", "userSecret", "userInum", "userEmail"}) @Test - public void whenValidCodeIsUsed_shouldGetTokenInResponse(String host, String opHost, String redirectUrls, String userId, String userSecret) { + public void whenValidCodeIsUsed_shouldGetTokenInResponse(String host, String opHost, String redirectUrls, String userId, String userSecret, String userInum, String userEmail) { ClientInterface client = Tester.newClient(host); final RegisterSiteResponse site = RegisterSiteTest.registerSite(client, opHost, redirectUrls); - GetTokensByCodeResponse2 tokensResponse = tokenByCode(client, site, opHost, userId, userSecret, site.getClientId(), redirectUrls, CoreUtils.secureRandomString(), CoreUtils.secureRandomString()); + AuthenticationDetails authenticationDetails = TestUtils.setAuthenticationDetails(host, opHost, userId, userSecret, site.getClientId(), redirectUrls, CoreUtils.secureRandomString(), CoreUtils.secureRandomString(), userInum, userEmail); + GetTokensByCodeResponse2 tokensResponse = tokenByCode(client, site, authenticationDetails); refreshToken(tokensResponse, client, site); } - @Parameters({"host", "opHost", "redirectUrls", "userId", "userSecret"}) + @Parameters({"host", "opHost", "redirectUrls", "userId", "userSecret", "userInum", "userEmail"}) @Test - public void withbase64urlencodeState_shouldGetTokenInResponse(String host, String opHost, String redirectUrls, String userId, String userSecret) throws Exception{ + public void withbase64urlencodeState_shouldGetTokenInResponse(String host, String opHost, String redirectUrls, String userId, String userSecret, String userInum, String userEmail) throws Exception{ ClientInterface client = Tester.newClient(host); final RegisterSiteResponse site = RegisterSiteTest.registerSite(client, opHost, redirectUrls); String state = Base64.encodeBase64String(Util.getBytes("https://www.gluu,org")); - GetTokensByCodeResponse2 tokensResponse = tokenByCode(client, site, opHost, userId, userSecret, site.getClientId(), redirectUrls, CoreUtils.secureRandomString(), state); + AuthenticationDetails authenticationDetails = TestUtils.setAuthenticationDetails(host, opHost, userId, userSecret, site.getClientId(), redirectUrls, CoreUtils.secureRandomString(), CoreUtils.secureRandomString(), userInum, userEmail); + GetTokensByCodeResponse2 tokensResponse = tokenByCode(client, site, authenticationDetails); refreshToken(tokensResponse, client, site); } - @Parameters({"host", "opHost", "redirectUrls", "userId", "userSecret"}) + @Parameters({"host", "opHost", "redirectUrls", "userId", "userSecret", "userInum", "userEmail"}) @Test - public void withAuthenticationMethod_shouldGetTokenInResponse(String host, String opHost, String redirectUrls, String userId, String userSecret) { + public void withAuthenticationMethod_shouldGetTokenInResponse(String host, String opHost, String redirectUrls, String userId, String userSecret, String userInum, String userEmail) { ClientInterface client = Tester.newClient(host); final RegisterSiteResponse site = RegisterSiteTest.registerSite_withAuthenticationMethod(client, opHost, redirectUrls, "PS256", AuthenticationMethod.PRIVATE_KEY_JWT.toString()); - GetTokensByCodeResponse2 tokensResponse = tokenByCode(client, site, opHost, userId, userSecret, site.getClientId(), redirectUrls, CoreUtils.secureRandomString(), CoreUtils.secureRandomString(), AuthenticationMethod.PRIVATE_KEY_JWT.toString(), "PS256"); + AuthenticationDetails authenticationDetails = TestUtils.setAuthenticationDetails(host, opHost, userId, userSecret, site.getClientId(), redirectUrls, CoreUtils.secureRandomString(), CoreUtils.secureRandomString(), userInum, userEmail); + GetTokensByCodeResponse2 tokensResponse = tokenByCode(client, site, authenticationDetails); } - @Parameters({"host", "opHost", "redirectUrls", "userId", "userSecret"}) + @Parameters({"host", "opHost", "redirectUrls", "userId", "userSecret", "userInum", "userEmail"}) @Test - public void getToken_withHS256(String host, String opHost, String redirectUrls, String userId, String userSecret) { + public void getToken_withHS256(String host, String opHost, String redirectUrls, String userId, String userSecret, String userInum, String userEmail) { ClientInterface client = Tester.newClient(host); final RegisterSiteResponse site = RegisterSiteTest.registerSite(client, opHost, redirectUrls, "HS256"); - GetTokensByCodeResponse2 tokensResponse = tokenByCode(client, site, opHost, userId, userSecret, site.getClientId(), redirectUrls, CoreUtils.secureRandomString(), CoreUtils.secureRandomString()); + AuthenticationDetails authenticationDetails = TestUtils.setAuthenticationDetails(host, opHost, userId, userSecret, site.getClientId(), redirectUrls, CoreUtils.secureRandomString(), CoreUtils.secureRandomString(), userInum, userEmail); + GetTokensByCodeResponse2 tokensResponse = tokenByCode(client, site, authenticationDetails); } - @Parameters({"host", "opHost", "redirectUrls", "userId", "userSecret"}) + @Parameters({"host", "opHost", "redirectUrls", "userId", "userSecret", "userInum", "userEmail"}) @Test - public void getToken_withHS384(String host, String opHost, String redirectUrls, String userId, String userSecret) { + public void getToken_withHS384(String host, String opHost, String redirectUrls, String userId, String userSecret, String userInum, String userEmail) { ClientInterface client = Tester.newClient(host); final RegisterSiteResponse site = RegisterSiteTest.registerSite(client, opHost, redirectUrls, "HS384"); - GetTokensByCodeResponse2 tokensResponse = tokenByCode(client, site, opHost, userId, userSecret, site.getClientId(), redirectUrls, CoreUtils.secureRandomString(), CoreUtils.secureRandomString()); + AuthenticationDetails authenticationDetails = TestUtils.setAuthenticationDetails(host, opHost, userId, userSecret, site.getClientId(), redirectUrls, CoreUtils.secureRandomString(), CoreUtils.secureRandomString(), userInum, userEmail); + GetTokensByCodeResponse2 tokensResponse = tokenByCode(client, site, authenticationDetails); } - @Parameters({"host", "opHost", "redirectUrls", "userId", "userSecret"}) + @Parameters({"host", "opHost", "redirectUrls", "userId", "userSecret", "userInum", "userEmail"}) @Test - public void getToken_withHS512(String host, String opHost, String redirectUrls, String userId, String userSecret) { + public void getToken_withHS512(String host, String opHost, String redirectUrls, String userId, String userSecret, String userInum, String userEmail) { ClientInterface client = Tester.newClient(host); final RegisterSiteResponse site = RegisterSiteTest.registerSite(client, opHost, redirectUrls, "HS512"); - GetTokensByCodeResponse2 tokensResponse = tokenByCode(client, site, opHost, userId, userSecret, site.getClientId(), redirectUrls, CoreUtils.secureRandomString(), CoreUtils.secureRandomString()); + AuthenticationDetails authenticationDetails = TestUtils.setAuthenticationDetails(host, opHost, userId, userSecret, site.getClientId(), redirectUrls, CoreUtils.secureRandomString(), CoreUtils.secureRandomString(), userInum, userEmail); + GetTokensByCodeResponse2 tokensResponse = tokenByCode(client, site, authenticationDetails); } - @Parameters({"host", "opHost", "redirectUrls", "userId", "userSecret"}) + @Parameters({"host", "opHost", "redirectUrls", "userId", "userSecret", "userInum", "userEmail"}) @Test - public void getToken_withRS256(String host, String opHost, String redirectUrls, String userId, String userSecret) { + public void getToken_withRS256(String host, String opHost, String redirectUrls, String userId, String userSecret, String userInum, String userEmail) { ClientInterface client = Tester.newClient(host); final RegisterSiteResponse site = RegisterSiteTest.registerSite(client, opHost, redirectUrls, "RS256"); - GetTokensByCodeResponse2 tokensResponse = tokenByCode(client, site, opHost, userId, userSecret, site.getClientId(), redirectUrls, CoreUtils.secureRandomString(), CoreUtils.secureRandomString()); + AuthenticationDetails authenticationDetails = TestUtils.setAuthenticationDetails(host, opHost, userId, userSecret, site.getClientId(), redirectUrls, CoreUtils.secureRandomString(), CoreUtils.secureRandomString(), userInum, userEmail); + GetTokensByCodeResponse2 tokensResponse = tokenByCode(client, site, authenticationDetails); } - @Parameters({"host", "opHost", "redirectUrls", "userId", "userSecret"}) + @Parameters({"host", "opHost", "redirectUrls", "userId", "userSecret", "userInum", "userEmail"}) @Test - public void getToken_withRS384(String host, String opHost, String redirectUrls, String userId, String userSecret) { + public void getToken_withRS384(String host, String opHost, String redirectUrls, String userId, String userSecret, String userInum, String userEmail) { ClientInterface client = Tester.newClient(host); final RegisterSiteResponse site = RegisterSiteTest.registerSite(client, opHost, redirectUrls, "RS384"); - GetTokensByCodeResponse2 tokensResponse = tokenByCode(client, site, opHost, userId, userSecret, site.getClientId(), redirectUrls, CoreUtils.secureRandomString(), CoreUtils.secureRandomString()); + AuthenticationDetails authenticationDetails = TestUtils.setAuthenticationDetails(host, opHost, userId, userSecret, site.getClientId(), redirectUrls, CoreUtils.secureRandomString(), CoreUtils.secureRandomString(), userInum, userEmail); + GetTokensByCodeResponse2 tokensResponse = tokenByCode(client, site, authenticationDetails); } - @Parameters({"host", "opHost", "redirectUrls", "userId", "userSecret"}) + @Parameters({"host", "opHost", "redirectUrls", "userId", "userSecret", "userInum", "userEmail"}) @Test - public void getToken_withRS512(String host, String opHost, String redirectUrls, String userId, String userSecret) { + public void getToken_withRS512(String host, String opHost, String redirectUrls, String userId, String userSecret, String userInum, String userEmail) { ClientInterface client = Tester.newClient(host); final RegisterSiteResponse site = RegisterSiteTest.registerSite(client, opHost, redirectUrls, "RS512"); - GetTokensByCodeResponse2 tokensResponse = tokenByCode(client, site, opHost, userId, userSecret, site.getClientId(), redirectUrls, CoreUtils.secureRandomString(), CoreUtils.secureRandomString()); + AuthenticationDetails authenticationDetails = TestUtils.setAuthenticationDetails(host, opHost, userId, userSecret, site.getClientId(), redirectUrls, CoreUtils.secureRandomString(), CoreUtils.secureRandomString(), userInum, userEmail); + GetTokensByCodeResponse2 tokensResponse = tokenByCode(client, site, authenticationDetails); } - @Parameters({"host", "opHost", "redirectUrls", "userId", "userSecret"}) + @Parameters({"host", "opHost", "redirectUrls", "userId", "userSecret", "userInum", "userEmail"}) @Test - public void getToken_withES256(String host, String opHost, String redirectUrls, String userId, String userSecret) { + public void getToken_withES256(String host, String opHost, String redirectUrls, String userId, String userSecret, String userInum, String userEmail) { ClientInterface client = Tester.newClient(host); final RegisterSiteResponse site = RegisterSiteTest.registerSite(client, opHost, redirectUrls, "ES256"); - GetTokensByCodeResponse2 tokensResponse = tokenByCode(client, site, opHost, userId, userSecret, site.getClientId(), redirectUrls, CoreUtils.secureRandomString(), CoreUtils.secureRandomString()); + AuthenticationDetails authenticationDetails = TestUtils.setAuthenticationDetails(host, opHost, userId, userSecret, site.getClientId(), redirectUrls, CoreUtils.secureRandomString(), CoreUtils.secureRandomString(), userInum, userEmail); + GetTokensByCodeResponse2 tokensResponse = tokenByCode(client, site, authenticationDetails); } - @Parameters({"host", "opHost", "redirectUrls", "userId", "userSecret"}) + @Parameters({"host", "opHost", "redirectUrls", "userId", "userSecret", "userInum", "userEmail"}) @Test - public void getToken_withES384(String host, String opHost, String redirectUrls, String userId, String userSecret) { + public void getToken_withES384(String host, String opHost, String redirectUrls, String userId, String userSecret, String userInum, String userEmail) { ClientInterface client = Tester.newClient(host); final RegisterSiteResponse site = RegisterSiteTest.registerSite(client, opHost, redirectUrls, "ES384"); - GetTokensByCodeResponse2 tokensResponse = tokenByCode(client, site, opHost, userId, userSecret, site.getClientId(), redirectUrls, CoreUtils.secureRandomString(), CoreUtils.secureRandomString()); + AuthenticationDetails authenticationDetails = TestUtils.setAuthenticationDetails(host, opHost, userId, userSecret, site.getClientId(), redirectUrls, CoreUtils.secureRandomString(), CoreUtils.secureRandomString(), userInum, userEmail); + GetTokensByCodeResponse2 tokensResponse = tokenByCode(client, site, authenticationDetails); } - @Parameters({"host", "opHost", "redirectUrls", "userId", "userSecret"}) + @Parameters({"host", "opHost", "redirectUrls", "userId", "userSecret", "userInum", "userEmail"}) @Test - public void getToken_withES512(String host, String opHost, String redirectUrls, String userId, String userSecret) { + public void getToken_withES512(String host, String opHost, String redirectUrls, String userId, String userSecret, String userInum, String userEmail) { ClientInterface client = Tester.newClient(host); final RegisterSiteResponse site = RegisterSiteTest.registerSite(client, opHost, redirectUrls, "ES512"); - GetTokensByCodeResponse2 tokensResponse = tokenByCode(client, site, opHost, userId, userSecret, site.getClientId(), redirectUrls, CoreUtils.secureRandomString(), CoreUtils.secureRandomString()); + AuthenticationDetails authenticationDetails = TestUtils.setAuthenticationDetails(host, opHost, userId, userSecret, site.getClientId(), redirectUrls, CoreUtils.secureRandomString(), CoreUtils.secureRandomString(), userInum, userEmail); + GetTokensByCodeResponse2 tokensResponse = tokenByCode(client, site, authenticationDetails); } - @Parameters({"host", "opHost", "redirectUrls", "userId", "userSecret"}) + @Parameters({"host", "opHost", "redirectUrls", "userId", "userSecret", "userInum", "userEmail"}) @Test - public void getToken_withPS256(String host, String opHost, String redirectUrls, String userId, String userSecret) { + public void getToken_withPS256(String host, String opHost, String redirectUrls, String userId, String userSecret, String userInum, String userEmail) { ClientInterface client = Tester.newClient(host); final RegisterSiteResponse site = RegisterSiteTest.registerSite(client, opHost, redirectUrls, "PS256"); - GetTokensByCodeResponse2 tokensResponse = tokenByCode(client, site, opHost, userId, userSecret, site.getClientId(), redirectUrls, CoreUtils.secureRandomString(), CoreUtils.secureRandomString()); + AuthenticationDetails authenticationDetails = TestUtils.setAuthenticationDetails(host, opHost, userId, userSecret, site.getClientId(), redirectUrls, CoreUtils.secureRandomString(), CoreUtils.secureRandomString(), userInum, userEmail); + GetTokensByCodeResponse2 tokensResponse = tokenByCode(client, site, authenticationDetails); } - @Parameters({"host", "opHost", "redirectUrls", "userId", "userSecret"}) + @Parameters({"host", "opHost", "redirectUrls", "userId", "userSecret", "userInum", "userEmail"}) @Test - public void getToken_withPS384(String host, String opHost, String redirectUrls, String userId, String userSecret) { + public void getToken_withPS384(String host, String opHost, String redirectUrls, String userId, String userSecret, String userInum, String userEmail) { ClientInterface client = Tester.newClient(host); final RegisterSiteResponse site = RegisterSiteTest.registerSite(client, opHost, redirectUrls, "PS384"); - GetTokensByCodeResponse2 tokensResponse = tokenByCode(client, site, opHost, userId, userSecret, site.getClientId(), redirectUrls, CoreUtils.secureRandomString(), CoreUtils.secureRandomString()); + AuthenticationDetails authenticationDetails = TestUtils.setAuthenticationDetails(host, opHost, userId, userSecret, site.getClientId(), redirectUrls, CoreUtils.secureRandomString(), CoreUtils.secureRandomString(), userInum, userEmail); + GetTokensByCodeResponse2 tokensResponse = tokenByCode(client, site, authenticationDetails); } - @Parameters({"host", "opHost", "redirectUrls", "userId", "userSecret"}) + @Parameters({"host", "opHost", "redirectUrls", "userId", "userSecret", "userInum", "userEmail"}) @Test - public void getToken_withPS512(String host, String opHost, String redirectUrls, String userId, String userSecret) { + public void getToken_withPS512(String host, String opHost, String redirectUrls, String userId, String userSecret, String userInum, String userEmail) { ClientInterface client = Tester.newClient(host); final RegisterSiteResponse site = RegisterSiteTest.registerSite(client, opHost, redirectUrls, "PS512"); - GetTokensByCodeResponse2 tokensResponse = tokenByCode(client, site, opHost, userId, userSecret, site.getClientId(), redirectUrls, CoreUtils.secureRandomString(), CoreUtils.secureRandomString()); + AuthenticationDetails authenticationDetails = TestUtils.setAuthenticationDetails(host, opHost, userId, userSecret, site.getClientId(), redirectUrls, CoreUtils.secureRandomString(), CoreUtils.secureRandomString(), userInum, userEmail); + GetTokensByCodeResponse2 tokensResponse = tokenByCode(client, site, authenticationDetails); } - @Parameters({"host", "opHost", "redirectUrls", "userId", "userSecret"}) + @Parameters({"host", "opHost", "redirectUrls", "userId", "userSecret", "userInum", "userEmail"}) @Test - public void getToken_withNoneAlgo(String host, String opHost, String redirectUrls, String userId, String userSecret) { + public void getToken_withNoneAlgo(String host, String opHost, String redirectUrls, String userId, String userSecret, String userInum, String userEmail) { ClientInterface client = Tester.newClient(host); final RegisterSiteResponse site = RegisterSiteTest.registerSite(client, opHost, redirectUrls, "none"); - GetTokensByCodeResponse2 tokensResponse = tokenByCode(client, site, opHost, userId, userSecret, site.getClientId(), redirectUrls, CoreUtils.secureRandomString(), CoreUtils.secureRandomString()); + AuthenticationDetails authenticationDetails = TestUtils.setAuthenticationDetails(host, opHost, userId, userSecret, site.getClientId(), redirectUrls, CoreUtils.secureRandomString(), CoreUtils.secureRandomString(), userInum, userEmail); + GetTokensByCodeResponse2 tokensResponse = tokenByCode(client, site, authenticationDetails); } - @Parameters({"host", "opHost", "redirectUrls", "userId", "userSecret"}) + @Parameters({"host", "opHost", "redirectUrls", "userId", "userSecret", "userInum", "userEmail"}) @Test - public void whenInvalidCodeIsUsed_shouldGet400BadRequest(String host, String opHost, String redirectUrls, String userId, String userSecret) { + public void whenInvalidCodeIsUsed_shouldGet400BadRequest(String host, String opHost, String redirectUrls, String userId, String userSecret, String userInum, String userEmail) { ClientInterface client = Tester.newClient(host); final RegisterSiteResponse site = RegisterSiteTest.registerSite(client, opHost, redirectUrls); tokenByInvalidCode(client, site, userId, userSecret, CoreUtils.secureRandomString()); @@ -186,24 +203,24 @@ public static GetClientTokenResponse refreshToken(GetTokensByCodeResponse2 resp, return refreshResponse; } - public static GetTokensByCodeResponse2 tokenByCode(ClientInterface client, RegisterSiteResponse site, String opHost, String userId, String userSecret, String clientId, String redirectUrls, String nonce, String state) { - return tokenByCode(client, site, opHost, userId, userSecret, clientId, redirectUrls, nonce, state, null, null); + public static GetTokensByCodeResponse2 tokenByCode(ClientInterface client, RegisterSiteResponse site, AuthenticationDetails authenticationDetails) { + return tokenByCode(client, site, authenticationDetails, null, null); } - public static GetTokensByCodeResponse2 tokenByCode(ClientInterface client, RegisterSiteResponse site, String opHost, String userId, String userSecret, String clientId, String redirectUrls, String nonce, String state, String authenticationMethod, String algorithm) { + public static GetTokensByCodeResponse2 tokenByCode(ClientInterface client, RegisterSiteResponse site, AuthenticationDetails authenticationDetails, String authenticationMethod, String algorithm) { - RegisterSiteResponse authServer = RegisterSiteTest.registerSite(client, opHost, redirectUrls); + RegisterSiteResponse authServer = RegisterSiteTest.registerSite(client, authenticationDetails.getOpHost(), authenticationDetails.getRedirectUrls()); String accessToken = Tester.getAuthorization(authServer); String authorizationOxdId = authServer.getOxdId(); - String code = codeRequest(client, opHost, site, userId, userSecret, clientId, redirectUrls, state, nonce, accessToken, authorizationOxdId); + String code = codeRequest(client, site, authenticationDetails, accessToken, authorizationOxdId); notEmpty(code); final GetTokensByCodeParams params = new GetTokensByCodeParams(); params.setOxdId(site.getOxdId()); params.setCode(code); - params.setState(state); + params.setState(authenticationDetails.getState()); params.setAuthenticationMethod(authenticationMethod); params.setAlgorithm(algorithm); @@ -245,18 +262,18 @@ public static GetTokensByCodeResponse2 tokenByInvalidCode(ClientInterface client return resp; } - public static String codeRequest(ClientInterface client, String opHost, RegisterSiteResponse site, String userId, String userSecret, String clientId, String redirectUrls, String state, String nonce) { - return codeRequest(client, opHost, site, userId, userSecret, clientId, redirectUrls, state, nonce, null, null); + public static String codeRequest(ClientInterface client,RegisterSiteResponse site, AuthenticationDetails authenticationDetails) { + return codeRequest(client, site, authenticationDetails, null, null); } - public static String codeRequest(ClientInterface client, String opHost, RegisterSiteResponse site, String userId, String userSecret, String clientId, String redirectUrls, String state, String nonce, String accessToken, String authorizationOxdId) { - SeleniumTestUtils.authorizeClient(opHost, userId, userSecret, clientId, redirectUrls, state, nonce, null, null); + public static String codeRequest(ClientInterface client, RegisterSiteResponse site, AuthenticationDetails authenticationDetails, String accessToken, String authorizationOxdId) { + SeleniumTestUtils.authorizeClient(authenticationDetails, null, null); GetAuthorizationCodeParams params = new GetAuthorizationCodeParams(); params.setOxdId(site.getOxdId()); - params.setUsername(userId); - params.setPassword(userSecret); - params.setState(state); - params.setNonce(nonce); + params.setUsername(authenticationDetails.getUserId()); + params.setPassword(authenticationDetails.getUserSecret()); + params.setState(authenticationDetails.getState()); + params.setNonce(authenticationDetails.getNonce()); accessToken = Strings.isNullOrEmpty(accessToken) ? Tester.getAuthorization(site) : accessToken; return client.getAuthorizationCode(accessToken, authorizationOxdId, params).getCode(); diff --git a/oxd-server/src/test/java/org/gluu/oxd/server/GetUserInfoTest.java b/oxd-server/src/test/java/org/gluu/oxd/server/GetUserInfoTest.java index 7b25ff379..489791981 100644 --- a/oxd-server/src/test/java/org/gluu/oxd/server/GetUserInfoTest.java +++ b/oxd-server/src/test/java/org/gluu/oxd/server/GetUserInfoTest.java @@ -4,6 +4,7 @@ import org.gluu.oxd.client.ClientInterface; import org.gluu.oxd.client.GetTokensByCodeResponse2; import org.gluu.oxd.common.CoreUtils; +import org.gluu.oxd.common.model.AuthenticationDetails; import org.gluu.oxd.common.params.GetTokensByCodeParams; import org.gluu.oxd.common.params.GetUserInfoParams; import org.gluu.oxd.common.response.RegisterSiteResponse; @@ -20,13 +21,14 @@ public class GetUserInfoTest { - @Parameters({"host", "opHost", "redirectUrls", "userId", "userSecret"}) + @Parameters({"host", "opHost", "redirectUrls", "userId", "userSecret", "userInum", "userEmail"}) @Test - public void test(String host, String opHost, String redirectUrls, String userId, String userSecret) { + public void test(String host, String opHost, String redirectUrls, String userId, String userSecret, String userInum, String userEmail) { ClientInterface client = Tester.newClient(host); final RegisterSiteResponse site = RegisterSiteTest.registerSite(client, opHost, redirectUrls); - final GetTokensByCodeResponse2 tokens = requestTokens(client, opHost, site, userId, userSecret, site.getClientId(), redirectUrls); + AuthenticationDetails authenticationDetails = TestUtils.setAuthenticationDetails(host, opHost, userId, userSecret, site.getClientId(), redirectUrls, CoreUtils.secureRandomString(), CoreUtils.secureRandomString(), userInum, userEmail); + final GetTokensByCodeResponse2 tokens = requestTokens(client, site, authenticationDetails); GetUserInfoParams params = new GetUserInfoParams(); params.setOxdId(site.getOxdId()); @@ -38,13 +40,14 @@ public void test(String host, String opHost, String redirectUrls, String userId, assertNotNull(resp.get("sub")); } - private GetTokensByCodeResponse2 requestTokens(ClientInterface client, String opHost, RegisterSiteResponse site, String userId, String userSecret, String clientId, String redirectUrls) { + private GetTokensByCodeResponse2 requestTokens(ClientInterface client, RegisterSiteResponse site, AuthenticationDetails authenticationDetails) { final String state = CoreUtils.secureRandomString(); final String nonce = CoreUtils.secureRandomString(); final GetTokensByCodeParams params = new GetTokensByCodeParams(); params.setOxdId(site.getOxdId()); - params.setCode(GetTokensByCodeTest.codeRequest(client, opHost, site, userId, userSecret, clientId, redirectUrls, state, nonce)); + + params.setCode(GetTokensByCodeTest.codeRequest(client, site, authenticationDetails)); params.setState(state); final GetTokensByCodeResponse2 resp = client.getTokenByCode(Tester.getAuthorization(site), null, params); diff --git a/oxd-server/src/test/java/org/gluu/oxd/server/RegisterSiteTest.java b/oxd-server/src/test/java/org/gluu/oxd/server/RegisterSiteTest.java index 5bf8cbad1..af392c786 100644 --- a/oxd-server/src/test/java/org/gluu/oxd/server/RegisterSiteTest.java +++ b/oxd-server/src/test/java/org/gluu/oxd/server/RegisterSiteTest.java @@ -2,6 +2,7 @@ import com.google.common.base.Strings; import com.google.common.collect.Lists; +import org.gluu.oxauth.model.common.AuthenticationMethod; import org.gluu.oxauth.model.common.GrantType; import org.gluu.oxd.client.ClientInterface; import org.gluu.oxd.common.params.RegisterSiteParams; @@ -180,6 +181,7 @@ public static RegisterSiteResponse registerSite(ClientInterface client, String o params.setGrantTypes(Lists.newArrayList( GrantType.AUTHORIZATION_CODE.getValue(), GrantType.OXAUTH_UMA_TICKET.getValue(), + GrantType.IMPLICIT.getValue(), GrantType.CLIENT_CREDENTIALS.getValue())); params.setSyncClientFromOp(syncClientFromOp); params.setSyncClientPeriodInSeconds(0); @@ -200,9 +202,11 @@ public static RegisterSiteResponse registerSite(ClientInterface client, String o params.setIdTokenSignedResponseAlg(idTokenSignedResponseAlg); params.setGrantTypes(Lists.newArrayList( GrantType.AUTHORIZATION_CODE.getValue(), + GrantType.CLIENT_CREDENTIALS.getValue(), GrantType.OXAUTH_UMA_TICKET.getValue(), - GrantType.CLIENT_CREDENTIALS.getValue())); - + GrantType.CLIENT_CREDENTIALS.getValue(), + GrantType.IMPLICIT.getValue())); + params.setClientTokenEndpointAuthMethod("client_secret_post"); final RegisterSiteResponse resp = client.registerSite(params); assertNotNull(resp); assertTrue(!Strings.isNullOrEmpty(resp.getOxdId())); diff --git a/oxd-server/src/test/java/org/gluu/oxd/server/SpontaneousScopeAuthTest.java b/oxd-server/src/test/java/org/gluu/oxd/server/SpontaneousScopeAuthTest.java index bbb82d1ab..6f9130669 100644 --- a/oxd-server/src/test/java/org/gluu/oxd/server/SpontaneousScopeAuthTest.java +++ b/oxd-server/src/test/java/org/gluu/oxd/server/SpontaneousScopeAuthTest.java @@ -3,7 +3,9 @@ import com.google.common.collect.Lists; import org.gluu.oxauth.client.AuthorizationResponse; import org.gluu.oxd.client.ClientInterface; +import org.gluu.oxd.common.CoreUtils; import org.gluu.oxd.common.SeleniumTestUtils; +import org.gluu.oxd.common.model.AuthenticationDetails; import org.gluu.oxd.common.response.RegisterSiteResponse; import org.testng.annotations.Parameters; import org.testng.annotations.Test; @@ -16,9 +18,9 @@ public class SpontaneousScopeAuthTest { - @Parameters({"host", "opHost", "paramRedirectUrl", "userId", "userSecret"}) + @Parameters({"host", "opHost", "paramRedirectUrl", "userId", "userSecret", "userInum", "userEmail"}) @Test - public void spontaneousScope(String host, String opHost, String paramRedirectUrl, String userId, String userSecret) throws Exception { + public void spontaneousScope(String host, String opHost, String paramRedirectUrl, String userId, String userSecret, String userInum, String userEmail) throws Exception { List spontaneousScopes = Lists.newArrayList("^transaction:.+$"); List responseTypes = Lists.newArrayList("code", "id_token", "token"); @@ -29,8 +31,8 @@ public void spontaneousScope(String host, String opHost, String paramRedirectUrl // Request authorization and receive the authorization code. List scopesWithSpontanious = Lists.newArrayList("openid", "profile", "address", "email", "phone", "user_name", "transaction:245", "transaction:8645"); - - AuthorizationResponse authorizationResponse = requestAuthorization(opHost, userId, userSecret, paramRedirectUrl, responseTypes, scopesWithSpontanious, registerResponse.getClientId()); + AuthenticationDetails authenticationDetails = TestUtils.setAuthenticationDetails(host, opHost, userId, userSecret, registerResponse.getClientId(), paramRedirectUrl, CoreUtils.secureRandomString(), CoreUtils.secureRandomString(), userInum, userEmail); + AuthorizationResponse authorizationResponse = requestAuthorization(authenticationDetails, responseTypes, scopesWithSpontanious); final String[] responseScopes = authorizationResponse.getScope().split(" "); @@ -54,11 +56,10 @@ private RegisterSiteResponse registerClient(String host, String opHost, String r return registerResponse; } - private AuthorizationResponse requestAuthorization(final String opHost, final String userId, final String userSecret, final String redirectUri, - List responseTypes, List scopesWithSpontanious, String clientId) { + private AuthorizationResponse requestAuthorization(AuthenticationDetails authenticationDetails, List responseTypes, List scopesWithSpontanious) { String state = UUID.randomUUID().toString(); String nonce = UUID.randomUUID().toString(); - AuthorizationResponse authorizationResponse = SeleniumTestUtils.authorizeClient(opHost, userId, userSecret, clientId, redirectUri, state, nonce, responseTypes, scopesWithSpontanious); + AuthorizationResponse authorizationResponse = SeleniumTestUtils.authorizeClient(authenticationDetails, responseTypes, scopesWithSpontanious); assertNotNull(authorizationResponse.getLocation(), "The location is null"); assertNotNull(authorizationResponse.getCode(), "The authorization code is null"); diff --git a/oxd-server/src/test/java/org/gluu/oxd/server/TestUtils.java b/oxd-server/src/test/java/org/gluu/oxd/server/TestUtils.java index fd3450e31..18df6196a 100644 --- a/oxd-server/src/test/java/org/gluu/oxd/server/TestUtils.java +++ b/oxd-server/src/test/java/org/gluu/oxd/server/TestUtils.java @@ -9,6 +9,7 @@ import org.apache.commons.lang.StringUtils; import org.gluu.oxd.common.ErrorResponse; import org.gluu.oxd.common.Jackson2; +import org.gluu.oxd.common.model.AuthenticationDetails; import javax.ws.rs.WebApplicationException; import java.io.File; @@ -62,4 +63,19 @@ public static OxdServerConfiguration parseConfiguration(String pathToYaml) throw ConfigurationFactory configurationFactory = configurationFactoryFactory.create(OxdServerConfiguration.class, Validators.newValidatorFactory().getValidator(), Jackson.newObjectMapper(), "dw"); return configurationFactory.build(file); } + + public static AuthenticationDetails setAuthenticationDetails(String host, String opHost, String userId, String userSecret, String clientId, String redirectUrls, String nonce, String state, String userInum, String userEmail) { + AuthenticationDetails authenticationDetails = new AuthenticationDetails(); + authenticationDetails.setHost(host); + authenticationDetails.setNonce(nonce); + authenticationDetails.setOpHost(opHost); + authenticationDetails.setRedirectUrls(redirectUrls); + authenticationDetails.setState(state); + authenticationDetails.setUserId(userId); + authenticationDetails.setUserInum(userInum); + authenticationDetails.setClientId(clientId); + authenticationDetails.setUserSecret(userSecret); + authenticationDetails.setUserEmail(userEmail); + return authenticationDetails; + } } diff --git a/oxd-server/src/test/java/org/gluu/oxd/server/Tester.java b/oxd-server/src/test/java/org/gluu/oxd/server/Tester.java index 3891cb33e..6672c44b0 100644 --- a/oxd-server/src/test/java/org/gluu/oxd/server/Tester.java +++ b/oxd-server/src/test/java/org/gluu/oxd/server/Tester.java @@ -66,7 +66,11 @@ public static String getAuthorization(RegisterSiteResponse site) { params.setOpHost(site.getOpHost()); params.setClientId(site.getClientId()); params.setClientSecret(site.getClientSecret()); - + System.out.println("========================================================"+site.getOpHost()); + System.out.println("========================================================"+site.getClientId()); + System.out.println("========================================================"+site.getClientSecret()); + System.out.println("========================================================"+HOST); + System.out.println("========================================================"+params.toString()); GetClientTokenResponse resp = Tester.newClient(HOST).getClientToken(params); assertNotNull(resp); assertTrue(!Strings.isNullOrEmpty(resp.getAccessToken())); diff --git a/oxd-server/src/test/resources/testng.xml b/oxd-server/src/test/resources/testng.xml index 951898ac3..96f152cad 100644 --- a/oxd-server/src/test/resources/testng.xml +++ b/oxd-server/src/test/resources/testng.xml @@ -5,6 +5,8 @@ + + @@ -95,259 +97,4 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/pom.xml b/pom.xml index 2b9d4ed8c..cd84d7e48 100644 --- a/pom.xml +++ b/pom.xml @@ -218,44 +218,21 @@ - org.seleniumhq.selenium - selenium-java - ${selenium.version} + junit + junit + 4.13.2 test org.seleniumhq.selenium - selenium-remote-driver - ${selenium.version} - - - org.seleniumhq.selenium - selenium-support + selenium-java 3.141.59 test - - net.sourceforge.htmlunit - htmlunit-cssparser - 1.14.0 - test - org.seleniumhq.selenium - htmlunit-driver - 2.52.0 - test - - - net.sourceforge.htmlunit - htmlunit - - - - - net.sourceforge.htmlunit - htmlunit - 2.52.0 + selenium-support + 3.141.59 test From 13a9f14c05081148ee8220552d616d1ab333fa46 Mon Sep 17 00:00:00 2001 From: Arnab Dutta Date: Mon, 25 Mar 2024 23:15:03 +0530 Subject: [PATCH 2/4] fix: correcting test-cases involving selenium Signed-off-by: Arnab Dutta --- oxd-server/src/test/resources/testng.xml | 255 +++++++++++++++++++++++ 1 file changed, 255 insertions(+) diff --git a/oxd-server/src/test/resources/testng.xml b/oxd-server/src/test/resources/testng.xml index 96f152cad..9d1e7badd 100644 --- a/oxd-server/src/test/resources/testng.xml +++ b/oxd-server/src/test/resources/testng.xml @@ -97,4 +97,259 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From dd9502c5fbc3f1ee6dd9df3ea62c5f30a2bfb993 Mon Sep 17 00:00:00 2001 From: Arnab Dutta Date: Mon, 25 Mar 2024 23:31:38 +0530 Subject: [PATCH 3/4] fix: correcting test-cases involving selenium Signed-off-by: Arnab Dutta --- .../test/java/io/swagger/client/api/GetTokensByCodeTest.java | 3 +-- .../src/test/java/io/swagger/client/api/GetUserInfoTest.java | 5 +---- .../java/org/gluu/oxd/server/DifferentAuthServerTest.java | 4 +--- .../src/test/java/org/gluu/oxd/server/GetUserInfoTest.java | 4 +--- 4 files changed, 4 insertions(+), 12 deletions(-) diff --git a/oxd-gen-client/src/test/java/io/swagger/client/api/GetTokensByCodeTest.java b/oxd-gen-client/src/test/java/io/swagger/client/api/GetTokensByCodeTest.java index 8c1405bb0..ae6e9298f 100644 --- a/oxd-gen-client/src/test/java/io/swagger/client/api/GetTokensByCodeTest.java +++ b/oxd-gen-client/src/test/java/io/swagger/client/api/GetTokensByCodeTest.java @@ -79,7 +79,6 @@ private static GetTokensByCodeResponse tokenByCode(DevelopersApi client, Registe private static GetTokensByCodeResponse tokenByCode(DevelopersApi client, RegisterSiteResponse site, AuthenticationDetails authenticationDetails, String authenticationMethod, String algorithm) throws Exception { - final String state = CoreUtils.secureRandomString(); final RegisterSiteResponse authServer = RegisterSiteTest.registerSite(client, authenticationDetails.getOpHost(), authenticationDetails.getRedirectUrls()); final String authorizationStr = Tester.getAuthorization(authServer); @@ -90,7 +89,7 @@ private static GetTokensByCodeResponse tokenByCode(DevelopersApi client, Registe final GetTokensByCodeParams params = new GetTokensByCodeParams(); params.setOxdId(site.getOxdId()); params.setCode(code); - params.setState(state); + params.setState(authenticationDetails.getState()); params.setAuthenticationMethod(authenticationMethod); params.setAlgorithm(algorithm); diff --git a/oxd-gen-client/src/test/java/io/swagger/client/api/GetUserInfoTest.java b/oxd-gen-client/src/test/java/io/swagger/client/api/GetUserInfoTest.java index 0244b190d..e1e13d2fe 100644 --- a/oxd-gen-client/src/test/java/io/swagger/client/api/GetUserInfoTest.java +++ b/oxd-gen-client/src/test/java/io/swagger/client/api/GetUserInfoTest.java @@ -64,13 +64,10 @@ public void testWithInvalidToken(String opHost, String redirectUrls, String user private GetTokensByCodeResponse requestTokens(DevelopersApi client, RegisterSiteResponse site, AuthenticationDetails authenticationDetails) throws Exception { - final String state = CoreUtils.secureRandomString(); - final String nonce = CoreUtils.secureRandomString(); - final GetTokensByCodeParams params = new GetTokensByCodeParams(); params.setOxdId(site.getOxdId()); params.setCode(GetTokensByCodeTest.codeRequest(client, authenticationDetails, site.getOxdId(), getAuthorization(site))); - params.setState(state); + params.setState(authenticationDetails.getState()); final GetTokensByCodeResponse resp = client.getTokensByCode(params, getAuthorization(site), null); assertNotNull(resp); diff --git a/oxd-server/src/test/java/org/gluu/oxd/server/DifferentAuthServerTest.java b/oxd-server/src/test/java/org/gluu/oxd/server/DifferentAuthServerTest.java index 66282cec2..d5db972c6 100644 --- a/oxd-server/src/test/java/org/gluu/oxd/server/DifferentAuthServerTest.java +++ b/oxd-server/src/test/java/org/gluu/oxd/server/DifferentAuthServerTest.java @@ -70,12 +70,10 @@ public void umaFullTest_withDifferentAuthServer(String host, String authServer, private GetTokensByCodeResponse2 requestTokens(ClientInterface client, RegisterSiteResponse site, RegisterSiteResponse authServer, AuthenticationDetails authServerResp) { - final String state = CoreUtils.secureRandomString(); - final String nonce = CoreUtils.secureRandomString(); final GetTokensByCodeParams params = new GetTokensByCodeParams(); params.setOxdId(site.getOxdId()); params.setCode(GetTokensByCodeTest.codeRequest(client, site, authServerResp)); - params.setState(state); + params.setState(authServerResp.getState()); final GetTokensByCodeResponse2 resp = client.getTokenByCode(Tester.getAuthorization(authServer), authServer.getOxdId(), params); assertNotNull(resp); diff --git a/oxd-server/src/test/java/org/gluu/oxd/server/GetUserInfoTest.java b/oxd-server/src/test/java/org/gluu/oxd/server/GetUserInfoTest.java index 489791981..319ff63af 100644 --- a/oxd-server/src/test/java/org/gluu/oxd/server/GetUserInfoTest.java +++ b/oxd-server/src/test/java/org/gluu/oxd/server/GetUserInfoTest.java @@ -42,13 +42,11 @@ public void test(String host, String opHost, String redirectUrls, String userId, private GetTokensByCodeResponse2 requestTokens(ClientInterface client, RegisterSiteResponse site, AuthenticationDetails authenticationDetails) { - final String state = CoreUtils.secureRandomString(); - final String nonce = CoreUtils.secureRandomString(); final GetTokensByCodeParams params = new GetTokensByCodeParams(); params.setOxdId(site.getOxdId()); params.setCode(GetTokensByCodeTest.codeRequest(client, site, authenticationDetails)); - params.setState(state); + params.setState(authenticationDetails.getState()); final GetTokensByCodeResponse2 resp = client.getTokenByCode(Tester.getAuthorization(site), null, params); assertNotNull(resp); From c52d3373d4d8ad09ab599625f20f9f84b56b9ba2 Mon Sep 17 00:00:00 2001 From: Arnab Dutta Date: Mon, 25 Mar 2024 23:40:45 +0530 Subject: [PATCH 4/4] fix: correcting test-cases involving selenium Signed-off-by: Arnab Dutta --- .../gluu/oxd/common/SeleniumTestUtils.java | 38 ------------------- .../test/java/org/gluu/oxd/server/Tester.java | 5 --- 2 files changed, 43 deletions(-) diff --git a/oxd-common/src/test/java/org/gluu/oxd/common/SeleniumTestUtils.java b/oxd-common/src/test/java/org/gluu/oxd/common/SeleniumTestUtils.java index 6b0f42402..3a4f2aeaa 100644 --- a/oxd-common/src/test/java/org/gluu/oxd/common/SeleniumTestUtils.java +++ b/oxd-common/src/test/java/org/gluu/oxd/common/SeleniumTestUtils.java @@ -49,7 +49,6 @@ private static AuthorizationResponse loginGluuServer( //navigate to opHost String authzUrl = getAuthorizationUrl(authenticationDetails, responseTypes, scopes); - System.out.println(authzUrl); driver.navigate().to(authzUrl); //driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); @@ -84,43 +83,6 @@ public WebElement apply(WebDriver d) { } - /*private static AuthorizationResponse acceptAuthorization(WebDriver driver) { - String authorizationResponseStr = driver.getCurrentUrl(); - AuthorizationResponse authorizationResponse = null; - // Check for authorization form if client has no persistent authorization - if (!authorizationResponseStr.contains("#")) { - Wait wait = new FluentWait(driver) - .withTimeout(Duration.ofSeconds(WAIT_OPERATION_TIMEOUT)) - .pollingEvery(Duration.ofMillis(500)) - .ignoring(NoSuchElementException.class); - - WebElement allowButton = wait.until(new Function() { - public WebElement apply(WebDriver d) { - //System.out.println(d.getCurrentUrl()); - //System.out.println(d.getPageSource()); - return d.findElement(By.id("authorizeForm:allowButton")); - } - }); - - // We have to use JavaScript because target is link with onclick - JavascriptExecutor jse = (JavascriptExecutor) driver; - jse.executeScript("scroll(0, 1000)"); - - String previousURL = driver.getCurrentUrl(); - - Actions actions = new Actions(driver); - actions.click(allowButton).perform(); - - authorizationResponseStr = driver.getCurrentUrl(); - authorizationResponse = new AuthorizationResponse(authorizationResponseStr); - - LOG.info("Authorization Response url is: " + driver.getCurrentUrl()); - } else { - fail("The authorization form was expected to be shown."); - } - return authorizationResponse; - }*/ - private static WebDriver initWebDriver(boolean enableJavascript, boolean cleanupCookies) { WebDriver currentDriver = new HtmlUnitDriver(); ((HtmlUnitDriver) currentDriver).setJavascriptEnabled(enableJavascript); diff --git a/oxd-server/src/test/java/org/gluu/oxd/server/Tester.java b/oxd-server/src/test/java/org/gluu/oxd/server/Tester.java index 6672c44b0..16131dbdf 100644 --- a/oxd-server/src/test/java/org/gluu/oxd/server/Tester.java +++ b/oxd-server/src/test/java/org/gluu/oxd/server/Tester.java @@ -66,11 +66,6 @@ public static String getAuthorization(RegisterSiteResponse site) { params.setOpHost(site.getOpHost()); params.setClientId(site.getClientId()); params.setClientSecret(site.getClientSecret()); - System.out.println("========================================================"+site.getOpHost()); - System.out.println("========================================================"+site.getClientId()); - System.out.println("========================================================"+site.getClientSecret()); - System.out.println("========================================================"+HOST); - System.out.println("========================================================"+params.toString()); GetClientTokenResponse resp = Tester.newClient(HOST).getClientToken(params); assertNotNull(resp); assertTrue(!Strings.isNullOrEmpty(resp.getAccessToken()));