Skip to content

Commit 2654b1a

Browse files
authored
V4 Signer (#36)
* Add a VM- and WebWorker-safe way to check if an object is an ArrayBuffer * Document expectations on headers and querystring params * WIP commit * WIP commit * Add a node stream collector * Add a hex encoding package * Add tests for getCanonicalQuery * Add tests for getPayloadHash * Remove dependency on and use of stream collectors. Streams should be considered always unsignable * Add tests to fully cover SignatureV4::signRequest * Remove unused packages * Update RequestSigner interface to take keywords args instead of positional arguments * Add presigner and functional and unit tests * Cover the last uncovered line of code * Allow the set of unsignable headers to be customized
1 parent e90603d commit 2654b1a

39 files changed

+1915
-65
lines changed

packages/crypto-sha256-node/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ function castSourceData(toCast: SourceData, encoding?: string): Buffer {
3232
return fromString(toCast, encoding);
3333
}
3434

35-
if (toCast instanceof ArrayBuffer) {
36-
return fromArrayBuffer(toCast);
35+
if (ArrayBuffer.isView(toCast)) {
36+
return fromArrayBuffer(toCast.buffer, toCast.byteOffset, toCast.byteLength);
3737
}
3838

39-
return fromArrayBuffer(toCast.buffer, toCast.byteOffset, toCast.byteLength);
39+
return fromArrayBuffer(toCast);
4040
}

packages/crypto-sha256-node/tsconfig.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"target": "es5",
44
"module": "commonjs",
55
"lib": [
6-
"ES5",
7-
"ES2015.Promise"
6+
"es5",
7+
"es2015.promise"
88
],
99
"declaration": true,
1010
"sourceMap": true,

packages/is-array-buffer/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*.js
2+
*.js.map
3+
*.d.ts
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { isArrayBuffer } from "../";
2+
3+
describe("isArrayBuffer", () => {
4+
const arrayBufferConstructor = ArrayBuffer;
5+
6+
afterEach(() => {
7+
(ArrayBuffer as any) = arrayBufferConstructor;
8+
});
9+
10+
it("should return true for ArrayBuffer objects", () => {
11+
expect(isArrayBuffer(new ArrayBuffer(0))).toBe(true);
12+
});
13+
14+
it("should return false for ArrayBufferView objects", () => {
15+
const view = new Uint8Array(0);
16+
17+
expect(isArrayBuffer(view)).toBe(false);
18+
expect(isArrayBuffer(view.buffer)).toBe(true);
19+
});
20+
21+
it("should return false for scalar values", () => {
22+
for (let scalar of ["string", 123.234, true, null, void 0]) {
23+
expect(isArrayBuffer(scalar)).toBe(false);
24+
}
25+
});
26+
27+
it("should return true for ArrayBuffers created with a different instance of the ArrayBuffer constructor", () => {
28+
const buffer = new ArrayBuffer(0);
29+
(ArrayBuffer as any) = () => buffer;
30+
31+
expect(buffer).not.toBeInstanceOf(ArrayBuffer);
32+
expect(isArrayBuffer(buffer)).toBe(true);
33+
});
34+
});

packages/is-array-buffer/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export function isArrayBuffer(arg: any): arg is ArrayBuffer {
2+
return (
3+
typeof ArrayBuffer === "function" &&
4+
(arg instanceof ArrayBuffer ||
5+
Object.prototype.toString.call(arg) === "[object ArrayBuffer]")
6+
);
7+
}

packages/is-array-buffer/package.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "@aws/is-array-buffer",
3+
"private": true,
4+
"version": "0.0.1",
5+
"description": "Provides a function for detecting if an argument is an ArrayBuffer",
6+
"scripts": {
7+
"pretest": "tsc",
8+
"test": "jest"
9+
},
10+
"author": "[email protected]",
11+
"license": "UNLICENSED",
12+
"main": "index.js",
13+
"devDependencies": {
14+
"@types/jest": "^20.0.2",
15+
"@types/node": "^7.0.12",
16+
"jest": "^20.0.4",
17+
"typescript": "^2.3"
18+
}
19+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es5",
4+
"module": "commonjs",
5+
"declaration": true,
6+
"strict": true,
7+
"sourceMap": true
8+
}
9+
}

packages/service-model/__fixtures__/index.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -195,14 +195,12 @@ export function deepCopy<T>(arg: T): T {
195195
}
196196

197197
if (typeof arg === "object") {
198-
return <T>(
199-
Object.keys(arg).reduce(
200-
(carry: object, item: keyof T) => ({
201-
...carry,
202-
[item]: deepCopy(arg[item])
203-
}),
204-
{}
205-
)
198+
return Object.keys(arg).reduce(
199+
(carry: T, item: keyof T) => ({
200+
...(carry as any),
201+
[item]: deepCopy(arg[item])
202+
}),
203+
{}
206204
);
207205
}
208206

packages/signature-v4/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/node_modules/
2+
*.js
3+
*.js.map
4+
*.d.ts

0 commit comments

Comments
 (0)