Skip to content

Commit

Permalink
fix(endpoint): e2e test fixes for endpoints 2.0 all services (#4044)
Browse files Browse the repository at this point in the history
  • Loading branch information
kuhe authored Oct 15, 2022
1 parent f2da618 commit b53f5bd
Show file tree
Hide file tree
Showing 12 changed files with 78 additions and 17 deletions.
2 changes: 1 addition & 1 deletion features/extra/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ Given("I run the {string} operation with params:", function (operation, params,
});

Then("the request should be successful", function (callback) {
this.assert.ok(!this.error, "Response was not successful");
this.assert.ok(!this.error, "Response was not successful: " + this.error);
callback();
});

Expand Down
3 changes: 2 additions & 1 deletion features/rds/rds.feature
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ Feature: Amazon Relational Database Service
I want to use Amazon Relational Database Service

Scenario: Describe DB security group
Given I create a RDS security group with prefix name "aws-sdk-js-rds-e2e"
Given I run the "describeDBSecurityGroups" operation
Then the request should be successful
And the value at "DBSecurityGroups" should be a list
And the value at "DBSecurityGroups" should contain "DBSecurityGroupDescription" with "default"
And the value at "DBSecurityGroups" should contain "DBSecurityGroupDescription" with "Description"

Scenario: Error handling
Given I create a RDS security group with prefix name ""
Expand Down
21 changes: 19 additions & 2 deletions features/rds/step_definitions/rds.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
const jmespath = require("jmespath");
const { Before, Given, Then } = require("@cucumber/cucumber");
const { After, Before, Given, Then } = require("@cucumber/cucumber");

const dbsgNames = [];

Before({ tags: "@rds" }, function (scenario, callback) {
const { RDS } = require("../../../clients/client-rds");
this.service = new RDS({});
callback();
});

After({ tags: "@rds" }, async function () {
while (dbsgNames.length) {
const name = dbsgNames.pop();
if (name) {
await this.service.deleteDBSecurityGroup({
DBSecurityGroupName: name,
});
}
}
});

Given("I create a RDS security group with prefix name {string}", function (prefix, callback) {
this.dbGroupName = this.uniqueName(prefix);
dbsgNames.push(this.dbGroupName);
const params = {
DBSecurityGroupDescription: "Description",
DBSecurityGroupName: this.dbGroupName,
Expand All @@ -24,7 +38,10 @@ Then("the value at {string} should contain {string} with {string}", function (pa
containDefault = true;
}
});
this.assert.ok(containDefault === true, `No ${path} has member key ${key} of the value ${value}`);
this.assert.ok(
containDefault === true,
`No ${path} has member key ${key} of the value ${value}: ${JSON.stringify(this.data, null, 2)}`
);
callback();
});

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"@commitlint/cli": "17.0.2",
"@commitlint/config-conventional": "17.0.2",
"@cucumber/cucumber": "8.5.3",
"@cucumber/pretty-formatter": "^1.0.0",
"@mixer/parallel-prettier": "2.0.3",
"@tsconfig/recommended": "1.0.1",
"@types/chai-as-promised": "^7.1.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/middleware-endpoint/src/endpointMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const endpointMiddleware = <T extends EndpointParameters>({

const authScheme: AuthScheme = context.authSchemes?.[0];
if (authScheme) {
context["signing_region"] = authScheme.signingScope;
context["signing_region"] = authScheme.signingRegion;
context["signing_service"] = authScheme.signingName;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const parseOutpostArnablesMiddleaware =
useDualstackEndpoint,
}))!);
} else {
signingRegion = context.endpointV2?.properties?.authSchemes?.[0]?.signingScope || baseRegion;
signingRegion = context.endpointV2?.properties?.authSchemes?.[0]?.signingRegion || baseRegion;
clientPartition = partition(signingRegion).name;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/middleware-signing/src/configuration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { resolveAwsAuthConfig, resolveSigV4AuthConfig } from "./configurations";
describe("AuthConfig", () => {
const authScheme = {
name: "sigv4",
signingScope: "UNIT_TEST_REGION",
signingRegion: "UNIT_TEST_REGION",
signingName: "UNIT_TEST_SERVICE_NAME",
properties: {},
};
Expand Down
18 changes: 14 additions & 4 deletions packages/middleware-signing/src/configurations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ interface PreviouslyResolved {
region: string | Provider<string>;
regionInfoProvider?: RegionInfoProvider;
signingName?: string;
defaultSigningName?: string;
serviceId: string;
sha256: HashConstructor;
useFipsEndpoint: Provider<boolean>;
Expand Down Expand Up @@ -170,10 +171,18 @@ export const resolveAwsAuthConfig = <T>(
// Handle endpoints v2 that resolved per-command
// TODO: need total refactor for reference auth architecture.
signer = async (authScheme?: AuthScheme) => {
if (!authScheme) {
throw new Error("Unexpected empty auth scheme config");
}
const signingRegion = authScheme.signingScope;
authScheme = Object.assign(
{},
{
name: "v4",
signingName: input.signingName || input.defaultSigningName!,
signingRegion: await normalizeProvider(input.region)(),
properties: {},
},
authScheme
);

const signingRegion = authScheme.signingRegion;
const signingService = authScheme.signingName;
// update client's singing region and signing service config if they are resolved.
// signing region resolving order: user supplied signingRegion -> endpoints.json inferred region -> client region
Expand All @@ -190,6 +199,7 @@ export const resolveAwsAuthConfig = <T>(
sha256,
uriEscapePath: signingEscapePath,
};

const SignerCtor = input.signerConstructor || SignatureV4;
return new SignerCtor(params);
};
Expand Down
3 changes: 1 addition & 2 deletions packages/middleware-signing/src/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { HttpRequest, HttpResponse } from "@aws-sdk/protocol-http";
import {
AuthScheme,
EndpointV2,
FinalizeHandler,
FinalizeHandlerArguments,
FinalizeHandlerOutput,
Expand All @@ -24,7 +23,7 @@ export const awsAuthMiddleware =
if (!HttpRequest.isInstance(args.request)) return next(args);

// TODO(identityandauth): call authScheme resolver
const authScheme: AuthScheme | undefined = (context.endpointV2)?.properties?.authSchemes?.[0];
const authScheme: AuthScheme | undefined = context.endpointV2?.properties?.authSchemes?.[0];

const signer = await options.signer(authScheme);

Expand Down
2 changes: 1 addition & 1 deletion packages/s3-request-presigner/src/getSignedUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const getSignedUrl = async <
s3Presigner = new S3RequestPresigner({
...client.config,
signingName: authScheme?.signingName,
region: async () => authScheme?.signingScope,
region: async () => authScheme?.signingRegion,
});
} else {
s3Presigner = new S3RequestPresigner(client.config);
Expand Down
14 changes: 11 additions & 3 deletions packages/types/src/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,24 @@
*/
export interface AuthScheme {
/**
* @example "v4" for SigV4
* @example "sigv4a" or "sigv4"
*/
name: string;
name: "sigv4" | "sigv4a" | string;
/**
* @example "s3"
*/
signingName: string;
/**
* @example "us-east-1"
*/
signingScope: string;
signingRegion: string;
/**
* TODO usage?
*/
signingRegionSet?: string[];
/**
* @deprecated this field was renamed to signingRegion.
*/
signingScope?: never;
properties: Record<string, unknown>;
}
25 changes: 25 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
"@aws-sdk/hash-node" "*"
"@aws-sdk/invalid-dependency" "*"
"@aws-sdk/middleware-content-length" "*"
"@aws-sdk/middleware-endpoint" "*"
"@aws-sdk/middleware-host-header" "*"
"@aws-sdk/middleware-logger" "*"
"@aws-sdk/middleware-recursion-detection" "*"
Expand Down Expand Up @@ -937,6 +938,16 @@
reflect-metadata "0.1.13"
uuid "8.3.2"

"@cucumber/pretty-formatter@^1.0.0":
version "1.0.0"
resolved "https://registry.yarnpkg.com/@cucumber/pretty-formatter/-/pretty-formatter-1.0.0.tgz#911014c8fb7472a4c54d00e60e819a7200fd9da3"
integrity sha512-wcnIMN94HyaHGsfq72dgCvr1d8q6VGH4Y6Gl5weJ2TNZw1qn2UY85Iki4c9VdaLUONYnyYH3+178YB+9RFe/Hw==
dependencies:
ansi-styles "^5.0.0"
cli-table3 "^0.6.0"
figures "^3.2.0"
ts-dedent "^2.0.0"

"@cucumber/tag-expressions@4.1.0":
version "4.1.0"
resolved "https://registry.yarnpkg.com/@cucumber/tag-expressions/-/tag-expressions-4.1.0.tgz#9a91b0e0dd2f2ba703e3038c52b49b9ac06c2c6f"
Expand Down Expand Up @@ -3947,6 +3958,15 @@ cli-table3@0.6.2:
optionalDependencies:
"@colors/colors" "1.5.0"

cli-table3@^0.6.0:
version "0.6.3"
resolved "https://registry.yarnpkg.com/cli-table3/-/cli-table3-0.6.3.tgz#61ab765aac156b52f222954ffc607a6f01dbeeb2"
integrity sha512-w5Jac5SykAeZJKntOxJCrm63Eg5/4dhMWIcuTbo9rpE+brgaSZo0RuNJZeOyMgsUdhDeojvgyQLmjI+K50ZGyg==
dependencies:
string-width "^4.2.0"
optionalDependencies:
"@colors/colors" "1.5.0"

cli-truncate@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/cli-truncate/-/cli-truncate-2.1.0.tgz#c39e28bf05edcde5be3b98992a22deed5a2b93c7"
Expand Down Expand Up @@ -11149,6 +11169,11 @@ trim-newlines@^3.0.0:
resolved "https://registry.yarnpkg.com/trim-newlines/-/trim-newlines-3.0.1.tgz#260a5d962d8b752425b32f3a7db0dcacd176c144"
integrity sha512-c1PTsA3tYrIsLGkJkzHF+w9F2EyxfXGo4UyJc4pFL++FMjnq0HJS69T3M7d//gKrFKwy429bouPescbjecU+Zw==

ts-dedent@^2.0.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/ts-dedent/-/ts-dedent-2.2.0.tgz#39e4bd297cd036292ae2394eb3412be63f563bb5"
integrity sha512-q5W7tVM71e2xjHZTlgfTDoPF/SmqKG5hddq9SzR49CH2hayqRKJtQ4mtRlSxKaJlR/+9rEM+mnBHf7I2/BQcpQ==

ts-jest@28.0.5:
version "28.0.5"
resolved "https://registry.yarnpkg.com/ts-jest/-/ts-jest-28.0.5.tgz#31776f768fba6dfc8c061d488840ed0c8eeac8b9"
Expand Down

0 comments on commit b53f5bd

Please sign in to comment.