@@ -4,7 +4,7 @@ import { ApiClient } from "../../../src/common/atlas/apiClient.js";
44import { HTTPServerProxyTestSetup } from "../fixtures/httpsServerProxyTest.js" ;
55
66describe ( "ApiClient integration test" , ( ) => {
7- describe ( "oauth authentication proxy" , ( ) => {
7+ describe ( `atlas API proxy integration` , ( ) => {
88 let apiClient : ApiClient ;
99 let proxyTestSetup : HTTPServerProxyTestSetup ;
1010
@@ -26,48 +26,63 @@ describe("ApiClient integration test", () => {
2626
2727 function withToken ( accessToken : string , expired : boolean ) {
2828 const apiClientMut = apiClient as unknown as { accessToken : AccessToken } ;
29- const expireAt = expired ? Date . now ( ) - 100000 : Date . now ( ) + 10000 ;
29+ const diff = 10_000 ;
30+ const now = Date . now ( ) ;
3031
3132 apiClientMut . accessToken = {
3233 access_token : accessToken ,
33- expires_at : expireAt ,
34+ expires_at : expired ? now - diff : now + diff ,
3435 } ;
3536 }
3637
38+ async function ignoringResult ( fn : ( ) => Promise < unknown > ) : Promise < void > {
39+ try {
40+ await fn ( ) ;
41+ } catch ( error : unknown ) {
42+ // we are ignoring the error because we know that
43+ // the type safe client will fail. It will fail
44+ // because we are returning an empty 200, and it expects
45+ // a specific format not relevant for these tests.
46+ }
47+ }
48+
3749 afterEach ( async ( ) => {
3850 delete process . env . NODE_TLS_REJECT_UNAUTHORIZED ;
3951 delete process . env . HTTP_PROXY ;
4052
41- await apiClient . close ( ) ;
53+ await ignoringResult ( ( ) => apiClient . close ( ) ) ;
4254 await proxyTestSetup . teardown ( ) ;
4355 } ) ;
4456
4557 it ( "should send the oauth request through a proxy if configured" , async ( ) => {
46- await apiClient . validateAccessToken ( ) ;
58+ await ignoringResult ( ( ) => apiClient . validateAccessToken ( ) ) ;
4759 expect ( proxyTestSetup . getRequestedUrls ( ) ) . toEqual ( [
4860 `http://localhost:${ proxyTestSetup . httpsServerPort } /api/oauth/token` ,
4961 ] ) ;
5062 } ) ;
5163
5264 it ( "should send the oauth revoke request through a proxy if configured" , async ( ) => {
5365 withToken ( "my non expired token" , false ) ;
54- await apiClient . close ( ) ;
66+ await ignoringResult ( ( ) => apiClient . close ( ) ) ;
5567 expect ( proxyTestSetup . getRequestedUrls ( ) ) . toEqual ( [
5668 `http://localhost:${ proxyTestSetup . httpsServerPort } /api/oauth/revoke` ,
5769 ] ) ;
5870 } ) ;
5971
6072 it ( "should make an atlas call when the token is not expired" , async ( ) => {
61- withToken ( "my not expired" , false ) ;
62- await apiClient . listOrganizations ( ) ;
73+ withToken ( "my non expired token " , false ) ;
74+ await ignoringResult ( ( ) => apiClient . listOrganizations ( ) ) ;
6375 expect ( proxyTestSetup . getRequestedUrls ( ) ) . toEqual ( [
6476 `http://localhost:${ proxyTestSetup . httpsServerPort } /api/atlas/v2/orgs` ,
6577 ] ) ;
6678 } ) ;
6779
68- it ( "should request a new token and an atlas call when the token is expired" , async ( ) => {
69- withToken ( "my expired" , true ) ;
70- await apiClient . listOrganizations ( ) ;
80+ it ( "should request a new token and make an atlas call when the token is expired" , async ( ) => {
81+ withToken ( "my expired token" , true ) ;
82+ await ignoringResult ( ( ) => apiClient . validateAccessToken ( ) ) ;
83+ withToken ( "my non expired token" , false ) ;
84+ await ignoringResult ( ( ) => apiClient . listOrganizations ( ) ) ;
85+
7186 expect ( proxyTestSetup . getRequestedUrls ( ) ) . toEqual ( [
7287 `http://localhost:${ proxyTestSetup . httpsServerPort } /api/oauth/token` ,
7388 `http://localhost:${ proxyTestSetup . httpsServerPort } /api/atlas/v2/orgs` ,
0 commit comments