1 package club.wpia.gigi.pages;
3 import static org.hamcrest.CoreMatchers.*;
4 import static org.junit.Assert.*;
6 import java.io.IOException;
7 import java.net.HttpURLConnection;
8 import java.net.MalformedURLException;
10 import java.net.URLConnection;
11 import java.security.GeneralSecurityException;
13 import org.junit.Test;
15 import club.wpia.gigi.GigiApiException;
16 import club.wpia.gigi.dbObjects.Country;
17 import club.wpia.gigi.dbObjects.Country.CountryCodeType;
18 import club.wpia.gigi.dbObjects.Group;
19 import club.wpia.gigi.dbObjects.Organisation;
20 import club.wpia.gigi.dbObjects.User;
21 import club.wpia.gigi.testUtils.ClientTest;
22 import club.wpia.gigi.testUtils.IOUtils;
24 public class TestMain extends ClientTest {
26 private User orgAdmin;
29 public void testPasswordLogin() throws MalformedURLException, IOException, GigiApiException {
30 URLConnection uc = new URL("https://" + getServerName()).openConnection();
31 uc.addRequestProperty("Cookie", cookie);
32 String content = IOUtils.readURL(uc);
34 assertThat(content, not(containsString("via certificate")));
37 uc = new URL("https://" + getServerName()).openConnection();
38 uc.addRequestProperty("Cookie", cookie);
39 content = IOUtils.readURL(uc);
40 assertThat(content, containsString("For some actions, e.g. add verification, support, you need to be authenticated via certificate."));
45 public void testCertLogin() throws GeneralSecurityException, IOException, GigiApiException, InterruptedException {
46 cookie = cookieWithCertificateLogin(u);
48 URLConnection uc = new URL("https://" + getSecureServerName()).openConnection();
49 authenticate((HttpURLConnection) uc);
50 String content = IOUtils.readURL(uc);
51 assertThat(content, not(containsString("via certificate")));
54 uc = new URL("https://" + getSecureServerName()).openConnection();
55 authenticate((HttpURLConnection) uc);
56 content = IOUtils.readURL(uc);
57 assertThat(content, containsString("You are authenticated via certificate, so you will be able to perform all actions."));
61 public void testPasswordLoginOrgAdmin() throws MalformedURLException, IOException, GigiApiException {
62 URLConnection uc = new URL("https://" + getServerName()).openConnection();
64 cookie = login(orgAdmin.getEmail(), TEST_PASSWORD);
65 loginCertificate = null;
66 uc.addRequestProperty("Cookie", cookie);
67 String content = IOUtils.readURL(uc);
68 assertThat(content, containsString("You need to be logged in via certificate to get access to the organisations."));
69 assertThat(content, containsString("For some actions, e.g. add verification, support, you need to be authenticated via certificate."));
74 public void testCertLoginOrgAdmin() throws GeneralSecurityException, IOException, GigiApiException, InterruptedException {
75 cookie = cookieWithCertificateLogin(u);
77 cookie = cookieWithCertificateLogin(orgAdmin);
79 URLConnection uc = new URL("https://" + getSecureServerName()).openConnection();
80 authenticate((HttpURLConnection) uc);
81 String content = IOUtils.readURL(uc);
83 assertThat(content, containsString("change to organisation administrator context"));
84 assertThat(content, containsString("You are authenticated via certificate, so you will be able to perform all actions."));
87 private void addOrgAdmin() throws GigiApiException, IOException {
89 u.grantGroup(getSupporter(), Group.ORG_AGENT);
91 Organisation o = new Organisation(createUniqueName(), Country.getCountryByCode("DE", CountryCodeType.CODE_2_CHARS), "pr", "city", "test@example.com", "", "", u);
92 orgAdmin = User.getById(createVerificationUser("testworker", "testname", createUniqueName() + "@testdom.com", TEST_PASSWORD));
93 makeAgent(orgAdmin.getId());
94 o.addAdmin(orgAdmin, u, true);