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

[Bug] Silent SSO token expiration #1072

Merged
merged 16 commits into from
Jun 24, 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
6 changes: 6 additions & 0 deletions .changes/unreleased/Fixes-20240605-125611.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Fixes
body: Surface SSO token expiration in logs
time: 2024-06-05T12:56:11.802237-04:00
custom:
Author: mikealfare, McKnight-42
Issue: "851"
6 changes: 5 additions & 1 deletion dbt/adapters/snowflake/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,11 @@ def _get_access_token(self) -> str:
f"""Did not receive valid json with access_token.
Showing json response: {result_json}"""
)

elif "access_token" not in result_json:
raise FailedToConnectError(
"This error occurs when authentication has expired. "
"Please reauth with your auth provider."
)
return result_json["access_token"]

def _get_private_key(self):
Expand Down
4 changes: 2 additions & 2 deletions tests/functional/oauth/test_oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
integration the same, just the refresh token changed)
"""

import pytest
import os
from dbt.tests.util import run_dbt, check_relations_equal
from dbt.tests.util import check_relations_equal, run_dbt
import pytest


_MODELS__MODEL_1_SQL = """
Expand Down
33 changes: 32 additions & 1 deletion tests/unit/test_connections.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import os
import pytest
from importlib import reload
from unittest.mock import Mock
from unittest.mock import Mock, patch
import multiprocessing
from dbt.adapters.exceptions.connection import FailedToConnectError
import dbt.adapters.snowflake.connections as connections
import dbt.adapters.events.logging

Expand Down Expand Up @@ -36,3 +39,31 @@ def test_connnections_credentials_replaces_underscores_with_hyphens():
}
creds = connections.SnowflakeCredentials(**credentials)
assert creds.account == "account-id-with-underscores"


def test_snowflake_oauth_expired_token_raises_error():
credentials = {
"account": "test_account",
"user": "test_user",
"authenticator": "oauth",
"token": "expired_or_incorrect_token",
"database": "database",
"schema": "schema",
}

mp_context = multiprocessing.get_context("spawn")
mock_credentials = connections.SnowflakeCredentials(**credentials)

with patch.object(
connections.SnowflakeConnectionManager,
"open",
side_effect=FailedToConnectError(
"This error occurs when authentication has expired. "
"Please reauth with your auth provider."
),
):

adapter = connections.SnowflakeConnectionManager(mock_credentials, mp_context)

with pytest.raises(FailedToConnectError):
adapter.open()
Loading