зеркало из https://github.com/Azure/cosmos-sign.git
Get formatting working
This commit is contained in:
Родитель
510f5a2bde
Коммит
99a9cb1ba0
|
@ -37,5 +37,8 @@
|
|||
"path": "./bundle.js",
|
||||
"maxSize": "3.2 kB"
|
||||
}
|
||||
]
|
||||
],
|
||||
"prettier": {
|
||||
"semi": false
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
14
src/node.ts
14
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
|
||||
|
|
|
@ -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
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче