Skip to content

Commit 27a87ad

Browse files
Add test
1 parent 9106ad0 commit 27a87ad

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

.evergreen/tests/test-mongodb-runner.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,21 @@ pushd $SCRIPT_DIR/.. > /dev/null
1515
# shellcheck disable=SC2120
1616
function connect_mongodb() {
1717
local use_tls=false
18+
local use_auth=false
1819

1920
# Parse flags
2021
while [[ $# -gt 0 ]]; do
2122
case "$1" in
2223
--ssl) use_tls=true; shift ;;
24+
--auth) use_auth=true; shift ;;
2325
*) echo "Unknown option: $1"; return 1 ;;
2426
esac
2527
done
2628

2729
URI="mongodb://localhost:27017/?directConnection=true&serverSelectionTimeoutMS=10000"
30+
if [[ "$use_auth" == "true" ]]; then
31+
URI="mongodb://bob:pwd123@localhost:27017/?directConnection=true&serverSelectionTimeoutMS=10000&authSource=admin"
32+
fi
2833
local TLS_OPTS=()
2934
if [[ "$use_tls" == "true" ]]; then
3035
TLS_OPTS+=("--tls" "--tlsCertificateKeyFile" "${DRIVERS_TOOLS}/.evergreen/x509gen/server.pem")
@@ -49,6 +54,15 @@ connect_mongodb --ssl
4954
bash ./run-mongodb.sh start --version latest --topology sharded_cluster --auth --ssl
5055
connect_mongodb --ssl
5156

57+
# Verify that auth is enforced when starting with AUTH=auth SSL=yes.
58+
# An unauthenticated connection must be rejected, and an authenticated one must succeed.
59+
AUTH=auth SSL=yes bash ./run-mongodb.sh start
60+
if connect_mongodb --ssl 2>/dev/null; then
61+
echo "ERROR: unauthenticated connection should have been rejected on an auth+ssl server"
62+
exit 1
63+
fi
64+
connect_mongodb --ssl --auth
65+
5266
# Ensure that we can use a downloaded mongodb directory.
5367
DOWNLOAD_DIR=mongodl_test
5468
rm -rf ${DOWNLOAD_DIR}

0 commit comments

Comments
 (0)