blob: 2c1d3fecd45bb61fe010b2d11221d5067d0eb794 [file] [log] [blame]
margaretha37c56722017-05-31 12:43:48 +02001package de.ids_mannheim.korap.web.service.full;
2
margarethae6f079d2017-10-09 15:57:27 +02003import static org.junit.Assert.assertEquals;
4import static org.junit.Assert.assertNotEquals;
5import static org.junit.Assert.assertNotNull;
6import static org.junit.Assert.assertTrue;
margaretha37c56722017-05-31 12:43:48 +02007
8import java.io.IOException;
9import java.net.URI;
10import java.text.ParseException;
11import java.util.HashMap;
12import java.util.Map;
13
margarethae6f079d2017-10-09 15:57:27 +020014import javax.ws.rs.core.MediaType;
15import javax.ws.rs.core.MultivaluedMap;
16
17import org.apache.commons.collections.map.LinkedMap;
18import org.junit.BeforeClass;
19import org.junit.Ignore;
20import org.junit.Test;
margaretha4b5c1412017-11-15 20:55:04 +010021import org.springframework.beans.factory.annotation.Autowired;
margarethae6f079d2017-10-09 15:57:27 +020022
23import com.fasterxml.jackson.databind.JsonNode;
24import com.nimbusds.jwt.SignedJWT;
25import com.sun.jersey.api.client.ClientResponse;
26import com.sun.jersey.core.util.MultivaluedMapImpl;
27
margaretha4b5c1412017-11-15 20:55:04 +010028import de.ids_mannheim.korap.authentication.framework.HttpAuthorizationHandler;
margarethae6f079d2017-10-09 15:57:27 +020029import de.ids_mannheim.korap.config.Attributes;
margaretha4b5c1412017-11-15 20:55:04 +010030import de.ids_mannheim.korap.config.AuthenticationType;
margarethae6f079d2017-10-09 15:57:27 +020031import de.ids_mannheim.korap.config.BeansFactory;
32import de.ids_mannheim.korap.config.JWTSigner;
33import de.ids_mannheim.korap.config.TestHelper;
34import de.ids_mannheim.korap.exceptions.KustvaktException;
35import de.ids_mannheim.korap.exceptions.StatusCodes;
margarethae6f079d2017-10-09 15:57:27 +020036import de.ids_mannheim.korap.utils.JsonUtils;
37import de.ids_mannheim.korap.utils.TimeUtils;
38import de.ids_mannheim.korap.web.service.FastJerseyTest;
margaretha37c56722017-05-31 12:43:48 +020039
margaretha843c4632017-10-25 19:16:12 +020040/** EM: To do: not implemented in the new DB yet
margaretha37c56722017-05-31 12:43:48 +020041 * @author hanl
42 * @date 21/03/2015
43 */
44
45// todo: do benchmarks for simple request to check access_token check and user
46// retrieval!
margaretha843c4632017-10-25 19:16:12 +020047@Ignore
margaretha37c56722017-05-31 12:43:48 +020048public class UserServiceTest extends FastJerseyTest {
49
margaretha4b5c1412017-11-15 20:55:04 +010050 @Autowired
51 HttpAuthorizationHandler handler;
52
margaretha37c56722017-05-31 12:43:48 +020053 private static String[] credentials;
54
55 @Override
56 public void initMethod() throws KustvaktException {
57 helper().setupAccount();
58 }
59
60 @BeforeClass
61 public static void setup() throws Exception {
margaretha37c56722017-05-31 12:43:48 +020062 credentials = new String[2];
63 credentials[0] = (String) TestHelper.getUserCredentials().get(Attributes.USERNAME);
64 credentials[1] = (String) TestHelper.getUserCredentials().get(Attributes.PASSWORD);
65 }
66
67 @Test
margaretha894a7d72017-11-08 19:24:20 +010068 public void testRegisterMissingFields() throws KustvaktException{
margaretha37c56722017-05-31 12:43:48 +020069
70 MultivaluedMap map = new MultivaluedMapImpl();
71 map.putSingle("username", "testuser"); // bodmer funktioniert noch nicht
72 map.putSingle("email", "hanl@ids-mannheim.de");
73 map.putSingle("password", "testPassword1234");
74 map.putSingle("firstName", "test");
75 map.putSingle("lastName", "user");
76
margarethaf18298b2017-09-14 22:14:32 +020077 ClientResponse response = resource().path("user").path("register")
margaretha37c56722017-05-31 12:43:48 +020078 .header("Content-Type", MediaType.APPLICATION_JSON).post(ClientResponse.class, JsonUtils.toJSON(map));
79 assertEquals(ClientResponse.Status.BAD_REQUEST.getStatusCode(), response.getStatus());
80 String ent = response.getEntity(String.class);
81 JsonNode node = JsonUtils.readTree(ent);
82 assertNotNull(node);
83 assertTrue(node.at("/errors/0/2").asText().contains("address"));
84
85 // map.putSingle("address", "Mannheim");
86
margaretha4b5c1412017-11-15 20:55:04 +010087 String enc = handler.createAuthorizationHeader(AuthenticationType.BASIC,"testuser", "testPassword1234");
margarethaf18298b2017-09-14 22:14:32 +020088 response = resource().path("user").path("info")
margaretha37c56722017-05-31 12:43:48 +020089 .header("Content-Type", MediaType.APPLICATION_JSON).header(Attributes.AUTHORIZATION, enc)
90 .get(ClientResponse.class);
91
92 assertEquals(ClientResponse.Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
93 }
94
95 // test if user locked and what error message you get back
96 @Test
margaretha4b5c1412017-11-15 20:55:04 +010097 public void testregisterWithoutConfirm() throws KustvaktException {
margaretha37c56722017-05-31 12:43:48 +020098 MultivaluedMap map = new MultivaluedMapImpl();
99 map.putSingle("username", "testuser2");
100 map.putSingle("email", "hanl@ids-mannheim.de");
101 map.putSingle("password", "testPassword1234");
102 map.putSingle("firstName", "test");
103 map.putSingle("lastName", "user");
104 map.putSingle("address", "Mannheim");
105
margarethaf18298b2017-09-14 22:14:32 +0200106 ClientResponse response = resource().path("user").path("register")
margaretha37c56722017-05-31 12:43:48 +0200107 .header("Content-Type", MediaType.APPLICATION_JSON).post(ClientResponse.class, map);
108 assertEquals(ClientResponse.Status.OK.getStatusCode(), response.getStatus());
109
110 // run login/ status --> exception or information about locked account
111 // should appear
margaretha4b5c1412017-11-15 20:55:04 +0100112 String enc = handler.createAuthorizationHeader(AuthenticationType.BASIC,"testuser2", "testPassword1234");
margarethaf18298b2017-09-14 22:14:32 +0200113 response = resource().path("user").path("info").header(Attributes.AUTHORIZATION, enc)
margaretha37c56722017-05-31 12:43:48 +0200114 .get(ClientResponse.class);
115 assertEquals(ClientResponse.Status.OK.getStatusCode(), response.getStatus());
116 String ent = response.getEntity(String.class);
117
118 }
119
120 // should be run over https, since password is transmitted in plain text
121 @Test
margaretha894a7d72017-11-08 19:24:20 +0100122 public void testRegisterAndConfirm() throws KustvaktException{
margaretha37c56722017-05-31 12:43:48 +0200123 MultivaluedMap map = new MultivaluedMapImpl();
124 map.putSingle("username", "testuser");
125 map.putSingle("email", "hanl@ids-mannheim.de");
126 map.putSingle("password", "testPassword1234");
127 map.putSingle("firstName", "test");
128 map.putSingle("lastName", "user");
129 map.putSingle("address", "Mannheim");
130
margarethaf18298b2017-09-14 22:14:32 +0200131 ClientResponse response = resource().path("user").path("register")
margaretha37c56722017-05-31 12:43:48 +0200132 .header("Content-Type", MediaType.APPLICATION_JSON).post(ClientResponse.class, map);
133
134 String ent = response.getEntity(String.class);
135
136 assertEquals(ClientResponse.Status.OK.getStatusCode(), response.getStatus());
137
138 JsonNode node = JsonUtils.readTree(ent);
139 assertNotNull(node);
140
141 String conf_uri = node.path("confirm_uri").asText();
142 response = resource().uri(URI.create(conf_uri)).get(ClientResponse.class);
143 assertEquals(ClientResponse.Status.OK.getStatusCode(), response.getStatus());
144
margaretha4b5c1412017-11-15 20:55:04 +0100145 String enc = handler.createAuthorizationHeader(AuthenticationType.BASIC,"testuser", "testPassword1234");
margarethaf18298b2017-09-14 22:14:32 +0200146 response = resource().path("user").path("info").header(Attributes.AUTHORIZATION, enc)
margaretha37c56722017-05-31 12:43:48 +0200147 .get(ClientResponse.class);
148 assertEquals(ClientResponse.Status.OK.getStatusCode(), response.getStatus());
149 }
150
151 @Test
margaretha4b5c1412017-11-15 20:55:04 +0100152 public void loginHTTP() throws KustvaktException {
153 String enc = handler.createAuthorizationHeader(AuthenticationType.BASIC,credentials[0], credentials[1]);
margarethaf18298b2017-09-14 22:14:32 +0200154 ClientResponse response = resource().path("user").path("info")
margaretha37c56722017-05-31 12:43:48 +0200155 .header(Attributes.AUTHORIZATION, enc).get(ClientResponse.class);
156 assertEquals(ClientResponse.Status.OK.getStatusCode(), response.getStatus());
157 }
158
159 // EM: This test require VPN / IDS Intranet
160 @Test
margaretha96b96582017-06-27 11:08:32 +0200161 @Ignore
margaretha894a7d72017-11-08 19:24:20 +0100162 public void loginJWT() throws KustvaktException{
margaretha4b5c1412017-11-15 20:55:04 +0100163 String en = handler.createAuthorizationHeader(AuthenticationType.BASIC,credentials[0], credentials[1]);
margaretha37c56722017-05-31 12:43:48 +0200164 /* lauffähige Version von Hanl: */
margarethaf18298b2017-09-14 22:14:32 +0200165 ClientResponse response = resource().path("auth").path("apiToken")
margaretha37c56722017-05-31 12:43:48 +0200166 .header(Attributes.AUTHORIZATION, en).get(ClientResponse.class);
167 /**/
168 /*
169 * Test : ClientResponse response = null; WebResource webRes =
margarethaf18298b2017-09-14 22:14:32 +0200170 * resource().path("auth") .path("apiToken");
margaretha37c56722017-05-31 12:43:48 +0200171 * webRes.header(Attributes.AUTHORIZATION, en);
172 *
173 * System.out.printf("resource: " + webRes.toString());
174 *
175 * response = webRes.get(ClientResponse.class);
176 *
177 */
178
179// assertEquals(ClientResponse.Status.BAD_REQUEST.getStatusCode(), response.getStatus());
180 String entity = response.getEntity(String.class);
181 System.out.println(entity);
182 JsonNode node = JsonUtils.readTree(entity);
183 assertEquals(2022, node.at("/errors/0/0").asInt());
184 }
185
186 // EM: cannot do test with LDAP
187 @Test
188 @Ignore
189 public void loginJWTExpired() throws InterruptedException, KustvaktException, ParseException {
190
191 assertTrue(BeansFactory.getKustvaktContext().getConfiguration().getTokenTTL() < 10);
192
margaretha4b5c1412017-11-15 20:55:04 +0100193 String en = handler.createAuthorizationHeader(AuthenticationType.BASIC,credentials[0], credentials[1]);
margarethaf18298b2017-09-14 22:14:32 +0200194 ClientResponse response = resource().path("auth").path("apiToken")
margaretha37c56722017-05-31 12:43:48 +0200195 .header(Attributes.AUTHORIZATION, en).get(ClientResponse.class);
196
197 assertEquals(ClientResponse.Status.OK.getStatusCode(), response.getStatus());
198
199 JsonNode node = JsonUtils.readTree(response.getEntity(String.class));
200 assertNotNull(node);
201 String token = node.path("token").asText();
202
203 JWTSigner sign = new JWTSigner(BeansFactory.getKustvaktContext().getConfiguration().getSharedSecret(),
204 BeansFactory.getKustvaktContext().getConfiguration().getIssuer(), -1);
205
206 SignedJWT jwt = sign.verifyToken(token);
207
208 while (true) {
209 if (TimeUtils.isExpired(jwt.getJWTClaimsSet().getExpirationTimeClaim()))
210 break;
211 }
212
margarethaf18298b2017-09-14 22:14:32 +0200213 response = resource().path("user").path("info")
margaretha37c56722017-05-31 12:43:48 +0200214 .header(Attributes.AUTHORIZATION, "api_token " + token).get(ClientResponse.class);
215 assertEquals(ClientResponse.Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
216
217 }
218
219 @Test
margaretha4b5c1412017-11-15 20:55:04 +0100220 public void testGetUserDetails() throws KustvaktException {
221 String enc = handler.createAuthorizationHeader(AuthenticationType.BASIC,credentials[0], credentials[1]);
margarethaf18298b2017-09-14 22:14:32 +0200222 ClientResponse response = resource().path("user").path("details")
margaretha37c56722017-05-31 12:43:48 +0200223 .header(Attributes.AUTHORIZATION, enc).get(ClientResponse.class);
224 assertEquals(ClientResponse.Status.OK.getStatusCode(), response.getStatus());
225 }
226
227 @Test
margaretha4b5c1412017-11-15 20:55:04 +0100228 public void testGetUserDetailsEmbeddedPointer() throws KustvaktException {
229 String enc = handler.createAuthorizationHeader(AuthenticationType.BASIC,credentials[0], credentials[1]);
margaretha37c56722017-05-31 12:43:48 +0200230 Map m = new LinkedMap();
231 m.put("test", "[100, \"error message\", true, \"another message\"]");
232
margarethaf18298b2017-09-14 22:14:32 +0200233 ClientResponse response = resource().path("user").path("details")
margaretha37c56722017-05-31 12:43:48 +0200234 .header(Attributes.AUTHORIZATION, enc).header("Content-Type", MediaType.APPLICATION_JSON)
235 .post(ClientResponse.class, m);
236 assertEquals(ClientResponse.Status.OK.getStatusCode(), response.getStatus());
237
margarethaf18298b2017-09-14 22:14:32 +0200238 response = resource().path("user").path("details").queryParam("pointer", "test")
margaretha37c56722017-05-31 12:43:48 +0200239 .header(Attributes.AUTHORIZATION, enc).get(ClientResponse.class);
240 assertEquals(ClientResponse.Status.OK.getStatusCode(), response.getStatus());
241 String ent = response.getEntity(String.class);
242 assertEquals("[100, \"error message\", true, \"another message\"]", ent);
243 }
244
245 @Test
margaretha894a7d72017-11-08 19:24:20 +0100246 public void testUpdateUserDetailsMerge() throws KustvaktException{
margaretha4b5c1412017-11-15 20:55:04 +0100247 String enc = handler.createAuthorizationHeader(AuthenticationType.BASIC,credentials[0], credentials[1]);
margaretha37c56722017-05-31 12:43:48 +0200248 Map m = new LinkedMap();
249 m.put("test", "test value 1");
250
margarethaf18298b2017-09-14 22:14:32 +0200251 ClientResponse response = resource().path("user").path("details")
margaretha37c56722017-05-31 12:43:48 +0200252 .header(Attributes.AUTHORIZATION, enc).header("Content-Type", MediaType.APPLICATION_JSON)
253 .post(ClientResponse.class, m);
254 assertEquals(ClientResponse.Status.OK.getStatusCode(), response.getStatus());
255
margarethaf18298b2017-09-14 22:14:32 +0200256 response = resource().path("user").path("details").header(Attributes.AUTHORIZATION, enc)
margaretha37c56722017-05-31 12:43:48 +0200257 .get(ClientResponse.class);
258 assertEquals(ClientResponse.Status.OK.getStatusCode(), response.getStatus());
259 String ent = response.getEntity(String.class);
260 JsonNode node = JsonUtils.readTree(ent);
261 assertNotNull(node);
262 assertEquals("test value 1", node.at("/test").asText());
263 assertEquals("user", node.at("/lastName").asText());
264 assertEquals("test@ids-mannheim.de", node.at("/email").asText());
265 }
266
267 @Test
margaretha4b5c1412017-11-15 20:55:04 +0100268 public void testGetUserDetailsPointer() throws KustvaktException {
269 String enc = handler.createAuthorizationHeader(AuthenticationType.BASIC,credentials[0], credentials[1]);
margarethaf18298b2017-09-14 22:14:32 +0200270 ClientResponse response = resource().path("user").path("details")
margaretha37c56722017-05-31 12:43:48 +0200271 .queryParam("pointer", "email").header(Attributes.AUTHORIZATION, enc).get(ClientResponse.class);
272 assertEquals(ClientResponse.Status.OK.getStatusCode(), response.getStatus());
273 String ent = response.getEntity(String.class);
274 assertEquals("test@ids-mannheim.de", ent);
275 }
276
277 @Test
278 public void testGetUserDetailsNonExistent() throws KustvaktException {
279 helper().setupSimpleAccount("userservicetest", "servicepass");
280
margaretha4b5c1412017-11-15 20:55:04 +0100281 String enc = handler.createAuthorizationHeader(AuthenticationType.BASIC,"userservicetest", "servicepass");
margarethaf18298b2017-09-14 22:14:32 +0200282 ClientResponse response = resource().path("user").path("details")
margaretha37c56722017-05-31 12:43:48 +0200283 .header(Attributes.AUTHORIZATION, enc).get(ClientResponse.class);
284 assertEquals(ClientResponse.Status.BAD_REQUEST.getStatusCode(), response.getStatus());
285 String entity = response.getEntity(String.class);
286 JsonNode node = JsonUtils.readTree(entity);
287 assertNotNull(node);
margarethaf6d5a822017-10-19 19:51:20 +0200288 assertEquals(StatusCodes.NO_RESULT_FOUND, node.at("/errors/0/0").asInt());
margaretha37c56722017-05-31 12:43:48 +0200289 assertEquals("UserDetails", node.at("/errors/0/2").asText());
290 helper().dropUser("userservicetest");
291 }
292
293 @Test
margaretha4b5c1412017-11-15 20:55:04 +0100294 public void testGetUserSettings() throws KustvaktException {
295 String enc = handler.createAuthorizationHeader(AuthenticationType.BASIC,credentials[0], credentials[1]);
margarethaf18298b2017-09-14 22:14:32 +0200296 ClientResponse response = resource().path("user").path("settings")
margaretha37c56722017-05-31 12:43:48 +0200297 .header(Attributes.AUTHORIZATION, enc).get(ClientResponse.class);
298 assertEquals(ClientResponse.Status.OK.getStatusCode(), response.getStatus());
299 }
300
301 @Test
margaretha894a7d72017-11-08 19:24:20 +0100302 public void testUpdateUserDetailsJson() throws KustvaktException{
margaretha4b5c1412017-11-15 20:55:04 +0100303 String enc = handler.createAuthorizationHeader(AuthenticationType.BASIC,credentials[0], credentials[1]);
margaretha37c56722017-05-31 12:43:48 +0200304 Map m = new LinkedMap();
305 m.put("firstName", "newName");
306 m.put("lastName", "newLastName");
307 m.put("email", "newtest@ids-mannheim.de");
308
margarethaf18298b2017-09-14 22:14:32 +0200309 ClientResponse response = resource().path("user").path("details")
margaretha37c56722017-05-31 12:43:48 +0200310 .header(Attributes.AUTHORIZATION, enc).header("Content-Type", MediaType.APPLICATION_JSON)
311 .post(ClientResponse.class, m);
312 assertEquals(ClientResponse.Status.OK.getStatusCode(), response.getStatus());
313
margarethaf18298b2017-09-14 22:14:32 +0200314 response = resource().path("user").path("details").header(Attributes.AUTHORIZATION, enc)
margaretha37c56722017-05-31 12:43:48 +0200315 .get(ClientResponse.class);
316
317 assertEquals(ClientResponse.Status.OK.getStatusCode(), response.getStatus());
318 JsonNode node = JsonUtils.readTree(response.getEntity(String.class));
319 assertNotNull(node);
320 assertEquals("newName", node.path("firstName").asText());
321 assertEquals("newLastName", node.path("lastName").asText());
322 assertEquals("newtest@ids-mannheim.de", node.path("email").asText());
323 assertEquals("Mannheim", node.path("address").asText());
324
325 m = new LinkedMap();
326 m.put("firstName", "test");
327 m.put("lastName", "user");
328 m.put("email", "test@ids-mannheim.de");
329
margarethaf18298b2017-09-14 22:14:32 +0200330 response = resource().path("user").path("details").header(Attributes.AUTHORIZATION, enc)
margaretha37c56722017-05-31 12:43:48 +0200331 .header("Content-Type", MediaType.APPLICATION_JSON).post(ClientResponse.class, m);
332 assertEquals(ClientResponse.Status.OK.getStatusCode(), response.getStatus());
333 }
334
335 @Test
336 @Ignore
margaretha894a7d72017-11-08 19:24:20 +0100337 public void testUpdateUserSettingsForm() throws IOException, KustvaktException{
margaretha4b5c1412017-11-15 20:55:04 +0100338 String enc = handler.createAuthorizationHeader(AuthenticationType.BASIC,credentials[0], credentials[1]);
margaretha37c56722017-05-31 12:43:48 +0200339 MultivaluedMap m = new MultivaluedMapImpl();
340 m.putSingle("queryLanguage", "poliqarp_test");
341 m.putSingle("pageLength", "200");
342
margarethaf18298b2017-09-14 22:14:32 +0200343 ClientResponse response = resource().path("user").path("settings")
margaretha4b5c1412017-11-15 20:55:04 +0100344 .header(Attributes.AUTHORIZATION, enc).header("Content-Type", "application/x-www-form-urlencodeBase64d")
margaretha37c56722017-05-31 12:43:48 +0200345 .get(ClientResponse.class);
346
347 assertEquals(ClientResponse.Status.OK.getStatusCode(), response.getStatus());
348
349 JsonNode map = JsonUtils.readTree(response.getEntity(String.class));
350 assertNotNull(map);
351
352 assertNotEquals(m.getFirst("queryLanguage"), map.get("queryLanguage"));
353 assertNotEquals(m.get("pageLength"), Integer.valueOf((String) m.getFirst("pageLength")));
354
355 assertEquals(ClientResponse.Status.OK.getStatusCode(), response.getStatus());
356
margarethaf18298b2017-09-14 22:14:32 +0200357 response = resource().path("user").path("settings").header(Attributes.AUTHORIZATION, enc)
margaretha4b5c1412017-11-15 20:55:04 +0100358 .header("Content-Type", "application/x-www-form-urlencodeBase64d").post(ClientResponse.class, m);
margaretha37c56722017-05-31 12:43:48 +0200359 assertEquals(ClientResponse.Status.OK.getStatusCode(), response.getStatus());
360
margarethaf18298b2017-09-14 22:14:32 +0200361 response = resource().path("user").path("settings").header(Attributes.AUTHORIZATION, enc)
margaretha4b5c1412017-11-15 20:55:04 +0100362 .header("Content-Type", "application/x-www-form-urlencodeBase64d").get(ClientResponse.class);
margaretha37c56722017-05-31 12:43:48 +0200363 assertEquals(ClientResponse.Status.OK.getStatusCode(), response.getStatus());
364
365 map = JsonUtils.readTree(response.getEntity(String.class));
366 assertNotNull(map);
367
368 assertEquals(map.get("queryLanguage"), m.getFirst("queryLanguage"));
369 int p1 = map.path("pageLength").asInt();
370 int p2 = Integer.valueOf((String) m.getFirst("pageLength"));
371 assertEquals(p1, p2);
372 }
373
374 @Test
margaretha894a7d72017-11-08 19:24:20 +0100375 public void testUpdateUserSettingsJson() throws IOException, KustvaktException {
margaretha4b5c1412017-11-15 20:55:04 +0100376 String enc = handler.createAuthorizationHeader(AuthenticationType.BASIC,credentials[0], credentials[1]);
margaretha37c56722017-05-31 12:43:48 +0200377 Map m = new HashMap<>();
378 m.put("queryLanguage", "poliqarp_test");
379 m.put("pageLength", "200");
380 m.put("setting_1", "value_1");
381
margarethaf18298b2017-09-14 22:14:32 +0200382 ClientResponse response = resource().path("user").path("settings")
margaretha37c56722017-05-31 12:43:48 +0200383 .header(Attributes.AUTHORIZATION, enc).header("Content-Type", MediaType.APPLICATION_JSON)
384 .get(ClientResponse.class);
385
386 assertEquals(ClientResponse.Status.OK.getStatusCode(), response.getStatus());
387
388 JsonNode map = JsonUtils.readTree(response.getEntity(String.class));
389 assertNotNull(map);
390
391 assertNotEquals(m.get("queryLanguage"), map.get("queryLanguage"));
392 assertNotEquals(m.get("pageLength"), Integer.valueOf((String) m.get("pageLength")));
393
394 assertEquals(ClientResponse.Status.OK.getStatusCode(), response.getStatus());
395
margarethaf18298b2017-09-14 22:14:32 +0200396 response = resource().path("user").path("settings").header(Attributes.AUTHORIZATION, enc)
margaretha37c56722017-05-31 12:43:48 +0200397 .header("Content-Type", MediaType.APPLICATION_JSON).post(ClientResponse.class, m);
398 assertEquals(ClientResponse.Status.OK.getStatusCode(), response.getStatus());
399
margarethaf18298b2017-09-14 22:14:32 +0200400 response = resource().path("user").path("settings").header(Attributes.AUTHORIZATION, enc)
margaretha37c56722017-05-31 12:43:48 +0200401 .get(ClientResponse.class);
402 assertEquals(ClientResponse.Status.OK.getStatusCode(), response.getStatus());
403
404 map = JsonUtils.readTree(response.getEntity(String.class));
405 assertNotNull(map);
406
407 assertEquals(map.path("queryLanguage").asText(), m.get("queryLanguage"));
408 int p1 = map.path("pageLength").asInt();
409 int p2 = Integer.valueOf((String) m.get("pageLength"));
410 assertEquals(p1, p2);
411 }
412
413 @Test
414 public void registerInvalidPassword() {
415 final String CREDENTIALS_INVALID = "{\"username\":\"testuser2\","
416 + "\"email\":\"hanl@ids-mannheim.de\",\"password\":\"testpassword\"}";
417 // Response response = given()
margaretha4b5c1412017-11-15 20:55:04 +0100418 // .contentType("application/x-www-form-urlencodeBase64d").when()
margaretha37c56722017-05-31 12:43:48 +0200419 // .body(CREDENTIALS_INVALID).post("/register");
420 // String body = response.getBody().asString();
421 // Assert.assertEquals("response is in error", true,
422 // body.contains("error"));
423 // JsonNode n = JsonUtils.readTree(body);
424 // String uri = n.path("uri").asText();
425 // Response r = given().get(URI.create(uri));
426 // System.out.println("RESPONSE " + r.getStatusCode());
427 // System.out.println("RESPONSE BODY " + n);
428 }
429
430 @Test
431 public void testLoginFailedLockAccount() {
432
433 }
434
435 @Test
436 @Ignore
437 public void delete() {
438
439 }
440
441 @Test
442 @Ignore
443 public void updatePassword() {
444
445 }
446
447}