-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
023595a
commit c5a72ac
Showing
8 changed files
with
82 additions
and
104 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
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
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
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,35 +1,26 @@ | ||
import boto3 | ||
import urllib | ||
import pretend | ||
|
||
from django_iam_dbauth.aws.mysql.base import DatabaseWrapper | ||
|
||
|
||
def test_get_connection_params(mocker): | ||
token_kwargs = {} | ||
|
||
def generate_db_auth_token(**kwargs): | ||
token_kwargs.update(kwargs) | ||
return "generated-token" | ||
|
||
client = pretend.stub(generate_db_auth_token=generate_db_auth_token) | ||
mocker.patch.object(boto3, "client", return_value=client) | ||
|
||
def test_get_connection_params(rds_client): | ||
settings = { | ||
"NAME": "example", | ||
"USER": "mysql", | ||
"PASSWORD": "secret", | ||
"PORT": 3306, | ||
"HOST": "example-cname.labd.nl", | ||
"ENGINE": "django_iam_dbauth.aws.mysql", | ||
"OPTIONS": {"use_iam_auth": 1, "region_name": "test"}, | ||
"OPTIONS": { | ||
"use_iam_auth": 1, | ||
"region_name": "test", | ||
"resolve_cname_enabled": False, | ||
}, | ||
} | ||
|
||
db = DatabaseWrapper(settings) | ||
params = db.get_connection_params() | ||
|
||
assert params["password"] == "generated-token" | ||
assert token_kwargs == { | ||
"DBHostname": "cluster-name.accountandregionhash.eu-west-1.rds.amazonaws.com", | ||
"DBUsername": "mysql", | ||
"Port": 3306, | ||
} | ||
assert params["password"].startswith("example-cname.labd.nl") |
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,42 +1,22 @@ | ||
import boto3 | ||
import pretend | ||
|
||
from django_iam_dbauth.aws.postgresql.base import DatabaseWrapper | ||
|
||
|
||
def test_get_connection_params(mocker): | ||
token_kwargs = {} | ||
|
||
def generate_db_auth_token(**kwargs): | ||
token_kwargs.update(kwargs) | ||
return "generated-token" | ||
|
||
client = pretend.stub(generate_db_auth_token=generate_db_auth_token) | ||
mocker.patch.object(boto3, "client", return_value=client) | ||
|
||
def test_get_connection_params(rds_client): | ||
settings = { | ||
"NAME": "example", | ||
"USER": "postgresql", | ||
"PASSWORD": "secret", | ||
"PORT": 5432, | ||
"HOST": "example-cname.labd.nl", | ||
"ENGINE": "django_iam_dbauth.aws.postgresql", | ||
"OPTIONS": {"use_iam_auth": 1, "region_name": "test"}, | ||
"OPTIONS": { | ||
"use_iam_auth": 1, | ||
"region_name": "test", | ||
"resolve_cname_enabled": False, | ||
}, | ||
} | ||
|
||
db = DatabaseWrapper(settings) | ||
params = db.get_connection_params() | ||
|
||
expected = { | ||
"database": "example", | ||
"user": "postgresql", | ||
"password": "generated-token", | ||
"port": 5432, | ||
"host": "example-cname.labd.nl", | ||
} | ||
assert params == expected | ||
assert token_kwargs == { | ||
"DBHostname": "cluster-name.accountandregionhash.eu-west-1.rds.amazonaws.com", | ||
"DBUsername": "postgresql", | ||
"Port": 5432, | ||
} | ||
assert params["password"].startswith("example-cname.labd.nl") |
oops