From 2d22db27c6fdddbfeeb48f6832395efbbda7a1db Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Sun, 25 Apr 2021 13:36:41 +0200 Subject: [PATCH] chore: update for deno 1.9.x (#14) --- .github/workflows/ci.yml | 10 +++++----- README.md | 4 ++-- deps.ts | 2 +- mod.ts | 12 ++---------- mod_test.ts | 14 +++++++++----- 5 files changed, 19 insertions(+), 23 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 32f7c1a..f607a8f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,18 +8,18 @@ on: jobs: build: - name: build-${{ matrix.deno-version == 'nightly' && 'nightly' || 'release' }}-${{ matrix.unstable && 'unstable' || 'stable' }}-${{ matrix.no-check && 'nocheck' || 'tsc' }} + name: build-${{ matrix.deno-version == 'canary' && 'canary' || 'release' }}-${{ matrix.unstable && 'unstable' || 'stable' }}-${{ matrix.no-check && 'nocheck' || 'tsc' }} runs-on: ubuntu-latest strategy: matrix: - deno-version: [v1.x, nightly] + deno-version: [v1.x, canary] unstable: [false, true] no-check: [false, true] steps: - - name: Setup Deno environment - uses: denolib/setup-deno@v2.3.0 + - name: Setup Deno + uses: denoland/setup-deno@main with: - deno-version: ${{ matrix.deno-version }} + deno-version: ${{ matrix.deno }} - uses: actions/checkout@v2 diff --git a/README.md b/README.md index c330f92..99f1594 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # deno_aws_sign_v4 ![ci](https://github.com/lucacasonato/deno_aws_sign_v4/workflows/ci/badge.svg) -[![deno doc](https://doc.deno.land/badge.svg)](https://doc.deno.land/https/deno.land/x/aws_sign_v4@1.0.0/mod.ts) +[![deno doc](https://doc.deno.land/badge.svg)](https://doc.deno.land/https/deno.land/x/aws_sign_v4@1.0.1/mod.ts) Generates AWS Signature V4 for AWS low-level REST APIs. @@ -16,7 +16,7 @@ credentials in following ENV variables: - AWS_REGION ```typescript -import { AWSSignerV4 } from "https://deno.land/x/aws_sign_v4@1.0.0/mod.ts"; +import { AWSSignerV4 } from "https://deno.land/x/aws_sign_v4@1.0.1/mod.ts"; const signer = new AWSSignerV4(); const body = new TextEncoder().encode("Hello World!"); diff --git a/deps.ts b/deps.ts index 7ddd5a3..e458cd7 100644 --- a/deps.ts +++ b/deps.ts @@ -1,6 +1,6 @@ export { hmac } from "https://deno.land/x/hmac@v2.0.1/mod.ts"; -import { createHash } from "https://deno.land/std@0.84.0/hash/mod.ts"; +import { createHash } from "https://deno.land/std@0.95.0/hash/mod.ts"; export function sha256Hex(data: string | Uint8Array): string { const hasher = createHash("sha256"); hasher.update(data); diff --git a/mod.ts b/mod.ts index 40c8b14..dd66e4f 100644 --- a/mod.ts +++ b/mod.ts @@ -95,8 +95,8 @@ export class AWSSignerV4 implements Signer { signedHeaders = signedHeaders.substring(0, signedHeaders.length - 1); const body = request.body ? new Uint8Array(await request.arrayBuffer()) - : new Uint8Array(); - const payloadHash = sha256Hex(body); + : null; + const payloadHash = sha256Hex(body ?? new Uint8Array()); const { awsAccessKeyId, awsSecretKey } = this.credentials; @@ -128,15 +128,7 @@ export class AWSSignerV4 implements Signer { headers, method: request.method, body, - cache: request.cache, - credentials: request.credentials, - integrity: request.integrity, - keepalive: request.keepalive, - mode: request.mode, redirect: request.redirect, - referrer: request.referrer, - referrerPolicy: request.referrerPolicy, - signal: request.signal, }); } diff --git a/mod_test.ts b/mod_test.ts index ff4a0eb..326a6b3 100644 --- a/mod_test.ts +++ b/mod_test.ts @@ -2,7 +2,7 @@ import { AWSSignerV4 } from "./mod.ts"; import { assertEquals, assertStringIncludes, -} from "https://deno.land/std@0.84.0/testing/asserts.ts"; +} from "https://deno.land/std@0.95.0/testing/asserts.ts"; Deno.test("construct from env vars", async () => { Deno.env.set("AWS_ACCESS_KEY_ID", "examplekey"); @@ -14,7 +14,7 @@ Deno.test("construct from env vars", async () => { const req = await signer.sign( "dynamodb", new Request("https://test.dynamodb.us-east-1.amazonaws.com", { - method: "GET", + method: "POST", headers: { "x-hello": "world" }, body: "A dynamodb request!", }), @@ -25,6 +25,8 @@ Deno.test("construct from env vars", async () => { .toString() .padStart(2, "0") }${now.getDate().toString().padStart(2, "0")}`; + assertEquals(req.method, "POST"); + assertEquals(await req.text(), "A dynamodb request!"); assertStringIncludes(req.headers.get("x-amz-date")!, `${today}T`); assertEquals(req.headers.get("x-amz-security-token"), "sessiontoken"); assertEquals(req.headers.get("x-hello"), "world"); @@ -34,7 +36,7 @@ Deno.test("construct from env vars", async () => { ); assertStringIncludes( req.headers.get("Authorization")!, - `AWS4-HMAC-SHA256 Credential=examplekey/${today}/us-east-1/dynamodb/aws4_request, SignedHeaders=host;x-amz-date;x-amz-security-token;x-hello, Signature=`, + `AWS4-HMAC-SHA256 Credential=examplekey/${today}/us-east-1/dynamodb/aws4_request, SignedHeaders=content-type;host;x-amz-date;x-amz-security-token;x-hello, Signature=`, ); }); @@ -47,7 +49,7 @@ Deno.test("construct manually", async () => { const req = await signer.sign( "dynamodb", new Request("https://test.dynamodb.us-east-1.amazonaws.com", { - method: "GET", + method: "POST", headers: { "x-hello": "world" }, body: "A dynamodb request!", }), @@ -58,6 +60,8 @@ Deno.test("construct manually", async () => { .toString() .padStart(2, "0") }${now.getDate().toString().padStart(2, "0")}`; + assertEquals(req.method, "POST"); + assertEquals(await req.text(), "A dynamodb request!"); assertStringIncludes(req.headers.get("x-amz-date")!, `${today}T`); assertEquals(req.headers.get("x-amz-security-token"), "session_token"); assertEquals(req.headers.get("x-hello"), "world"); @@ -67,7 +71,7 @@ Deno.test("construct manually", async () => { ); assertStringIncludes( req.headers.get("Authorization")!, - `AWS4-HMAC-SHA256 Credential=example_key/${today}/us-east-2/dynamodb/aws4_request, SignedHeaders=host;x-amz-date;x-amz-security-token;x-hello, Signature=`, + `AWS4-HMAC-SHA256 Credential=example_key/${today}/us-east-2/dynamodb/aws4_request, SignedHeaders=content-type;host;x-amz-date;x-amz-security-token;x-hello, Signature=`, ); });