-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(experimentalIdentityAndAuth): add
@aws.auth#sigv4
integration …
…tests
- Loading branch information
Steven Yuan
committed
Oct 10, 2023
1 parent
e5ee17a
commit 016537d
Showing
5 changed files
with
182 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@smithy/experimental-identity-and-auth": patch | ||
--- | ||
|
||
Add `@aws.auth#sigv4` integration tests. |
117 changes: 117 additions & 0 deletions
117
packages/experimental-identity-and-auth/src/integration/sigv4.integ.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
import { | ||
OnlySigv4AuthCommand, | ||
OnlySigv4AuthOptionalCommand, | ||
SameAsServiceCommand, | ||
Sigv4ServiceClient, | ||
} from "@smithy/identity-and-auth-sigv4-service"; | ||
import { AwsCredentialIdentity } from "@smithy/types"; | ||
import { requireRequestsFrom } from "@smithy/util-test"; | ||
|
||
describe("@aws.auth#sigv4 integration tests", () => { | ||
// TODO(experimentalIdentityAndAuth): should match `Sigv4Service` `@aws.auth#sigv4` trait | ||
const MOCK_CREDENTIALS: AwsCredentialIdentity = { | ||
accessKeyId: "MOCK_ACCESS_KEY_ID", | ||
secretAccessKey: "SECRET_ACCESS_KEY", | ||
sessionToken: "SESSION_TOKEN", | ||
}; | ||
const MOCK_REGION = "us-east-1"; | ||
|
||
// Arbitrary mock endpoint (`requireRequestsFrom()` intercepts network requests) | ||
const MOCK_ENDPOINT = "https://foo.bar"; | ||
|
||
describe("`@aws.auth#sigv4` `region` configuration", () => { | ||
it("Client should throw if `region` is not configured", async () => { | ||
const client = new Sigv4ServiceClient({ | ||
endpoint: MOCK_ENDPOINT, | ||
}); | ||
requireRequestsFrom(client).toMatch({}); | ||
await expect(client.send(new OnlySigv4AuthOptionalCommand({}))).rejects.toThrow( | ||
"expected `region` to be configured for `aws.auth#sigv4`" | ||
); | ||
}); | ||
|
||
it("Client should NOT throw if `region` is configured", async () => { | ||
const client = new Sigv4ServiceClient({ | ||
endpoint: MOCK_ENDPOINT, | ||
region: MOCK_REGION, | ||
}); | ||
requireRequestsFrom(client).toMatch({ | ||
headers: { | ||
Authorization: (value) => expect(value).toBeUndefined(), | ||
}, | ||
}); | ||
await client.send(new OnlySigv4AuthOptionalCommand({})); | ||
}); | ||
}); | ||
|
||
describe("Operation requires `@aws.auth#sigv4`", () => { | ||
it("Request is thrown when `credentials` is not configured", async () => { | ||
const client = new Sigv4ServiceClient({ | ||
endpoint: MOCK_ENDPOINT, | ||
region: MOCK_REGION, | ||
}); | ||
requireRequestsFrom(client).toMatch({}); | ||
await expect(client.send(new OnlySigv4AuthCommand({}))).rejects.toThrow( | ||
"HttpAuthScheme `aws.auth#sigv4` did not have an IdentityProvider configured." | ||
); | ||
}); | ||
|
||
it("Request is signed given configured `credentials`", async () => { | ||
const client = new Sigv4ServiceClient({ | ||
endpoint: MOCK_ENDPOINT, | ||
region: MOCK_REGION, | ||
credentials: async () => MOCK_CREDENTIALS, | ||
}); | ||
requireRequestsFrom(client).toMatch({}); | ||
await client.send(new OnlySigv4AuthCommand({})); | ||
}); | ||
}); | ||
|
||
describe("Operation has `@aws.auth#sigv4` and `@optionalAuth`", () => { | ||
it("Request is NOT thrown and NOT signed when `credentials` is not configured", async () => { | ||
const client = new Sigv4ServiceClient({ | ||
endpoint: MOCK_ENDPOINT, | ||
region: MOCK_REGION, | ||
}); | ||
requireRequestsFrom(client).toMatch({ | ||
headers: { | ||
Authorization: (value) => expect(value).toBeUndefined(), | ||
}, | ||
}); | ||
await client.send(new OnlySigv4AuthOptionalCommand({})); | ||
}); | ||
|
||
it("Request is signed given configured `credentials`", async () => { | ||
const client = new Sigv4ServiceClient({ | ||
endpoint: MOCK_ENDPOINT, | ||
region: MOCK_REGION, | ||
credentials: async () => MOCK_CREDENTIALS, | ||
}); | ||
requireRequestsFrom(client).toMatch({}); | ||
await client.send(new OnlySigv4AuthOptionalCommand({})); | ||
}); | ||
}); | ||
|
||
describe("Service has `@aws.auth#sigv4`", () => { | ||
it("Request is thrown when `credentials` is not configured", async () => { | ||
const client = new Sigv4ServiceClient({ | ||
endpoint: MOCK_ENDPOINT, | ||
region: MOCK_REGION, | ||
}); | ||
requireRequestsFrom(client).toMatch({}); | ||
await expect(client.send(new SameAsServiceCommand({}))).rejects.toThrow( | ||
"HttpAuthScheme `aws.auth#sigv4` did not have an IdentityProvider configured." | ||
); | ||
}); | ||
|
||
it("Request is signed given configured `credentials`", async () => { | ||
const client = new Sigv4ServiceClient({ | ||
endpoint: MOCK_ENDPOINT, | ||
region: MOCK_REGION, | ||
credentials: async () => MOCK_CREDENTIALS, | ||
}); | ||
requireRequestsFrom(client).toMatch({}); | ||
await client.send(new SameAsServiceCommand({})); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
smithy-typescript-codegen-test/model/identity-and-auth/sigv4/Sigv4Service.smithy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
$version: "2.0" | ||
|
||
namespace identity.auth.sigv4 | ||
|
||
use aws.auth#sigv4 | ||
use common#fakeProtocol | ||
|
||
@fakeProtocol | ||
@sigv4(name: "weather") | ||
service Sigv4Service { | ||
operations: [ | ||
OnlySigv4Auth | ||
OnlySigv4AuthOptional | ||
SameAsService | ||
] | ||
} | ||
|
||
@http(method: "GET", uri: "/OnlySigv4Auth") | ||
@auth([sigv4]) | ||
operation OnlySigv4Auth {} | ||
|
||
@http(method: "GET", uri: "/OnlySigv4AuthOptional") | ||
@auth([sigv4]) | ||
@optionalAuth | ||
operation OnlySigv4AuthOptional {} | ||
|
||
@http(method: "GET", uri: "/SameAsService") | ||
operation SameAsService {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters