Skip to content

Commit

Permalink
use lowercase header, use same etag value as in other tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gr2m committed Sep 18, 2024
1 parent 47c473e commit e71f3f1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
14 changes: 8 additions & 6 deletions lib/verification.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,18 @@ export async function verifyRequest(rawBody, signature, key) {

/** @type {import('..').FetchVerificationKeysInterface} */
export async function fetchVerificationKeys(
{ token = "", request = defaultRequest, cache = { id: "", keys: [] } } = { request: defaultRequest }
{ token = "", request = defaultRequest, cache = { id: "", keys: [] } } = {
request: defaultRequest,
},
) {
try {
try {
const headers = token
? {
Authorization: `token ${token}`,
}
: {};

if (cache.id) headers["If-None-Match"] = cache.id;
if (cache.id) headers["if-none-match"] = cache.id;

const response = await request("GET /meta/public_keys/copilot_api", {
headers,
Expand All @@ -58,7 +60,7 @@ export async function verifyRequestByKeyId(
rawBody,
signature,
keyId,
requestOptions
requestOptions,
) {
// verify arguments
assertValidString(rawBody, "Invalid payload");
Expand All @@ -74,12 +76,12 @@ export async function verifyRequestByKeyId(
if (!publicKey) {
const keyNotFoundError = Object.assign(
new Error(
"[@copilot-extensions/preview-sdk] No public key found matching key identifier"
"[@copilot-extensions/preview-sdk] No public key found matching key identifier",
),
{
keyId,
keys,
}
},
);
throw keyNotFoundError;
}
Expand Down
4 changes: 2 additions & 2 deletions test/verification.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ test("fetchVerificationKeys() - with token", async (t) => {
headers: {
"content-type": "application/json",
"x-request-id": "<request-id>",
etag: 'W/"123"',
etag: 'W/"db60f89fb432b6c2362ac024c9322df5e6e2a8326595f7c1d35f807767d66e85"',
},
},
);
Expand All @@ -390,7 +390,7 @@ test("fetchVerificationKeys() - with token", async (t) => {
});

t.deepEqual(result, {
id: 'W/"123"',
id: 'W/"db60f89fb432b6c2362ac024c9322df5e6e2a8326595f7c1d35f807767d66e85"',
keys: [
{
is_current: true,
Expand Down

0 comments on commit e71f3f1

Please sign in to comment.