forked from eldersantos/community
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #706 from systay/jakewins
Consoles in webadmin can now be disabled
- Loading branch information
Showing
22 changed files
with
587 additions
and
83 deletions.
There are no files selected for viewing
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
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
80 changes: 80 additions & 0 deletions
80
...ionaltest/java/org/neo4j/server/webadmin/rest/ConfigureEnabledManagementConsolesTest.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,80 @@ | ||
/** | ||
* Copyright (c) 2002-2012 "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 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 General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.neo4j.server.webadmin.rest; | ||
|
||
import static org.hamcrest.Matchers.is; | ||
import static org.junit.Assert.assertThat; | ||
import static org.neo4j.server.helpers.ServerBuilder.server; | ||
|
||
import org.junit.After; | ||
import org.junit.Test; | ||
import org.neo4j.server.NeoServer; | ||
import org.neo4j.server.configuration.Configurator; | ||
import org.neo4j.server.rest.JaxRsResponse; | ||
import org.neo4j.server.rest.RestRequest; | ||
import org.neo4j.test.server.ExclusiveServerTestBase; | ||
|
||
public class ConfigureEnabledManagementConsolesTest extends ExclusiveServerTestBase { | ||
|
||
private NeoServer server; | ||
|
||
@After | ||
public void stopTheServer() | ||
{ | ||
server.stop(); | ||
} | ||
|
||
@Test | ||
public void shouldBeAbleToDisableGremlinConsole() throws Exception { | ||
server = server().withProperty(Configurator.MANAGEMENT_CONSOLE_ENGINES, "shell").build(); | ||
server.start(); | ||
|
||
assertThat(exec("g","gremlin").getStatus(), is(400)); | ||
assertThat(exec("ls","shell").getStatus(), is(200)); | ||
} | ||
|
||
@Test | ||
public void shouldBeAbleToExplicitlySetConsolesToEnabled() throws Exception | ||
{ | ||
server = server().withProperty(Configurator.MANAGEMENT_CONSOLE_ENGINES, "shell,gremlin").build(); | ||
server.start(); | ||
|
||
assertThat(exec("g","gremlin").getStatus(), is(200)); | ||
assertThat(exec("ls","shell").getStatus(), is(200)); | ||
} | ||
|
||
|
||
|
||
@Test | ||
public void gremlinAndShellConsolesShouldBeEnabledByDefault() throws Exception { | ||
server = server().build(); | ||
server.start(); | ||
|
||
assertThat(exec("g","gremlin").getStatus(), is(200)); | ||
assertThat(exec("ls","shell").getStatus(), is(200)); | ||
} | ||
|
||
private JaxRsResponse exec(String command, String engine) | ||
{ | ||
return RestRequest.req().post(server.baseUri() + "db/manage/server/console", "{" + | ||
"\"engine\":\""+engine+"\"," + | ||
"\"command\":\""+command+"\\n\"}"); | ||
} | ||
} |
111 changes: 111 additions & 0 deletions
111
server/src/functionaltest/java/org/neo4j/server/webadmin/rest/ConsoleServiceTest.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,111 @@ | ||
/** | ||
* Copyright (c) 2002-2012 "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 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 General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.neo4j.server.webadmin.rest; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.containsString; | ||
import static org.junit.Assert.assertEquals; | ||
|
||
import java.io.UnsupportedEncodingException; | ||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
import java.util.ArrayList; | ||
|
||
import javax.ws.rs.core.Response; | ||
|
||
import org.junit.Test; | ||
import org.neo4j.server.database.Database; | ||
import org.neo4j.server.rest.repr.OutputFormat; | ||
import org.neo4j.server.rest.repr.formats.JsonFormat; | ||
import org.neo4j.server.webadmin.console.ScriptSession; | ||
|
||
public class ConsoleServiceTest | ||
{ | ||
private final URI uri = URI.create( "http://peteriscool.com:6666/" ); | ||
|
||
@Test | ||
public void correctRepresentation() throws URISyntaxException, UnsupportedEncodingException | ||
{ | ||
ConsoleService consoleService = new ConsoleService( new ShellOnlyConsoleSessionFactory(), null, new OutputFormat( new JsonFormat(), uri, null ) ); | ||
|
||
Response consoleResponse = consoleService.getServiceDefinition(); | ||
|
||
assertEquals( 200, consoleResponse.getStatus() ); | ||
String response = decode( consoleResponse ); | ||
assertThat( response, containsString( "resources" ) ); | ||
assertThat( response, containsString( uri.toString() ) ); | ||
} | ||
|
||
@Test | ||
public void advertisesAvailableConsoleEngines() throws URISyntaxException, UnsupportedEncodingException | ||
{ | ||
ConsoleService consoleServiceWithJustShellEngine = new ConsoleService( new ShellOnlyConsoleSessionFactory(), null, new OutputFormat( new JsonFormat(), uri, null ) ); | ||
|
||
String response = decode( consoleServiceWithJustShellEngine.getServiceDefinition()); | ||
|
||
assertThat( response, containsString( "\"engines\" : [ \"shell\" ]" ) ); | ||
|
||
ConsoleService consoleServiceWithShellAndGremlin = new ConsoleService( new GremlinAndShellConsoleSessionFactory(), null, new OutputFormat( new JsonFormat(), uri, null ) ); | ||
|
||
response = decode( consoleServiceWithShellAndGremlin.getServiceDefinition()); | ||
|
||
assertThat( response, containsString( "\"engines\" : [ \"shell\", \"gremlin\" ]" ) ); | ||
} | ||
|
||
private String decode( final Response response ) throws UnsupportedEncodingException | ||
{ | ||
return new String( (byte[]) response.getEntity(), "UTF-8" ); | ||
} | ||
|
||
private static class ShellOnlyConsoleSessionFactory implements ConsoleSessionFactory | ||
{ | ||
@Override | ||
public ScriptSession createSession(String engineName, Database database) | ||
{ | ||
return null; | ||
} | ||
|
||
@Override | ||
public Iterable<String> supportedEngines() | ||
{ | ||
return new ArrayList<String>(){{ | ||
add("shell"); | ||
}}; | ||
} | ||
} | ||
|
||
private static class GremlinAndShellConsoleSessionFactory implements ConsoleSessionFactory | ||
{ | ||
@Override | ||
public ScriptSession createSession(String engineName, Database database) | ||
{ | ||
return null; | ||
} | ||
|
||
@Override | ||
public Iterable<String> supportedEngines() | ||
{ | ||
return new ArrayList<String>(){{ | ||
add("shell"); | ||
add("gremlin"); | ||
}}; | ||
} | ||
} | ||
} |
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
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
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
Oops, something went wrong.