-
Notifications
You must be signed in to change notification settings - Fork 0
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
Adding a few simple tests to verify the newly added connection properties #1
Conversation
Adds two new connection properties that can be used to specify a custom TrustManager implementation: trustManagerClass - Class name of the custom TrustManager trustManagerConstructorArg - Optional argument to pass to the constructor constructor of the custom TrustManager. If encryption is enabled and the trustManagerClass property is specified, it will be retrieved via Class.forName(...). If the optional property trustManagerConstructorArg is specified, then a constructor will be retrieved via getDeclaredConstructors(String.class). The TrustManager will then be instantiated by specified the optional argument as a parameter. If the optional property trustManagerConstructorArg is not specfied, then the default no argument constructor of the class will be retrieved and instantiated.
Codecov Report
@@ Coverage Diff @@
## custom-trust-manager #1 +/- ##
==========================================================
+ Coverage 33.76% 33.76% +<.01%
+ Complexity 1520 1518 -2
==========================================================
Files 101 101
Lines 23625 23625
Branches 3881 3881
==========================================================
+ Hits 7976 7978 +2
+ Misses 14080 14078 -2
Partials 1569 1569
Continue to review full report at Codecov.
|
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.
Very nice. Couple minor edits (newlines at EOF), missing resource cleanup, and replacing dynamic class name with static .class
references.
return null; | ||
} | ||
|
||
} |
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.
Missing a new line here.
public X509Certificate[] getAcceptedIssuers() { | ||
return new X509Certificate[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.
Missing newline.
public X509Certificate[] getAcceptedIssuers() { | ||
return new X509Certificate[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.
Missing newline.
*/ | ||
@Test | ||
public void testWithPermissiveX509TrustManager() throws Exception { | ||
String url = connectionString + ";trustManagerClass=" + this.getClass().getPackage().getName() + ".PermissiveTrustManager" + ";encrypt=true;"; |
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.
There's no need for generating the class name from the package plus a string. You can directly reference the class and call getName(), i.e. TrustManagerWithConstructorArg.class.getName(). That way it'll be strongly typed and catch name changes to the dummy trust manager classes.
public void testWithTrustManagerConstructorArg() throws Exception { | ||
String url = connectionString + ";trustManagerClass=" + this.getClass().getPackage().getName() + ".TrustManagerWithConstructorArg" | ||
+ ";trustManagerConstructorArg=dummyString;" + ";encrypt=true;"; | ||
SQLServerConnection con = (SQLServerConnection) DriverManager.getConnection(url); |
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.
Connection should be closed. Easiest would be to wrap in a try-with-resources and have the assert within the try block.
String url = connectionString + ";trustManagerClass=" + this.getClass().getPackage().getName() + ".InvalidTrustManager" | ||
+ ";encrypt=true;"; | ||
SQLServerConnection con = (SQLServerConnection) DriverManager.getConnection(url); | ||
assertTrue(con == null); |
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.
Rather than an assert that the connection is null I'd assert.fail(...)
here. That line should never be reached if (correctly) an exception is thrown.
5f4100e
to
bb481c1
Compare
No description provided.