Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -4147,7 +4147,11 @@
final byte fedAuthOffset;
if (fedAuthRequiredByUser) {
messageLength = TDS.B_PRELOGIN_MESSAGE_LENGTH_WITH_FEDAUTH;
requestedEncryptionLevel = TDS.ENCRYPT_ON;
if (encryptOption.compareToIgnoreCase(EncryptOption.STRICT.toString()) == 0) {
requestedEncryptionLevel = TDS.ENCRYPT_NOT_SUP;

Check warning on line 4151 in src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java#L4151

Added line #L4151 was not covered by tests
} else {
requestedEncryptionLevel = TDS.ENCRYPT_ON;

Check warning on line 4153 in src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java#L4153

Added line #L4153 was not covered by tests
}

// since we added one more line for prelogin option with fedauth,
// we also needed to modify the offsets above, by adding 5 to each offset,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package com.microsoft.sqlserver.jdbc;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
Expand Down Expand Up @@ -1370,4 +1371,35 @@ public void testGetSqlFedAuthTokenFailureNagativeWaiting() throws SQLException {
}
}

@Test
@Tag(Constants.xAzureSQLDW)
@Tag(Constants.xAzureSQLMI)
@Tag(Constants.xSQLv11)
@Tag(Constants.xSQLv12)
@Tag(Constants.xSQLv14)
@Tag(Constants.xSQLv15)
@Tag(Constants.xSQLv16)
public void testManagedIdentityWithEncryptStrict() {
SQLServerDataSource ds = new SQLServerDataSource();

String connectionUrl = connectionString;
if (connectionUrl.contains("user=")) {
connectionUrl = TestUtils.removeProperty(connectionUrl, "user");
}
if (connectionUrl.contains("password=")) {
connectionUrl = TestUtils.removeProperty(connectionUrl, "password");
}

ds.setURL(connectionUrl);
ds.setAuthentication("ActiveDirectoryMSI");
ds.setEncrypt("strict");
ds.setHostNameInCertificate("*.database.windows.net");

try (Connection con = ds.getConnection()) {
assertNotNull(con);
} catch (SQLException e) {
fail("Connection failed: " + e.getMessage());
}
}

}
Loading