Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(client-s3): dot segment in URI Label #6262

Merged
merged 3 commits into from
Jul 10, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions clients/client-s3/test/unit/dotSegmentInUriLabel.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/// <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 EXPECTED_REQUEST_SERIALIZATION_ERROR extends Error {
trivikr marked this conversation as resolved.
Show resolved Hide resolved
constructor(readonly request: HttpRequest) {
super();
}
}

class RequestSerializationTestHandler implements HttpHandler {
async handle(request: HttpRequest, options?: HttpHandlerOptions): Promise<{ response: HttpResponse }> {
throw new EXPECTED_REQUEST_SERIALIZATION_ERROR(request);
}
updateHttpClientConfig(key: never, value: never): void {}
httpHandlerConfigs() {
return {};
}
}

describe("Dot Segment in URI Label", () => {
it("S3PreservesLeadingDotSegmentInUriLabel", async () => {
const client = new S3({
requestHandler: new RequestSerializationTestHandler(),
trivikr marked this conversation as resolved.
Show resolved Hide resolved
});

try {
await client.getObject({
Bucket: "mybucket",
Key: "../key.txt",
});
fail("Expected an EXPECTED_REQUEST_SERIALIZATION_ERROR to be thrown");
} catch (err) {
if (!(err instanceof EXPECTED_REQUEST_SERIALIZATION_ERROR)) {
fail(err);
}
const r = err.request;
expect(r.method).to.eql("GET");
expect(r.path).to.eql("/../key.txt");
}
});

it("S3PreservesEmbeddedDotSegmentInUriLabel", async () => {
const client = new S3({
requestHandler: new RequestSerializationTestHandler(),
});

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 EXPECTED_REQUEST_SERIALIZATION_ERROR)) {
fail(err);
}
const r = err.request;
expect(r.method).to.eql("GET");
expect(r.path).to.eql("/foo/../key.txt");
}
});
});
Loading