Skip to content

Commit 507cc99

Browse files
committed
test: move core unit tests from core/unit => unit/core
1 parent 53cb799 commit 507cc99

File tree

258 files changed

+3693
-82
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

258 files changed

+3693
-82
lines changed

lib/core/uri_parser.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,10 @@ function applyAuthExpectations(parsed) {
335335
const options = parsed.options;
336336
const authSource = options.authsource || options.authSource;
337337
if (authSource != null) {
338+
if (parsed.auth == null || parsed.auth.username == null) {
339+
throw new MongoParseError('Auth source provided without username');
340+
}
341+
338342
parsed.auth = Object.assign({}, parsed.auth, { db: authSource });
339343
}
340344

@@ -549,12 +553,20 @@ function parseConnectionString(uri, options, callback) {
549553
return callback(new MongoParseError('Unescaped at-sign in authority section'));
550554
}
551555

556+
if (authorityParts[0] == null || authorityParts[0] === '') {
557+
return callback(new MongoParseError('No username provided in authority section'));
558+
}
559+
552560
if (authorityParts.length > 1) {
553561
const authParts = authorityParts.shift().split(':');
554562
if (authParts.length > 2) {
555563
return callback(new MongoParseError('Unescaped colon in authority section'));
556564
}
557565

566+
if (authParts[0] === '') {
567+
return callback(new MongoParseError('Invalid empty username provided'));
568+
}
569+
558570
if (!auth.username) auth.username = qs.unescape(authParts[0]);
559571
if (!auth.password) auth.password = authParts[1] ? qs.unescape(authParts[1]) : null;
560572
}

test/core/functional/replset_state.test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22

33
const expect = require('chai').expect,
44
f = require('util').format,
5+
p = require('path'),
56
fs = require('fs'),
67
ObjectId = require('bson').ObjectId,
78
ReplSetState = require('../../../lib/core/topologies/replset_state');
89

910
describe('ReplicaSet state', function() {
10-
const path = f('%s/../spec/server-discovery-and-monitoring/rs', __dirname);
11+
const path = p.resolve(__dirname, '../../spec/server-discovery-and-monitoring/rs');
1112

1213
fs
1314
.readdirSync(path)

test/spec/auth/README.rst

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
==========
2+
Auth Tests
3+
==========
4+
5+
The YAML and JSON files in this directory tree are platform-independent tests
6+
that drivers can use to prove their conformance to the Auth Spec at least with
7+
respect to connection string URI input.
8+
9+
Drivers should do additional unit testing if there are alternate ways of
10+
configuring credentials on a client.
11+
12+
Driver must also conduct the prose tests in the Auth Spec test plan section.
13+
14+
Format
15+
------
16+
17+
Each YAML file contains an object with a single ``tests`` key. This key is an
18+
array of test case objects, each of which have the following keys:
19+
20+
- ``description``: A string describing the test.
21+
- ``uri``: A string containing the URI to be parsed.
22+
- ``valid:`` A boolean indicating if the URI should be considered valid.
23+
- ``credential``: If null, the credential must not be considered configured for the
24+
the purpose of deciding if the driver should authenticate to the topology. If non-null,
25+
it is an object containing one or more of the following properties of a credential:
26+
27+
- ``username``: A string containing the username. For auth mechanisms
28+
that do not utilize a password, this may be the entire ``userinfo`` token
29+
from the connection string.
30+
- ``password``: A string containing the password.
31+
- ``source``: A string containing the authentication database.
32+
- ``mechanism``: A string containing the authentication mechanism. A null value for
33+
this key is used to indicate that a mechanism wasn't specified and that mechanism
34+
negotiation is required. Test harnesses should modify the mechanism test as needed
35+
to assert this condition.
36+
- ``mechanism_properties``: A document containing mechanism-specific properties. It
37+
specifies a subset of properties that must match. If a key exists in the test data,
38+
it must exist with the corresponding value in the credential. Other values may
39+
exist in the credential without failing the test.
40+
41+
If any key is missing, no assertion about that key is necessary. Except as
42+
specified explicitly above, if a key is present, but the test value is null,
43+
the observed value for that key must be uninitialized (whatever that means for
44+
a given driver and data type).
45+
46+
Implementation notes
47+
====================
48+
49+
Testing whether a URI is valid or not should simply be a matter of checking
50+
whether URI parsing (or MongoClient construction) raises an error or exception.
51+
52+
If a credential is configured, its properties must be compared to the
53+
``credential`` field.

0 commit comments

Comments
 (0)