From 99a9cb1ba0d1f1c07048340854dd765eccf54c63 Mon Sep 17 00:00:00 2001 From: Steve Faulkner Date: Sat, 17 Nov 2018 14:29:37 -0500 Subject: [PATCH] Get formatting working --- package.json | 5 ++++- src/browser.test.ts | 40 ++++++++++++++++++++-------------------- src/browser.ts | 18 +++++++++--------- src/node.test.ts | 40 ++++++++++++++++++++-------------------- src/node.ts | 14 +++++++------- src/signer.ts | 20 ++++++++++---------- 6 files changed, 70 insertions(+), 67 deletions(-) diff --git a/package.json b/package.json index fa585be..51c1450 100644 --- a/package.json +++ b/package.json @@ -37,5 +37,8 @@ "path": "./bundle.js", "maxSize": "3.2 kB" } - ] + ], + "prettier": { + "semi": false + } } diff --git a/src/browser.test.ts b/src/browser.test.ts index 8ce116f..44a6ace 100644 --- a/src/browser.test.ts +++ b/src/browser.test.ts @@ -1,20 +1,20 @@ -import { generateSignature, generateheaders } from "./browser"; +import { generateSignature, generateheaders } from "./browser" -const date = new Date("Sat, 17 Nov 2018 01:06:05 GMT"); +const date = new Date("Sat, 17 Nov 2018 01:06:05 GMT") const masterKey = - "BGejtJoCPl06h6oxaEVI1qXENjaBFNJn47GTfJR5V8bq00v3GiOn36ZZgQv9ogDJfvxEAi4RJi0nEscmXGAe5w=="; -const method = "GET"; -const resourceId = ""; -const resourceType = ""; + "BGejtJoCPl06h6oxaEVI1qXENjaBFNJn47GTfJR5V8bq00v3GiOn36ZZgQv9ogDJfvxEAi4RJi0nEscmXGAe5w==" +const method = "GET" +const resourceId = "" +const resourceType = "" const expectedSignature = encodeURIComponent( "type=master&ver=1.0&sig=dFkNJGBUXu+ggUJnH1qh+7S1K7BcFdYYtxggMonBH8I=" -); +) const expectedHeaders = { Authorization: expectedSignature, "x-ms-date": date.toUTCString() -}; +} const signature = generateSignature( masterKey, @@ -22,7 +22,7 @@ const signature = generateSignature( resourceType, resourceId, date -); +) const headers = generateheaders( masterKey, @@ -30,21 +30,21 @@ const headers = generateheaders( resourceType, resourceId, date -); +) if (expectedSignature !== signature) { - console.log("FAILURE!"); - console.log("Expected:", expectedSignature); - console.log("Result:", signature); - process.exit(1); + console.log("FAILURE!") + console.log("Expected:", expectedSignature) + console.log("Result:", signature) + process.exit(1) } if (expectedHeaders !== headers) { - console.log("FAILURE!"); - console.log("Expected:", expectedHeaders); - console.log("Result:", headers); - process.exit(1); + console.log("FAILURE!") + console.log("Expected:", expectedHeaders) + console.log("Result:", headers) + process.exit(1) } -console.log("BROWSER PASSED"); -process.exit(0); +console.log("BROWSER PASSED") +process.exit(0) diff --git a/src/browser.ts b/src/browser.ts index 14d8675..688e219 100644 --- a/src/browser.ts +++ b/src/browser.ts @@ -1,14 +1,14 @@ -import { Signer } from "./buildSign"; -import sha256 from "crypto-js/hmac-sha256"; -import Base64 from "crypto-js/enc-base64"; +import { Signer } from "./buildSign" +import sha256 from "crypto-js/hmac-sha256" +import Base64 from "crypto-js/enc-base64" const hmac = (key: string, message: string) => { - var hash = sha256(message, Base64.parse(key)); - return Base64.stringify(hash); -}; + var hash = sha256(message, Base64.parse(key)) + return Base64.stringify(hash) +} -const signer = Signer(hmac); +const signer = Signer(hmac) -export const generateSignature = signer.signature; +export const generateSignature = signer.signature -export const generateheaders = signer.headers; +export const generateheaders = signer.headers diff --git a/src/node.test.ts b/src/node.test.ts index f746e35..e0f773b 100644 --- a/src/node.test.ts +++ b/src/node.test.ts @@ -1,20 +1,20 @@ -import { generateSignature, generateheaders } from "./node"; +import { generateSignature, generateheaders } from "./node" -const date = new Date("Sat, 17 Nov 2018 01:06:05 GMT"); +const date = new Date("Sat, 17 Nov 2018 01:06:05 GMT") const masterKey = - "BGejtJoCPl06h6oxaEVI1qXENjaBFNJn47GTfJR5V8bq00v3GiOn36ZZgQv9ogDJfvxEAi4RJi0nEscmXGAe5w=="; -const method = "GET"; -const resourceId = ""; -const resourceType = ""; + "BGejtJoCPl06h6oxaEVI1qXENjaBFNJn47GTfJR5V8bq00v3GiOn36ZZgQv9ogDJfvxEAi4RJi0nEscmXGAe5w==" +const method = "GET" +const resourceId = "" +const resourceType = "" const expectedSignature = encodeURIComponent( "type=master&ver=1.0&sig=dFkNJGBUXu+ggUJnH1qh+7S1K7BcFdYYtxggMonBH8I=" -); +) const expectedHeaders = { Authorization: expectedSignature, "x-ms-date": date.toUTCString() -}; +} const signature = generateSignature( masterKey, @@ -22,7 +22,7 @@ const signature = generateSignature( resourceType, resourceId, date -); +) const headers = generateheaders( masterKey, @@ -30,21 +30,21 @@ const headers = generateheaders( resourceType, resourceId, date -); +) if (expectedSignature !== signature) { - console.log("FAILURE!"); - console.log("Expected:", expectedSignature); - console.log("Result:", signature); - process.exit(1); + console.log("FAILURE!") + console.log("Expected:", expectedSignature) + console.log("Result:", signature) + process.exit(1) } if (expectedHeaders !== headers) { - console.log("FAILURE!"); - console.log("Expected:", expectedHeaders); - console.log("Result:", headers); - process.exit(1); + console.log("FAILURE!") + console.log("Expected:", expectedHeaders) + console.log("Result:", headers) + process.exit(1) } -console.log("NODE PASSED"); -process.exit(0); +console.log("NODE PASSED") +process.exit(0) diff --git a/src/node.ts b/src/node.ts index 10ef241..9f8ee5f 100644 --- a/src/node.ts +++ b/src/node.ts @@ -1,14 +1,14 @@ -import { createHmac } from "crypto"; -import { Signer } from "./buildSign"; +import { createHmac } from "crypto" +import { Signer } from "./signer" const hmac = (key: string, message: string) => { return createHmac("sha256", Buffer.from(key, "base64")) .update(message) - .digest("base64"); -}; + .digest("base64") +} -const signer = Signer(hmac); +const signer = Signer(hmac) -export const generateSignature = signer.signature; +export const generateSignature = signer.signature -export const generateheaders = signer.headers; +export const generateheaders = signer.headers diff --git a/src/signer.ts b/src/signer.ts index bf22461..e9bc561 100644 --- a/src/signer.ts +++ b/src/signer.ts @@ -1,5 +1,5 @@ -const type = "master"; -const version = "1.0"; +const type = "master" +const version = "1.0" type ResourceType = | "dbs" @@ -15,9 +15,9 @@ type ResourceType = | "conflicts" | "pkranges" | "offers" - | ""; + | "" -type Method = "GET" | "POST" | "PUT" | "PATCH" | "DELETE"; +type Method = "GET" | "POST" | "PUT" | "PATCH" | "DELETE" export function Signer(hmac: (key: string, message: string) => string) { function signature( @@ -37,13 +37,13 @@ export function Signer(hmac: (key: string, message: string) => string) { date.toUTCString().toLowerCase() + "\n" + "" + - "\n"; + "\n" - var signature = hmac(masterKey, text); + var signature = hmac(masterKey, text) return encodeURIComponent( "type=" + type + "&ver=" + version + "&sig=" + signature - ); + ) } function headers( @@ -59,16 +59,16 @@ export function Signer(hmac: (key: string, message: string) => string) { resourceType, resourceId, date - ); + ) return { Authorization: sig, "x-ms-date": date.toUTCString() - }; + } } return { headers, signature - }; + } }