Search in sources :

Example 6 with OutputFormat

use of org.neo4j.server.rest.repr.OutputFormat in project neo4j by neo4j.

the class UserServiceTest method shouldReturnValidUserRepresentation.

@Test
public void shouldReturnValidUserRepresentation() 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.getUser("neo4j", req);
    // Then
    assertThat(response.getStatus(), equalTo(200));
    String json = new String((byte[]) response.getEntity());
    assertNotNull(json);
    assertThat(json, containsString("\"username\" : \"neo4j\""));
    assertThat(json, containsString("\"password_change\" : \"http://www.example.com/user/neo4j/password\""));
    assertThat(json, containsString("\"password_change_required\" : true"));
}
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 7 with OutputFormat

use of org.neo4j.server.rest.repr.OutputFormat in project neo4j by neo4j.

the class UserServiceTest method shouldReturn422IfEmptyPassword.

@Test
public void shouldReturn422IfEmptyPassword() 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\" : \"\" }");
    // 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\" : \"A password cannot be empty.\""));
}
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 8 with OutputFormat

use of org.neo4j.server.rest.repr.OutputFormat in project neo4j by neo4j.

the class StreamingJsonFormatTest method createOutputFormat.

@BeforeEach
void createOutputFormat() throws Exception {
    stream = new ByteArrayOutputStream();
    json = new OutputFormat(new StreamingJsonFormat().writeTo(stream).usePrettyPrinter(), new URI("http://localhost/"));
}
Also used : OutputFormat(org.neo4j.server.rest.repr.OutputFormat) ByteArrayOutputStream(java.io.ByteArrayOutputStream) URI(java.net.URI) StreamingJsonFormat(org.neo4j.server.http.cypher.format.output.json.StreamingJsonFormat) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 9 with OutputFormat

use of org.neo4j.server.rest.repr.OutputFormat 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");
}
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 10 with OutputFormat

use of org.neo4j.server.rest.repr.OutputFormat 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));
}
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)

Aggregations

URI (java.net.URI)14 OutputFormat (org.neo4j.server.rest.repr.OutputFormat)14 HttpServletRequest (javax.servlet.http.HttpServletRequest)13 Response (javax.ws.rs.core.Response)13 Test (org.junit.Test)13 JsonFormat (org.neo4j.server.rest.repr.formats.JsonFormat)13 EntityOutputFormat (org.neo4j.test.server.EntityOutputFormat)13 Matchers.containsString (org.hamcrest.Matchers.containsString)6 BasicAuthManager (org.neo4j.server.security.auth.BasicAuthManager)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 UserManager (org.neo4j.kernel.api.security.UserManager)1 StreamingJsonFormat (org.neo4j.server.http.cypher.format.output.json.StreamingJsonFormat)1