mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-11-13 22:15:26 +00:00
Merge branch 'master' into permission-vertical
Conflicts: java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/server/SailingServiceImpl.java java/com.sap.sse.security.userstore.mongodb/src/com/sap/sse/security/userstore/mongodb/impl/MongoObjectFactoryImpl.java
This commit is contained in:
commit
b9a2e73899
19 files changed
+232
-47
No files matched your search
@@ -41,7 +41,7 @@
|
||||
-->
|
||||
<system-properties>
|
||||
<system-property>
|
||||
<name>webdriver.enable.native.events </name>
|
||||
<name>webdriver.enable.native.events</name>
|
||||
<value>true</value>
|
||||
</system-property>
|
||||
<!--
|
||||
|
||||
+24
-11
@@ -4,6 +4,7 @@ import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Files;
|
||||
@@ -13,6 +14,9 @@ import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.json.JSONTokener;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.rules.TestWatcher;
|
||||
@@ -60,7 +64,9 @@ public abstract class AbstractSeleniumTest {
|
||||
|
||||
private static final String CLEAR_STATE_URL = "sailingserver/test-support/clearState"; //$NON-NLS-1$
|
||||
|
||||
private static final String LOGIN_URL = "security/api/restsecurity/login";
|
||||
private static final String OBTAIN_ACCESS_TOKEN_URL = "security/api/restsecurity/access_token";
|
||||
|
||||
private static final String CREATE_SESSION_URL = "sailingserver/test-support/createSession";
|
||||
|
||||
private static final int CLEAR_STATE_SUCCESFUL_STATUS_CODE = 204;
|
||||
|
||||
@@ -121,9 +127,13 @@ public abstract class AbstractSeleniumTest {
|
||||
protected void setUpAuthenticatedSession(WebDriver webDriver) {
|
||||
// To be able to set a cookie we need to load a page having the target origin
|
||||
webDriver.get(getContextRoot());
|
||||
|
||||
logger.info("Authenticating session...");
|
||||
Cookie sessionCookie = authenticate(getContextRoot());
|
||||
Cookie sessionCookie;
|
||||
try {
|
||||
sessionCookie = authenticate(getContextRoot());
|
||||
} catch (JSONException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
webDriver.get(getContextRoot() + "index.html"); // initialize web driver so setting a cookie for the local domain is possible
|
||||
final Cookie cookieWithoutDomain = new Cookie(sessionCookie.getName(), sessionCookie.getValue(), null, sessionCookie.getPath(), sessionCookie.getExpiry(), sessionCookie.isSecure(), sessionCookie.isHttpOnly());
|
||||
webDriver.manage().addCookie(cookieWithoutDomain);
|
||||
@@ -147,20 +157,23 @@ public abstract class AbstractSeleniumTest {
|
||||
* @return the cookie that represents the authenticated session or <code>null</code> if the session
|
||||
* couldn't successfully be authenticated
|
||||
*/
|
||||
protected Cookie authenticate(String contextRoot) {
|
||||
protected Cookie authenticate(String contextRoot) throws JSONException {
|
||||
try {
|
||||
Cookie result = null;
|
||||
URL url = new URL(contextRoot + LOGIN_URL);
|
||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||
connection.setInstanceFollowRedirects(false);
|
||||
URL accessTokenUrl = new URL(contextRoot + OBTAIN_ACCESS_TOKEN_URL);
|
||||
HttpURLConnection connection = (HttpURLConnection) accessTokenUrl.openConnection();
|
||||
connection.setRequestMethod("POST");
|
||||
connection.setDoOutput(true);
|
||||
connection.connect();
|
||||
connection.getOutputStream().write("username=admin&password=admin".getBytes());
|
||||
if (connection.getResponseCode() / 100 != 3) { // expecting something like "302 Found" which redirects to the success page
|
||||
throw new RuntimeException("" + connection.getResponseCode() + " "+connection.getResponseMessage());
|
||||
}
|
||||
List<String> cookies = connection.getHeaderFields().get("Set-Cookie");
|
||||
final JSONObject jsonResponse = new JSONObject(new JSONTokener(new InputStreamReader((InputStream) connection.getContent())));
|
||||
final String accessToken = jsonResponse.getString("access_token");
|
||||
URL createSessionUrl = new URL(contextRoot + CREATE_SESSION_URL);
|
||||
HttpURLConnection adminConsoleConnection = (HttpURLConnection) createSessionUrl.openConnection();
|
||||
adminConsoleConnection.setRequestProperty("Authorization", "Bearer "+accessToken);
|
||||
adminConsoleConnection.setRequestMethod("GET");
|
||||
adminConsoleConnection.connect();
|
||||
List<String> cookies = adminConsoleConnection.getHeaderFields().get("Set-Cookie");
|
||||
if (cookies != null) {
|
||||
for (String cookie : cookies) {
|
||||
if (cookie.startsWith(SESSION_COOKIE_NAME + "=")) {
|
||||
|
||||
Reference in new issue
Block a user