Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test script for bypassing backend authentication issue #4119

Draft
wants to merge 24 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions .github/workflows/js.yml
Expand Up @@ -74,14 +74,15 @@ jobs:
--proxy-addr=127.0.0.1:47017
--mode=diff-normal
--handler=pg
--postgresql-url='postgres://username@127.0.0.1:5432/ferretdb'
--postgresql-url='postgres://127.0.0.1:5433/ferretdb'
AlekSi marked this conversation as resolved.
Show resolved Hide resolved
--test-enable-new-auth=true
2> ferretdb.log &

- name: Run testjs for MongoDB
run: bin/task testjs TESTJS_PORT=47017

- name: Run testjs for FerretDB
run: bin/task testjs
run: bin/task testjs-auth

- name: Compress FerretDB log before upload
if: failure()
Expand Down
8 changes: 8 additions & 0 deletions Taskfile.yml
Expand Up @@ -553,6 +553,14 @@ tasks:
'mongodb://host.docker.internal:{{.TESTJS_PORT}}/'
/legacy-mongo-shell/test.js

testjs-auth:
desc: "Run legacy MongoDB shell (`mongo`) with test.js script using PLAIN authentication mechanism"
cmds:
- >
docker compose run --rm legacy-mongo-shell
'mongodb://username:password@host.docker.internal:{{.TESTJS_PORT}}/?authMechanism=PLAIN'
/legacy-mongo-shell/test.js

docker-init:
run: once
cmds:
Expand Down
25 changes: 25 additions & 0 deletions build/legacy-mongo-shell/test.js
Expand Up @@ -3,5 +3,30 @@
(function() {
'use strict';

let port = 27017;

let roles = [];

if (db.getSiblingDB('admin').runCommand({getParameter: '*'}).wiredTigerConcurrentReadTransactions !== undefined) {
roles.push({role: 'read', db: 'admin'});
port = 47017;
};

db.getSiblingDB('admin').system.users.remove({});
AlekSi marked this conversation as resolved.
Show resolved Hide resolved

db.getSiblingDB('admin').createUser({user: 'username', pwd: 'password', roles: roles});
AlekSi marked this conversation as resolved.
Show resolved Hide resolved

const mongoClient = function(uri) {
return new Mongo(uri);
}

const uri = 'mongodb://username:password@host.docker.internal:' + port + '/?authMechanism=SCRAM-SHA-1';
AlekSi marked this conversation as resolved.
Show resolved Hide resolved

try {
mongoClient(uri);
} catch (e) {
throw new Error('test.js failed: ' + e);
}

print('test.js passed!');
})();