Search in sources :

Example 1 with EntityOutputFormat

use of org.neo4j.test.server.EntityOutputFormat in project neo4j by neo4j.

the class UserServiceTest method shouldReturn422IfPasswordIdentical.

@Test
public void shouldReturn422IfPasswordIdentical() 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\" : \"neo4j\" }");
    // Then
    assertThat(response.getStatus(), equalTo(422));
    String json = new String((byte[]) response.getEntity());
    assertNotNull(json);
    assertThat(json, containsString("\"code\" : \"Neo.ClientError.General.InvalidArguments\""));
    assertThat(json, containsString("\"message\" : \"Old password and new password cannot be the same.\""));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Response(javax.ws.rs.core.Response) JsonFormat(org.neo4j.server.rest.repr.formats.JsonFormat) EntityOutputFormat(org.neo4j.test.server.EntityOutputFormat) OutputFormat(org.neo4j.server.rest.repr.OutputFormat) Matchers.containsString(org.hamcrest.Matchers.containsString) URI(java.net.URI) EntityOutputFormat(org.neo4j.test.server.EntityOutputFormat) Test(org.junit.Test)

Example 2 with EntityOutputFormat

use of org.neo4j.test.server.EntityOutputFormat in project neo4j by neo4j.

the class UserServiceTest method shouldReturn404WhenRequestingUserIfDifferentUser.

@Test
public void shouldReturn404WhenRequestingUserIfDifferentUser() 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.getUser("fred", req);
    // Then
    assertThat(response.getStatus(), equalTo(404));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Response(javax.ws.rs.core.Response) JsonFormat(org.neo4j.server.rest.repr.formats.JsonFormat) BasicAuthManager(org.neo4j.server.security.auth.BasicAuthManager) EntityOutputFormat(org.neo4j.test.server.EntityOutputFormat) OutputFormat(org.neo4j.server.rest.repr.OutputFormat) URI(java.net.URI) EntityOutputFormat(org.neo4j.test.server.EntityOutputFormat) Test(org.junit.Test)

Example 3 with EntityOutputFormat

use of org.neo4j.test.server.EntityOutputFormat in project neo4j by neo4j.

the class UserServiceTest method shouldReturn404WhenChangingPasswordIfDifferentUser.

@Test
public void shouldReturn404WhenChangingPasswordIfDifferentUser() throws Exception {
    // Given
    HttpServletRequest req = mock(HttpServletRequest.class);
    when(req.getUserPrincipal()).thenReturn(neo4jPrinciple);
    UserManager userManager = mock(UserManager.class);
    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("fred", req, "{ \"password\" : \"test\" }");
    // Then
    assertThat(response.getStatus(), equalTo(404));
    verifyZeroInteractions(userManager);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Response(javax.ws.rs.core.Response) JsonFormat(org.neo4j.server.rest.repr.formats.JsonFormat) UserManager(org.neo4j.kernel.api.security.UserManager) EntityOutputFormat(org.neo4j.test.server.EntityOutputFormat) OutputFormat(org.neo4j.server.rest.repr.OutputFormat) URI(java.net.URI) EntityOutputFormat(org.neo4j.test.server.EntityOutputFormat) Test(org.junit.Test)

Example 4 with EntityOutputFormat

use of org.neo4j.test.server.EntityOutputFormat in project neo4j by neo4j.

the class UserServiceTest method shouldReturn404WhenRequestingUserIfUnknownUser.

@Test
public void shouldReturn404WhenRequestingUserIfUnknownUser() throws Exception {
    // Given
    HttpServletRequest req = mock(HttpServletRequest.class);
    when(req.getUserPrincipal()).thenReturn(neo4jPrinciple);
    userManagerSupplier.getUserManager().deleteUser("neo4j");
    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));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Response(javax.ws.rs.core.Response) JsonFormat(org.neo4j.server.rest.repr.formats.JsonFormat) EntityOutputFormat(org.neo4j.test.server.EntityOutputFormat) OutputFormat(org.neo4j.server.rest.repr.OutputFormat) URI(java.net.URI) EntityOutputFormat(org.neo4j.test.server.EntityOutputFormat) Test(org.junit.Test)

Example 5 with EntityOutputFormat

use of org.neo4j.test.server.EntityOutputFormat in project neo4j by neo4j.

the class UserServiceTest method shouldReturn404WhenChangingPasswordIfNotAuthenticated.

@Test
public void shouldReturn404WhenChangingPasswordIfNotAuthenticated() 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(mock(BasicAuthManager.class), new JsonFormat(), outputFormat);
    // When
    Response response = userService.setPassword("neo4j", req, "{ \"password\" : \"test\" }");
    // Then
    assertThat(response.getStatus(), equalTo(404));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Response(javax.ws.rs.core.Response) JsonFormat(org.neo4j.server.rest.repr.formats.JsonFormat) BasicAuthManager(org.neo4j.server.security.auth.BasicAuthManager) EntityOutputFormat(org.neo4j.test.server.EntityOutputFormat) OutputFormat(org.neo4j.server.rest.repr.OutputFormat) URI(java.net.URI) EntityOutputFormat(org.neo4j.test.server.EntityOutputFormat) Test(org.junit.Test)

Aggregations

JsonFormat (org.neo4j.server.rest.repr.formats.JsonFormat)18 EntityOutputFormat (org.neo4j.test.server.EntityOutputFormat)18 URI (java.net.URI)15 Response (javax.ws.rs.core.Response)15 Test (org.junit.Test)14 HttpServletRequest (javax.servlet.http.HttpServletRequest)13 OutputFormat (org.neo4j.server.rest.repr.OutputFormat)13 Matchers.containsString (org.hamcrest.Matchers.containsString)7 BasicAuthManager (org.neo4j.server.security.auth.BasicAuthManager)5 WrappedDatabase (org.neo4j.server.database.WrappedDatabase)3 GraphDbHelper (org.neo4j.server.rest.domain.GraphDbHelper)3 LeaseManager (org.neo4j.server.rest.paging.LeaseManager)3 TestGraphDatabaseFactory (org.neo4j.test.TestGraphDatabaseFactory)3 Before (org.junit.Before)2 BeforeClass (org.junit.BeforeClass)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 MethodSource (org.junit.jupiter.params.provider.MethodSource)1 Config (org.neo4j.configuration.Config)1 UserManager (org.neo4j.kernel.api.security.UserManager)1 Config (org.neo4j.kernel.configuration.Config)1