-
Notifications
You must be signed in to change notification settings - Fork 587
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(client-s3): dot segment in URI Label (#6262)
- Loading branch information
Showing
1 changed file
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/// <reference types="mocha" /> | ||
import { HttpHandler, HttpRequest, HttpResponse } from "@smithy/protocol-http"; | ||
import { HttpHandlerOptions } from "@smithy/types"; | ||
import { S3 } from "../../src/S3"; | ||
import chai from "chai"; | ||
import chaiAsPromised from "chai-as-promised"; | ||
|
||
chai.use(chaiAsPromised); | ||
const { expect } = chai; | ||
|
||
/** | ||
* Throws an expected exception that contains the serialized request. | ||
*/ | ||
class ExpectedRequestSerializationError extends Error { | ||
constructor(readonly request: HttpRequest) { | ||
super(); | ||
} | ||
} | ||
|
||
class RequestSerializationTestHandler implements HttpHandler { | ||
async handle(request: HttpRequest, options?: HttpHandlerOptions): Promise<{ response: HttpResponse }> { | ||
throw new ExpectedRequestSerializationError(request); | ||
} | ||
updateHttpClientConfig(key: never, value: never): void {} | ||
httpHandlerConfigs() { | ||
return {}; | ||
} | ||
} | ||
|
||
describe("Dot Segment in URI Label", () => { | ||
const client = new S3({ | ||
credentials: { accessKeyId: "mockAccessKeyId", secretAccessKey: "mockSecretAccessKey" }, | ||
requestHandler: new RequestSerializationTestHandler(), | ||
}); | ||
|
||
it("S3PreservesLeadingDotSegmentInUriLabel", async () => { | ||
try { | ||
await client.getObject({ | ||
Bucket: "mybucket", | ||
Key: "../key.txt", | ||
}); | ||
fail("Expected an EXPECTED_REQUEST_SERIALIZATION_ERROR to be thrown"); | ||
} catch (err) { | ||
if (!(err instanceof ExpectedRequestSerializationError)) { | ||
fail(err); | ||
} | ||
const r = err.request; | ||
expect(r.method).to.eql("GET"); | ||
expect(r.path).to.eql("/../key.txt"); | ||
} | ||
}); | ||
|
||
it("S3PreservesEmbeddedDotSegmentInUriLabel", async () => { | ||
try { | ||
await client.getObject({ | ||
Bucket: "mybucket", | ||
Key: "foo/../key.txt", | ||
}); | ||
fail("Expected an EXPECTED_REQUEST_SERIALIZATION_ERROR to be thrown"); | ||
} catch (err) { | ||
if (!(err instanceof ExpectedRequestSerializationError)) { | ||
fail(err); | ||
} | ||
const r = err.request; | ||
expect(r.method).to.eql("GET"); | ||
expect(r.path).to.eql("/foo/../key.txt"); | ||
} | ||
}); | ||
}); |