| 245 | }); |
| 246 | |
| 247 | const testSigning = async creds => { |
| 248 | const host = 'sts.amazonaws.com'; |
| 249 | const body = 'Action=GetCallerIdentity&Version=2011-06-15'; |
| 250 | const headers: { |
| 251 | 'Content-Type': 'application/x-www-form-urlencoded'; |
| 252 | 'Content-Length': number; |
| 253 | 'X-MongoDB-Server-Nonce': string; |
| 254 | 'X-MongoDB-GS2-CB-Flag': 'n'; |
| 255 | } = { |
| 256 | 'Content-Type': 'application/x-www-form-urlencoded', |
| 257 | 'Content-Length': body.length, |
| 258 | 'X-MongoDB-Server-Nonce': 'fakenonce', |
| 259 | 'X-MongoDB-GS2-CB-Flag': 'n' |
| 260 | }; |
| 261 | const signedHeaders = await aws4Sign( |
| 262 | { |
| 263 | method: 'POST', |
| 264 | host, |
| 265 | path: '/', |
| 266 | region: 'us-east-1', |
| 267 | service: 'sts', |
| 268 | headers: headers, |
| 269 | body, |
| 270 | date: new Date() |
| 271 | }, |
| 272 | creds |
| 273 | ); |
| 274 | |
| 275 | const authorization = signedHeaders.Authorization; |
| 276 | const xAmzDate = signedHeaders['X-Amz-Date']; |
| 277 | |
| 278 | const fetchHeaders = new Headers(); |
| 279 | for (const [key, value] of Object.entries(headers)) { |
| 280 | fetchHeaders.append(key, value.toString()); |
| 281 | } |
| 282 | if (credentials && credentials.sessionToken) { |
| 283 | fetchHeaders.append('X-Amz-Security-Token', credentials.sessionToken); |
| 284 | } |
| 285 | fetchHeaders.append('Authorization', authorization); |
| 286 | fetchHeaders.append('X-Amz-Date', xAmzDate); |
| 287 | const response = await fetch('https://sts.amazonaws.com', { |
| 288 | method: 'POST', |
| 289 | headers: fetchHeaders, |
| 290 | body |
| 291 | }); |
| 292 | const text = await response.text(); |
| 293 | |
| 294 | expect(response.status).to.equal(200); |
| 295 | expect(response.statusText).to.equal('OK'); |
| 296 | expect(text).to.match( |
| 297 | /<GetCallerIdentityResponse xmlns="https:\/\/sts.amazonaws.com\/doc\/2011-06-15\/">/ |
| 298 | ); |
| 299 | }; |
| 300 | |
| 301 | describe('when using premanent credentials', function () { |
| 302 | beforeEach(async function () { |
no test coverage detected