@@ -30,6 +30,8 @@ const metadata: MongoDBMetadataUI = {
3030 }
3131} ;
3232
33+ const closeSignal = new AbortController ( ) . signal ;
34+
3335context ( 'Azure KMS Mock Server Tests' , function ( ) {
3436 context ( 'Case 1: Success' , metadata , function ( ) {
3537 // Do not set an ``X-MongoDB-HTTP-TestParams`` header.
@@ -44,7 +46,7 @@ context('Azure KMS Mock Server Tests', function () {
4446 // 5. The token will have a resource of ``"https://vault.azure.net"``
4547
4648 it ( 'returns a properly formatted access token' , async ( ) => {
47- const credentials = await fetchAzureKMSToken ( new KMSRequestOptions ( ) ) ;
49+ const credentials = await fetchAzureKMSToken ( new KMSRequestOptions ( ) , closeSignal ) ;
4850 expect ( credentials ) . to . have . property ( 'accessToken' , 'magic-cookie' ) ;
4951 } ) ;
5052 } ) ;
@@ -59,7 +61,10 @@ context('Azure KMS Mock Server Tests', function () {
5961 // The test case should ensure that this error condition is handled gracefully.
6062
6163 it ( 'returns an error' , async ( ) => {
62- const error = await fetchAzureKMSToken ( new KMSRequestOptions ( 'empty-json' ) ) . catch ( e => e ) ;
64+ const error = await fetchAzureKMSToken (
65+ new KMSRequestOptions ( 'empty-json' ) ,
66+ closeSignal
67+ ) . catch ( e => e ) ;
6368
6469 expect ( error ) . to . be . instanceof ( MongoCryptAzureKMSRequestError ) ;
6570 } ) ;
@@ -74,7 +79,9 @@ context('Azure KMS Mock Server Tests', function () {
7479 // The test case should ensure that this error condition is handled gracefully.
7580
7681 it ( 'returns an error' , async ( ) => {
77- const error = await fetchAzureKMSToken ( new KMSRequestOptions ( 'bad-json' ) ) . catch ( e => e ) ;
82+ const error = await fetchAzureKMSToken ( new KMSRequestOptions ( 'bad-json' ) , closeSignal ) . catch (
83+ e => e
84+ ) ;
7885
7986 expect ( error ) . to . be . instanceof ( MongoCryptAzureKMSRequestError ) ;
8087 } ) ;
@@ -89,7 +96,9 @@ context('Azure KMS Mock Server Tests', function () {
8996 // 2. The response body is unspecified.
9097 // The test case should ensure that this error condition is handled gracefully.
9198 it ( 'returns an error' , async ( ) => {
92- const error = await fetchAzureKMSToken ( new KMSRequestOptions ( '404' ) ) . catch ( e => e ) ;
99+ const error = await fetchAzureKMSToken ( new KMSRequestOptions ( '404' ) , closeSignal ) . catch (
100+ e => e
101+ ) ;
93102
94103 expect ( error ) . to . be . instanceof ( MongoCryptAzureKMSRequestError ) ;
95104 } ) ;
@@ -104,7 +113,9 @@ context('Azure KMS Mock Server Tests', function () {
104113 // 2. The response body is unspecified.
105114 // The test case should ensure that this error condition is handled gracefully.
106115 it ( 'returns an error' , async ( ) => {
107- const error = await fetchAzureKMSToken ( new KMSRequestOptions ( '500' ) ) . catch ( e => e ) ;
116+ const error = await fetchAzureKMSToken ( new KMSRequestOptions ( '500' ) , closeSignal ) . catch (
117+ e => e
118+ ) ;
108119
109120 expect ( error ) . to . be . instanceof ( MongoCryptAzureKMSRequestError ) ;
110121 } ) ;
@@ -117,7 +128,9 @@ context('Azure KMS Mock Server Tests', function () {
117128 // The HTTP response from the ``fake_azure`` server will take at least 1000 seconds
118129 // to complete. The request should fail with a timeout.
119130 it ( 'returns an error after the request times out' , async ( ) => {
120- const error = await fetchAzureKMSToken ( new KMSRequestOptions ( 'slow' ) ) . catch ( e => e ) ;
131+ const error = await fetchAzureKMSToken ( new KMSRequestOptions ( 'slow' ) , closeSignal ) . catch (
132+ e => e
133+ ) ;
121134
122135 expect ( error ) . to . be . instanceof ( MongoCryptAzureKMSRequestError ) ;
123136 } ) ;
0 commit comments