use of org.neo4j.test.server.EntityOutputFormat in project neo4j by neo4j.
the class UserServiceTest method shouldChangePasswordAndReturnSuccess.
@Test
public void shouldChangePasswordAndReturnSuccess() throws Exception {
// Given
HttpServletRequest req = mock(HttpServletRequest.class);
when(req.getUserPrincipal()).thenReturn(neo4jPrinciple);
OutputFormat outputFormat = new EntityOutputFormat(new JsonFormat(), new URI("http://www.example.com"), null);
UserService userService = new UserService(userManagerSupplier, new JsonFormat(), outputFormat);
// When
Response response = userService.setPassword("neo4j", req, "{ \"password\" : \"test\" }");
// Then
assertThat(response.getStatus(), equalTo(200));
userManagerSupplier.getUserManager().getUser("neo4j").credentials().matchesPassword("test");
}
use of org.neo4j.test.server.EntityOutputFormat in project neo4j by neo4j.
the class UserServiceTest method shouldReturn422WhenChangingPasswordIfUnknownUser.
@Test
public void shouldReturn422WhenChangingPasswordIfUnknownUser() throws Exception {
// Given
HttpServletRequest req = mock(HttpServletRequest.class);
when(req.getUserPrincipal()).thenReturn(neo4jPrinciple);
OutputFormat outputFormat = new EntityOutputFormat(new JsonFormat(), new URI("http://www.example.com"), null);
UserService userService = new UserService(userManagerSupplier, new JsonFormat(), outputFormat);
userRepository.delete(NEO4J_USER);
// When
Response response = userService.setPassword("neo4j", req, "{ \"password\" : \"test\" }");
// Then
assertThat(response.getStatus(), equalTo(422));
}
use of org.neo4j.test.server.EntityOutputFormat in project neo4j by neo4j.
the class UserServiceTest method shouldReturn422IfMissingPassword.
@Test
public void shouldReturn422IfMissingPassword() throws Exception {
// Given
HttpServletRequest req = mock(HttpServletRequest.class);
when(req.getUserPrincipal()).thenReturn(neo4jPrinciple);
OutputFormat outputFormat = new EntityOutputFormat(new JsonFormat(), new URI("http://www.example.com"), null);
UserService userService = new UserService(mock(BasicAuthManager.class), new JsonFormat(), outputFormat);
// When
Response response = userService.setPassword("neo4j", req, "{ \"unknown\" : \"unknown\" }");
// Then
assertThat(response.getStatus(), equalTo(422));
String json = new String((byte[]) response.getEntity());
assertNotNull(json);
assertThat(json, containsString("\"code\" : \"Neo.ClientError.Request.InvalidFormat\""));
assertThat(json, containsString("\"message\" : \"Required parameter 'password' is missing.\""));
}
use of org.neo4j.test.server.EntityOutputFormat in project neo4j by neo4j.
the class UserServiceTest method shouldReturn422IfInvalidPasswordType.
@Test
public void shouldReturn422IfInvalidPasswordType() throws Exception {
// Given
HttpServletRequest req = mock(HttpServletRequest.class);
when(req.getUserPrincipal()).thenReturn(neo4jPrinciple);
OutputFormat outputFormat = new EntityOutputFormat(new JsonFormat(), new URI("http://www.example.com"), null);
UserService userService = new UserService(mock(BasicAuthManager.class), new JsonFormat(), outputFormat);
// When
Response response = userService.setPassword("neo4j", req, "{ \"password\" : 1 }");
// Then
assertThat(response.getStatus(), equalTo(422));
String json = new String((byte[]) response.getEntity());
assertNotNull(json);
assertThat(json, containsString("\"code\" : \"Neo.ClientError.Request.InvalidFormat\""));
assertThat(json, containsString("\"message\" : \"Expected 'password' to be a string.\""));
}
use of org.neo4j.test.server.EntityOutputFormat in project neo4j by neo4j.
the class UserServiceTest method shouldReturn404WhenRequestingUserIfNotAuthenticated.
@Test
public void shouldReturn404WhenRequestingUserIfNotAuthenticated() throws Exception {
// Given
HttpServletRequest req = mock(HttpServletRequest.class);
when(req.getUserPrincipal()).thenReturn(null);
OutputFormat outputFormat = new EntityOutputFormat(new JsonFormat(), new URI("http://www.example.com"), null);
UserService userService = new UserService(userManagerSupplier, new JsonFormat(), outputFormat);
// When
Response response = userService.getUser("neo4j", req);
// Then
assertThat(response.getStatus(), equalTo(404));
}
Aggregations