branch develop updated (7c43e75 -> 19ba20f)
This is an automated email from the git hooks/post-receive script. New change to branch develop in repository coselmar. See http://git.codelutin.com/coselmar.git from 7c43e75 fixes #6440 Merge branch 'feature/6440-add-second-input-for-password-change' into develop new 19ba20f fix unit test for login The 1 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "adds" were already present in the repository and have only been added to this reference. Detailed log of new commits: commit 19ba20f68f7032187734d3ea9bfb1439f624eb6d Author: Yannick Martel <martel@©odelutin.com> Date: Wed Jan 21 12:03:20 2015 +0100 fix unit test for login Summary of changes: .../coselmar/services/UsersWebServiceTest.java | 54 ++++++++++++++++++---- 1 file changed, 46 insertions(+), 8 deletions(-) -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
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>.
participants (1)
-
codelutin.com scm