-
Notifications
You must be signed in to change notification settings - Fork 155
Fail correctly when connecting to a server with an unknown server identifier #542
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@@ -71,11 +72,25 @@ public void onRecord( Value[] fields ) | |||
throw new UnsupportedOperationException(); | |||
} | |||
|
|||
private static ServerVersion extractServerVersion( Map<String,Value> metadata ) | |||
private static ServerVersion extractServerVersion( Map<String,Value> metadata ) throws UntrustedServerException |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
throws
can be removed because UntrustedServerException
is a runtime exception
} | ||
else | ||
{ | ||
throw new UntrustedServerException( "Server does not identify as a genuine Neo4j instance" ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nice to include the received product string in the error message
|
||
private static final String NEO4J_IN_DEV_VERSION_STRING = "Neo4j/dev"; | ||
private static final Pattern PATTERN = | ||
Pattern.compile( "(Neo4j/)?(\\d+)\\.(\\d+)(?:\\.)?(\\d*)(\\.|-|\\+)?([0-9A-Za-z-.]*)?" ); | ||
Pattern.compile( "([^/]*)/(\\d+)\\.(\\d+)(?:\\.)?(\\d*)(\\.|-|\\+)?([0-9A-Za-z-.]*)?" ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will match strings like "/3.5.0" where the product part is absent. It is okay?
@@ -141,6 +142,10 @@ public boolean lessThanOrEqual(ServerVersion other) | |||
|
|||
private int compareTo( ServerVersion o ) | |||
{ | |||
if ( !product.equals( o.product ) ) | |||
{ | |||
throw new IllegalArgumentException("Comparing different products"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nice to include product names in the error message
public static final ServerVersion v3_1_0 = new ServerVersion( 3, 1, 0 ); | ||
public static final ServerVersion v3_0_0 = new ServerVersion( 3, 0, 0 ); | ||
public static final ServerVersion vInDev = new ServerVersion( Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE ); | ||
public static final ServerVersion v3_5_0 = new ServerVersion( "Neo4j", 3, 5, 0 ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Constant for string "Neo4j" would be nice
Make version parser not accept version strings like "/3.5.0".
9ebba3d
to
1f1898e
Compare
While we currently parse the "server" string returned in the INIT metadata to extract the server version, no logic existed to validate the product part of that string. Indeed, an unexpected product name would have caused the internal regex to fail and an unhelpful error would surface. This PR raises a new
UntrustedServerException
in the case that the product string does not identifyNeo4j
.