Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add testing of legacy Cypher HTTP endpoint
This works very much like the transactional REST/HTTP endpoint, so it inherits and uses most of the pre-existing functionality, with some minor alterations in the JSON input and output.
- Loading branch information
Showing
5 changed files
with
273 additions
and
9 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
.../src/test/java/org/neo4j/server/rest/security/CypherRESTAuthScenariosInteractionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright (c) 2002-2016 "Neo Technology," | ||
* Network Engine for Objects in Lund AB [http://neotechnology.com] | ||
* | ||
* This file is part of Neo4j. | ||
* | ||
* Neo4j is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.neo4j.server.rest.security; | ||
|
||
import org.junit.Rule; | ||
|
||
import java.util.Map; | ||
|
||
import org.neo4j.server.security.enterprise.auth.AuthScenariosInteractionTestBase; | ||
import org.neo4j.server.security.enterprise.auth.NeoInteractionLevel; | ||
import org.neo4j.test.rule.SuppressOutput; | ||
|
||
import static org.neo4j.test.rule.SuppressOutput.suppressAll; | ||
|
||
public class CypherRESTAuthScenariosInteractionTest extends AuthScenariosInteractionTestBase<RESTSubject> | ||
{ | ||
@Rule | ||
public SuppressOutput suppressOutput = suppressAll(); | ||
|
||
public CypherRESTAuthScenariosInteractionTest() | ||
{ | ||
super(); | ||
CHANGE_PWD_ERR_MSG = "User is required to change their password."; | ||
PWD_CHANGE_CHECK_FIRST = true; | ||
IS_EMBEDDED = false; | ||
} | ||
|
||
@Override | ||
protected NeoInteractionLevel<RESTSubject> setUpNeoServer( Map<String,String> config ) throws Throwable | ||
{ | ||
return new CypherRESTInteraction( config ); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
.../test/java/org/neo4j/server/rest/security/CypherRESTBuiltInProceduresInteractionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright (c) 2002-2016 "Neo Technology," | ||
* Network Engine for Objects in Lund AB [http://neotechnology.com] | ||
* | ||
* This file is part of Neo4j. | ||
* | ||
* Neo4j is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.neo4j.server.rest.security; | ||
|
||
import org.junit.Rule; | ||
|
||
import java.util.Map; | ||
|
||
import org.neo4j.server.security.enterprise.auth.BuiltInProceduresInteractionTestBase; | ||
import org.neo4j.server.security.enterprise.auth.NeoInteractionLevel; | ||
import org.neo4j.test.rule.SuppressOutput; | ||
|
||
import static org.neo4j.test.rule.SuppressOutput.suppressAll; | ||
|
||
public class CypherRESTBuiltInProceduresInteractionTest extends BuiltInProceduresInteractionTestBase<RESTSubject> | ||
{ | ||
@Rule | ||
public SuppressOutput suppressOutput = suppressAll(); | ||
|
||
public CypherRESTBuiltInProceduresInteractionTest() | ||
{ | ||
super(); | ||
CHANGE_PWD_ERR_MSG = "User is required to change their password."; | ||
PWD_CHANGE_CHECK_FIRST = true; | ||
IS_EMBEDDED = false; | ||
} | ||
|
||
@Override | ||
public NeoInteractionLevel<RESTSubject> setUpNeoServer( Map<String, String> config ) throws Throwable | ||
{ | ||
return new CypherRESTInteraction( config ); | ||
} | ||
} |
105 changes: 105 additions & 0 deletions
105
...server-enterprise/src/test/java/org/neo4j/server/rest/security/CypherRESTInteraction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/* | ||
* Copyright (c) 2002-2016 "Neo Technology," | ||
* Network Engine for Objects in Lund AB [http://neotechnology.com] | ||
* | ||
* This file is part of Neo4j. | ||
* | ||
* Neo4j is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.neo4j.server.rest.security; | ||
|
||
import org.codehaus.jackson.JsonNode; | ||
|
||
import java.io.IOException; | ||
import java.util.Map; | ||
import java.util.function.Consumer; | ||
import javax.ws.rs.core.HttpHeaders; | ||
|
||
import org.neo4j.graphdb.ResourceIterator; | ||
import org.neo4j.server.rest.domain.JsonHelper; | ||
import org.neo4j.server.rest.domain.JsonParseException; | ||
import org.neo4j.test.server.HTTP; | ||
|
||
import static org.junit.Assert.fail; | ||
import static org.neo4j.test.server.HTTP.RawPayload.quotedJson; | ||
|
||
class CypherRESTInteraction extends RESTInteraction | ||
{ | ||
|
||
@Override | ||
String commitPath() | ||
{ | ||
return "db/data/cypher"; | ||
} | ||
|
||
CypherRESTInteraction( Map<String,String> config ) throws IOException | ||
{ | ||
super( config ); | ||
} | ||
|
||
@Override | ||
public String executeQuery( RESTSubject subject, String call, Map<String,Object> params, | ||
Consumer<ResourceIterator<Map<String, Object>>> resultConsumer ) | ||
{ | ||
HTTP.RawPayload payload = constructQuery( call ); | ||
HTTP.Response response = HTTP.withHeaders( HttpHeaders.AUTHORIZATION, subject.principalCredentials ) | ||
.request( POST, commitURL(), payload ); | ||
|
||
try | ||
{ | ||
String error = parseErrorMessage( response ); | ||
if ( !error.isEmpty() ) | ||
{ | ||
return error; | ||
} | ||
JsonNode data = JsonHelper.jsonNode( response.rawContent() ); | ||
if ( data.has( "data" ) && data.get( "data" ).has( 0 ) ) | ||
{ | ||
resultConsumer.accept( new CypherRESTResult( data ) ); | ||
} | ||
} | ||
catch ( JsonParseException e ) | ||
{ | ||
fail( "Unexpected error parsing Json!" ); | ||
} | ||
|
||
return ""; | ||
} | ||
|
||
private HTTP.RawPayload constructQuery( String query ) | ||
{ | ||
return quotedJson( " { 'query': '" + query.replace( "'", "\\'" ).replace( "\"", "\\\"" ) + "' }" ); | ||
} | ||
|
||
@Override | ||
protected HTTP.Response authenticate( String principalCredentials ) | ||
{ | ||
return HTTP.withHeaders( HttpHeaders.AUTHORIZATION, principalCredentials ) | ||
.request( POST, commitURL(), constructQuery( "RETURN 1" ) ); | ||
} | ||
|
||
private class CypherRESTResult extends RESTResult | ||
{ | ||
CypherRESTResult( JsonNode fullResult ) | ||
{ | ||
super( fullResult ); | ||
} | ||
|
||
@Override | ||
JsonNode getRow( JsonNode data, int i ) | ||
{ | ||
return data.get( i ); | ||
} | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
...ava/org/neo4j/server/rest/security/CypherRESTUserManagementProceduresInteractionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright (c) 2002-2016 "Neo Technology," | ||
* Network Engine for Objects in Lund AB [http://neotechnology.com] | ||
* | ||
* This file is part of Neo4j. | ||
* | ||
* Neo4j is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.neo4j.server.rest.security; | ||
|
||
import org.junit.Rule; | ||
|
||
import java.util.Map; | ||
|
||
import org.neo4j.server.security.enterprise.auth.AuthProceduresInteractionTestBase; | ||
import org.neo4j.server.security.enterprise.auth.NeoInteractionLevel; | ||
import org.neo4j.test.rule.SuppressOutput; | ||
|
||
import static org.neo4j.test.rule.SuppressOutput.suppressAll; | ||
|
||
public class CypherRESTUserManagementProceduresInteractionTest extends AuthProceduresInteractionTestBase<RESTSubject> | ||
{ | ||
@Rule | ||
public SuppressOutput suppressOutput = suppressAll(); | ||
|
||
public CypherRESTUserManagementProceduresInteractionTest() | ||
{ | ||
super(); | ||
CHANGE_PWD_ERR_MSG = "User is required to change their password."; | ||
PWD_CHANGE_CHECK_FIRST = true; | ||
IS_EMBEDDED = false; | ||
} | ||
|
||
@Override | ||
public NeoInteractionLevel<RESTSubject> setUpNeoServer( Map<String,String> config ) throws Throwable | ||
{ | ||
return new CypherRESTInteraction( config ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters