Skip to content

Commit

Permalink
test(client-s3): dot segment in URI Label (#6262)
Browse files Browse the repository at this point in the history
  • Loading branch information
trivikr authored Jul 10, 2024
1 parent fa3b603 commit 992c63a
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions clients/client-s3/test/unit/dotSegmentInUriLabel.spec.ts
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");
}
});
});

0 comments on commit 992c63a

Please sign in to comment.