Skip to content

fix(e2e): delete IAM+ resources in After call #3952

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions features/elastictranscoder/elastictranscoder.feature
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ Feature: Elastic Transcoder
And I pause the pipeline
And I read the pipeline
Then the pipeline status should be "Paused"
And I delete the pipeline
And I delete the bucket
And I delete the IAM role

@error
Scenario: Error handling
Expand Down
78 changes: 31 additions & 47 deletions features/elastictranscoder/step_definitions/elastictranscoder.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
const { Before, Given, Then } = require("@cucumber/cucumber");
const { After, Before, Given, Then } = require("@cucumber/cucumber");

Before({ tags: "@elastictranscoder" }, function (scenario, callback) {
Before({ tags: "@elastictranscoder" }, function () {
const { S3 } = require("../../../clients/client-s3");
const { IAM } = require("../../../clients/client-iam");
const { ElasticTranscoder } = require("../../../clients/client-elastic-transcoder");
this.iam = new IAM({});
this.s3 = new S3({});
this.service = new ElasticTranscoder({});
callback();
});

Given("I create an Elastic Transcoder pipeline with name prefix {string}", function (prefix, callback) {
After({ tags: "@elastictranscoder" }, async function () {
if (this.iamRoleName) {
await this.iam.deleteRole({ RoleName: this.iamRoleName });
this.iamRoleName = undefined;
}
if (this.pipelineId) {
await this.service.deletePipeline({ Id: this.pipelineId });
this.pipelineId = undefined;
}
});

Given("I create an Elastic Transcoder pipeline with name prefix {string}", async function (prefix) {
this.pipelineName = this.uniqueName(prefix);
const params = {
Name: this.pipelineName,
Expand All @@ -25,62 +35,36 @@ Given("I create an Elastic Transcoder pipeline with name prefix {string}", funct
},
};

const world = this;
const next = function () {
if (world.data) world.pipelineId = world.data.Pipeline.Id;
callback();
};

this.request(null, "createPipeline", params, next, false);
try {
this.data = await this.service.createPipeline(params);
this.pipelineId = this.data.Pipeline.Id;
} catch (error) {
this.error = error;
}
});

Given("I list pipelines", function (callback) {
this.request(null, "listPipelines", {}, callback);
Given("I list pipelines", async function () {
this.data = await this.service.listPipelines({});
});

Then("the list should contain the pipeline", function (callback) {
Then("the list should contain the pipeline", function () {
const id = this.pipelineId;
this.assert.contains(this.data.Pipelines, function (pipeline) {
return pipeline.Id === id;
});
callback();
});

Then("I pause the pipeline", function (callback) {
this.request(
null,
"updatePipelineStatus",
{
Id: this.pipelineId,
Status: "Paused",
},
callback
);
Then("I pause the pipeline", async function () {
this.data = await this.service.updatePipelineStatus({
Id: this.pipelineId,
Status: "Paused",
});
});

Then("I read the pipeline", function (callback) {
this.request(
null,
"readPipeline",
{
Id: this.pipelineId,
},
callback
);
Then("I read the pipeline", async function () {
this.data = await this.service.readPipeline({ Id: this.pipelineId });
});

Then("the pipeline status should be {string}", function (status, callback) {
Then("the pipeline status should be {string}", function (status) {
this.assert.equal(this.data.Pipeline.Status, status);
callback();
});

Then("I delete the pipeline", function (callback) {
this.request(
null,
"deletePipeline",
{
Id: this.pipelineId,
},
callback
);
});
4 changes: 0 additions & 4 deletions features/iam/iam.feature
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,14 @@ Feature: IAM
Scenario: Users
Given I have an IAM username "js-test"
And I create an IAM user with the username
And I get the IAM user
Then the IAM user should exist
And I delete the IAM user

Scenario: Roles
Given I create an IAM role with name prefix "aws-sdk-js"
Then the IAM role should exist
And I delete the IAM role

Scenario: Error handling
Given I have an IAM username "js-test-dupe"
And I create an IAM user with the username
And I create an IAM user with the username
Then the error code should be "EntityAlreadyExists"
And I delete the IAM user
92 changes: 30 additions & 62 deletions features/iam/step_definitions/iam.js
Original file line number Diff line number Diff line change
@@ -1,60 +1,43 @@
const { Before, Given, Then } = require("@cucumber/cucumber");
const { After, Before, Given, Then } = require("@cucumber/cucumber");

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

Given("I have an IAM username {string}", function (name, callback) {
this.iamUserArn = "";
this.iamUser = this.uniqueName(name);
callback();
});

Given("I create an IAM user with the username", function (callback) {
const world = this;
const next = function () {
if (world.data) this.iamUserArn = world.data.User.Arn;
else this.iamUserArn = null;
callback();
};
next.fail = callback;
this.request(
"iam",
"createUser",
{
UserName: this.iamUser,
},
next,
false
);
After({ tags: "@iam" }, async function () {
if (this.iamUser) {
await this.iam.deleteUser({ UserName: this.iamUser });
this.iamUser = undefined;
}
if (this.iamRoleName) {
await this.iam.deleteRole({ RoleName: this.iamRoleName });
this.iamRoleName = undefined;
}
});

Given("I get the IAM user", function (callback) {
this.request("iam", "getUser", { UserName: this.iamUser }, callback);
Given("I have an IAM username {string}", function (name) {
this.iamUser = this.uniqueName(name);
});

Then("the IAM user should exist", function (callback) {
this.assert.equal(this.data.User.UserName, this.iamUser);
callback();
Given("I create an IAM user with the username", async function () {
try {
const { User } = await this.iam.createUser({ UserName: this.iamUser });
this.iamUserArn = User.Arn;
} catch (error) {
this.error = error;
}
});

Then("I delete the IAM user", function (callback) {
this.request(
"iam",
"deleteUser",
{
UserName: this.iamUser,
},
callback
);
Then("the IAM user should exist", async function () {
const { User } = await this.iam.getUser({ UserName: this.iamUser });
this.assert.equal(User.UserName, this.iamUser);
this.assert.equal(User.Arn, this.iamUserArn);
});

Given("I create an IAM role with name prefix {string}", function (name, callback) {
Given("I create an IAM role with name prefix {string}", async function (name) {
this.iamRoleName = this.uniqueName(name);

const world = this;
const assumeRolePolicyDocument =
'{"Version":"2008-10-17","Statement":[' +
'{"Effect":"Allow","Principal":{"Service":["ec2.amazonaws.com"]},' +
Expand All @@ -63,27 +46,12 @@ Given("I create an IAM role with name prefix {string}", function (name, callback
RoleName: this.iamRoleName,
AssumeRolePolicyDocument: assumeRolePolicyDocument,
};
const next = function () {
world.iamRoleArn = world.data.Role.Arn;
callback();
};
next.fail = callback;

this.request("iam", "createRole", params, next);
});

Then("the IAM role should exist", function (callback) {
this.assert.compare(this.iamRoleArn.length, ">", 0);
callback();
this.data = await this.iam.createRole(params);
this.iamRoleArn = this.data.Role.Arn;
});

Then("I delete the IAM role", function (callback) {
this.request(
"iam",
"deleteRole",
{
RoleName: this.iamRoleName,
},
callback
);
Then("the IAM role should exist", async function () {
const { Role } = await this.iam.getRole({ RoleName: this.iamRoleName });
this.assert.equal(Role.RoleName, this.iamRoleName);
});
4 changes: 1 addition & 3 deletions features/opsworks/opsworks.feature
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,12 @@ Feature: AWS OpsWorks
Then the IAM user ARN should be in the result
And the name should be equal to the IAM username
And the SSH username should be equal to the IAM username
And I delete the OpsWorks user profile
And I delete the IAM user

Scenario: Error handling
Given I have an IAM username ""
And I create an OpsWorks user profile with the IAM user ARN
Then the error code should be "ValidationException"
Then the error message should be:
"""
Please provide user ARN
IAM User does not exist
"""
57 changes: 27 additions & 30 deletions features/opsworks/step_definitions/opsworks.js
Original file line number Diff line number Diff line change
@@ -1,50 +1,47 @@
const { Before, Given, Then } = require("@cucumber/cucumber");
const { After, Before, Given, Then } = require("@cucumber/cucumber");

Before({ tags: "@opsworks" }, function (scenario, callback) {
Before({ tags: "@opsworks" }, function () {
const { IAM } = require("../../../clients/client-iam");
this.iam = new IAM({ region: "us-west-2" });
const { OpsWorks } = require("../../../clients/client-opsworks");
this.service = new OpsWorks({ region: "us-west-2" });
callback();

this.iam = new IAM({});
this.service = new OpsWorks({});
});

After({ tags: "@opsworks" }, async function () {
if (this.iamUser) {
await this.iam.deleteUser({ UserName: this.iamUser });
await this.service.deleteUserProfile({ IamUserArn: this.iamUserArn });
this.iamUser = undefined;
}
});

Given("I create an OpsWorks user profile with the IAM user ARN", function (callback) {
const params = {
IamUserArn: this.iamUserArn,
};
this.request(null, "createUserProfile", params, callback, false);
Given("I create an OpsWorks user profile with the IAM user ARN", async function () {
try {
const params = { IamUserArn: this.iamUserArn };
this.data = await this.service.createUserProfile(params);
} catch (error) {
this.error = error;
}
});

Given("the IAM user ARN is in the result", function (callback) {
Given("the IAM user ARN is in the result", function () {
this.assert.equal(this.data.IamUserArn, this.iamUserArn);
callback();
});

Given("I describe the OpsWorks user profiles", function (callback) {
const params = {
IamUserArns: [this.iamUserArn],
};
this.request(null, "describeUserProfiles", params, callback);
Given("I describe the OpsWorks user profiles", async function () {
const params = { IamUserArns: [this.iamUserArn] };
this.data = await this.service.describeUserProfiles(params);
});

Then("the IAM user ARN should be in the result", function (callback) {
Then("the IAM user ARN should be in the result", function () {
this.assert.equal(this.data.UserProfiles[0].IamUserArn, this.iamUserArn);
callback();
});

Then("the name should be equal to the IAM username", function (callback) {
Then("the name should be equal to the IAM username", function () {
this.assert.equal(this.data.UserProfiles[0].Name, this.iamUser);
callback();
});

Then("the SSH username should be equal to the IAM username", function (callback) {
Then("the SSH username should be equal to the IAM username", function () {
this.assert.equal(this.data.UserProfiles[0].SshUsername, this.iamUser);
callback();
});

Then("I delete the OpsWorks user profile", function (callback) {
const params = {
IamUserArn: this.iamUserArn,
};
this.request(null, "deleteUserProfile", params, callback, false);
});