Skip to content

Commit 175c1c1

Browse files
committed
Fix auth enforcement test, pass --auth credentials
ping is on MongoDB's auth bypass list and always succeeds even when --auth is enabled, so the unauthenticated connection check never actually tested auth enforcement. Use listDatabases instead, which requires authentication and will fail without credentials. Addresses the inconsistency where connect_mongodb was called without credentials against auth-enabled deployments. These tests now verify that user creation worked and that bob's credentials are valid.
1 parent 81595ed commit 175c1c1

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@ pushd $SCRIPT_DIR/.. > /dev/null
1616
function connect_mongodb() {
1717
local use_tls=false
1818
local use_auth=false
19+
local eval_cmd='db.runCommand({"ping":1})'
1920

2021
# Parse flags
2122
while [[ $# -gt 0 ]]; do
2223
case "$1" in
2324
--ssl) use_tls=true; shift ;;
2425
--auth) use_auth=true; shift ;;
26+
--eval-cmd) eval_cmd="$2"; shift 2 ;;
2527
*) echo "Unknown option: $1"; return 1 ;;
2628
esac
2729
done
@@ -37,7 +39,7 @@ function connect_mongodb() {
3739
fi
3840
echo "Connecting to server..."
3941
# shellcheck disable=SC2068
40-
$MONGODB_BINARIES/mongosh "$URI" ${TLS_OPTS[@]:-} --eval "db.runCommand({\"ping\":1})"
42+
$MONGODB_BINARIES/mongosh "$URI" ${TLS_OPTS[@]:-} --eval "$eval_cmd"
4143
echo "Connecting to server... done."
4244
}
4345

@@ -46,18 +48,18 @@ bash ./run-mongodb.sh start
4648
connect_mongodb
4749

4850
bash ./run-mongodb.sh start --topology standalone --auth
49-
connect_mongodb
51+
connect_mongodb --auth
5052

5153
bash ./run-mongodb.sh start --version 7.0 --topology replica_set --ssl
5254
connect_mongodb --ssl
5355

5456
bash ./run-mongodb.sh start --version latest --topology sharded_cluster --auth --ssl
55-
connect_mongodb --ssl
57+
connect_mongodb --ssl --auth
5658

5759
# Verify that auth is enforced when starting with AUTH=auth SSL=yes.
5860
# An unauthenticated connection must be rejected, and an authenticated one must succeed.
5961
AUTH=auth SSL=yes bash ./run-mongodb.sh start
60-
if connect_mongodb --ssl 2>/dev/null; then
62+
if connect_mongodb --ssl --eval-cmd 'db.adminCommand({listDatabases:1})' 2>/dev/null; then
6163
echo "ERROR: unauthenticated connection should have been rejected on an auth+ssl server"
6264
exit 1
6365
fi

0 commit comments

Comments
 (0)