@@ -14,21 +14,14 @@ const connectionString = new ConnectionString(process.env.MONGODB_URI!);
14
14
describe ( 'x509 Authentication' , function ( ) {
15
15
let client : MongoClient ;
16
16
const validOptions : MongoClientOptions = {
17
- tls : true ,
18
- tlsCertificateKeyFile : process . env . SSL_KEY_FILE ,
19
- tlsCAFile : process . env . SSL_CA_FILE ,
20
- authMechanism : 'MONGODB-X509' as const ,
21
- authSource : '$external'
17
+ tlsCertificateKeyFile : process . env . SSL_KEY_FILE
22
18
} ;
23
19
24
20
this . afterEach ( ( ) => {
25
21
return client ?. close ( ) ;
26
22
} ) ;
27
23
28
24
context ( 'When the user provides a valid certificate' , function ( ) {
29
- before ( 'create x509 user' , createX509User ) ;
30
- after ( 'drop x509 user' , dropX509User ) ;
31
-
32
25
it ( 'successfully authenticates using x509' , async function ( ) {
33
26
client = new MongoClient ( connectionString . toString ( ) , validOptions ) ;
34
27
const result = await client
@@ -64,9 +57,7 @@ describe('x509 Authentication', function () {
64
57
const invalidOptions : MongoClientOptions = {
65
58
// use an expired key file
66
59
tlsCertificateKeyFile : process . env . SSL_KEY_FILE_EXPIRED ,
67
- tlsCAFile : process . env . SSL_CA_FILE ,
68
- authMechanism : 'MONGODB-X509' as const ,
69
- authSource : '$external'
60
+ serverSelectionTimeoutMS : 2000
70
61
} ;
71
62
client = new MongoClient ( connectionString . toString ( ) , {
72
63
...invalidOptions ,
@@ -82,7 +73,10 @@ describe('x509 Authentication', function () {
82
73
'when a valid cert is provided but the certificate does not correspond to a user' ,
83
74
function ( ) {
84
75
it ( 'fails to authenticate' , async function ( ) {
85
- client = new MongoClient ( connectionString . toString ( ) , validOptions ) ;
76
+ client = new MongoClient ( connectionString . toString ( ) , {
77
+ tlsCertificateKeyFile : process . env . SSL_KEY_FILE_NO_USER ,
78
+ serverSelectionTimeoutMS : 2000
79
+ } ) ;
86
80
const error = await client . connect ( ) . catch ( error => error ) ;
87
81
88
82
expect ( error ) . to . be . instanceOf ( MongoServerError ) ;
@@ -91,42 +85,3 @@ describe('x509 Authentication', function () {
91
85
}
92
86
) ;
93
87
} ) ;
94
-
95
- async function createX509User ( ) {
96
- const utilClient = new MongoClient ( connectionString . toString ( ) , {
97
- tls : true ,
98
- tlsCertificateKeyFile : process . env . SSL_KEY_FILE ,
99
- tlsCAFile : process . env . SSL_CA_FILE ,
100
- serverSelectionTimeoutMS : 2000
101
- } ) ;
102
-
103
- try {
104
- await utilClient . connect ( ) ;
105
- await utilClient . db ( '$external' ) . command ( {
106
- createUser : process . env . SUBJECT ,
107
- roles : [
108
- { role : 'readWrite' , db : 'test' } ,
109
- { role : 'userAdminAnyDatabase' , db : 'admin' }
110
- ]
111
- } ) ;
112
- } finally {
113
- await utilClient . close ( ) ;
114
- }
115
- }
116
-
117
- async function dropX509User ( ) {
118
- const utilClient = new MongoClient ( connectionString . toString ( ) , {
119
- tls : true ,
120
- tlsCertificateKeyFile : process . env . SSL_KEY_FILE ,
121
- tlsCAFile : process . env . SSL_CA_FILE ,
122
- serverSelectionTimeoutMS : 2000
123
- } ) ;
124
- try {
125
- await utilClient . connect ( ) ;
126
- await utilClient . db ( '$external' ) . command ( {
127
- dropUser : process . env . SUBJECT
128
- } ) ;
129
- } finally {
130
- await utilClient . close ( ) ;
131
- }
132
- }
0 commit comments