Skip to content

Commit bb272b1

Browse files
committed
PYTHON-2139 Test MONGODB-AWS auth on macOS and Windows
Replace jq with python as macOS does not have jq. Use sys.stdout.write instead of print to avoid trailing newlines.
1 parent ce60119 commit bb272b1

File tree

2 files changed

+86
-20
lines changed

2 files changed

+86
-20
lines changed

.evergreen/config.yml

Lines changed: 64 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ functions:
476476
silent: true
477477
script: |
478478
cat <<'EOF' > "${PROJECT_DIRECTORY}/prepare_mongodb_aws.sh"
479-
alias urlencode='python -c "import sys, urllib as ul; print ul.quote_plus(sys.argv[1])"'
479+
alias urlencode='python -c "import sys, urllib as ul; sys.stdout.write(ul.quote_plus(sys.argv[1]))"'
480480
USER=$(urlencode ${iam_auth_ecs_account})
481481
PASS=$(urlencode ${iam_auth_ecs_secret_access_key})
482482
MONGODB_URI="mongodb://$USER:$PASS@localhost"
@@ -487,7 +487,7 @@ functions:
487487
working_dir: "src"
488488
script: |
489489
${PREPARE_SHELL}
490-
.evergreen/run-mongodb-aws-test.sh
490+
PYTHON_BINARY=${PYTHON_BINARY} .evergreen/run-mongodb-aws-test.sh
491491
492492
"run aws auth test with assume role credentials":
493493
- command: shell.exec
@@ -496,6 +496,14 @@ functions:
496496
working_dir: "src"
497497
script: |
498498
${PREPARE_SHELL}
499+
# The aws_e2e_assume_role script requires python3 with boto3.
500+
virtualenv -p ${python3_binary} mongovenv
501+
if [ "Windows_NT" = "$OS" ]; then
502+
. mongovenv/Scripts/activate
503+
else
504+
. mongovenv/bin/activate
505+
fi
506+
pip install boto3
499507
cd ${DRIVERS_TOOLS}/.evergreen/auth_aws
500508
mongo aws_e2e_assume_role.js
501509
- command: shell.exec
@@ -506,12 +514,13 @@ functions:
506514
script: |
507515
# DO NOT ECHO WITH XTRACE (which PREPARE_SHELL does)
508516
cat <<'EOF' > "${PROJECT_DIRECTORY}/prepare_mongodb_aws.sh"
509-
alias urlencode='python -c "import sys, urllib as ul; print ul.quote_plus(sys.argv[1])"'
510-
USER=$(jq -r '.AccessKeyId' ${DRIVERS_TOOLS}/.evergreen/auth_aws/creds.json)
517+
alias urlencode='python -c "import sys, urllib as ul; sys.stdout.write(ul.quote_plus(sys.argv[1]))"'
518+
alias jsonkey='python -c "import json,sys;sys.stdout.write(json.load(sys.stdin)[sys.argv[1]])" < ${DRIVERS_TOOLS}/.evergreen/auth_aws/creds.json'
519+
USER=$(jsonkey AccessKeyId)
511520
USER=$(urlencode $USER)
512-
PASS=$(jq -r '.SecretAccessKey' ${DRIVERS_TOOLS}/.evergreen/auth_aws/creds.json)
521+
PASS=$(jsonkey SecretAccessKey)
513522
PASS=$(urlencode $PASS)
514-
SESSION_TOKEN=$(jq -r '.SessionToken' ${DRIVERS_TOOLS}/.evergreen/auth_aws/creds.json)
523+
SESSION_TOKEN=$(jsonkey SessionToken)
515524
SESSION_TOKEN=$(urlencode $SESSION_TOKEN)
516525
MONGODB_URI="mongodb://$USER:$PASS@localhost"
517526
EOF
@@ -521,7 +530,7 @@ functions:
521530
working_dir: "src"
522531
script: |
523532
${PREPARE_SHELL}
524-
.evergreen/run-mongodb-aws-test.sh
533+
PYTHON_BINARY=${PYTHON_BINARY} .evergreen/run-mongodb-aws-test.sh
525534
526535
"run aws auth test with aws EC2 credentials":
527536
- command: shell.exec
@@ -530,6 +539,16 @@ functions:
530539
working_dir: "src"
531540
script: |
532541
${PREPARE_SHELL}
542+
if [ "${skip_EC2_auth_test}" == "true" ]; then
543+
echo "This platform does not support the EC2 auth test, skipping..."
544+
exit 0
545+
fi
546+
# The mongovenv was created earlier in "run aws auth test with assume role credentials".
547+
if [ "Windows_NT" = "$OS" ]; then
548+
. mongovenv/Scripts/activate
549+
else
550+
. mongovenv/bin/activate
551+
fi
533552
cd ${DRIVERS_TOOLS}/.evergreen/auth_aws
534553
mongo aws_e2e_ec2.js
535554
- command: shell.exec
@@ -538,7 +557,7 @@ functions:
538557
working_dir: "src"
539558
script: |
540559
${PREPARE_SHELL}
541-
.evergreen/run-mongodb-aws-test.sh
560+
PYTHON_BINARY=${PYTHON_BINARY} .evergreen/run-mongodb-aws-test.sh
542561
543562
"run aws auth test with aws credentials as environment variables":
544563
- command: shell.exec
@@ -558,7 +577,7 @@ functions:
558577
working_dir: "src"
559578
script: |
560579
${PREPARE_SHELL}
561-
PROJECT_DIRECTORY=${PROJECT_DIRECTORY} .evergreen/run-mongodb-aws-test.sh
580+
PYTHON_BINARY=${PYTHON_BINARY} PROJECT_DIRECTORY=${PROJECT_DIRECTORY} .evergreen/run-mongodb-aws-test.sh
562581
563582
"run aws auth test with aws credentials and session token as environment variables":
564583
- command: shell.exec
@@ -569,17 +588,18 @@ functions:
569588
script: |
570589
# DO NOT ECHO WITH XTRACE (which PREPARE_SHELL does)
571590
cat <<'EOF' > "${PROJECT_DIRECTORY}/prepare_mongodb_aws.sh"
572-
export AWS_ACCESS_KEY_ID=$(jq -r '.AccessKeyId' ${DRIVERS_TOOLS}/.evergreen/auth_aws/creds.json)
573-
export AWS_SECRET_ACCESS_KEY=$(jq -r '.SecretAccessKey' ${DRIVERS_TOOLS}/.evergreen/auth_aws/creds.json)
574-
export AWS_SESSION_TOKEN=$(jq -r '.SessionToken' ${DRIVERS_TOOLS}/.evergreen/auth_aws/creds.json)
591+
alias jsonkey='python -c "import json,sys;sys.stdout.write(json.load(sys.stdin)[sys.argv[1]])" < ${DRIVERS_TOOLS}/.evergreen/auth_aws/creds.json'
592+
export AWS_ACCESS_KEY_ID=$(jsonkey AccessKeyId)
593+
export AWS_SECRET_ACCESS_KEY=$(jsonkey SecretAccessKey)
594+
export AWS_SESSION_TOKEN=$(jsonkey SessionToken)
575595
EOF
576596
- command: shell.exec
577597
type: test
578598
params:
579599
working_dir: "src"
580600
script: |
581601
${PREPARE_SHELL}
582-
.evergreen/run-mongodb-aws-test.sh
602+
PYTHON_BINARY=${PYTHON_BINARY} .evergreen/run-mongodb-aws-test.sh
583603
584604
"run aws ECS auth test":
585605
- command: shell.exec
@@ -588,8 +608,11 @@ functions:
588608
working_dir: "src"
589609
script: |
590610
${PREPARE_SHELL}
611+
if [ "${skip_ECS_auth_test}" == "true" ]; then
612+
echo "This platform does not support the ECS auth test, skipping..."
613+
exit 0
614+
fi
591615
cd ${DRIVERS_TOOLS}/.evergreen/auth_aws
592-
593616
cat <<EOF > setup.js
594617
const mongo_binaries = "$MONGODB_BINARIES";
595618
const project_dir = "$PROJECT_DIRECTORY";
@@ -1211,6 +1234,9 @@ axes:
12111234
display_name: "macOS 10.14"
12121235
run_on: macos-1014
12131236
variables:
1237+
skip_EC2_auth_test: true
1238+
skip_ECS_auth_test: true
1239+
python3_binary: python3
12141240
libmongocrypt_url: https://s3.amazonaws.com/mciuploads/libmongocrypt/macos/master/latest/libmongocrypt.tar.gz
12151241
- id: rhel62
12161242
display_name: "RHEL 6.2 (x86_64)"
@@ -1254,6 +1280,8 @@ axes:
12541280
display_name: "Ubuntu 18.04"
12551281
run_on: ubuntu1804-test
12561282
batchtime: 10080 # 7 days
1283+
variables:
1284+
python3_binary: python3
12571285
- id: ubuntu1604-arm64-small
12581286
display_name: "Ubuntu 16.04 (ARM64)"
12591287
run_on: ubuntu1604-arm64-small
@@ -1293,6 +1321,8 @@ axes:
12931321
run_on: windows-64-vsMulti-small
12941322
batchtime: 10080 # 7 days
12951323
variables:
1324+
skip_ECS_auth_test: true
1325+
python3_binary: "C:/python/Python38/python.exe"
12961326
libmongocrypt_url: https://s3.amazonaws.com/mciuploads/libmongocrypt/windows-test/master/latest/libmongocrypt.tar.gz
12971327

12981328
# Test with authentication?
@@ -1426,6 +1456,15 @@ axes:
14261456
display_name: "Python 3.8"
14271457
variables:
14281458
PYTHON_BINARY: "C:/python/Python38/python.exe"
1459+
# System python
1460+
- id: "system-python"
1461+
display_name: "Python"
1462+
variables:
1463+
PYTHON_BINARY: "python"
1464+
- id: "system-python3"
1465+
display_name: "Python3"
1466+
variables:
1467+
PYTHON_BINARY: "python3"
14291468

14301469
# Choice of mod_wsgi version
14311470
- id: mod-wsgi-version
@@ -2141,9 +2180,17 @@ buildvariants:
21412180

21422181
- matrix_name: "aws-auth-test"
21432182
matrix_spec:
2144-
platform: ubuntu-18.04
2145-
display_name: "MONGODB-AWS Auth test"
2146-
run_on: ubuntu1804-test
2183+
platform: [ubuntu-18.04, macos-1014]
2184+
python-version: ["system-python", "system-python3"]
2185+
display_name: "MONGODB-AWS Auth ${platform} ${python-version}"
2186+
tasks:
2187+
- name: "aws-auth-test"
2188+
2189+
- matrix_name: "aws-auth-test-windows"
2190+
matrix_spec:
2191+
platform: [windows-64-vsMulti-small]
2192+
python-version: ["win-vs2015-2.7", "win-vs2010-3.4", "win-vs2015-3.5", "win-vs2015-3.6", "win-vs2015-3.7", "win-vs2015-3.8"]
2193+
display_name: "MONGODB-AWS Auth ${platform} ${python-version}"
21472194
tasks:
21482195
- name: "aws-auth-test"
21492196

.evergreen/run-mongodb-aws-test.sh

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ set -o errexit # Exit the script with error if any of the commands fail
77
# Main Program #
88
############################################
99

10+
# Supported/used environment variables:
11+
# MONGODB_URI Set the URI, including an optional username/password to use
12+
# to connect to the server via MONGODB-AWS authentication
13+
# mechanism.
14+
# PYTHON_BINARY The Python version to use.
15+
1016
echo "Running MONGODB-AWS authentication tests"
1117
# ensure no secrets are printed in log files
1218
set +x
@@ -29,17 +35,30 @@ set -x
2935
VIRTUALENV=$(command -v virtualenv)
3036

3137
authtest () {
38+
if [ "Windows_NT" = "$OS" ]; then
39+
PYTHON=$(cygpath -m $PYTHON)
40+
fi
41+
3242
echo "Running MONGODB-AWS authentication tests with $PYTHON"
3343
$PYTHON --version
3444

3545
$VIRTUALENV -p $PYTHON --system-site-packages --never-download venvaws
36-
. venvaws/bin/activate
46+
if [ "Windows_NT" = "$OS" ]; then
47+
. venvaws/Scripts/activate
48+
else
49+
. venvaws/bin/activate
50+
fi
3751
pip install requests botocore
3852

3953
python test/auth_aws/test_auth_aws.py
4054
deactivate
4155
rm -rf venvaws
4256
}
4357

44-
PYTHON=$(command -v python) authtest
45-
PYTHON=$(command -v python3) authtest
58+
PYTHON=${PYTHON_BINARY:-}
59+
if [ -z "$PYTHON" ]; then
60+
echo "Cannot test without specifying PYTHON_BINARY"
61+
exit 1
62+
fi
63+
64+
authtest

0 commit comments

Comments
 (0)