diff --git a/cypher-shell/src/integration-test/java/org/neo4j/shell/MainIntegrationTest.java b/cypher-shell/src/integration-test/java/org/neo4j/shell/MainIntegrationTest.java index 222c977a..04be98e4 100644 --- a/cypher-shell/src/integration-test/java/org/neo4j/shell/MainIntegrationTest.java +++ b/cypher-shell/src/integration-test/java/org/neo4j/shell/MainIntegrationTest.java @@ -273,7 +273,7 @@ public void wrongPortWithBolt() throws Exception { // given CliArgs cliArgs = new CliArgs(); - cliArgs.setScheme( "bolt://", "" ); + cliArgs.setScheme( "bolt", "" ); cliArgs.setPort( 1234 ); ShellAndConnection sac = getShell( cliArgs ); @@ -290,7 +290,7 @@ public void wrongPortWithNeo4j() throws Exception { // given CliArgs cliArgs = new CliArgs(); - cliArgs.setScheme( "neo4j://", "" ); + cliArgs.setScheme( "neo4j", "" ); cliArgs.setPort( 1234 ); ShellAndConnection sac = getShell( cliArgs ); diff --git a/cypher-shell/src/integration-test/java/org/neo4j/shell/commands/CypherShellIntegrationTest.java b/cypher-shell/src/integration-test/java/org/neo4j/shell/commands/CypherShellIntegrationTest.java index 0a728ecb..20f13796 100644 --- a/cypher-shell/src/integration-test/java/org/neo4j/shell/commands/CypherShellIntegrationTest.java +++ b/cypher-shell/src/integration-test/java/org/neo4j/shell/commands/CypherShellIntegrationTest.java @@ -12,6 +12,6 @@ abstract class CypherShellIntegrationTest CypherShell shell; void connect(String password) throws CommandException { - shell.connect( new ConnectionConfig( "bolt://", "localhost", 7687, "neo4j", password, Encryption.DEFAULT, ABSENT_DB_NAME ) ); + shell.connect( new ConnectionConfig( "bolt", "localhost", 7687, "neo4j", password, Encryption.DEFAULT, ABSENT_DB_NAME ) ); } } diff --git a/cypher-shell/src/integration-test/java/org/neo4j/shell/commands/CypherShellMultiDatabaseIntegrationTest.java b/cypher-shell/src/integration-test/java/org/neo4j/shell/commands/CypherShellMultiDatabaseIntegrationTest.java index 4aaff41d..0390a5c1 100644 --- a/cypher-shell/src/integration-test/java/org/neo4j/shell/commands/CypherShellMultiDatabaseIntegrationTest.java +++ b/cypher-shell/src/integration-test/java/org/neo4j/shell/commands/CypherShellMultiDatabaseIntegrationTest.java @@ -46,7 +46,7 @@ public void setUp() throws Exception beginCommand = new Begin( shell ); rollbackCommand = new Rollback( shell ); - shell.connect( new ConnectionConfig( "bolt://", "localhost", 7687, "neo4j", "neo", Encryption.DEFAULT, ABSENT_DB_NAME ) ); + shell.connect( new ConnectionConfig( "bolt", "localhost", 7687, "neo4j", "neo", Encryption.DEFAULT, ABSENT_DB_NAME ) ); // Multiple databases are only available from 4.0 assumeTrue( majorVersion( shell.getServerVersion() ) >= 4 ); @@ -138,7 +138,7 @@ public void switchingToNonExistingDatabaseShouldGiveErrorResponseFromServerInter { shell = new CypherShell( linePrinter, new PrettyConfig( Format.PLAIN, true, 1000 ), true, new ShellParameterMap() ); useCommand = new Use( shell ); - shell.connect( new ConnectionConfig( "bolt://", "localhost", 7687, "neo4j", "neo", Encryption.DEFAULT, ABSENT_DB_NAME ) ); + shell.connect( new ConnectionConfig( "bolt", "localhost", 7687, "neo4j", "neo", Encryption.DEFAULT, ABSENT_DB_NAME ) ); useCommand.execute( SYSTEM_DB_NAME ); diff --git a/cypher-shell/src/integration-test/java/org/neo4j/shell/commands/CypherShellProtocolIntegrationTest.java b/cypher-shell/src/integration-test/java/org/neo4j/shell/commands/CypherShellProtocolIntegrationTest.java index 3aab672d..a4d52547 100644 --- a/cypher-shell/src/integration-test/java/org/neo4j/shell/commands/CypherShellProtocolIntegrationTest.java +++ b/cypher-shell/src/integration-test/java/org/neo4j/shell/commands/CypherShellProtocolIntegrationTest.java @@ -21,7 +21,7 @@ public class CypherShellProtocolIntegrationTest{ @Test public void shouldConnectWithBoltProtocol() throws Exception { CypherShell shell = new CypherShell( new StringLinePrinter(), new PrettyConfig( Format.PLAIN, true, 1000), false, new ShellParameterMap()); - shell.connect( new ConnectionConfig( "bolt://", "localhost", 7687, "neo4j", "neo", Encryption.DEFAULT, ABSENT_DB_NAME ) ); + shell.connect( new ConnectionConfig( "bolt", "localhost", 7687, "neo4j", "neo", Encryption.DEFAULT, ABSENT_DB_NAME ) ); assertTrue(shell.isConnected()); } @@ -29,7 +29,7 @@ public void shouldConnectWithBoltProtocol() throws Exception { public void shouldConnectWithNeo4jProtocol() throws Exception { CypherShell shell = new CypherShell( new StringLinePrinter(), new PrettyConfig( Format.PLAIN, true, 1000), false, new ShellParameterMap()); // This should work even on older databases without the neo4j protocol, by falling back to bolt - shell.connect( new ConnectionConfig( "neo4j://", "localhost", 7687, "neo4j", "neo", Encryption.DEFAULT, ABSENT_DB_NAME ) ); + shell.connect( new ConnectionConfig( "neo4j", "localhost", 7687, "neo4j", "neo", Encryption.DEFAULT, ABSENT_DB_NAME ) ); assertTrue(shell.isConnected()); } @@ -38,7 +38,7 @@ public void shouldConnectWithBoltSSCProtocol() throws Exception { CypherShell shell = new CypherShell( new StringLinePrinter(), new PrettyConfig( Format.PLAIN, true, 1000), false, new ShellParameterMap()); // Given 3.X series where X > 1, where SSC are the default. Hard to test in 4.0 sadly. onlyIn3_2to3_6( shell); - shell.connect( new ConnectionConfig( "bolt+ssc://", "localhost", 7687, "neo4j", "neo", Encryption.DEFAULT, ABSENT_DB_NAME ) ); + shell.connect( new ConnectionConfig( "bolt+ssc", "localhost", 7687, "neo4j", "neo", Encryption.DEFAULT, ABSENT_DB_NAME ) ); assertTrue(shell.isConnected()); } @@ -48,7 +48,7 @@ public void shouldConnectWithNeo4jSSCProtocol() throws Exception { // Given 3.X series where X > 1, where SSC are the default. Hard to test in 4.0 sadly. onlyIn3_2to3_6( shell); // This should work by falling back to bolt+ssc - shell.connect( new ConnectionConfig( "neo4j+ssc://", "localhost", 7687, "neo4j", "neo", Encryption.DEFAULT, ABSENT_DB_NAME ) ); + shell.connect( new ConnectionConfig( "neo4j+ssc", "localhost", 7687, "neo4j", "neo", Encryption.DEFAULT, ABSENT_DB_NAME ) ); assertTrue(shell.isConnected()); } @@ -56,7 +56,7 @@ public void shouldConnectWithNeo4jSSCProtocol() throws Exception { private void onlyIn3_2to3_6( CypherShell shell) throws Exception { // Default connection settings - shell.connect( new ConnectionConfig( "bolt://", "localhost", 7687, "neo4j", "neo", Encryption.DEFAULT, ABSENT_DB_NAME ) ); + shell.connect( new ConnectionConfig( "bolt", "localhost", 7687, "neo4j", "neo", Encryption.DEFAULT, ABSENT_DB_NAME ) ); assumeTrue( majorVersion( shell.getServerVersion() ) == 3 ); assumeTrue( minorVersion( shell.getServerVersion() ) > 1 ); shell.disconnect(); diff --git a/cypher-shell/src/main/java/org/neo4j/shell/ConnectionConfig.java b/cypher-shell/src/main/java/org/neo4j/shell/ConnectionConfig.java index 88654f1a..6db56e9f 100644 --- a/cypher-shell/src/main/java/org/neo4j/shell/ConnectionConfig.java +++ b/cypher-shell/src/main/java/org/neo4j/shell/ConnectionConfig.java @@ -76,7 +76,7 @@ public String newPassword() { @Nonnull public String driverUrl() { - return String.format("%s%s:%d", scheme(), host(), port()); + return String.format("%s://%s:%d", scheme(), host(), port()); } @Nonnull diff --git a/cypher-shell/src/main/java/org/neo4j/shell/cli/CliArgHelper.java b/cypher-shell/src/main/java/org/neo4j/shell/cli/CliArgHelper.java index 2b646977..4b278a91 100644 --- a/cypher-shell/src/main/java/org/neo4j/shell/cli/CliArgHelper.java +++ b/cypher-shell/src/main/java/org/neo4j/shell/cli/CliArgHelper.java @@ -14,6 +14,8 @@ import net.sourceforge.argparse4j.inf.Namespace; import java.io.PrintWriter; +import java.net.URI; +import java.net.URISyntaxException; import java.util.regex.Matcher; import java.util.regex.Pattern; import javax.annotation.Nonnull; @@ -31,9 +33,6 @@ */ public class CliArgHelper { - static final Pattern ADDRESS_ARG_PATTERN = - Pattern.compile("\\s*(?[a-zA-Z0-9+\\-.]+://)?((?\\w+):(?[^\\s]+)@)?(?[a-zA-Z\\d\\-.]+)?(:(?\\d+))?\\s*"); - /** * @param args to parse * @return null in case of error, commandline arguments otherwise @@ -70,22 +69,21 @@ public static CliArgs parseAndThrow( @Nonnull String... args ) throws ArgumentPa private static CliArgs getCliArgs( CliArgs cliArgs, ArgumentParser parser, Namespace ns ) { // Parse address string, returns null on error - final Matcher addressMatcher = parseAddressMatcher( parser, ns.getString( "address")); + final URI uri = parseURI( parser, ns.getString( "address")); - if (addressMatcher == null) { + if (uri == null) { return null; } //--------------------- // Connection arguments - cliArgs.setScheme(addressMatcher.group("scheme"), "bolt://"); - cliArgs.setHost(addressMatcher.group("host"), "localhost"); - // Safe, regex only matches integers - String portString = addressMatcher.group("port"); - cliArgs.setPort(portString == null ? CliArgs.DEFAULT_PORT : Integer.parseInt(portString)); + cliArgs.setScheme(uri.getScheme(), "bolt"); + cliArgs.setHost(uri.getHost(), "localhost"); + + int port = uri.getPort(); + cliArgs.setPort(port == -1 ? 7687 : port); // Also parse username and password from address if available - cliArgs.setUsername(addressMatcher.group("username"), ""); - cliArgs.setPassword(addressMatcher.group("password"), ""); + parseUserInfo( uri, cliArgs ); // Only overwrite user/pass from address string if the arguments were specified String user = ns.getString("username"); @@ -125,19 +123,46 @@ private static CliArgs getCliArgs( CliArgs cliArgs, ArgumentParser parser, Names return cliArgs; } + private static void parseUserInfo(URI uri, CliArgs cliArgs) + { + String userInfo = uri.getUserInfo(); + String user = null; + String password = null; + if (userInfo != null) + { + String[] split = userInfo.split( ":" ); + if (split.length == 0) + { + user = userInfo; + } else if (split.length == 2) + { + user = split[0]; + password = split[1]; + } else { + throw new IllegalArgumentException("Cannot parse user and password from " + userInfo); + } + + } + cliArgs.setUsername(user, ""); + cliArgs.setPassword(password, ""); + } + @Nullable - private static Matcher parseAddressMatcher(ArgumentParser parser, String address) { - Matcher matcher = ADDRESS_ARG_PATTERN.matcher(address); - if (!matcher.matches()) { - // Match behavior in built-in error handling - PrintWriter printWriter = new PrintWriter(System.err); - parser.printUsage(printWriter); - printWriter.println("cypher-shell: error: Failed to parse address: '" + address + "'"); - printWriter.println("\n Address should be of the form: [scheme://][username:password@][host][:port]"); + static URI parseURI( ArgumentParser parser, String address ) + { + try + { + return new URI( address ); + } + catch ( URISyntaxException e ) + { + PrintWriter printWriter = new PrintWriter( System.err ); + parser.printUsage( printWriter ); + printWriter.println( "cypher-shell: error: Failed to parse address: '" + address + "'" ); + printWriter.println( "\n Address should be of the form: [scheme://][username:password@][host][:port]" ); printWriter.flush(); return null; } - return matcher; } private static ArgumentParser setupParser(ParameterMap parameterMap) @@ -153,7 +178,7 @@ private static ArgumentParser setupParser(ParameterMap parameterMap) ArgumentGroup connGroup = parser.addArgumentGroup("connection arguments"); connGroup.addArgument("-a", "--address") .help("address and port to connect to") - .setDefault(String.format("%s%s:%d", CliArgs.DEFAULT_SCHEME, CliArgs.DEFAULT_HOST, CliArgs.DEFAULT_PORT)); + .setDefault(String.format("%s://%s:%d", CliArgs.DEFAULT_SCHEME, CliArgs.DEFAULT_HOST, CliArgs.DEFAULT_PORT)); connGroup.addArgument("-u", "--username") .setDefault("") .help("username to connect as. Can also be specified using environment variable " + ConnectionConfig.USERNAME_ENV_VAR); diff --git a/cypher-shell/src/main/java/org/neo4j/shell/cli/CliArgs.java b/cypher-shell/src/main/java/org/neo4j/shell/cli/CliArgs.java index 3b87e937..fc5ecacd 100644 --- a/cypher-shell/src/main/java/org/neo4j/shell/cli/CliArgs.java +++ b/cypher-shell/src/main/java/org/neo4j/shell/cli/CliArgs.java @@ -10,7 +10,7 @@ import static org.neo4j.shell.DatabaseManager.ABSENT_DB_NAME; public class CliArgs { - static final String DEFAULT_SCHEME = "neo4j://"; + static final String DEFAULT_SCHEME = "neo4j"; static final String DEFAULT_HOST = "localhost"; static final int DEFAULT_PORT = 7687; static final int DEFAULT_NUM_SAMPLE_ROWS = 1000; diff --git a/cypher-shell/src/main/java/org/neo4j/shell/state/BoltStateHandler.java b/cypher-shell/src/main/java/org/neo4j/shell/state/BoltStateHandler.java index 85640b03..95c76c9b 100644 --- a/cypher-shell/src/main/java/org/neo4j/shell/state/BoltStateHandler.java +++ b/cypher-shell/src/main/java/org/neo4j/shell/state/BoltStateHandler.java @@ -195,20 +195,20 @@ public void connect( @Nonnull ConnectionConfig connectionConfig, ThrowingAction< String fallbackScheme; switch ( scheme ) { - case Scheme.NEO4J_URI_SCHEME + "://": + case Scheme.NEO4J_URI_SCHEME: fallbackScheme = Scheme.BOLT_URI_SCHEME; break; - case Scheme.NEO4J_LOW_TRUST_URI_SCHEME + "://": + case Scheme.NEO4J_LOW_TRUST_URI_SCHEME: fallbackScheme = Scheme.BOLT_LOW_TRUST_URI_SCHEME; break; - case Scheme.NEO4J_HIGH_TRUST_URI_SCHEME + "://": + case Scheme.NEO4J_HIGH_TRUST_URI_SCHEME: fallbackScheme = Scheme.BOLT_HIGH_TRUST_URI_SCHEME; break; default: throw e; } connectionConfig = new ConnectionConfig( - fallbackScheme + "://", + fallbackScheme, connectionConfig.host(), connectionConfig.port(), connectionConfig.username(), diff --git a/cypher-shell/src/test/java/org/neo4j/shell/ConnectionConfigTest.java b/cypher-shell/src/test/java/org/neo4j/shell/ConnectionConfigTest.java index 2f357a0d..3930c401 100644 --- a/cypher-shell/src/test/java/org/neo4j/shell/ConnectionConfigTest.java +++ b/cypher-shell/src/test/java/org/neo4j/shell/ConnectionConfigTest.java @@ -18,13 +18,13 @@ public class ConnectionConfigTest { = new EnvironmentVariables(); private Logger logger = mock(Logger.class); - private ConnectionConfig config = new ConnectionConfig("bolt://", "localhost", 1, "bob", + private ConnectionConfig config = new ConnectionConfig("bolt", "localhost", 1, "bob", "pass", Encryption.DEFAULT, "db"); @Test public void scheme() { - assertEquals("bolt://", config.scheme()); + assertEquals("bolt", config.scheme()); } @Test @@ -45,7 +45,7 @@ public void username() { @Test public void usernameDefaultsToEnvironmentVar() { environmentVariables.set(ConnectionConfig.USERNAME_ENV_VAR, "alice"); - ConnectionConfig configWithEmptyParams = new ConnectionConfig("bolt://", "localhost", 1, "", + ConnectionConfig configWithEmptyParams = new ConnectionConfig("bolt", "localhost", 1, "", "", Encryption.DEFAULT, ABSENT_DB_NAME); assertEquals("alice", configWithEmptyParams.username()); } @@ -58,7 +58,7 @@ public void password() { @Test public void passwordDefaultsToEnvironmentVar() { environmentVariables.set(ConnectionConfig.PASSWORD_ENV_VAR, "ssap"); - ConnectionConfig configWithEmptyParams = new ConnectionConfig("bolt://", "localhost", 1, "", + ConnectionConfig configWithEmptyParams = new ConnectionConfig("bolt", "localhost", 1, "", "", Encryption.DEFAULT, ABSENT_DB_NAME); assertEquals("ssap", configWithEmptyParams.password()); } @@ -71,7 +71,7 @@ public void database() { @Test public void databaseDefaultsToEnvironmentVar() { environmentVariables.set(ConnectionConfig.DATABASE_ENV_VAR, "funnyDB"); - ConnectionConfig configWithEmptyParams = new ConnectionConfig("bolt://", "localhost", 1, "", + ConnectionConfig configWithEmptyParams = new ConnectionConfig("bolt", "localhost", 1, "", "", Encryption.DEFAULT, ABSENT_DB_NAME); assertEquals("funnyDB", configWithEmptyParams.database()); } @@ -82,8 +82,8 @@ public void driverUrlDefaultScheme() { @Test public void encryption() { - assertEquals(Encryption.DEFAULT, new ConnectionConfig("bolt://", "", -1, "", "", Encryption.DEFAULT, ABSENT_DB_NAME).encryption()); - assertEquals(Encryption.TRUE, new ConnectionConfig("bolt://", "", -1, "", "", Encryption.TRUE, ABSENT_DB_NAME).encryption()); - assertEquals(Encryption.FALSE, new ConnectionConfig("bolt://", "", -1, "", "", Encryption.FALSE, ABSENT_DB_NAME).encryption()); + assertEquals(Encryption.DEFAULT, new ConnectionConfig("bolt", "", -1, "", "", Encryption.DEFAULT, ABSENT_DB_NAME).encryption()); + assertEquals(Encryption.TRUE, new ConnectionConfig("bolt", "", -1, "", "", Encryption.TRUE, ABSENT_DB_NAME).encryption()); + assertEquals(Encryption.FALSE, new ConnectionConfig("bolt", "", -1, "", "", Encryption.FALSE, ABSENT_DB_NAME).encryption()); } } diff --git a/cypher-shell/src/test/java/org/neo4j/shell/CypherShellTest.java b/cypher-shell/src/test/java/org/neo4j/shell/CypherShellTest.java index 224cd9e6..a252d61e 100644 --- a/cypher-shell/src/test/java/org/neo4j/shell/CypherShellTest.java +++ b/cypher-shell/src/test/java/org/neo4j/shell/CypherShellTest.java @@ -63,7 +63,7 @@ public void setup() { @Test public void verifyDelegationOfConnectionMethods() throws CommandException { - ConnectionConfig cc = new ConnectionConfig("bolt://", "", 1, "", "", Encryption.DEFAULT, ABSENT_DB_NAME); + ConnectionConfig cc = new ConnectionConfig("bolt", "", 1, "", "", Encryption.DEFAULT, ABSENT_DB_NAME); CypherShell shell = new CypherShell(logger, mockedBoltStateHandler, mockedPrettyPrinter, new ShellParameterMap()); shell.connect(cc); diff --git a/cypher-shell/src/test/java/org/neo4j/shell/cli/AddressArgPatternTest.java b/cypher-shell/src/test/java/org/neo4j/shell/cli/AddressArgPatternTest.java deleted file mode 100644 index cb6c0585..00000000 --- a/cypher-shell/src/test/java/org/neo4j/shell/cli/AddressArgPatternTest.java +++ /dev/null @@ -1,113 +0,0 @@ -package org.neo4j.shell.cli; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.regex.Matcher; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - -@SuppressWarnings("PMD.AvoidUsingHardCodedIP") -@RunWith(Parameterized.class) -public class AddressArgPatternTest { - - private final String scheme; - private final String host; - private final String port; - private final String username; - private final String password; - private final String connString; - - public AddressArgPatternTest(String scheme, String host, String port, - String username, String password) { - - this.scheme = scheme; - this.host = host; - this.port = port; - this.username = username; - this.password = password; - - StringBuilder connString = new StringBuilder().append(scheme); - // Only expect username/pass in case host is present - if (!host.isEmpty() && !username.isEmpty() && !password.isEmpty()) { - connString.append(username).append(":").append(password).append("@"); - } - if (!host.isEmpty()) { - connString.append(host); - } - if (!port.isEmpty()) { - connString.append(":").append(port); - } - this.connString = connString.toString(); - } - - @Parameterized.Parameters - public static Collection parameters() { - Collection data = new ArrayList<>(); - for (final String scheme : getSchemes()) { - for (final String username : getUsernames()) { - for (final String password : getPasswords()) { - for (final String host : getHosts()) { - for (final String port : getPorts()) { - data.add(new String[]{scheme, host, port, username, password}); - } - } - } - } - } - return data; - } - - private static String[] getPorts() { - return new String[]{"", "1", "23642"}; - } - - private static String[] getHosts() { - return new String[]{"", "localhost", "127.0.0.1", "ec2-54-73-70-121.eu-west-1.compute.amazonaws.com"}; - } - - private static String[] getPasswords() { - return new String[]{"pass1", "p@assw0rd"}; - } - - private static String[] getUsernames() { - return new String[]{"", "bob1"}; - } - - private static String[] getSchemes() { - return new String[]{"", "bolt://", "bolt+routing://", "w31rd.-+://"}; - } - - @Test - public void testUserPassschemeHostPort() { - Matcher m = CliArgHelper.ADDRESS_ARG_PATTERN.matcher(" " + connString + " "); - assertTrue("Expected a match: " + connString, m.matches()); - if (host.isEmpty()) { - assertNull("Host should have been null", m.group("host")); - } else { - assertEquals("Mismatched host", host, m.group("host")); - } - if (port.isEmpty()) { - assertNull("Port should have been null", m.group("port")); - } else { - assertEquals("Mismatched port", port, m.group("port")); - } - if (host.isEmpty() || username.isEmpty() || password.isEmpty()) { - assertNull("Username should have been null", m.group("username")); - assertNull("Password should have been null", m.group("password")); - } else { - assertEquals("Mismatched username", username, m.group("username")); - assertEquals("Mismatched password", password, m.group("password")); - } - if (scheme.isEmpty()) { - assertNull("scheme should have been null", m.group("scheme")); - } else { - assertEquals("Mismatched scheme", scheme, m.group("scheme")); - } - } -} diff --git a/cypher-shell/src/test/java/org/neo4j/shell/cli/CliArgHelperTest.java b/cypher-shell/src/test/java/org/neo4j/shell/cli/CliArgHelperTest.java index d1f0427c..9fde41a6 100644 --- a/cypher-shell/src/test/java/org/neo4j/shell/cli/CliArgHelperTest.java +++ b/cypher-shell/src/test/java/org/neo4j/shell/cli/CliArgHelperTest.java @@ -66,7 +66,7 @@ public void testWrap() { public void testDefaultScheme() { CliArgs arguments = CliArgHelper.parse(); assertNotNull( arguments ); - assertEquals( "neo4j://", arguments.getScheme() ); + assertEquals( "neo4j", arguments.getScheme() ); } @Test @@ -150,7 +150,7 @@ public void parseFullAddress() { assertNotNull(cliArgs); assertEquals("alice", cliArgs.getUsername()); assertEquals("foo", cliArgs.getPassword()); - assertEquals("bolt+routing://", cliArgs.getScheme()); + assertEquals("bolt+routing", cliArgs.getScheme()); assertEquals("bar", cliArgs.getHost()); assertEquals(69, cliArgs.getPort()); } @@ -165,6 +165,16 @@ public void defaultAddress() assertEquals( CliArgs.DEFAULT_PORT, cliArgs.getPort() ); } + @Test + public void parseAddressWithRoutingContext() + { + CliArgs cliArgs = CliArgHelper.parse( "--address", "neo4j://localhost:7697?policy=one" ); + assertNotNull( cliArgs ); + assertEquals( "neo4j", cliArgs.getScheme() ); + assertEquals( "localhost", cliArgs.getHost() ); + assertEquals( 7697, cliArgs.getPort() ); + } + @Test public void nonsenseArgsGiveError() { ByteArrayOutputStream bout = new ByteArrayOutputStream(); @@ -183,7 +193,7 @@ public void nonsenseUrlGivesError() { ByteArrayOutputStream bout = new ByteArrayOutputStream(); System.setErr(new PrintStream(bout)); - CliArgs cliargs = CliArgHelper.parse("--address", "host;port"); + CliArgs cliargs = CliArgHelper.parse("--address", "host port"); assertNull("should have failed", cliargs); diff --git a/cypher-shell/src/test/java/org/neo4j/shell/state/BoltStateHandlerTest.java b/cypher-shell/src/test/java/org/neo4j/shell/state/BoltStateHandlerTest.java index c19f77e1..4dd817a5 100644 --- a/cypher-shell/src/test/java/org/neo4j/shell/state/BoltStateHandlerTest.java +++ b/cypher-shell/src/test/java/org/neo4j/shell/state/BoltStateHandlerTest.java @@ -64,7 +64,7 @@ public class BoltStateHandlerTest { private final Logger logger = mock(Logger.class); private final Driver mockDriver = mock(Driver.class); private final OfflineBoltStateHandler boltStateHandler = new OfflineBoltStateHandler(mockDriver); - private final ConnectionConfig config = new ConnectionConfig("bolt://", "", -1, "", "", Encryption.DEFAULT, ABSENT_DB_NAME); + private final ConnectionConfig config = new ConnectionConfig("bolt", "", -1, "", "", Encryption.DEFAULT, ABSENT_DB_NAME); @Before public void setup() { @@ -387,7 +387,7 @@ public void turnOffEncryptionIfRequested() throws CommandException { public void turnOnEncryptionIfRequested() throws CommandException { RecordingDriverProvider provider = new RecordingDriverProvider(); BoltStateHandler handler = new BoltStateHandler(provider, false); - ConnectionConfig config = new ConnectionConfig("bolt://", "", -1, "", "", Encryption.TRUE, ABSENT_DB_NAME); + ConnectionConfig config = new ConnectionConfig("bolt", "", -1, "", "", Encryption.TRUE, ABSENT_DB_NAME); handler.connect(config); assertTrue(provider.config.encrypted()); } @@ -407,7 +407,7 @@ public Driver apply(String uri, AuthToken authToken, Config config) { } }; BoltStateHandler handler = new BoltStateHandler(provider, false); - ConnectionConfig config = new ConnectionConfig("neo4j://", "", -1, "", "", Encryption.DEFAULT, ABSENT_DB_NAME); + ConnectionConfig config = new ConnectionConfig("neo4j", "", -1, "", "", Encryption.DEFAULT, ABSENT_DB_NAME); handler.connect(config); assertEquals("bolt", uriScheme[0]); @@ -451,7 +451,7 @@ public Driver apply(String uri, AuthToken authToken, Config config) { } }; BoltStateHandler handler = new BoltStateHandler(provider, false); - ConnectionConfig config = new ConnectionConfig("neo4j+ssc://", "", -1, "", "", Encryption.DEFAULT, ABSENT_DB_NAME); + ConnectionConfig config = new ConnectionConfig("neo4j+ssc", "", -1, "", "", Encryption.DEFAULT, ABSENT_DB_NAME); handler.connect(config); assertEquals("bolt+ssc", uriScheme[0]); @@ -461,7 +461,7 @@ public Driver apply(String uri, AuthToken authToken, Config config) { public void shouldChangePasswordAndKeepSystemDbBookmark() throws CommandException { // Given - ConnectionConfig config = new ConnectionConfig("bolt://", "", -1, "", "", Encryption.DEFAULT, ABSENT_DB_NAME); + ConnectionConfig config = new ConnectionConfig("bolt", "", -1, "", "", Encryption.DEFAULT, ABSENT_DB_NAME); config.setNewPassword("newPW"); Bookmark bookmark = InternalBookmark.parse("myBookmark"); @@ -481,7 +481,7 @@ public void shouldChangePasswordAndKeepSystemDbBookmark() throws CommandExceptio assertNull(handler.session); // When connecting to system db again - handler.connect( new ConnectionConfig("bolt://", "", -1, "", "", Encryption.DEFAULT, SYSTEM_DB_NAME) ); + handler.connect( new ConnectionConfig("bolt", "", -1, "", "", Encryption.DEFAULT, SYSTEM_DB_NAME) ); // Then use bookmark for system DB verify( driverMock ).session(SessionConfig.builder() @@ -495,7 +495,7 @@ public void shouldChangePasswordAndKeepSystemDbBookmark() throws CommandExceptio @Test public void shouldKeepOneBookmarkPerDatabase() throws CommandException { - ConnectionConfig config = new ConnectionConfig("bolt://", "", -1, "", "", Encryption.DEFAULT, "database1"); + ConnectionConfig config = new ConnectionConfig("bolt", "", -1, "", "", Encryption.DEFAULT, "database1"); Bookmark db1Bookmark = InternalBookmark.parse("db1"); Bookmark db2Bookmark = InternalBookmark.parse("db2"); @@ -581,7 +581,7 @@ public Driver apply(String uri, AuthToken authToken, Config config) { } }; BoltStateHandler handler = new BoltStateHandler(provider, false); - ConnectionConfig config = new ConnectionConfig("neo4j+s://", "", -1, "", "", Encryption.DEFAULT, ABSENT_DB_NAME); + ConnectionConfig config = new ConnectionConfig("neo4j+s", "", -1, "", "", Encryption.DEFAULT, ABSENT_DB_NAME); handler.connect(config); assertEquals("bolt+s", uriScheme[0]); @@ -635,7 +635,7 @@ public OfflineBoltStateHandler(Driver driver) { } public void connect() throws CommandException { - connect(new ConnectionConfig("bolt://", "", 1, "", "", Encryption.DEFAULT, ABSENT_DB_NAME)); + connect(new ConnectionConfig("bolt", "", 1, "", "", Encryption.DEFAULT, ABSENT_DB_NAME)); } }