Skip to content
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

Enable AD integrated tests for non-Windows #1425

Merged
merged 43 commits into from
Oct 5, 2020
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
c97b863
Fix AEv2 tests exclude for reqExternalSetup and cleanup (#1247)
lilgreenbird Feb 5, 2020
54b5a19
Fix | Add null check for getObject() with LocalTime and LocalDate (#1…
peterbae Feb 8, 2020
672b7d6
added all AKV tests to use reqExternalSetup tag so they will be skipp…
lilgreenbird Feb 10, 2020
3c3331b
Merge remote-tracking branch 'upstream/dev' into dev
lilgreenbird Mar 25, 2020
e2c5640
Merge remote-tracking branch 'upstream/dev' into dev
lilgreenbird Mar 26, 2020
aad6966
Merge remote-tracking branch 'upstream/dev' into dev
lilgreenbird Mar 28, 2020
92bf04c
Merge remote-tracking branch 'upstream/dev' into dev
lilgreenbird Mar 31, 2020
3ba5ab7
Merge remote-tracking branch 'upstream/dev' into dev
lilgreenbird Apr 4, 2020
d20823d
Merge remote-tracking branch 'upstream/dev' into dev
lilgreenbird Apr 7, 2020
4cc959f
Merge remote-tracking branch 'upstream/dev' into dev
lilgreenbird Apr 29, 2020
7b301f8
Merge remote-tracking branch 'upstream/dev' into dev
lilgreenbird Apr 30, 2020
56bcf13
Merge remote-tracking branch 'upstream/dev' into dev
lilgreenbird May 7, 2020
744e0ca
Merge remote-tracking branch 'upstream/dev' into dev
lilgreenbird May 12, 2020
df8fd41
Merge remote-tracking branch 'upstream/dev' into dev
lilgreenbird May 19, 2020
652e68b
Merge remote-tracking branch 'upstream/dev' into dev
lilgreenbird May 26, 2020
53736db
Merge remote-tracking branch 'upstream/dev' into dev
lilgreenbird May 26, 2020
9ba6a42
Merge remote-tracking branch 'upstream/dev' into dev
lilgreenbird Jun 2, 2020
6d156f7
Merge remote-tracking branch 'upstream/dev' into dev
lilgreenbird Jun 5, 2020
e08ffe5
Merge remote-tracking branch 'upstream/dev' into dev
lilgreenbird Jun 10, 2020
6b6cab2
Merge remote-tracking branch 'upstream/dev' into dev
lilgreenbird Jun 18, 2020
c202590
Merge remote-tracking branch 'upstream/dev' into dev
lilgreenbird Jun 24, 2020
0515d4b
Merge remote-tracking branch 'upstream/dev' into dev
lilgreenbird Jun 24, 2020
2c63b58
Merge remote-tracking branch 'upstream/dev' into dev
lilgreenbird Jun 25, 2020
78aa941
Merge remote-tracking branch 'upstream/dev' into dev
lilgreenbird Jul 2, 2020
90e99cd
Merge remote-tracking branch 'upstream/dev' into dev
lilgreenbird Jul 2, 2020
da1004b
Merge remote-tracking branch 'upstream/dev' into dev
lilgreenbird Jul 6, 2020
9ca1284
Merge remote-tracking branch 'upstream/dev' into dev
lilgreenbird Jul 28, 2020
c67d8ed
Merge remote-tracking branch 'upstream/dev' into dev
lilgreenbird Aug 1, 2020
1d0a4ad
Merge remote-tracking branch 'upstream/dev' into dev
lilgreenbird Aug 5, 2020
f1b1dfb
Merge remote-tracking branch 'upstream/dev' into dev
lilgreenbird Aug 26, 2020
d9bad87
Merge remote-tracking branch 'upstream/dev' into dev
lilgreenbird Sep 2, 2020
a2e50b9
Merge remote-tracking branch 'upstream/dev' into dev
lilgreenbird Sep 9, 2020
7ff97de
enable ADintegrated tests for non-windows
lilgreenbird Sep 9, 2020
7cae3b4
fixed user test for kerberos
lilgreenbird Sep 11, 2020
d0e8c6e
testing
lilgreenbird Sep 17, 2020
4cc5e30
add sync
lilgreenbird Sep 17, 2020
d0e41f9
update exception
lilgreenbird Sep 18, 2020
25abedb
debug
lilgreenbird Sep 18, 2020
b85a336
debug
lilgreenbird Sep 18, 2020
406e8fa
removed debug
lilgreenbird Sep 18, 2020
d26a4e9
log error
lilgreenbird Sep 18, 2020
e77f0c8
Merge remote-tracking branch 'upstream/dev' into testkerb
lilgreenbird Sep 30, 2020
838012e
review updates
lilgreenbird Sep 30, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,30 @@ static SqlFedAuthToken getSqlFedAuthToken(SqlFedAuthInfo fedAuthInfo, String use
return new SqlFedAuthToken(authenticationResult.getAccessToken(), authenticationResult.getExpiresOnDate());
} catch (MalformedURLException | InterruptedException e) {
throw new SQLServerException(e.getMessage(), e);
} catch (ExecutionException e) {
} catch (Exception e) {
lilgreenbird marked this conversation as resolved.
Show resolved Hide resolved
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_ADALExecution"));
Object[] msgArgs = {user, authenticationString};
Object[] msgArgs = {user, authenticationString, e.getMessage()};

/*
* the cause error message uses \\n\\r which does not give correct format change it to \r\n to provide
* correct format
*/
String correctedErrorMessage = e.getCause().getMessage().replaceAll("\\\\r\\\\n", "\r\n");
AuthenticationException correctedAuthenticationException = new AuthenticationException(
correctedErrorMessage);
if (null == e.getCause() || null == e.getCause().getMessage()) {
throw new SQLServerException(form.format(msgArgs), null);
} else {
String correctedErrorMessage = e.getCause().getMessage().replaceAll("\\\\r\\\\n", "\r\n");
AuthenticationException correctedAuthenticationException = new AuthenticationException(
correctedErrorMessage);

/*
* SQLServerException is caused by ExecutionException, which is caused by AuthenticationException to match
* the exception tree before error message correction
*/
ExecutionException correctedExecutionException = new ExecutionException(correctedAuthenticationException);
/*
* SQLServerException is caused by ExecutionException, which is caused by AuthenticationException to
* match the exception tree before error message correction
*/
ExecutionException correctedExecutionException = new ExecutionException(
correctedAuthenticationException);

throw new SQLServerException(form.format(msgArgs), null, 0, correctedExecutionException);
throw new SQLServerException(form.format(msgArgs), null, 0, correctedExecutionException);
}
} finally {
executorService.shutdown();
}
Expand Down Expand Up @@ -90,9 +95,9 @@ static SqlFedAuthToken getSqlFedAuthTokenIntegrated(SqlFedAuthInfo fedAuthInfo,
return new SqlFedAuthToken(authenticationResult.getAccessToken(), authenticationResult.getExpiresOnDate());
} catch (InterruptedException | IOException e) {
throw new SQLServerException(e.getMessage(), e);
} catch (ExecutionException e) {
} catch (Exception e) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_ADALExecution"));
Object[] msgArgs = {"", authenticationString};
Object[] msgArgs = {"", authenticationString, e.getMessage()};

if (null == e.getCause() || null == e.getCause().getMessage()) {
// the case when Future's outcome has no AuthenticationResult but exception
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ protected Object[][] getContents() {
"FEDAUTHINFO token stream is not long enough ({0}) to contain the data it claims to."},
{"R_FedAuthInfoDoesNotContainStsurlAndSpn",
"FEDAUTHINFO token stream does not contain both STSURL and SPN."},
{"R_ADALExecution", "Failed to authenticate the user {0} in Active Directory (Authentication={1})."},
{"R_ADALExecution", "Failed to authenticate the user {0} in Active Directory (Authentication={1}). {2}"},
{"R_UnrequestedFeatureAckReceived", "Unrequested feature acknowledge is received. Feature ID: {0}."},
{"R_FedAuthFeatureAckContainsExtraData",
"Federated authentication feature extension ack for ADAL and Security Token includes extra data."},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public void testConcurrentLogin() throws Exception {

t1.start();
t2.start();
if (isWindows && enableADIntegrated) {
if (enableADIntegrated) {
Thread t3 = new Thread(r3);
t3.setUncaughtExceptionHandler(handler);
t3.start();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void testAccessTokenExpiredThenCreateNewStatementADPassword() throws SQLE

@Test
public void testAccessTokenExpiredThenCreateNewStatementADIntegrated() throws SQLException {
org.junit.Assume.assumeTrue(isWindows && enableADIntegrated);
org.junit.Assume.assumeTrue(enableADIntegrated);

testAccessTokenExpiredThenCreateNewStatement(SqlAuthentication.ActiveDirectoryIntegrated);
}
Expand Down Expand Up @@ -107,7 +107,7 @@ public void testAccessTokenExpiredThenExecuteUsingSameStatementADPassword() thro

@Test
public void testAccessTokenExpiredThenExecuteUsingSameStatementADIntegrated() throws SQLException {
org.junit.Assume.assumeTrue(isWindows && enableADIntegrated);
org.junit.Assume.assumeTrue(enableADIntegrated);

testAccessTokenExpiredThenExecuteUsingSameStatement(SqlAuthentication.ActiveDirectoryIntegrated);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
@Tag(Constants.fedAuth)
public class ErrorMessageTest extends FedauthCommon {

String userName = "abc" + azureUserName;
String badUserName = "abc" + azureUserName;
String connectionUrl = "jdbc:sqlserver://" + azureServer + ";database=" + azureDatabase;

@Test
Expand Down Expand Up @@ -214,13 +214,14 @@ public void testSQLPasswordWithUntrustedSqlDB() throws SQLException {

@Test
public void testADPasswordUnregisteredUserWithConnectionStringUserName() throws SQLException {
try (Connection connection = DriverManager.getConnection(connectionUrl + ";userName=" + userName + ";password="
+ azurePassword + ";Authentication=" + SqlAuthentication.ActiveDirectoryPassword.toString())) {
try (Connection connection = DriverManager
.getConnection(connectionUrl + ";userName=" + badUserName + ";password=" + azurePassword
+ ";Authentication=" + SqlAuthentication.ActiveDirectoryPassword.toString())) {
fail(EXPECTED_EXCEPTION_NOT_THROWN);
} catch (SQLServerException e) {
assertTrue(INVALID_EXCEPION_MSG + ": " + e.getMessage(),
e.getMessage()
.contains(ERR_MSG_FAILED_AUTHENTICATE + " the user " + userName
.contains(ERR_MSG_FAILED_AUTHENTICATE + " the user " + badUserName
+ " in Active Directory (Authentication=ActiveDirectoryPassword).")
&& e.getCause().getCause().getMessage().contains(ERR_MSG_SIGNIN_ADD));
}
Expand All @@ -232,7 +233,7 @@ public void testADPasswordUnregisteredUserWithDatasource() throws SQLException {
SQLServerDataSource ds = new SQLServerDataSource();
ds.setServerName(azureServer);
ds.setDatabaseName(azureDatabase);
ds.setUser(userName);
ds.setUser(badUserName);
ds.setPassword(azurePassword);
ds.setAuthentication(SqlAuthentication.ActiveDirectoryPassword.toString());

Expand All @@ -241,21 +242,21 @@ public void testADPasswordUnregisteredUserWithDatasource() throws SQLException {
} catch (SQLServerException e) {
assertTrue(INVALID_EXCEPION_MSG + ": " + e.getMessage(),
e.getMessage()
.contains(ERR_MSG_FAILED_AUTHENTICATE + " the user " + userName
.contains(ERR_MSG_FAILED_AUTHENTICATE + " the user " + badUserName
+ " in Active Directory (Authentication=ActiveDirectoryPassword).")
&& e.getCause().getCause().getMessage().contains(ERR_MSG_SIGNIN_ADD));
}
}

@Test
public void testADPasswordUnregisteredUserWithConnectionStringUser() throws SQLException {
try (Connection connection = DriverManager.getConnection(connectionUrl + ";user=" + userName + ";password="
try (Connection connection = DriverManager.getConnection(connectionUrl + ";user=" + badUserName + ";password="
+ azurePassword + ";Authentication=" + SqlAuthentication.ActiveDirectoryPassword.toString())) {
fail(EXPECTED_EXCEPTION_NOT_THROWN);
} catch (SQLServerException e) {
assertTrue(INVALID_EXCEPION_MSG + ": " + e.getMessage(),
e.getMessage()
.contains(ERR_MSG_FAILED_AUTHENTICATE + " the user " + userName
.contains(ERR_MSG_FAILED_AUTHENTICATE + " the user " + badUserName
+ " in Active Directory (Authentication=ActiveDirectoryPassword).")
&& e.getCause().getCause().getMessage().contains(ERR_MSG_SIGNIN_ADD));
}
Expand All @@ -268,20 +269,20 @@ public void testAuthenticationAgainstSQLServerWithActivedirectorypassword() thro
info.put("Authentication", SqlAuthentication.ActiveDirectoryPassword.toString());

try (Connection connection = DriverManager
.getConnection(connectionUrl + ";user=" + userName + ";password=" + azurePassword, info)) {
.getConnection(connectionUrl + ";user=" + badUserName + ";password=" + azurePassword, info)) {
fail(EXPECTED_EXCEPTION_NOT_THROWN);
} catch (Exception e) {
if (!(e instanceof SQLServerException)) {
fail(EXPECTED_EXCEPTION_NOT_THROWN);
}
assertTrue(INVALID_EXCEPION_MSG + ": " + e.getMessage(), e.getMessage().contains(ERR_MSG_FAILED_AUTHENTICATE
+ " the user " + userName + " in Active Directory (Authentication=ActiveDirectoryPassword)."));
+ " the user " + badUserName + " in Active Directory (Authentication=ActiveDirectoryPassword)."));
}
}

@Test
public void testAuthenticationAgainstSQLServerWithActivedirectoryIntegrated() throws SQLException {
org.junit.Assume.assumeTrue(isWindows && enableADIntegrated);
org.junit.Assume.assumeTrue(enableADIntegrated);

java.util.Properties info = new Properties();
info.put("TrustServerCertificate", "true");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public static void getConfigs() throws Exception {
azureGroupUserName = getConfiguredProperty("azureGroupUserName");

String prop = getConfiguredProperty("enableADIntegrated");
enableADIntegrated = (isWindows && null != prop && prop.equalsIgnoreCase("true")) ? true : false;
enableADIntegrated = (null != prop && prop.equalsIgnoreCase("true")) ? true : false;

adPasswordConnectionStr = "jdbc:sqlserver://" + azureServer + ";database=" + azureDatabase + ";user="
+ azureUserName + ";password=" + azurePassword + ";Authentication="
Expand Down Expand Up @@ -158,7 +158,12 @@ void testUserName(Connection conn, String user, SqlAuthentication authentication
if (SqlAuthentication.ActiveDirectoryIntegrated != authentication) {
assertTrue(user.equals(rs.getString(1)));
} else {
assertTrue(rs.getString(1).contains(System.getProperty("user.name")));
if (isWindows) {
assertTrue(rs.getString(1).contains(System.getProperty("user.name")));
} else {
// cannot verify user in kerberos tickets so just check it's not empty
assertTrue(!rs.getString(1).isEmpty());
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public void testActiveDirectoryPasswordDS() throws Exception {

@Test
public void testActiveDirectoryIntegratedDS() throws Exception {
org.junit.Assume.assumeTrue(isWindows && enableADIntegrated);
org.junit.Assume.assumeTrue(enableADIntegrated);

SQLServerDataSource ds = new SQLServerDataSource();
ds.setServerName(azureServer);
Expand Down Expand Up @@ -173,7 +173,7 @@ public void testNotValidSqlPassword() throws SQLException {

@Test
public void testNotValidActiveDirectoryIntegrated() throws SQLException {
org.junit.Assume.assumeTrue(isWindows && enableADIntegrated);
org.junit.Assume.assumeTrue(enableADIntegrated);

testNotValid(SqlAuthentication.ActiveDirectoryIntegrated.toString(), false, true);
testNotValid(SqlAuthentication.ActiveDirectoryIntegrated.toString(), true, true);
Expand All @@ -200,7 +200,7 @@ public void testValidSqlPassword() throws SQLException {

@Test
public void testValidActiveDirectoryIntegrated() throws SQLException {
org.junit.Assume.assumeTrue(isWindows && enableADIntegrated);
org.junit.Assume.assumeTrue(enableADIntegrated);

testValid(SqlAuthentication.ActiveDirectoryIntegrated.toString(), false, true);
testValid(SqlAuthentication.ActiveDirectoryIntegrated.toString(), true, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void testPooledConnectionAccessTokenExpiredThenReconnectADPassword() thro

@Test
public void testPooledConnectionAccessTokenExpiredThenReconnectADIntegrated() throws SQLException {
org.junit.Assume.assumeTrue(isWindows && enableADIntegrated);
org.junit.Assume.assumeTrue(enableADIntegrated);

// suspend 5 mins
testPooledConnectionAccessTokenExpiredThenReconnect((long) 5 * 60, SqlAuthentication.ActiveDirectoryIntegrated);
Expand Down Expand Up @@ -132,7 +132,7 @@ public void testPooledConnectionMultiThreadADPassword() throws SQLException {

@Test
public void testPooledConnectionMultiThreadADIntegrated() throws SQLException {
org.junit.Assume.assumeTrue(isWindows && enableADIntegrated);
org.junit.Assume.assumeTrue(enableADIntegrated);

testPooledConnectionMultiThread(secondsBeforeExpiration, SqlAuthentication.ActiveDirectoryIntegrated);
}
Expand Down