MongoDB supports various authentication strategies across various versions. When authentication is turned on in the database, a driver must authenticate before it is allowed to communicate with the server. This spec defines when and how a driver performs authentication with a MongoDB server.
This report is following a specification from the Mongodb
website and is shown below.
Mongo credential
Drivers SHOULD contain a type called MongoCredential. In this driver it is called MongoDB::Authenticate::Credential.
use MongoDB::Authenticate::Credential;
my MongoDB::Authenticate::Credential $cred .= new(
:username<user>, :password<pencil>,
:auth-mechanism<SCRAM-SHA-1>
);
ok $cred.defined, 'T0';
is $cred.password, "pencil", 'T1';
✔
T0: Credential is defined. Not all named arguments are used. There are also :source and :mechanism-properties. Btw. the field mechanism is named auth-mechanism because of the name authMechanism used in the url as an option.
✔
T1: Data can also be retrieved from it again.
use lib 't';
use Test-support;
use MongoDB::Client;
my MongoDB::Test-support $ts .= new;
my Int $p1 = $ts.server-control.get-port-number('s1');
my MongoDB::Client $client .= new(:uri("mongodb://localhost:$p1"));
ok $client.defined, 'T2';
✔
T2: Returned client object is defined, even when the uri is not pointing to an existing mongod server.