@@ -66,24 +66,27 @@ if (nodeVersion >= 16) {
6666 sandbox . restore ( ) ;
6767 } ) ;
6868
69- it ( 'Should inject SigV4 Headers successfully' , async ( ) => {
69+ it ( 'Should inject SigV4 Headers successfully' , done => {
7070 const exporter = new mockModule . OTLPAwsSpanExporter ( XRAY_OTLP_ENDPOINT + XRAY_OTLP_ENDPOINT_PATH ) ;
7171
72- scope . on ( 'request' , ( req , interceptor , body ) => {
73- const headers = req . headers ;
74- expect ( headers ) . toHaveProperty ( AUTHORIZATION_HEADER . toLowerCase ( ) ) ;
75- expect ( headers ) . toHaveProperty ( X_AMZ_SECURITY_TOKEN_HEADER . toLowerCase ( ) ) ;
76- expect ( headers ) . toHaveProperty ( X_AMZ_DATE_HEADER . toLowerCase ( ) ) ;
77-
78- expect ( headers [ AUTHORIZATION_HEADER . toLowerCase ( ) ] ) . toBe ( EXPECTED_AUTH_HEADER ) ;
79- expect ( headers [ X_AMZ_SECURITY_TOKEN_HEADER . toLowerCase ( ) ] ) . toBe ( EXPECTED_AUTH_SECURITY_TOKEN ) ;
80- expect ( headers [ X_AMZ_DATE_HEADER . toLowerCase ( ) ] ) . toBe ( EXPECTED_AUTH_X_AMZ_DATE ) ;
72+ exporter
73+ . export ( [ ] , ( ) => { } )
74+ . then ( ( ) => {
75+ scope . on ( 'request' , ( req , interceptor , body ) => {
76+ const headers = req . headers ;
77+ expect ( headers ) . toHaveProperty ( AUTHORIZATION_HEADER . toLowerCase ( ) ) ;
78+ expect ( headers ) . toHaveProperty ( X_AMZ_SECURITY_TOKEN_HEADER . toLowerCase ( ) ) ;
79+ expect ( headers ) . toHaveProperty ( X_AMZ_DATE_HEADER . toLowerCase ( ) ) ;
8180
82- expect ( headers [ 'content-type' ] ) . toBe ( 'application/x-protobuf' ) ;
83- expect ( headers [ 'user-agent' ] ) . toMatch ( / ^ O T e l - O T L P - E x p o r t e r - J a v a S c r i p t \/ \d + \. \d + \. \d + $ / ) ;
84- } ) ;
81+ expect ( headers [ AUTHORIZATION_HEADER . toLowerCase ( ) ] ) . toBe ( EXPECTED_AUTH_HEADER ) ;
82+ expect ( headers [ X_AMZ_SECURITY_TOKEN_HEADER . toLowerCase ( ) ] ) . toBe ( EXPECTED_AUTH_SECURITY_TOKEN ) ;
83+ expect ( headers [ X_AMZ_DATE_HEADER . toLowerCase ( ) ] ) . toBe ( EXPECTED_AUTH_X_AMZ_DATE ) ;
8584
86- await exporter . export ( [ ] , ( ) => { } ) ;
85+ expect ( headers [ 'content-type' ] ) . toBe ( 'application/x-protobuf' ) ;
86+ expect ( headers [ 'user-agent' ] ) . toMatch ( / ^ O T e l - O T L P - E x p o r t e r - J a v a S c r i p t \/ \d + \. \d + \. \d + $ / ) ;
87+ done ( ) ;
88+ } ) ;
89+ } ) ;
8790 } ) ;
8891
8992 describe ( 'Should not inject SigV4 headers if dependencies are missing' , ( ) => {
@@ -95,42 +98,35 @@ if (nodeVersion >= 16) {
9598 ] ;
9699
97100 dependencies . forEach ( dependency => {
98- it ( `should not sign headers if missing dependency: ${ dependency } ` , async ( ) => {
101+ it ( `should not sign headers if missing dependency: ${ dependency } ` , done => {
99102 const exporter = new OTLPAwsSpanExporter ( XRAY_OTLP_ENDPOINT + XRAY_OTLP_ENDPOINT_PATH ) ;
100103
101- scope . on ( 'request' , ( req , interceptor , body ) => {
102- const headers = req . headers ;
103- expect ( headers ) . not . toHaveProperty ( AUTHORIZATION_HEADER ) ;
104- expect ( headers ) . not . toHaveProperty ( X_AMZ_DATE_HEADER ) ;
105- expect ( headers ) . not . toHaveProperty ( X_AMZ_SECURITY_TOKEN_HEADER ) ;
106-
107- expect ( headers [ 'content-type' ] ) . toBe ( 'application/x-protobuf' ) ;
108- expect ( headers [ 'user-agent' ] ) . toMatch ( / ^ O T e l - O T L P - E x p o r t e r - J a v a S c r i p t \/ \d + \. \d + \. \d + $ / ) ;
109- } ) ;
110-
111104 Object . keys ( require . cache ) . forEach ( key => {
112105 delete require . cache [ key ] ;
113106 } ) ;
114107 const requireStub = sandbox . stub ( require ( 'module' ) , '_load' ) ;
115108 requireStub . withArgs ( dependency ) . throws ( new Error ( `Cannot find module '${ dependency } '` ) ) ;
116109 requireStub . callThrough ( ) ;
117110
118- await exporter . export ( [ ] , ( ) => { } ) ;
111+ exporter
112+ . export ( [ ] , ( ) => { } )
113+ . then ( ( ) => {
114+ scope . on ( 'request' , ( req , interceptor , body ) => {
115+ const headers = req . headers ;
116+ expect ( headers ) . not . toHaveProperty ( AUTHORIZATION_HEADER ) ;
117+ expect ( headers ) . not . toHaveProperty ( X_AMZ_DATE_HEADER ) ;
118+ expect ( headers ) . not . toHaveProperty ( X_AMZ_SECURITY_TOKEN_HEADER ) ;
119+
120+ expect ( headers [ 'content-type' ] ) . toBe ( 'application/x-protobuf' ) ;
121+ expect ( headers [ 'user-agent' ] ) . toMatch ( / ^ O T e l - O T L P - E x p o r t e r - J a v a S c r i p t \/ \d + \. \d + \. \d + $ / ) ;
122+ done ( ) ;
123+ } ) ;
124+ } ) ;
119125 } ) ;
120126 } ) ;
121127 } ) ;
122128
123- it ( 'should not inject SigV4 headers if failure to sign headers' , async ( ) => {
124- scope . on ( 'request' , ( req , interceptor , body ) => {
125- const headers = req . headers ;
126- expect ( headers ) . not . toHaveProperty ( AUTHORIZATION_HEADER ) ;
127- expect ( headers ) . not . toHaveProperty ( X_AMZ_DATE_HEADER ) ;
128- expect ( headers ) . not . toHaveProperty ( X_AMZ_SECURITY_TOKEN_HEADER ) ;
129-
130- expect ( headers [ 'content-type' ] ) . toBe ( 'application/x-protobuf' ) ;
131- expect ( headers [ 'user-agent' ] ) . toMatch ( / ^ O T e l - O T L P - E x p o r t e r - J a v a S c r i p t \/ \d + \. \d + \. \d + $ / ) ;
132- } ) ;
133-
129+ it ( 'should not inject SigV4 headers if failure to sign headers' , done => {
134130 const stubbedModule = proxyquire ( '../src/otlp-aws-span-exporter' , {
135131 '@smithy/signature-v4' : {
136132 SignatureV4 : class MockSignatureV4 {
@@ -141,22 +137,25 @@ if (nodeVersion >= 16) {
141137 } ,
142138 } ) ;
143139
144- const exporter = new stubbedModule . OTLPAwsSpanExporter ( XRAY_OTLP_ENDPOINT ) ;
145-
146- await exporter . export ( [ ] , ( ) => { } ) ;
147- } ) ;
140+ const exporter = new stubbedModule . OTLPAwsSpanExporter ( XRAY_OTLP_ENDPOINT + XRAY_OTLP_ENDPOINT_PATH ) ;
148141
149- it ( 'should not inject SigV4 headers if failure to retrieve credentials' , async ( ) => {
150- scope . on ( 'request' , ( req , interceptor , body ) => {
151- const headers = req . headers ;
152- expect ( headers ) . not . toHaveProperty ( AUTHORIZATION_HEADER ) ;
153- expect ( headers ) . not . toHaveProperty ( X_AMZ_DATE_HEADER ) ;
154- expect ( headers ) . not . toHaveProperty ( X_AMZ_SECURITY_TOKEN_HEADER ) ;
142+ exporter
143+ . export ( [ ] , ( ) => { } )
144+ . then ( ( ) => {
145+ scope . on ( 'request' , ( req , interceptor , body ) => {
146+ const headers = req . headers ;
147+ expect ( headers ) . not . toHaveProperty ( AUTHORIZATION_HEADER ) ;
148+ expect ( headers ) . not . toHaveProperty ( X_AMZ_DATE_HEADER ) ;
149+ expect ( headers ) . not . toHaveProperty ( X_AMZ_SECURITY_TOKEN_HEADER ) ;
155150
156- expect ( headers [ 'content-type' ] ) . toBe ( 'application/x-protobuf' ) ;
157- expect ( headers [ 'user-agent' ] ) . toMatch ( / ^ O T e l - O T L P - E x p o r t e r - J a v a S c r i p t \/ \d + \. \d + \. \d + $ / ) ;
158- } ) ;
151+ expect ( headers [ 'content-type' ] ) . toBe ( 'application/x-protobuf' ) ;
152+ expect ( headers [ 'user-agent' ] ) . toMatch ( / ^ O T e l - O T L P - E x p o r t e r - J a v a S c r i p t \/ \d + \. \d + \. \d + $ / ) ;
153+ done ( ) ;
154+ } ) ;
155+ } ) ;
156+ } ) ;
159157
158+ it ( 'should not inject SigV4 headers if failure to retrieve credentials' , done => {
160159 const stubbedModule = proxyquire ( '../src/otlp-aws-span-exporter' , {
161160 '@aws-sdk/credential-provider-node' : {
162161 defaultProvider : ( ) => async ( ) => {
@@ -165,9 +164,22 @@ if (nodeVersion >= 16) {
165164 } ,
166165 } ) ;
167166
168- const exporter = new stubbedModule . OTLPAwsSpanExporter ( XRAY_OTLP_ENDPOINT ) ;
167+ const exporter = new stubbedModule . OTLPAwsSpanExporter ( XRAY_OTLP_ENDPOINT + XRAY_OTLP_ENDPOINT_PATH ) ;
169168
170- await exporter . export ( [ ] , ( ) => { } ) ;
169+ exporter
170+ . export ( [ ] , ( ) => { } )
171+ . then ( ( ) => {
172+ scope . on ( 'request' , ( req , interceptor , body ) => {
173+ const headers = req . headers ;
174+ expect ( headers ) . not . toHaveProperty ( AUTHORIZATION_HEADER ) ;
175+ expect ( headers ) . not . toHaveProperty ( X_AMZ_DATE_HEADER ) ;
176+ expect ( headers ) . not . toHaveProperty ( X_AMZ_SECURITY_TOKEN_HEADER ) ;
177+
178+ expect ( headers [ 'content-type' ] ) . toBe ( 'application/x-protobuf' ) ;
179+ expect ( headers [ 'user-agent' ] ) . toMatch ( / ^ O T e l - O T L P - E x p o r t e r - J a v a S c r i p t \/ \d + \. \d + \. \d + $ / ) ;
180+ done ( ) ;
181+ } ) ;
182+ } ) ;
171183 } ) ;
172184 } ) ;
173185}
0 commit comments