Skip to content

Commit 3c39cb5

Browse files
authored
Sync hodgepodge of spec tests (#656)
1 parent 4d5d367 commit 3c39cb5

File tree

82 files changed

+970
-204
lines changed

Some content is hidden

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

82 files changed

+970
-204
lines changed

Tests/LinuxMain.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,8 @@ extension RetryableReadsTests {
285285

286286
extension RetryableWritesTests {
287287
static var allTests = [
288-
("testRetryableWrites", testRetryableWrites),
288+
("testRetryableWritesLegacy", testRetryableWritesLegacy),
289+
("testRetryableWritesUnified", testRetryableWritesUnified),
289290
]
290291
}
291292

Tests/MongoSwiftSyncTests/RetryableWritesTests.swift

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,12 @@ final class RetryableWritesTests: MongoSwiftTestCase {
6363
}
6464
}
6565

66-
func testRetryableWrites() throws {
67-
let tests = try retrieveSpecTestFiles(specName: "retryable-writes", asType: RetryableWritesTestFile.self)
66+
func testRetryableWritesLegacy() throws {
67+
let tests = try retrieveSpecTestFiles(
68+
specName: "retryable-writes",
69+
subdirectory: "legacy",
70+
asType: RetryableWritesTestFile.self
71+
)
6872
for (fileName, testFile) in tests {
6973
let setupClient = try MongoClient.makeTestClient()
7074

@@ -138,4 +142,15 @@ final class RetryableWritesTests: MongoSwiftTestCase {
138142
}
139143
}
140144
}
145+
146+
func testRetryableWritesUnified() throws {
147+
let tests = try retrieveSpecTestFiles(
148+
specName: "retryable-writes",
149+
subdirectory: "unified",
150+
asType: UnifiedTestFile.self
151+
).map { $0.1 }
152+
153+
let runner = try UnifiedTestRunner()
154+
try runner.runFiles(tests)
155+
}
141156
}

Tests/MongoSwiftTests/AuthTests.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ final class AuthTests: MongoSwiftTestCase {
2727

2828
for (_, file) in testFiles {
2929
for testCase in file.tests {
30+
// skipping due to CDRIVER-3517
31+
// TODO: SWIFT-1298 unskip this test
32+
guard testCase.description != "must raise an error when the authSource is empty" else {
33+
continue
34+
}
35+
3036
guard testCase.valid else {
3137
expect(try ConnectionString(testCase.uri))
3238
.to(

Tests/Specs/auth/tests/connection-string.json

Lines changed: 81 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,16 @@
107107
}
108108
}
109109
},
110+
{
111+
"description": "must raise an error when the authSource is empty",
112+
"uri": "mongodb://user:password@localhost/foo?authSource=",
113+
"valid": false
114+
},
115+
{
116+
"description": "must raise an error when the authSource is empty without credentials",
117+
"uri": "mongodb://localhost/admin?authSource=",
118+
"valid": false
119+
},
110120
{
111121
"description": "should throw an exception if authSource is invalid (GSSAPI)",
112122
"uri": "mongodb://user%40DOMAIN.COM@localhost/?authMechanism=GSSAPI&authSource=foo",
@@ -206,6 +216,18 @@
206216
"mechanism_properties": null
207217
}
208218
},
219+
{
220+
"description": "should recognize the mechanism with no username when auth source is explicitly specified (MONGODB-X509)",
221+
"uri": "mongodb://localhost/?authMechanism=MONGODB-X509&authSource=$external",
222+
"valid": true,
223+
"credential": {
224+
"username": null,
225+
"password": null,
226+
"source": "$external",
227+
"mechanism": "MONGODB-X509",
228+
"mechanism_properties": null
229+
}
230+
},
209231
{
210232
"description": "should throw an exception if supplied a password (MONGODB-X509)",
211233
"uri": "mongodb://user:password@localhost/?authMechanism=MONGODB-X509",
@@ -352,9 +374,10 @@
352374
"credential": null
353375
},
354376
{
355-
"description": "authSource without username is invalid (default mechanism)",
377+
"description": "authSource without username doesn't create credential (default mechanism)",
356378
"uri": "mongodb://localhost/?authSource=foo",
357-
"valid": false
379+
"valid": true,
380+
"credential": null
358381
},
359382
{
360383
"description": "should throw an exception if no username provided (userinfo implies default mechanism)",
@@ -365,6 +388,62 @@
365388
"description": "should throw an exception if no username/password provided (userinfo implies default mechanism)",
366389
"uri": "mongodb://:@localhost.com/",
367390
"valid": false
391+
},
392+
{
393+
"description": "should recognise the mechanism (MONGODB-AWS)",
394+
"uri": "mongodb://localhost/?authMechanism=MONGODB-AWS",
395+
"valid": true,
396+
"credential": {
397+
"username": null,
398+
"password": null,
399+
"source": "$external",
400+
"mechanism": "MONGODB-AWS",
401+
"mechanism_properties": null
402+
}
403+
},
404+
{
405+
"description": "should recognise the mechanism when auth source is explicitly specified (MONGODB-AWS)",
406+
"uri": "mongodb://localhost/?authMechanism=MONGODB-AWS&authSource=$external",
407+
"valid": true,
408+
"credential": {
409+
"username": null,
410+
"password": null,
411+
"source": "$external",
412+
"mechanism": "MONGODB-AWS",
413+
"mechanism_properties": null
414+
}
415+
},
416+
{
417+
"description": "should throw an exception if username and no password (MONGODB-AWS)",
418+
"uri": "mongodb://user@localhost/?authMechanism=MONGODB-AWS",
419+
"valid": false,
420+
"credential": null
421+
},
422+
{
423+
"description": "should use username and password if specified (MONGODB-AWS)",
424+
"uri": "mongodb://user%21%40%23%24%25%5E%26%2A%28%29_%2B:pass%21%40%23%24%25%5E%26%2A%28%29_%2B@localhost/?authMechanism=MONGODB-AWS",
425+
"valid": true,
426+
"credential": {
427+
"username": "user!@#$%^&*()_+",
428+
"password": "pass!@#$%^&*()_+",
429+
"source": "$external",
430+
"mechanism": "MONGODB-AWS",
431+
"mechanism_properties": null
432+
}
433+
},
434+
{
435+
"description": "should use username, password and session token if specified (MONGODB-AWS)",
436+
"uri": "mongodb://user:password@localhost/?authMechanism=MONGODB-AWS&authMechanismProperties=AWS_SESSION_TOKEN:token%21%40%23%24%25%5E%26%2A%28%29_%2B",
437+
"valid": true,
438+
"credential": {
439+
"username": "user",
440+
"password": "password",
441+
"source": "$external",
442+
"mechanism": "MONGODB-AWS",
443+
"mechanism_properties": {
444+
"AWS_SESSION_TOKEN": "token!@#$%^&*()_+"
445+
}
446+
}
368447
}
369448
]
370449
}

Tests/Specs/change-streams/tests/legacy/change-streams-errors.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@
7878
"target": "collection",
7979
"topology": [
8080
"replicaset",
81-
"sharded"
81+
"sharded",
82+
"load-balanced"
8283
],
8384
"changeStreamPipeline": [
8485
{
@@ -125,7 +126,8 @@
125126
"target": "collection",
126127
"topology": [
127128
"replicaset",
128-
"sharded"
129+
"sharded",
130+
"load-balanced"
129131
],
130132
"changeStreamPipeline": [],
131133
"changeStreamOptions": {},

Tests/Specs/change-streams/tests/legacy/change-streams-resume-whitelist.json renamed to Tests/Specs/change-streams/tests/legacy/change-streams-resume-allowlist.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
"target": "collection",
2121
"topology": [
2222
"replicaset",
23-
"sharded"
23+
"sharded",
24+
"load-balanced"
2425
],
2526
"changeStreamPipeline": [],
2627
"changeStreamOptions": {},
@@ -777,7 +778,7 @@
777778
}
778779
},
779780
{
780-
"description": "change stream resumes after NotMaster",
781+
"description": "change stream resumes after NotWritablePrimary",
781782
"minServerVersion": "4.2",
782783
"maxServerVersion": "4.2.99",
783784
"failPoint": {
@@ -1068,7 +1069,7 @@
10681069
}
10691070
},
10701071
{
1071-
"description": "change stream resumes after NotMasterNoSlaveOk",
1072+
"description": "change stream resumes after NotPrimaryNoSecondaryOk",
10721073
"minServerVersion": "4.2",
10731074
"maxServerVersion": "4.2.99",
10741075
"failPoint": {
@@ -1165,7 +1166,7 @@
11651166
}
11661167
},
11671168
{
1168-
"description": "change stream resumes after NotMasterOrSecondary",
1169+
"description": "change stream resumes after NotPrimaryOrSecondary",
11691170
"minServerVersion": "4.2",
11701171
"maxServerVersion": "4.2.99",
11711172
"failPoint": {

0 commit comments

Comments
 (0)