blob: 43986a2bd99e03d1c04f1d0285ef92655ee0f04b [file] [log] [blame]
Michael Hanlc4446022016-02-12 18:03:17 +01001package de.ids_mannheim.korap.web.service.full;
2
3import com.sun.jersey.api.client.ClientResponse;
Michael Hanlc4446022016-02-12 18:03:17 +01004import de.ids_mannheim.korap.config.TestHelper;
Michael Hanldaf86602016-05-12 14:31:52 +02005import de.ids_mannheim.korap.exceptions.KustvaktException;
Michael Hanlc4446022016-02-12 18:03:17 +01006import de.ids_mannheim.korap.security.auth.BasicHttpAuth;
Michael Hanl00b64e02016-05-24 20:24:27 +02007import de.ids_mannheim.korap.config.Attributes;
Michael Hanlc4446022016-02-12 18:03:17 +01008import de.ids_mannheim.korap.web.service.FastJerseyTest;
9import org.eclipse.jetty.server.Response;
Michael Hanlc0ed00f2016-06-23 14:33:10 +020010import org.junit.Assert;
Michael Hanlc4446022016-02-12 18:03:17 +010011import org.junit.BeforeClass;
Michael Hanlc0ed00f2016-06-23 14:33:10 +020012import org.junit.Ignore;
Michael Hanlc4446022016-02-12 18:03:17 +010013import org.junit.Test;
14
Michael Hanlc0ed00f2016-06-23 14:33:10 +020015import static org.junit.Assert.assertEquals;
16
Michael Hanlc4446022016-02-12 18:03:17 +010017/**
18 * @author hanl
19 * @date 08/02/2016
20 */
21public class FilterTest extends FastJerseyTest {
22
23 @BeforeClass
Michael Hanl8abaf9e2016-05-23 16:46:35 +020024 public static void setup () throws Exception {
Michael Hanlc4446022016-02-12 18:03:17 +010025 FastJerseyTest.setPackages("de.ids_mannheim.korap.web.service.full",
26 "de.ids_mannheim.korap.web.filter",
27 "de.ids_mannheim.korap.web.utils");
Michael Hanlc4446022016-02-12 18:03:17 +010028 }
29
Michael Hanl8abaf9e2016-05-23 16:46:35 +020030
Michael Hanlc4446022016-02-12 18:03:17 +010031 @Test
Michael Hanl8abaf9e2016-05-23 16:46:35 +020032 public void testTestUserAuth () {
33 ClientResponse resp = resource()
34 .path(getAPIVersion())
35 .path("user/info")
36 .header(Attributes.AUTHORIZATION,
37 BasicHttpAuth.encode(
Michael Hanlc0ed00f2016-06-23 14:33:10 +020038 (String) TestHelper.getUserCredentials().get(Attributes.USERNAME),
39 (String) TestHelper.getUserCredentials().get(Attributes.PASSWORD)))
Michael Hanlc4446022016-02-12 18:03:17 +010040 .get(ClientResponse.class);
41 assert resp.getStatus() == Response.SC_OK;
Michael Hanlc4446022016-02-12 18:03:17 +010042 }
43
Michael Hanl8abaf9e2016-05-23 16:46:35 +020044
Michael Hanlc4446022016-02-12 18:03:17 +010045 @Test
Michael Hanlc0ed00f2016-06-23 14:33:10 +020046 @Ignore
Michael Hanl8abaf9e2016-05-23 16:46:35 +020047 public void testDemoAuth () {
48 ClientResponse resp = resource().path(getAPIVersion())
49 .path("user/info").get(ClientResponse.class);
Michael Hanlc0ed00f2016-06-23 14:33:10 +020050 assertEquals(ClientResponse.Status.OK.getStatusCode(), resp.getStatus());
Michael Hanlc4446022016-02-12 18:03:17 +010051 }
52
Michael Hanl8abaf9e2016-05-23 16:46:35 +020053
Michael Hanlc4446022016-02-12 18:03:17 +010054 @Test
Michael Hanl8abaf9e2016-05-23 16:46:35 +020055 public void testUnauthorizedAuth () {
56 ClientResponse resp = resource()
57 .path(getAPIVersion())
58 .path("user/info")
Michael Hanlc4446022016-02-12 18:03:17 +010059 .header(Attributes.AUTHORIZATION,
60 BasicHttpAuth.encode("kustvakt", "kustvakt2015"))
61 .get(ClientResponse.class);
Michael Hanlc0ed00f2016-06-23 14:33:10 +020062 assertEquals(ClientResponse.Status.UNAUTHORIZED.getStatusCode(), resp.getStatus());
Michael Hanlc4446022016-02-12 18:03:17 +010063 }
Michael Hanldaf86602016-05-12 14:31:52 +020064
Michael Hanl8abaf9e2016-05-23 16:46:35 +020065
Michael Hanldaf86602016-05-12 14:31:52 +020066 @Override
Michael Hanl8abaf9e2016-05-23 16:46:35 +020067 public void initMethod () throws KustvaktException {
Michael Hanldaf86602016-05-12 14:31:52 +020068 helper().setupAccount();
69 }
Michael Hanlc4446022016-02-12 18:03:17 +010070}