Skip to content

Commit

Permalink
Allow empty username with JWT auth
Browse files Browse the repository at this point in the history
Summary: Newer engine versions can infer the username from JWT without the need for the client to provide username.

Test Plan: https://app.circleci.com/pipelines/github/memsql/singlestore-odbc-connector/2944/workflows/55781d52-840a-46c0-9cef-640469369ca9

Reviewers: amakarovych-ua

Reviewed By: amakarovych-ua

Subscribers: engineering-list

JIRA Issues: PLAT-6853

Differential Revision: https://grizzly.internal.memcompute.com/D65498
  • Loading branch information
pmishchenko-ua committed Nov 9, 2023
1 parent 57cbe08 commit 132d1e1
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 49 deletions.
56 changes: 14 additions & 42 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ workflows:
test:
jobs:
- build-ubuntu:
name: build-ubuntu-sanitizer-unicode-8.0.15-<< matrix.build_type >>
name: build-ubuntu-sanitizer-unicode-8.1.27-<< matrix.build_type >>
matrix:
parameters:
machine_class:
Expand All @@ -404,7 +404,7 @@ workflows:
test_driver:
- SingleStore ODBC Unicode Driver
memsql_image:
- singlestore/cluster-in-a-box:alma-8.0.15-0b9b66384f-4.0.11-1.15.2
- singlestore/cluster-in-a-box:alma-8.1.27-a1e489fcb4-4.0.15-1.17.5
with_sanitizer:
- true
- build-ubuntu:
Expand Down Expand Up @@ -539,7 +539,7 @@ workflows:
- master
jobs:
- build-ubuntu:
name: build-ubuntu-sanitizer-unicode-8.0.15-<< matrix.build_type >>
name: build-ubuntu-sanitizer-unicode-8.1.27-<< matrix.build_type >>
matrix:
parameters:
machine_class:
Expand All @@ -551,11 +551,11 @@ workflows:
test_driver:
- SingleStore ODBC Unicode Driver
memsql_image:
- singlestore/cluster-in-a-box:alma-8.0.15-0b9b66384f-4.0.11-1.15.2
- singlestore/cluster-in-a-box:alma-8.1.27-a1e489fcb4-4.0.15-1.17.5
with_sanitizer:
- true
- build-ubuntu:
name: build-ubuntu-unicode-8.0.15-<< matrix.build_type >>
name: build-ubuntu-unicode-8.1.27-<< matrix.build_type >>
matrix:
parameters:
machine_class:
Expand All @@ -567,9 +567,9 @@ workflows:
test_driver:
- SingleStore ODBC Unicode Driver
memsql_image:
- singlestore/cluster-in-a-box:alma-8.0.15-0b9b66384f-4.0.11-1.15.2
- singlestore/cluster-in-a-box:alma-8.1.27-a1e489fcb4-4.0.15-1.17.5
- build-ubuntu:
name: build-ubuntu-ansi-8.0.15-<< matrix.build_type >>
name: build-ubuntu-ansi-8.1.27-<< matrix.build_type >>
matrix:
parameters:
machine_class:
Expand All @@ -581,9 +581,9 @@ workflows:
test_driver:
- SingleStore ODBC ANSI Driver
memsql_image:
- singlestore/cluster-in-a-box:alma-8.0.15-0b9b66384f-4.0.11-1.15.2
- singlestore/cluster-in-a-box:alma-8.1.27-a1e489fcb4-4.0.15-1.17.5
- build-ubuntu:
name: build-ubuntu-unicode-7.5.12-<< matrix.build_type >>
name: build-ubuntu-unicode-8.0.15-<< matrix.build_type >>
matrix:
parameters:
machine_class:
Expand All @@ -595,21 +595,21 @@ workflows:
test_driver:
- SingleStore ODBC Unicode Driver
memsql_image:
- singlestore/cluster-in-a-box:centos-7.5.12-3112a491c2-4.0.0-1.12.5
- singlestore/cluster-in-a-box:alma-8.0.15-0b9b66384f-4.0.11-1.15.2
- build-ubuntu:
name: build-ubuntu-unicode-7.6.14-<< matrix.build_type >>
name: build-ubuntu-ansi-8.0.15-<< matrix.build_type >>
matrix:
parameters:
machine_class:
- large
build_type:
- RelWithDebInfo
test_dsn:
- ssodbc_test_w
- ssodbc_test_a
test_driver:
- SingleStore ODBC Unicode Driver
- SingleStore ODBC ANSI Driver
memsql_image:
- singlestore/cluster-in-a-box:alma-7.6.14-6f67cb4355-4.0.4-1.13.6
- singlestore/cluster-in-a-box:alma-8.0.15-0b9b66384f-4.0.11-1.15.2
- build-ubuntu:
name: build-ubuntu-sanitizer-unicode-7.8.19-<< matrix.build_type >>
matrix:
Expand All @@ -624,34 +624,6 @@ workflows:
- SingleStore ODBC Unicode Driver
memsql_image:
- singlestore/cluster-in-a-box:alma-7.8.19-4263b2d130-4.0.10-1.14.4
- build-ubuntu:
name: build-ubuntu-ansi-7.5.12-<< matrix.build_type >>
matrix:
parameters:
machine_class:
- large
build_type:
- RelWithDebInfo
test_dsn:
- ssodbc_test_a
test_driver:
- SingleStore ODBC ANSI Driver
memsql_image:
- singlestore/cluster-in-a-box:centos-7.5.12-3112a491c2-4.0.0-1.12.5
- build-ubuntu:
name: build-ubuntu-ansi-7.6.14-<< matrix.build_type >>
matrix:
parameters:
machine_class:
- large
build_type:
- RelWithDebInfo
test_dsn:
- ssodbc_test_a
test_driver:
- SingleStore ODBC ANSI Driver
memsql_image:
- singlestore/cluster-in-a-box:centos-7.5.12-3112a491c2-4.0.0-1.12.5
- build-ubuntu:
name: build-ubuntu-ansi-7.8.19-<< matrix.build_type >>
matrix:
Expand Down
2 changes: 1 addition & 1 deletion .circleci/setup-cluster.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ set -eu
# this script must be run from the top-level of the repo
cd "$(git rev-parse --show-toplevel)"

DEFAULT_IMAGE_NAME="singlestore/cluster-in-a-box:alma-8.0.15-0b9b66384f-4.0.11-1.15.2"
DEFAULT_IMAGE_NAME="singlestore/cluster-in-a-box:alma-8.1.27-a1e489fcb4-4.0.15-1.17.5"
IMAGE_NAME="${MEMSQL_IMAGE:-$DEFAULT_IMAGE_NAME}"
CONTAINER_NAME="memsql-integration"
S2_MASTER_PORT="${MEMSQL_PORT:-5506}"
Expand Down
17 changes: 11 additions & 6 deletions ma_connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,17 @@ SQLRETURN MADB_DbcConnectDB(MADB_Dbc *Connection,
return SQL_ERROR;

char *emailForSSO = Dsn->UserName;
if (Dsn->JWT)
{
// we will send JWT as the password
Dsn->Password = Dsn->JWT;
if (!Dsn->UserName || !Dsn->UserName[0])
{
Dsn->UserName = MADB_ALLOC(2*sizeof(char));
strcpy(Dsn->UserName, "*");
}
Dsn->JWT = NULL;
}
if (Dsn->IsBrowserAuth)
{
if (GetCredentialsBrowserSSO(Connection, Dsn, emailForSSO, TRUE /*readCached*/))
Expand Down Expand Up @@ -2374,12 +2385,6 @@ SQLRETURN MADB_DriverConnect(MADB_Dbc *Dbc, SQLHWND WindowHandle, SQLCHAR *InCon
MADB_SetError(&Dbc->Error, MADB_ERR_HY000, "Only one of PASSWORD, JWT, BROWSER_SSO can be specified", 0);
goto error;
}
if (Dsn->JWT)
{
// we will send JWT as the password
Dsn->Password = Dsn->JWT;
Dsn->JWT = NULL;
}

/* if DSN prompt is off, adjusting DriverCompletion */
if (Dsn->ConnectPrompt)
Expand Down
18 changes: 18 additions & 0 deletions test/connect.c
Original file line number Diff line number Diff line change
Expand Up @@ -1953,6 +1953,24 @@ ODBC_TEST(driver_connect_jwt) {
if (check_connection_string(conn_out_len, strlen((char*)conn), conn_out, conn) == FAIL) { return FAIL; }

HSTMT hstmt;
// check that we can omit username when connecting to newer servers with JWT
if (ServerNotOlderThan(hdbc, 8, 1, 20))
{
HSTMT hdbc2;
SQLCHAR conn2[2048];
SQLCHAR conn_out_2[2048];

CHECK_ENV_RC(Env, SQLAllocConnect(Env, &hdbc2));
SQLSMALLINT conn_out_len;
sprintf((char*)conn2, "DRIVER=%s;JWT=%s;SERVER=%s;PORT=%u;DB=%s;",
my_drivername, jwt_password, my_servername, my_port, my_schema);
CHECK_DBC_RC(hdbc2, SQLDriverConnect(hdbc2, NULL, conn2, SQL_NTS,
conn_out_2, 2048 * sizeof(SQLCHAR), &conn_out_len,
SQL_DRIVER_NOPROMPT));
if (check_connection_string(conn_out_len, strlen((char*)conn2), conn_out_2, conn2) == FAIL) { return FAIL; }
CHECK_DBC_RC(hdbc2, SQLDisconnect(hdbc2));
}

CHECK_DBC_RC(hdbc, SQLAllocHandle(SQL_HANDLE_STMT, hdbc, &hstmt));
OK_SIMPLE_STMT(hstmt, "DROP TABLE IF EXISTS some_table");
CHECK_STMT_RC(hstmt, SQLFreeHandle(SQL_HANDLE_STMT, hstmt));
Expand Down

0 comments on commit 132d1e1

Please sign in to comment.