| Michael Hanl | c444602 | 2016-02-12 18:03:17 +0100 | [diff] [blame] | 1 | package de.ids_mannheim.korap.web.service.full; |
| 2 | |
| 3 | import com.sun.jersey.api.client.ClientResponse; |
| Michael Hanl | c444602 | 2016-02-12 18:03:17 +0100 | [diff] [blame] | 4 | import de.ids_mannheim.korap.config.TestHelper; |
| Michael Hanl | daf8660 | 2016-05-12 14:31:52 +0200 | [diff] [blame] | 5 | import de.ids_mannheim.korap.exceptions.KustvaktException; |
| Michael Hanl | c444602 | 2016-02-12 18:03:17 +0100 | [diff] [blame] | 6 | import de.ids_mannheim.korap.security.auth.BasicHttpAuth; |
| Michael Hanl | 00b64e0 | 2016-05-24 20:24:27 +0200 | [diff] [blame] | 7 | import de.ids_mannheim.korap.config.Attributes; |
| Michael Hanl | c444602 | 2016-02-12 18:03:17 +0100 | [diff] [blame] | 8 | import de.ids_mannheim.korap.web.service.FastJerseyTest; |
| 9 | import org.eclipse.jetty.server.Response; |
| Michael Hanl | c0ed00f | 2016-06-23 14:33:10 +0200 | [diff] [blame] | 10 | import org.junit.Assert; |
| Michael Hanl | c444602 | 2016-02-12 18:03:17 +0100 | [diff] [blame] | 11 | import org.junit.BeforeClass; |
| Michael Hanl | c0ed00f | 2016-06-23 14:33:10 +0200 | [diff] [blame] | 12 | import org.junit.Ignore; |
| Michael Hanl | c444602 | 2016-02-12 18:03:17 +0100 | [diff] [blame] | 13 | import org.junit.Test; |
| 14 | |
| Michael Hanl | c0ed00f | 2016-06-23 14:33:10 +0200 | [diff] [blame] | 15 | import static org.junit.Assert.assertEquals; |
| 16 | |
| Michael Hanl | c444602 | 2016-02-12 18:03:17 +0100 | [diff] [blame] | 17 | /** |
| 18 | * @author hanl |
| 19 | * @date 08/02/2016 |
| 20 | */ |
| 21 | public class FilterTest extends FastJerseyTest { |
| 22 | |
| 23 | @BeforeClass |
| Michael Hanl | 8abaf9e | 2016-05-23 16:46:35 +0200 | [diff] [blame] | 24 | public static void setup () throws Exception { |
| Michael Hanl | c444602 | 2016-02-12 18:03:17 +0100 | [diff] [blame] | 25 | FastJerseyTest.setPackages("de.ids_mannheim.korap.web.service.full", |
| 26 | "de.ids_mannheim.korap.web.filter", |
| 27 | "de.ids_mannheim.korap.web.utils"); |
| Michael Hanl | c444602 | 2016-02-12 18:03:17 +0100 | [diff] [blame] | 28 | } |
| 29 | |
| Michael Hanl | 8abaf9e | 2016-05-23 16:46:35 +0200 | [diff] [blame] | 30 | |
| Michael Hanl | c444602 | 2016-02-12 18:03:17 +0100 | [diff] [blame] | 31 | @Test |
| Michael Hanl | 8abaf9e | 2016-05-23 16:46:35 +0200 | [diff] [blame] | 32 | public void testTestUserAuth () { |
| 33 | ClientResponse resp = resource() |
| 34 | .path(getAPIVersion()) |
| 35 | .path("user/info") |
| 36 | .header(Attributes.AUTHORIZATION, |
| 37 | BasicHttpAuth.encode( |
| Michael Hanl | c0ed00f | 2016-06-23 14:33:10 +0200 | [diff] [blame] | 38 | (String) TestHelper.getUserCredentials().get(Attributes.USERNAME), |
| 39 | (String) TestHelper.getUserCredentials().get(Attributes.PASSWORD))) |
| Michael Hanl | c444602 | 2016-02-12 18:03:17 +0100 | [diff] [blame] | 40 | .get(ClientResponse.class); |
| 41 | assert resp.getStatus() == Response.SC_OK; |
| Michael Hanl | c444602 | 2016-02-12 18:03:17 +0100 | [diff] [blame] | 42 | } |
| 43 | |
| Michael Hanl | 8abaf9e | 2016-05-23 16:46:35 +0200 | [diff] [blame] | 44 | |
| Michael Hanl | c444602 | 2016-02-12 18:03:17 +0100 | [diff] [blame] | 45 | @Test |
| Michael Hanl | c0ed00f | 2016-06-23 14:33:10 +0200 | [diff] [blame] | 46 | @Ignore |
| Michael Hanl | 8abaf9e | 2016-05-23 16:46:35 +0200 | [diff] [blame] | 47 | public void testDemoAuth () { |
| 48 | ClientResponse resp = resource().path(getAPIVersion()) |
| 49 | .path("user/info").get(ClientResponse.class); |
| Michael Hanl | c0ed00f | 2016-06-23 14:33:10 +0200 | [diff] [blame] | 50 | assertEquals(ClientResponse.Status.OK.getStatusCode(), resp.getStatus()); |
| Michael Hanl | c444602 | 2016-02-12 18:03:17 +0100 | [diff] [blame] | 51 | } |
| 52 | |
| Michael Hanl | 8abaf9e | 2016-05-23 16:46:35 +0200 | [diff] [blame] | 53 | |
| Michael Hanl | c444602 | 2016-02-12 18:03:17 +0100 | [diff] [blame] | 54 | @Test |
| Michael Hanl | 8abaf9e | 2016-05-23 16:46:35 +0200 | [diff] [blame] | 55 | public void testUnauthorizedAuth () { |
| 56 | ClientResponse resp = resource() |
| 57 | .path(getAPIVersion()) |
| 58 | .path("user/info") |
| Michael Hanl | c444602 | 2016-02-12 18:03:17 +0100 | [diff] [blame] | 59 | .header(Attributes.AUTHORIZATION, |
| 60 | BasicHttpAuth.encode("kustvakt", "kustvakt2015")) |
| 61 | .get(ClientResponse.class); |
| Michael Hanl | c0ed00f | 2016-06-23 14:33:10 +0200 | [diff] [blame] | 62 | assertEquals(ClientResponse.Status.UNAUTHORIZED.getStatusCode(), resp.getStatus()); |
| Michael Hanl | c444602 | 2016-02-12 18:03:17 +0100 | [diff] [blame] | 63 | } |
| Michael Hanl | daf8660 | 2016-05-12 14:31:52 +0200 | [diff] [blame] | 64 | |
| Michael Hanl | 8abaf9e | 2016-05-23 16:46:35 +0200 | [diff] [blame] | 65 | |
| Michael Hanl | daf8660 | 2016-05-12 14:31:52 +0200 | [diff] [blame] | 66 | @Override |
| Michael Hanl | 8abaf9e | 2016-05-23 16:46:35 +0200 | [diff] [blame] | 67 | public void initMethod () throws KustvaktException { |
| Michael Hanl | daf8660 | 2016-05-12 14:31:52 +0200 | [diff] [blame] | 68 | helper().setupAccount(); |
| 69 | } |
| Michael Hanl | c444602 | 2016-02-12 18:03:17 +0100 | [diff] [blame] | 70 | } |