Skip to content

Commit

Permalink
Remove exception and validation for user/password with AccessTokenCal…
Browse files Browse the repository at this point in the history
…lback (#2549)

* Removed the if statement, that throws exception R_AccessTokenCallbackWithUserPassword. This logic may be too restrictive and may be removed

* Updated testDSPooledConnectionAccessTokenCallbackClassExceptions test case in PooledConnectionTest.java

* Updated testDSPooledConnectionAccessTokenCallbackClassExceptions test case.

* Added import statement.
  • Loading branch information
Ananya2 authored Nov 29, 2024
1 parent cb990f4 commit ae462f9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 24 deletions.
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);
}

// Should fail with invalid accessTokenCallbackClass value
Expand Down

0 comments on commit ae462f9

Please sign in to comment.