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