-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add integration tests for IAM User auth (#774)
* move connection fixtures into the functional scope * add iam user creds to the test.env template * add test for database connection method * add iam user auth test * maintain existing behavior when not providing profile * add AWS IAM profile in CI * pull in new env vars in CI * updates to make space for iam role --------- Co-authored-by: Colin Rogers <[email protected]>
- Loading branch information
1 parent
12b5cd7
commit 2d653c6
Showing
16 changed files
with
1,114 additions
and
794 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
kind: Features | ||
body: Support IAM user auth via direct parameters, in addition to the existing profile | ||
method | ||
time: 2024-04-19T14:52:08.086607-04:00 | ||
custom: | ||
Author: mikealfare | ||
Issue: "760" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,21 @@ | ||
# Note: Make sure you have a Redshift account that is set up so these fields are easy to complete. | ||
|
||
### Test Environment field definitions | ||
# These will all be gathered from account information or created by you. | ||
# Endpoint for Redshift connection | ||
|
||
# Database Authentication Method | ||
REDSHIFT_TEST_HOST= | ||
# Username on your account | ||
REDSHIFT_TEST_USER= | ||
# Password for Redshift account | ||
REDSHIFT_TEST_PASS= | ||
# Local port to connect on | ||
REDSHIFT_TEST_PORT= | ||
# Name of Redshift database in your account to test against | ||
REDSHIFT_TEST_DBNAME= | ||
# Users for testing | ||
REDSHIFT_TEST_USER= | ||
REDSHIFT_TEST_PASS= | ||
REDSHIFT_TEST_REGION= | ||
|
||
# IAM User Authentication Method | ||
REDSHIFT_TEST_CLUSTER_ID= | ||
REDSHIFT_TEST_IAM_USER_PROFILE= | ||
REDSHIFT_TEST_IAM_USER_ACCESS_KEY_ID= | ||
REDSHIFT_TEST_IAM_USER_SECRET_ACCESS_KEY= | ||
|
||
# Database users for testing | ||
DBT_TEST_USER_1=dbt_test_user_1 | ||
DBT_TEST_USER_2=dbt_test_user_2 | ||
DBT_TEST_USER_3=dbt_test_user_3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1 @@ | ||
import pytest | ||
import os | ||
|
||
# Import the functional fixtures as a plugin | ||
# Note: fixtures with session scope need to be local | ||
|
||
pytest_plugins = ["dbt.tests.fixtures.project"] | ||
|
||
|
||
# The profile dictionary, used to write out profiles.yml | ||
@pytest.fixture(scope="class") | ||
def dbt_profile_target(): | ||
return { | ||
"type": "redshift", | ||
"threads": 1, | ||
"retries": 6, | ||
"host": os.getenv("REDSHIFT_TEST_HOST"), | ||
"port": int(os.getenv("REDSHIFT_TEST_PORT")), | ||
"user": os.getenv("REDSHIFT_TEST_USER"), | ||
"pass": os.getenv("REDSHIFT_TEST_PASS"), | ||
"dbname": os.getenv("REDSHIFT_TEST_DBNAME"), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import os | ||
|
||
import pytest | ||
|
||
|
||
# The profile dictionary, used to write out profiles.yml | ||
@pytest.fixture(scope="class") | ||
def dbt_profile_target(): | ||
return { | ||
"type": "redshift", | ||
"host": os.getenv("REDSHIFT_TEST_HOST"), | ||
"port": int(os.getenv("REDSHIFT_TEST_PORT")), | ||
"dbname": os.getenv("REDSHIFT_TEST_DBNAME"), | ||
"user": os.getenv("REDSHIFT_TEST_USER"), | ||
"pass": os.getenv("REDSHIFT_TEST_PASS"), | ||
"region": os.getenv("REDSHIFT_TEST_REGION"), | ||
"threads": 1, | ||
"retries": 6, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import os | ||
|
||
import pytest | ||
|
||
from dbt.adapters.redshift.connections import RedshiftConnectionMethod | ||
from dbt.tests.util import run_dbt | ||
|
||
|
||
MY_SEED = """ | ||
id,name | ||
1,apple | ||
2,banana | ||
3,cherry | ||
""".strip() | ||
|
||
|
||
MY_VIEW = """ | ||
select * from {{ ref("my_seed") }} | ||
""" | ||
|
||
|
||
class AuthMethod: | ||
|
||
@pytest.fixture(scope="class") | ||
def seeds(self): | ||
yield {"my_seed.csv": MY_SEED} | ||
|
||
@pytest.fixture(scope="class") | ||
def models(self): | ||
yield {"my_view.sql": MY_VIEW} | ||
|
||
def test_connection(self, project): | ||
run_dbt(["seed"]) | ||
results = run_dbt(["run"]) | ||
assert len(results) == 1 | ||
|
||
|
||
class TestDatabaseMethod(AuthMethod): | ||
@pytest.fixture(scope="class") | ||
def dbt_profile_target(self): | ||
return { | ||
"type": "redshift", | ||
"method": RedshiftConnectionMethod.DATABASE.value, | ||
"host": os.getenv("REDSHIFT_TEST_HOST"), | ||
"port": int(os.getenv("REDSHIFT_TEST_PORT")), | ||
"dbname": os.getenv("REDSHIFT_TEST_DBNAME"), | ||
"user": os.getenv("REDSHIFT_TEST_USER"), | ||
"pass": os.getenv("REDSHIFT_TEST_PASS"), | ||
"threads": 1, | ||
"retries": 6, | ||
} | ||
|
||
|
||
class TestIAMUserMethodProfile(AuthMethod): | ||
@pytest.fixture(scope="class") | ||
def dbt_profile_target(self): | ||
return { | ||
"type": "redshift", | ||
"method": RedshiftConnectionMethod.IAM.value, | ||
"cluster_id": os.getenv("REDSHIFT_TEST_CLUSTER_ID"), | ||
"dbname": os.getenv("REDSHIFT_TEST_DBNAME"), | ||
"iam_profile": os.getenv("REDSHIFT_TEST_IAM_USER_PROFILE"), | ||
"user": os.getenv("REDSHIFT_TEST_USER"), | ||
"threads": 1, | ||
"retries": 6, | ||
"host": "", # host is a required field in dbt-core | ||
"port": 0, # port is a required field in dbt-core | ||
} | ||
|
||
|
||
class TestIAMUserMethodExplicit(AuthMethod): | ||
@pytest.fixture(scope="class") | ||
def dbt_profile_target(self): | ||
return { | ||
"type": "redshift", | ||
"method": RedshiftConnectionMethod.IAM.value, | ||
"cluster_id": os.getenv("REDSHIFT_TEST_CLUSTER_ID"), | ||
"dbname": os.getenv("REDSHIFT_TEST_DBNAME"), | ||
"access_key_id": os.getenv("REDSHIFT_TEST_IAM_USER_ACCESS_KEY_ID"), | ||
"secret_access_key": os.getenv("REDSHIFT_TEST_IAM_USER_SECRET_ACCESS_KEY"), | ||
"region": os.getenv("REDSHIFT_TEST_REGION"), | ||
"user": os.getenv("REDSHIFT_TEST_USER"), | ||
"threads": 1, | ||
"retries": 6, | ||
"host": "", # host is a required field in dbt-core | ||
"port": 0, # port is a required field in dbt-core | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.