Skip to content

Commit 3c14efb

Browse files
committed
tests(plugin, adfs): run AdfsCredentialsProvider integration tests
1 parent 8d8d186 commit 3c14efb

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

test/conftest.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,9 @@ def adfs_idp():
175175
"user": conf.get("adfs-idp", "user", fallback="mock_user"),
176176
"credentials_provider": conf.get("adfs-idp", "credentials_provider", fallback="AdfsCredentialsProvider"),
177177
"idp_host": conf.get("adfs-idp", "idp_host", fallback="mock_idp_host"),
178+
"cluster_identifier": conf.get("adfs-idp", "cluster_identifier", fallback="mock_adfs_cluster_identifier"),
179+
"region": conf.get("adfs-idp", "region", fallback="mock-region"),
180+
"ssl_insecure": conf.getboolean("adfs-idp", "ssl_insecure", fallback=False),
178181
}
179182
return {**_get_default_iam_connection_args(), **db_connect}
180183

test/integration/plugin/test_credentials_providers.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
conf.read(root_path + "/config.ini")
1515

1616

17-
NON_BROWSER_IDP: typing.List[str] = ["okta_idp", "azure_idp"]
17+
NON_BROWSER_IDP: typing.List[str] = ["okta_idp", "azure_idp", "adfs_idp"]
1818
ALL_IDP: typing.List[str] = ["okta_browser_idp", "azure_browser_idp"] + NON_BROWSER_IDP
1919

2020

@@ -51,7 +51,10 @@ def testIdpPassword(idp_arg):
5151
idp_arg = idp_arg
5252
idp_arg["password"] = "wrong_password"
5353

54-
with pytest.raises(redshift_connector.InterfaceError, match=r"(Unauthorized)|(400 Client Error: Bad Request)"):
54+
with pytest.raises(
55+
redshift_connector.InterfaceError,
56+
match=r"(Unauthorized)|(400 Client Error: Bad Request)|(Failed to find Adfs access_token)",
57+
):
5558
redshift_connector.connect(**idp_arg)
5659

5760

@@ -91,14 +94,17 @@ def test_preferred_role_invalid_should_fail(idp_arg):
9194

9295
@pytest.mark.parametrize("idp_arg", NON_BROWSER_IDP, indirect=True)
9396
def test_invalid_db_group(idp_arg):
97+
import botocore.exceptions
98+
9499
idp_arg["db_groups"] = ["girl_dont_do_it"]
95100
with pytest.raises(
96-
redshift_connector.ProgrammingError, match='Group "{}" does not exist'.format(idp_arg["db_groups"][0])
101+
expected_exception=(redshift_connector.ProgrammingError, botocore.exceptions.ClientError),
102+
match="{}".format(idp_arg["db_groups"][0]),
97103
):
98104
redshift_connector.connect(**idp_arg)
99105

100106

101-
@pytest.mark.parametrize("idp_arg", NON_BROWSER_IDP, indirect=True)
107+
@pytest.mark.parametrize("idp_arg", ["okta_idp", "azure_idp"], indirect=True)
102108
@pytest.mark.parametrize("ssl_insecure_val", [True, False])
103109
def test_ssl_insecure_is_used(idp_arg, ssl_insecure_val):
104110
idp_arg["ssl_insecure"] = ssl_insecure_val
@@ -162,21 +168,17 @@ def use_cached_temporary_credentials(idp_arg):
162168
assert first_cred_cache_entry == redshift_connector.IamHelper.credentials_cache.popitem()
163169

164170

165-
@pytest.mark.skip
166-
# TODO: https://docs.aws.amazon.com/redshift/latest/dg/r_STL_CONNECTION_LOG.html plugin_name column character limit
167-
# TODO: causes field value cut-off
168171
@pytest.mark.parametrize("idp_arg", NON_BROWSER_IDP, indirect=True)
169172
def test_stl_connection_log_contains_plugin_name(idp_arg, db_kwargs):
170173
idp_arg["auto_create"] = True
171174
with redshift_connector.connect(**idp_arg) as conn:
172-
pass
173-
with redshift_connector.connect(**db_kwargs) as conn:
174175
with conn.cursor() as cursor:
175-
# verify stl_connection_log contains driver version as expected
176176
cursor.execute(
177-
"select top 1 1 from stl_connection_log where driver_version = '{}' and plugin_name = 'redshift_connector.plugin.{}'".format(
178-
DriverInfo.driver_full_name(), idp_arg["credentials_provider"]
179-
)
177+
"select top 1 1 from stl_connection_log where driver_version = %s and plugin_name like %s",
178+
(
179+
DriverInfo.driver_full_name(),
180+
"redshift_connector.plugin.{}".format(idp_arg["credentials_provider"])[:32],
181+
),
180182
)
181183
res = cursor.fetchone()
182184
assert res is not None

0 commit comments

Comments
 (0)