Skip to content

Commit

Permalink
Merge branch 'grabowski/authentication-tests'
Browse files Browse the repository at this point in the history
* grabowski/authentication-tests:
  app: tests: use CSRF token from 'wrong' site
  app: tests: add rest of authentication tests
  app: tests: part of the admin tests
  • Loading branch information
eloquenza committed Dec 9, 2018
2 parents ace08ba + 02cb43c commit b0cb5e7
Show file tree
Hide file tree
Showing 2 changed files with 266 additions and 31 deletions.
10 changes: 8 additions & 2 deletions src/app/extension/test/WSTestClientStateful.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
public class WSTestClientStateful {
private WSClient ws;
private List<WSCookie> cookies;
private boolean followRedirects;

public WSTestClientStateful(int port) {
this.ws = WSTestClient.newClient(port);
this.cookies = new ArrayList<>();
followRedirects = false;
}

private void updateCookies(WSResponse response) {
Expand All @@ -31,19 +33,23 @@ private void updateCookies(WSResponse response) {
}

public WSResponse get(String url) throws ExecutionException, InterruptedException {
WSResponse response = ws.url(url).setCookies(cookies).get().toCompletableFuture().get();
WSResponse response = ws.url(url).setFollowRedirects(followRedirects).setCookies(cookies).get().toCompletableFuture().get();
updateCookies(response);
return response;
}

public WSResponse post(String url, List<NameValuePair> parameter) throws ExecutionException, InterruptedException {
String encParameters = URLEncodedUtils.format(parameter, "utf-8");
WSResponse response = ws.url(url).setCookies(cookies).setContentType("application/x-www-form-urlencoded").post(encParameters).toCompletableFuture().get();
WSResponse response = ws.url(url).setFollowRedirects(followRedirects).setCookies(cookies).setContentType("application/x-www-form-urlencoded").post(encParameters).toCompletableFuture().get();
updateCookies(response);
return response;
}

public void close() throws IOException {
ws.close();
}

public void setFollowRedirects(boolean value) {
followRedirects = value;
}
}
Loading

0 comments on commit b0cb5e7

Please sign in to comment.