|
| 1 | +import pytest |
| 2 | + |
| 3 | +import redshift_connector |
| 4 | +from redshift_connector.idp_auth_helper import SupportedSSLMode |
| 5 | + |
| 6 | +""" |
| 7 | +These functional tests ensure connections to Redshift provisioned customer with custom domain name can be established |
| 8 | +when using various authentication methods. |
| 9 | +
|
| 10 | +Pre-requisites: |
| 11 | +1) Redshift provisioned configuration |
| 12 | +2) Existing custom domain association with instance created in step 1 |
| 13 | +""" |
| 14 | + |
| 15 | + |
| 16 | +# @pytest.mark.skip(reason="manual") |
| 17 | +@pytest.mark.parametrize("sslmode", (SupportedSSLMode.VERIFY_CA, SupportedSSLMode.VERIFY_FULL)) |
| 18 | +def test_native_connect(provisioned_cname_db_kwargs, sslmode): |
| 19 | + # this test requires aws default profile contains valid credentials that provide permissions for |
| 20 | + # redshift:GetClusterCredentials ( Only called from this test method) |
| 21 | + import boto3 |
| 22 | + |
| 23 | + profile = "default" |
| 24 | + client = boto3.client( |
| 25 | + service_name="redshift", |
| 26 | + region_name="eu-north-1", |
| 27 | + ) |
| 28 | + # fetch cluster credentials and pass them as driver connect parameters |
| 29 | + response = client.get_cluster_credentials( |
| 30 | + CustomDomainName=provisioned_cname_db_kwargs["host"], DbUser=provisioned_cname_db_kwargs["db_user"] |
| 31 | + ) |
| 32 | + |
| 33 | + provisioned_cname_db_kwargs["password"] = response["DbPassword"] |
| 34 | + provisioned_cname_db_kwargs["user"] = response["DbUser"] |
| 35 | + provisioned_cname_db_kwargs["profile"] = profile |
| 36 | + provisioned_cname_db_kwargs["ssl"] = True |
| 37 | + provisioned_cname_db_kwargs["sslmode"] = sslmode.value |
| 38 | + |
| 39 | + with redshift_connector.connect(**provisioned_cname_db_kwargs): |
| 40 | + pass |
| 41 | + |
| 42 | + |
| 43 | +# @pytest.mark.skip(reason="manual") |
| 44 | +@pytest.mark.parametrize("sslmode", (SupportedSSLMode.VERIFY_CA, SupportedSSLMode.VERIFY_FULL)) |
| 45 | +def test_iam_connect(provisioned_cname_db_kwargs, sslmode): |
| 46 | + # this test requires aws default profile contains valid credentials that provide permissions for |
| 47 | + # redshift:GetClusterCredentials (called from driver) |
| 48 | + # redshift:DescribeClusters (called from driver) |
| 49 | + # redshift:DescribeCustomDomainAssociations (called from driver) |
| 50 | + provisioned_cname_db_kwargs["iam"] = True |
| 51 | + provisioned_cname_db_kwargs["profile"] = "default" |
| 52 | + provisioned_cname_db_kwargs["auto_create"] = True |
| 53 | + provisioned_cname_db_kwargs["region"] = "eu-north-1" |
| 54 | + provisioned_cname_db_kwargs["ssl"] = True |
| 55 | + provisioned_cname_db_kwargs["sslmode"] = sslmode.value |
| 56 | + with redshift_connector.connect(**provisioned_cname_db_kwargs): |
| 57 | + pass |
| 58 | + |
| 59 | + |
| 60 | +def test_idp_connect(okta_idp, provisioned_cname_db_kwargs): |
| 61 | + # todo |
| 62 | + pass |
| 63 | + |
| 64 | + |
| 65 | +# @pytest.mark.skip(reason="manual") |
| 66 | +def test_nlb_connect(): |
| 67 | + args = { |
| 68 | + "iam": True, |
| 69 | + # "access_key_id": "xxx", |
| 70 | + # "secret_access_key": "xxx", |
| 71 | + "cluster_identifier": "replace-me", |
| 72 | + "region": "us-east-1", |
| 73 | + "host": "replace-me", |
| 74 | + "port": 5439, |
| 75 | + "database": "dev", |
| 76 | + "db_user": "replace-me", |
| 77 | + } |
| 78 | + with redshift_connector.connect(**args): |
| 79 | + pass |
0 commit comments