blob: da84a0654c4ffb6969c7fb619028dad56103d996 [file] [log] [blame]
margarethaec247dd2018-06-12 21:55:46 +02001package de.ids_mannheim.korap.web.controller;
2
3import static org.junit.Assert.assertEquals;
4import static org.junit.Assert.assertTrue;
5
6import java.net.URI;
7
8import javax.ws.rs.core.MultivaluedMap;
9
10import org.apache.http.entity.ContentType;
11import org.junit.Test;
12import org.springframework.beans.factory.annotation.Autowired;
13
14import com.google.common.net.HttpHeaders;
15import com.sun.jersey.api.client.ClientHandlerException;
16import com.sun.jersey.api.client.ClientResponse;
17import com.sun.jersey.api.client.UniformInterfaceException;
18import com.sun.jersey.core.util.MultivaluedMapImpl;
19
20import de.ids_mannheim.korap.authentication.http.HttpAuthorizationHandler;
21import de.ids_mannheim.korap.config.Attributes;
22import de.ids_mannheim.korap.config.SpringJerseyTest;
23import de.ids_mannheim.korap.exceptions.KustvaktException;
24
25public class OAuth2OpenIdControllerTest extends SpringJerseyTest {
26
27 @Autowired
28 private HttpAuthorizationHandler handler;
29
30 @Test
31 public void testAuthorize () throws UniformInterfaceException,
32 ClientHandlerException, KustvaktException {
33
34 String redirectUri =
35 "https://korap.ids-mannheim.de/confidential/redirect";
36 MultivaluedMap<String, String> form = new MultivaluedMapImpl();
37 form.add("response_type", "code");
38 form.add("scope", "openid");
39 form.add("redirect_uri", redirectUri);
40 form.add("client_id", "fCBbQkAyYzI4NzUxMg");
41
42 ClientResponse response = resource().path("oauth2").path("openid")
43 .path("authorize")
44 .header(Attributes.AUTHORIZATION,
45 handler.createBasicAuthorizationHeaderValue("dory",
46 "password"))
47 .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
48 .header(HttpHeaders.CONTENT_TYPE,
49 ContentType.APPLICATION_FORM_URLENCODED)
50 .entity(form).post(ClientResponse.class);
51
52 URI location = response.getLocation();
53
54 assertEquals(redirectUri, location.getScheme() + "://"
55 + location.getHost() + location.getPath());
56 assertTrue(location.getQuery().startsWith("code"));
57 }
58
59}