Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into paw/record
Browse files Browse the repository at this point in the history
  • Loading branch information
peterallenwebb committed Jun 25, 2024
2 parents 7d879f0 + 2576a08 commit 09866aa
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 4 deletions.
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 @@ -268,7 +268,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()

0 comments on commit 09866aa

Please sign in to comment.