Skip to content

Commit

Permalink
fix(signature-v4): address feedbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
AllanZhengYP committed Dec 19, 2020
1 parent 9ea5f88 commit d42efa0
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions packages/signature-v4/src/credentialDerivation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,14 @@ describe("getSigningKey", () => {
});

describe("caching", () => {
it("should return the same promise when called with the same date, region, service, and credentials", async () => {
const promise1 = await getSigningKey(Sha256, credentials, shortDate, region, service);
const promise2 = await getSigningKey(Sha256, credentials, shortDate, region, service);
expect(promise1).toBe(promise2);
it("should return the same signing key when called with the same date, region, service, and credentials", async () => {
const mockSha256Constructor = jest.fn().mockImplementation((args) => {
return new Sha256(args);
});
const key1 = await getSigningKey(mockSha256Constructor, credentials, shortDate, region, service);
const key2 = await getSigningKey(mockSha256Constructor, credentials, shortDate, region, service);
expect(key1).toBe(key2);
expect(mockSha256Constructor).toHaveBeenCalledTimes(6);
});

it("should cache a maximum of 50 entries", async () => {
Expand All @@ -63,10 +67,10 @@ describe("getSigningKey", () => {
await getSigningKey(Sha256, credentials, shortDate, `us-foo-50`, service);

// the second oldest member should still be in cache
expect(keys[1]).toBe(await getSigningKey(Sha256, credentials, shortDate, `us-foo-1`, service));
await expect(getSigningKey(Sha256, credentials, shortDate, `us-foo-1`, service)).resolves.toStrictEqual(keys[1]);

// the oldest member should not be in the cache
expect(keys[0]).not.toBe(await getSigningKey(Sha256, credentials, shortDate, `us-foo-0`, service));
await expect(getSigningKey(Sha256, credentials, shortDate, `us-foo-0`, service)).resolves.not.toBe(keys[0]);
});
});
});

0 comments on commit d42efa0

Please sign in to comment.