@@ -10,20 +10,10 @@ const semver = require('semver');
10
10
const { TopologyType } = require ( '../../../src' ) ;
11
11
12
12
describe ( 'auth prose tests' , ( ) => {
13
- beforeEach ( async function ( ) {
14
- if ( ! semver . satisfies ( this . configuration . version , '>=3.7.3' ) ) {
15
- this . currentTest . skipReason = 'Requires version >=3.7.3' ;
16
- return this . skip ( ) ;
17
- }
18
- if ( this . configuration . topologyType === TopologyType . LoadBalanced ) {
19
- this . currentTest . skipReason = 'Requires non-loadbalanced topology' ;
20
- return this . skip ( ) ;
21
- }
22
- } ) ;
23
-
24
13
describe ( 'SCRAM-SHA-256 prose test' , ( ) => {
25
14
describe ( 'SCRAM-SHA-256 prose test Steps 1-3' , function ( ) {
26
- const test = { } ;
15
+ let sandbox ;
16
+ let oldDbName ;
27
17
const userMap = {
28
18
sha1 : {
29
19
description : 'user with sha1 credentials' ,
@@ -51,18 +41,29 @@ describe('auth prose tests', () => {
51
41
52
42
const users = Object . keys ( userMap ) . map ( name => userMap [ name ] ) ;
53
43
54
- afterEach ( ( ) => test . sandbox . restore ( ) ) ;
44
+ afterEach ( ( ) => {
45
+ if ( sandbox ) sandbox . restore ( ) ;
46
+ } ) ;
55
47
56
48
/**
57
49
* Step 1
58
50
* Create three test users, one with only SHA-1, one with only SHA-256 and one with both.
59
51
*/
60
52
beforeEach ( async function ( ) {
61
- test . sandbox = sinon . createSandbox ( ) ;
53
+ if ( ! semver . satisfies ( this . configuration . version , '>=3.7.3' ) ) {
54
+ this . currentTest . skipReason = 'Requires version >=3.7.3' ;
55
+ return this . skip ( ) ;
56
+ }
57
+ if ( this . configuration . topologyType === TopologyType . LoadBalanced ) {
58
+ this . currentTest . skipReason = 'Requires non-loadbalanced topology' ;
59
+ return this . skip ( ) ;
60
+ }
61
+
62
+ sandbox = sinon . createSandbox ( ) ;
62
63
await setupDatabase ( this . configuration ) ;
63
64
64
65
const client = this . configuration . newClient ( ) ;
65
- test . oldDbName = this . configuration . db ;
66
+ oldDbName = this . configuration . db ;
66
67
this . configuration . db = 'admin' ;
67
68
const db = client . db ( this . configuration . db ) ;
68
69
@@ -80,7 +81,7 @@ describe('auth prose tests', () => {
80
81
afterEach ( async function ( ) {
81
82
const client = this . configuration . newClient ( ) ;
82
83
const db = client . db ( this . configuration . db ) ;
83
- this . configuration . db = test . oldDbName ;
84
+ this . configuration . db = oldDbName ;
84
85
85
86
await Promise . all ( users . map ( user => db . removeUser ( user . username ) . catch ( ( ) => null ) ) ) ;
86
87
await client . close ( ) ;
@@ -167,7 +168,7 @@ describe('auth prose tests', () => {
167
168
authSource : this . configuration . db
168
169
} ;
169
170
170
- test . sandbox . spy ( ScramSHA256 . prototype , 'auth' ) ;
171
+ sandbox . spy ( ScramSHA256 . prototype , 'auth' ) ;
171
172
172
173
const client = this . configuration . newClient ( { } , options ) ;
173
174
await client . db ( ) . command ( { ping : 1 } ) ;
@@ -188,19 +189,17 @@ describe('auth prose tests', () => {
188
189
} ;
189
190
190
191
let runCommandSpy ;
191
- test . sandbox
192
- . stub ( ScramSHA256 . prototype , 'auth' )
193
- . callsFake ( function ( authContext , callback ) {
194
- const connection = authContext . connection ;
195
- const auth = ScramSHA256 . prototype . auth . wrappedMethod ;
196
- runCommandSpy = test . sandbox . spy ( connection , 'command' ) ;
197
- function _callback ( err , res ) {
198
- runCommandSpy . restore ( ) ;
199
- callback ( err , res ) ;
200
- }
201
-
202
- auth . apply ( this , [ authContext , _callback ] ) ;
203
- } ) ;
192
+ sandbox . stub ( ScramSHA256 . prototype , 'auth' ) . callsFake ( function ( authContext , callback ) {
193
+ const connection = authContext . connection ;
194
+ const auth = ScramSHA256 . prototype . auth . wrappedMethod ;
195
+ runCommandSpy = sandbox . spy ( connection , 'command' ) ;
196
+ function _callback ( err , res ) {
197
+ runCommandSpy . restore ( ) ;
198
+ callback ( err , res ) ;
199
+ }
200
+
201
+ auth . apply ( this , [ authContext , _callback ] ) ;
202
+ } ) ;
204
203
205
204
const client = this . configuration . newClient ( { } , options ) ;
206
205
await client . db ( ) . command ( { ping : 1 } ) ;
@@ -286,7 +285,7 @@ describe('auth prose tests', () => {
286
285
authSource : this . configuration . db
287
286
} ;
288
287
289
- const commandSpy = test . sandbox . spy ( Connection . prototype , 'command' ) ;
288
+ const commandSpy = sandbox . spy ( Connection . prototype , 'command' ) ;
290
289
const client = this . configuration . newClient ( { } , options ) ;
291
290
await client . db ( ) . command ( { ping : 1 } ) ;
292
291
const calls = commandSpy
@@ -334,6 +333,14 @@ describe('auth prose tests', () => {
334
333
] ;
335
334
336
335
beforeEach ( async function ( ) {
336
+ if ( ! semver . satisfies ( this . configuration . version , '>=3.7.3' ) ) {
337
+ this . currentTest . skipReason = 'Requires version >=3.7.3' ;
338
+ return this . skip ( ) ;
339
+ }
340
+ if ( this . configuration . topologyType === TopologyType . LoadBalanced ) {
341
+ this . currentTest . skipReason = 'Requires non-loadbalanced topology' ;
342
+ return this . skip ( ) ;
343
+ }
337
344
await setupDatabase ( this . configuration ) ;
338
345
339
346
const client = this . configuration . newClient ( ) ;
0 commit comments