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

Remove exception and validation for user/password with AccessTokenCallback #2549

Merged
merged 4 commits into from
Nov 29, 2024
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 @@ -2802,13 +2802,6 @@ Connection connectInternal(Properties propsIn,
&& !activeConnectionProperties
.getProperty(SQLServerDriverStringProperty.ACCESS_TOKEN_CALLBACK_CLASS.toString())
.isEmpty();
if ((null != accessTokenCallback || hasAccessTokenCallbackClass) && (!activeConnectionProperties
.getProperty(SQLServerDriverStringProperty.USER.toString()).isEmpty()
|| !activeConnectionProperties.getProperty(SQLServerDriverStringProperty.PASSWORD.toString())
.isEmpty())) {
throw new SQLServerException(
SQLServerException.getErrString("R_AccessTokenCallbackWithUserPassword"), null);
}

sPropKey = SQLServerDriverStringProperty.ACCESS_TOKEN_CALLBACK_CLASS.toString();
sPropValue = activeConnectionProperties.getProperty(sPropKey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import static org.junit.jupiter.api.Assertions.assertNotNull;

import java.lang.reflect.Field;
import java.sql.Connection;
Expand Down Expand Up @@ -435,27 +436,15 @@ public void testDSPooledConnectionAccessTokenCallbackClassExceptions() throws Ex

// User/password is not required for access token callback
AbstractTest.updateDataSource(accessTokenCallbackConnectionString, ds);

ds.setAccessTokenCallbackClass(AccessTokenCallbackClass.class.getName());
ds.setUser("user");
SQLServerPooledConnection pc;

// Should fail with user set
try {
pc = (SQLServerPooledConnection) ds.getPooledConnection();
fail(TestResource.getResource("R_expectedFailPassed"));
} catch (SQLServerException e) {
assertTrue(e.getMessage().matches(TestUtils.formatErrorMsg("R_AccessTokenCallbackWithUserPassword")));
}

ds.setUser("");
ds.setPassword(UUID.randomUUID().toString());
SQLServerPooledConnection pc;

// Should fail with password set
try {
pc = (SQLServerPooledConnection) ds.getPooledConnection();
fail(TestResource.getResource("R_expectedFailPassed"));
} catch (SQLServerException e) {
assertTrue(e.getMessage().matches(TestUtils.formatErrorMsg("R_AccessTokenCallbackWithUserPassword")));
pc = (SQLServerPooledConnection) ds.getPooledConnection();
try (Connection conn1 = pc.getConnection()) {
assertNotNull(conn1);
Ananya2 marked this conversation as resolved.
Show resolved Hide resolved
}

// Should fail with invalid accessTokenCallbackClass value
Expand Down