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 all 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
1 change: 1 addition & 0 deletions .github/workflows/js.yml
Expand Up @@ -75,6 +75,7 @@ jobs:
--mode=diff-normal
--handler=pg
--postgresql-url='postgres://username@127.0.0.1:5432/ferretdb'
--test-enable-new-auth=true
2> ferretdb.log &

- name: Run testjs for MongoDB
Expand Down
43 changes: 43 additions & 0 deletions build/legacy-mongo-shell/test.js
@@ -1,7 +1,50 @@
/* eslint-disable max-len */
// Please do not merge changes in this file.

(function() {
'use strict';

let client = db.runCommand({whatsmyuri: 1}).you;

print('connected to: ' + client);

const t = db.foo;
t.drop();

const admin = db.getSiblingDB('admin');

let res = db.runCommand({ping: 1});
assert.eq(res.ok, 1, 'ping failed');

res = t.insert({});
assert.writeOK(res, 'insert failed');

let port = 27017;

const roles = [];

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


admin.system.users.remove({user: 'user'});
admin.createUser({user: 'user', pwd: '1234', roles: roles});

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

const uri = 'mongodb://user:1234@host.docker.internal:' + port + '/?authMechanism=SCRAM-SHA-1';

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

print('connected to: ' + client.getDB('test').runCommand({whatsmyuri: 1}).you);

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