Skip to content

Adding a few simple tests to verify the newly added connection properties#1

Closed
ulvii wants to merge 2 commits intosehrope:custom-trust-managerfrom
ulvii:customTM
Closed

Adding a few simple tests to verify the newly added connection properties#1
ulvii wants to merge 2 commits intosehrope:custom-trust-managerfrom
ulvii:customTM

Conversation

@ulvii
Copy link
Copy Markdown

@ulvii ulvii commented Aug 31, 2017

No description provided.

sehrope and others added 2 commits April 19, 2017 08:08
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-io
Copy link
Copy Markdown

Codecov Report

Merging #1 into custom-trust-manager will increase coverage by <.01%.
The diff coverage is n/a.

Impacted file tree graph

@@                    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
Flag Coverage Δ Complexity Δ
#JDBC41 33.59% <ø> (-0.03%) 1509 <ø> (-3)
#JDBC42 33.68% <ø> (+0.07%) 1512 <ø> (-2) ⬇️
Impacted Files Coverage Δ Complexity Δ
...om/microsoft/sqlserver/jdbc/SimpleInputStream.java 40.44% <0%> (-1.48%) 9% <0%> (-1%)
...rc/main/java/com/microsoft/sqlserver/jdbc/DDC.java 27% <0%> (-0.67%) 48% <0%> (ø)
...m/microsoft/sqlserver/jdbc/SQLServerResultSet.java 24.59% <0%> (-0.59%) 175% <0%> (-4%)
...oft/sqlserver/jdbc/SQLServerPreparedStatement.java 30.1% <0%> (-0.09%) 84% <0%> (-1%)
.../microsoft/sqlserver/jdbc/SQLServerConnection.java 41.39% <0%> (+0.08%) 230% <0%> (+2%) ⬆️
...in/java/com/microsoft/sqlserver/jdbc/IOBuffer.java 37.98% <0%> (+0.37%) 0% <0%> (ø) ⬇️
...om/microsoft/sqlserver/jdbc/SQLServerBulkCopy.java 45.63% <0%> (+0.65%) 183% <0%> (+2%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5f4100e...d680891. Read the comment docs.

Copy link
Copy Markdown
Owner

@sehrope sehrope left a 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;
}

} No newline at end of file
Copy link
Copy Markdown
Owner

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];
}
} No newline at end of file
Copy link
Copy Markdown
Owner

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];
}
} No newline at end of file
Copy link
Copy Markdown
Owner

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;";
Copy link
Copy Markdown
Owner

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);
Copy link
Copy Markdown
Owner

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);
Copy link
Copy Markdown
Owner

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.

@ulvii
Copy link
Copy Markdown
Author

ulvii commented Aug 31, 2017

Hi @sehrope ,

Feel free to merge the PR and apply your review comments. The changes will automatically show up here.

@sehrope sehrope force-pushed the custom-trust-manager branch from 5f4100e to bb481c1 Compare September 1, 2017 12:02
@sehrope sehrope closed this Sep 1, 2017
sehrope pushed a commit that referenced this pull request Mar 21, 2018
sehrope pushed a commit that referenced this pull request Mar 21, 2018
sehrope pushed a commit that referenced this pull request Mar 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants