Skip to content

Commit c82133c

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 981c78b commit c82133c

39 files changed

+1929
-64
lines changed

packages/crypto-sha256-node/index.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ function castSourceData(toCast: SourceData, encoding?: string): Buffer {
3737
return fromString(toCast, encoding);
3838
}
3939

40-
if (toCast instanceof ArrayBuffer) {
41-
return fromArrayBuffer(toCast);
40+
if (ArrayBuffer.isView(toCast)) {
41+
return fromArrayBuffer(
42+
toCast.buffer,
43+
toCast.byteOffset,
44+
toCast.byteLength
45+
);
4246
}
4347

44-
return fromArrayBuffer(
45-
toCast.buffer,
46-
toCast.byteOffset,
47-
toCast.byteLength
48-
);
48+
return fromArrayBuffer(toCast);
4949
}

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: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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(
28+
'should return true for ArrayBuffers created with a different instance of the ArrayBuffer constructor',
29+
() => {
30+
const buffer = new ArrayBuffer(0);
31+
(ArrayBuffer as any) = () => buffer;
32+
33+
expect(buffer).not.toBeInstanceOf(ArrayBuffer);
34+
expect(isArrayBuffer(buffer)).toBe(true);
35+
}
36+
);
37+
});

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 typeof ArrayBuffer === 'function'
3+
&& (
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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,10 @@ export function deepCopy<T>(arg: T): T {
202202
}
203203

204204
if (typeof arg === 'object') {
205-
return <T>Object.keys(arg).reduce((
206-
carry: object,
205+
return Object.keys(arg).reduce((
206+
carry: T,
207207
item: keyof T
208-
) => ({...carry, [item]: deepCopy(arg[item])}), {});
208+
) => ({...carry as any, [item]: deepCopy(arg[item])}), {});
209209
}
210210

211211
return arg;

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)