This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository coselmar. See http://git.codelutin.com/coselmar.git commit 19ba20f68f7032187734d3ea9bfb1439f624eb6d Author: Yannick Martel <martel@©odelutin.com> Date: Wed Jan 21 12:03:20 2015 +0100 fix unit test for login --- .../coselmar/services/UsersWebServiceTest.java | 54 ++++++++++++++++++---- 1 file changed, 46 insertions(+), 8 deletions(-) diff --git a/coselmar-rest/src/test/java/fr/ifremer/coselmar/services/UsersWebServiceTest.java b/coselmar-rest/src/test/java/fr/ifremer/coselmar/services/UsersWebServiceTest.java index fcfe84f..7658d48 100644 --- a/coselmar-rest/src/test/java/fr/ifremer/coselmar/services/UsersWebServiceTest.java +++ b/coselmar-rest/src/test/java/fr/ifremer/coselmar/services/UsersWebServiceTest.java @@ -55,16 +55,31 @@ public class UsersWebServiceTest extends AbstractCoselmarWebServiceTest { @Test public void testAuthentication() throws Exception { - Request addUserRequest = createRequest("/v1/users") - .addParameter("user", "{firstName: 'test', name: 'her', mail: 'test@test.org', role: 'supervisor', qualification: 'unit tester', password : 'iamatester'}") + Request loginRequest = createRequest("/v1/users/login") + .addParameter("mail", "admin@temporary.coselmar") + .addParameter("password", "manager1234") .Post(); - HttpResponse addUserResponse = addUserRequest.execute().returnResponse(); - Assert.assertEquals(200, addUserResponse.getStatusLine().getStatusCode()); + Response loginResponse = loginRequest.execute(); + String loginContent = loginResponse.returnContent().asString(); + Assert.assertNotNull(loginContent); + showTestResult(loginContent); + + Gson gson = new Gson(); + Map<String, String> map = gson.fromJson(loginContent, Map.class); + + String webSecurityKey = getServiceContext().getCoselmarServicesConfig().getWebSecurityKey(); + JWTVerifier jwtVerifier = new JWTVerifier(Base64.encodeBase64String(webSecurityKey.getBytes("utf8")), "audience"); + String token = map.get("jwt"); + jwtVerifier.verify(token); + } + + @Test + public void testNewUserAuthentication() throws Exception { Request loginRequest = createRequest("/v1/users/login") - .addParameter("mail", "test@test.org") - .addParameter("password", "iamatester") + .addParameter("mail", "admin@temporary.coselmar") + .addParameter("password", "manager1234") .Post(); Response loginResponse = loginRequest.execute(); @@ -73,11 +88,34 @@ public class UsersWebServiceTest extends AbstractCoselmarWebServiceTest { showTestResult(loginContent); Gson gson = new Gson(); - Map<String, String> map = gson.fromJson(loginContent, Map.class); + Map<String, String> loginMap = gson.fromJson(loginContent, Map.class); + + String adminToken = loginMap.get("jwt"); + + + Request addUserRequest = createRequest("/v1/users") + .addParameter("user", "{firstName: 'test', name: 'her', mail: 'test@test.org', role: 'supervisor', qualification: 'unit tester', password : 'iamatester'}") + .Post() + .addHeader("Authorization", "Bearer " + adminToken); + + HttpResponse addUserResponse = addUserRequest.execute().returnResponse(); + Assert.assertEquals(200, addUserResponse.getStatusLine().getStatusCode()); + + loginRequest = createRequest("/v1/users/login") + .addParameter("mail", "test@test.org") + .addParameter("password", "iamatester") + .Post(); + + loginResponse = loginRequest.execute(); + loginContent = loginResponse.returnContent().asString(); + Assert.assertNotNull(loginContent); + showTestResult(loginContent); + + Map<String, String> newUserLoginMap = gson.fromJson(loginContent, Map.class); String webSecurityKey = getServiceContext().getCoselmarServicesConfig().getWebSecurityKey(); JWTVerifier jwtVerifier = new JWTVerifier(Base64.encodeBase64String(webSecurityKey.getBytes("utf8")), "audience"); - String token = map.get("jwt"); + String token = newUserLoginMap.get("jwt"); jwtVerifier.verify(token); } } -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.