@@ -14,21 +14,14 @@ const connectionString = new ConnectionString(process.env.MONGODB_URI!);
1414describe ( 'x509 Authentication' , function ( ) {
1515 let client : MongoClient ;
1616 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
2218 } ;
2319
2420 this . afterEach ( ( ) => {
2521 return client ?. close ( ) ;
2622 } ) ;
2723
2824 context ( 'When the user provides a valid certificate' , function ( ) {
29- before ( 'create x509 user' , createX509User ) ;
30- after ( 'drop x509 user' , dropX509User ) ;
31-
3225 it ( 'successfully authenticates using x509' , async function ( ) {
3326 client = new MongoClient ( connectionString . toString ( ) , validOptions ) ;
3427 const result = await client
@@ -64,9 +57,7 @@ describe('x509 Authentication', function () {
6457 const invalidOptions : MongoClientOptions = {
6558 // use an expired key file
6659 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
7061 } ;
7162 client = new MongoClient ( connectionString . toString ( ) , {
7263 ...invalidOptions ,
@@ -82,7 +73,10 @@ describe('x509 Authentication', function () {
8273 'when a valid cert is provided but the certificate does not correspond to a user' ,
8374 function ( ) {
8475 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+ } ) ;
8680 const error = await client . connect ( ) . catch ( error => error ) ;
8781
8882 expect ( error ) . to . be . instanceOf ( MongoServerError ) ;
@@ -91,42 +85,3 @@ describe('x509 Authentication', function () {
9185 }
9286 ) ;
9387} ) ;
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