Skip to content

Commit aaff6ed

Browse files
authored
PYTHON-3912 Migrate Enterprise Auth Tests to AWS Secrets Vault (#1356)
1 parent 5bd444a commit aaff6ed

File tree

4 files changed

+28
-28
lines changed

4 files changed

+28
-28
lines changed

.evergreen/config.yml

+20-23
Original file line numberDiff line numberDiff line change
@@ -511,31 +511,23 @@ functions:
511511
bash ${PROJECT_DIRECTORY}/.evergreen/tox.sh -m test-eg
512512
513513
"run enterprise auth tests":
514-
- command: shell.exec
515-
type: test
514+
- command: ec2.assume_role
516515
params:
517-
silent: true
518-
working_dir: "src"
519-
script: |
520-
cat <<EOT > prepare_enterprise_auth.sh
521-
export SASL_HOST='${sasl_host}'
522-
export SASL_PORT='${sasl_port}'
523-
export SASL_USER='${sasl_user}'
524-
export SASL_PASS='${sasl_pass}'
525-
export SASL_DB='${sasl_db}'
526-
export PRINCIPAL='${principal}'
527-
export GSSAPI_DB='${gssapi_db}'
528-
export KEYTAB_BASE64='${keytab_base64}'
529-
EOT
516+
role_arn: ${aws_test_secrets_role}
530517
- command: shell.exec
531518
type: test
532519
params:
533520
working_dir: "src"
534521
script: |
535-
# Disable xtrace (just in case it was accidentally set).
522+
# Disable xtrace for security reasons (just in case it was accidentally set).
536523
set +x
537-
. ./prepare_enterprise_auth.sh
538-
rm -f ./prepare_enterprise_auth.sh
524+
525+
DRIVERS_TOOLS="${DRIVERS_TOOLS}" \
526+
AWS_ACCESS_KEY_ID="${AWS_ACCESS_KEY_ID}" \
527+
AWS_SECRET_ACCESS_KEY="${AWS_SECRET_ACCESS_KEY}" \
528+
AWS_SESSION_TOKEN="${AWS_SESSION_TOKEN}" \
529+
bash ${PROJECT_DIRECTORY}/.evergreen/tox.sh -m aws-secrets -- drivers/enterprise_auth
530+
539531
PROJECT_DIRECTORY="${PROJECT_DIRECTORY}" \
540532
PYTHON_BINARY="${PYTHON_BINARY}" \
541533
TEST_ENTERPRISE_AUTH=1 \
@@ -549,16 +541,21 @@ functions:
549541
- command: shell.exec
550542
type: test
551543
params:
552-
add_expansions_to_env: true
553544
working_dir: "src"
554545
script: |
555546
# Disable xtrace for security reasons (just in case it was accidentally set).
556547
set +x
557-
set -o errexit
558-
set -o xtrace
559548
560-
bash ${PROJECT_DIRECTORY}/.evergreen/tox.sh -m aws-secrets -- drivers/atlas_connect
561-
TEST_ATLAS=1 bash ${PROJECT_DIRECTORY}/.evergreen/tox.sh -m test-eg
549+
DRIVERS_TOOLS="${DRIVERS_TOOLS}" \
550+
AWS_ACCESS_KEY_ID="${AWS_ACCESS_KEY_ID}" \
551+
AWS_SECRET_ACCESS_KEY="${AWS_SECRET_ACCESS_KEY}" \
552+
AWS_SESSION_TOKEN="${AWS_SESSION_TOKEN}" \
553+
bash ${PROJECT_DIRECTORY}/.evergreen/tox.sh -m aws-secrets -- drivers/atlas_connect
554+
555+
PROJECT_DIRECTORY="${PROJECT_DIRECTORY}" \
556+
PYTHON_BINARY="${PYTHON_BINARY}" \
557+
TEST_ATLAS=1 \
558+
bash ${PROJECT_DIRECTORY}/.evergreen/tox.sh -m test-eg
562559
563560
"add aws auth variables to file":
564561
- command: shell.exec

.evergreen/run-tests.sh

+5-4
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ PYTHON=$(which python)
4141

4242
python -c "import sys; sys.exit(sys.prefix == sys.base_prefix)" || (echo "Not inside a virtual env!"; exit 1)
4343

44+
# Try to source exported AWS Secrets
45+
if [ -f ./secrets-export.sh ]; then
46+
source ./secrets-export.sh
47+
fi
48+
4449
if [ "$AUTH" != "noauth" ]; then
4550
if [ ! -z "$TEST_DATA_LAKE" ]; then
4651
export DB_USER="mhuser"
@@ -234,10 +239,6 @@ fi
234239
echo "Running $AUTH tests over $SSL with python $PYTHON"
235240
python -c 'import sys; print(sys.version)'
236241

237-
# Try to source exported AWS Secrets
238-
if [ -f ./secrets-export.sh ]; then
239-
source ./secrets-export.sh
240-
fi
241242

242243
# Run the tests, and store the results in Evergreen compatible XUnit XML
243244
# files in the xunit-results/ directory.

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ mongocryptd.pid
1717
.idea/
1818
.nova/
1919
venv/
20-
secrets-expansion.yml
2120
secrets-export.sh
2221

2322
# Lambda temp files

test/test_client.py

+3
Original file line numberDiff line numberDiff line change
@@ -1758,6 +1758,9 @@ def _test_handshake(self, env_vars, expected_env):
17581758
metadata = copy.deepcopy(_METADATA)
17591759
if expected_env is not None:
17601760
metadata["env"] = expected_env
1761+
1762+
if "AWS_REGION" not in env_vars:
1763+
os.environ["AWS_REGION"] = ""
17611764
with rs_or_single_client(serverSelectionTimeoutMS=10000) as client:
17621765
client.admin.command("ping")
17631766
options = client._MongoClient__options

0 commit comments

Comments
 (0)