Skip to content

Commit

Permalink
fix(middleware-sdk-ec2): remove double encoding of presigned url (#3022)
Browse files Browse the repository at this point in the history
  • Loading branch information
trivikr authored Nov 12, 2021
1 parent fff5e2a commit 7cf73ea
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
1 change: 0 additions & 1 deletion packages/middleware-sdk-ec2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
"@aws-sdk/signature-v4": "3.40.0",
"@aws-sdk/types": "3.40.0",
"@aws-sdk/util-format-url": "3.40.0",
"@aws-sdk/util-uri-escape": "3.37.0",
"tslib": "^2.3.0"
},
"devDependencies": {
Expand Down
22 changes: 11 additions & 11 deletions packages/middleware-sdk-ec2/src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@ describe("middleware-sdk-ec2", () => {
expect(middlewareOutput.input.SourceSnapshotId).toEqual(params.SourceSnapshotId);
expect(middlewareOutput.input.DestinationRegion).toEqual(await region());
const presignedUrl = middlewareOutput.input.PresignedUrl;
expect(presignedUrl).toMatch(/https%3A%2F%2Fec2.src-region.amazonaws.com%2F%3F/);
expect(presignedUrl).toMatch(/Action%3DCopySnapshot/);
expect(presignedUrl).toMatch(/Version%3D2016\-11\-15/);
expect(presignedUrl).toMatch(/https\:\/\/ec2.src-region.amazonaws.com\/\?/);
expect(presignedUrl).toMatch(/Action\=CopySnapshot/);
expect(presignedUrl).toMatch(/Version\=2016\-11\-15/);
expect(presignedUrl).toMatch(
/DestinationRegion%3Dmock\-region%26SourceRegion%3Dsrc\-region%26SourceSnapshotId%3Dsnap\-123456789/
/DestinationRegion\=mock\-region\&SourceRegion\=src\-region\&SourceSnapshotId\=snap\-123456789/
);
expect(presignedUrl).toMatch(/X\-Amz\-Security\-Token%3Dsession/);
expect(presignedUrl).toMatch(/X\-Amz\-Algorithm%3DAWS4\-HMAC\-SHA256/);
expect(presignedUrl).toMatch(/X\-Amz\-SignedHeaders%3Dhost/);
expect(presignedUrl).toMatch(/X\-Amz\-Credential%3D/);
expect(presignedUrl).toMatch(/X\-Amz\-Date%3D/);
expect(presignedUrl).toMatch(/X-Amz-Expires%3D([\d]+)/);
expect(presignedUrl).toMatch(/X-Amz-Signature%3D000000/);
expect(presignedUrl).toMatch(/X\-Amz\-Security\-Token\=session/);
expect(presignedUrl).toMatch(/X\-Amz\-Algorithm\=AWS4\-HMAC\-SHA256/);
expect(presignedUrl).toMatch(/X\-Amz\-SignedHeaders\=host/);
expect(presignedUrl).toMatch(/X\-Amz\-Credential\=/);
expect(presignedUrl).toMatch(/X\-Amz\-Date\=/);
expect(presignedUrl).toMatch(/X-Amz-Expires\=([\d]+)/);
expect(presignedUrl).toMatch(/X-Amz-Signature\=000000/);
});

it("does not modify input if PresignedUrl has already been set", async () => {
Expand Down
3 changes: 1 addition & 2 deletions packages/middleware-sdk-ec2/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
Provider,
} from "@aws-sdk/types";
import { formatUrl } from "@aws-sdk/util-format-url";
import { escapeUri } from "@aws-sdk/util-uri-escape";

interface PreviouslyResolved {
credentials: Provider<Credentials>;
Expand Down Expand Up @@ -65,7 +64,7 @@ export function copySnapshotPresignedUrlMiddleware(options: PreviouslyResolved):
input: {
...args.input,
DestinationRegion: region,
PresignedUrl: escapeUri(formatUrl(presignedRequest)),
PresignedUrl: formatUrl(presignedRequest),
},
};
}
Expand Down

0 comments on commit 7cf73ea

Please sign in to comment.