Skip to content

Commit b30b9b2

Browse files
authored
fix(e2e): delete IAM+ resources in After call (#3952)
1 parent 5da7879 commit b30b9b2

File tree

6 files changed

+89
-148
lines changed

6 files changed

+89
-148
lines changed

features/elastictranscoder/elastictranscoder.feature

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ Feature: Elastic Transcoder
1414
And I pause the pipeline
1515
And I read the pipeline
1616
Then the pipeline status should be "Paused"
17-
And I delete the pipeline
1817
And I delete the bucket
19-
And I delete the IAM role
2018

2119
@error
2220
Scenario: Error handling
Lines changed: 31 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,26 @@
1-
const { Before, Given, Then } = require("@cucumber/cucumber");
1+
const { After, Before, Given, Then } = require("@cucumber/cucumber");
22

3-
Before({ tags: "@elastictranscoder" }, function (scenario, callback) {
3+
Before({ tags: "@elastictranscoder" }, function () {
44
const { S3 } = require("../../../clients/client-s3");
55
const { IAM } = require("../../../clients/client-iam");
66
const { ElasticTranscoder } = require("../../../clients/client-elastic-transcoder");
77
this.iam = new IAM({});
88
this.s3 = new S3({});
99
this.service = new ElasticTranscoder({});
10-
callback();
1110
});
1211

13-
Given("I create an Elastic Transcoder pipeline with name prefix {string}", function (prefix, callback) {
12+
After({ tags: "@elastictranscoder" }, async function () {
13+
if (this.iamRoleName) {
14+
await this.iam.deleteRole({ RoleName: this.iamRoleName });
15+
this.iamRoleName = undefined;
16+
}
17+
if (this.pipelineId) {
18+
await this.service.deletePipeline({ Id: this.pipelineId });
19+
this.pipelineId = undefined;
20+
}
21+
});
22+
23+
Given("I create an Elastic Transcoder pipeline with name prefix {string}", async function (prefix) {
1424
this.pipelineName = this.uniqueName(prefix);
1525
const params = {
1626
Name: this.pipelineName,
@@ -25,62 +35,36 @@ Given("I create an Elastic Transcoder pipeline with name prefix {string}", funct
2535
},
2636
};
2737

28-
const world = this;
29-
const next = function () {
30-
if (world.data) world.pipelineId = world.data.Pipeline.Id;
31-
callback();
32-
};
33-
34-
this.request(null, "createPipeline", params, next, false);
38+
try {
39+
this.data = await this.service.createPipeline(params);
40+
this.pipelineId = this.data.Pipeline.Id;
41+
} catch (error) {
42+
this.error = error;
43+
}
3544
});
3645

37-
Given("I list pipelines", function (callback) {
38-
this.request(null, "listPipelines", {}, callback);
46+
Given("I list pipelines", async function () {
47+
this.data = await this.service.listPipelines({});
3948
});
4049

41-
Then("the list should contain the pipeline", function (callback) {
50+
Then("the list should contain the pipeline", function () {
4251
const id = this.pipelineId;
4352
this.assert.contains(this.data.Pipelines, function (pipeline) {
4453
return pipeline.Id === id;
4554
});
46-
callback();
4755
});
4856

49-
Then("I pause the pipeline", function (callback) {
50-
this.request(
51-
null,
52-
"updatePipelineStatus",
53-
{
54-
Id: this.pipelineId,
55-
Status: "Paused",
56-
},
57-
callback
58-
);
57+
Then("I pause the pipeline", async function () {
58+
this.data = await this.service.updatePipelineStatus({
59+
Id: this.pipelineId,
60+
Status: "Paused",
61+
});
5962
});
6063

61-
Then("I read the pipeline", function (callback) {
62-
this.request(
63-
null,
64-
"readPipeline",
65-
{
66-
Id: this.pipelineId,
67-
},
68-
callback
69-
);
64+
Then("I read the pipeline", async function () {
65+
this.data = await this.service.readPipeline({ Id: this.pipelineId });
7066
});
7167

72-
Then("the pipeline status should be {string}", function (status, callback) {
68+
Then("the pipeline status should be {string}", function (status) {
7369
this.assert.equal(this.data.Pipeline.Status, status);
74-
callback();
75-
});
76-
77-
Then("I delete the pipeline", function (callback) {
78-
this.request(
79-
null,
80-
"deletePipeline",
81-
{
82-
Id: this.pipelineId,
83-
},
84-
callback
85-
);
8670
});

features/iam/iam.feature

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,14 @@ Feature: IAM
77
Scenario: Users
88
Given I have an IAM username "js-test"
99
And I create an IAM user with the username
10-
And I get the IAM user
1110
Then the IAM user should exist
12-
And I delete the IAM user
1311

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

1916
Scenario: Error handling
2017
Given I have an IAM username "js-test-dupe"
2118
And I create an IAM user with the username
2219
And I create an IAM user with the username
2320
Then the error code should be "EntityAlreadyExists"
24-
And I delete the IAM user

features/iam/step_definitions/iam.js

Lines changed: 30 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,43 @@
1-
const { Before, Given, Then } = require("@cucumber/cucumber");
1+
const { After, Before, Given, Then } = require("@cucumber/cucumber");
22

3-
Before({ tags: "@iam" }, function (scenario, callback) {
3+
Before({ tags: "@iam" }, function () {
44
const { IAM } = require("../../../clients/client-iam");
55
this.iam = new IAM({});
6-
callback();
76
});
87

9-
Given("I have an IAM username {string}", function (name, callback) {
10-
this.iamUserArn = "";
11-
this.iamUser = this.uniqueName(name);
12-
callback();
13-
});
14-
15-
Given("I create an IAM user with the username", function (callback) {
16-
const world = this;
17-
const next = function () {
18-
if (world.data) this.iamUserArn = world.data.User.Arn;
19-
else this.iamUserArn = null;
20-
callback();
21-
};
22-
next.fail = callback;
23-
this.request(
24-
"iam",
25-
"createUser",
26-
{
27-
UserName: this.iamUser,
28-
},
29-
next,
30-
false
31-
);
8+
After({ tags: "@iam" }, async function () {
9+
if (this.iamUser) {
10+
await this.iam.deleteUser({ UserName: this.iamUser });
11+
this.iamUser = undefined;
12+
}
13+
if (this.iamRoleName) {
14+
await this.iam.deleteRole({ RoleName: this.iamRoleName });
15+
this.iamRoleName = undefined;
16+
}
3217
});
3318

34-
Given("I get the IAM user", function (callback) {
35-
this.request("iam", "getUser", { UserName: this.iamUser }, callback);
19+
Given("I have an IAM username {string}", function (name) {
20+
this.iamUser = this.uniqueName(name);
3621
});
3722

38-
Then("the IAM user should exist", function (callback) {
39-
this.assert.equal(this.data.User.UserName, this.iamUser);
40-
callback();
23+
Given("I create an IAM user with the username", async function () {
24+
try {
25+
const { User } = await this.iam.createUser({ UserName: this.iamUser });
26+
this.iamUserArn = User.Arn;
27+
} catch (error) {
28+
this.error = error;
29+
}
4130
});
4231

43-
Then("I delete the IAM user", function (callback) {
44-
this.request(
45-
"iam",
46-
"deleteUser",
47-
{
48-
UserName: this.iamUser,
49-
},
50-
callback
51-
);
32+
Then("the IAM user should exist", async function () {
33+
const { User } = await this.iam.getUser({ UserName: this.iamUser });
34+
this.assert.equal(User.UserName, this.iamUser);
35+
this.assert.equal(User.Arn, this.iamUserArn);
5236
});
5337

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

57-
const world = this;
5841
const assumeRolePolicyDocument =
5942
'{"Version":"2008-10-17","Statement":[' +
6043
'{"Effect":"Allow","Principal":{"Service":["ec2.amazonaws.com"]},' +
@@ -63,27 +46,12 @@ Given("I create an IAM role with name prefix {string}", function (name, callback
6346
RoleName: this.iamRoleName,
6447
AssumeRolePolicyDocument: assumeRolePolicyDocument,
6548
};
66-
const next = function () {
67-
world.iamRoleArn = world.data.Role.Arn;
68-
callback();
69-
};
70-
next.fail = callback;
71-
72-
this.request("iam", "createRole", params, next);
73-
});
7449

75-
Then("the IAM role should exist", function (callback) {
76-
this.assert.compare(this.iamRoleArn.length, ">", 0);
77-
callback();
50+
this.data = await this.iam.createRole(params);
51+
this.iamRoleArn = this.data.Role.Arn;
7852
});
7953

80-
Then("I delete the IAM role", function (callback) {
81-
this.request(
82-
"iam",
83-
"deleteRole",
84-
{
85-
RoleName: this.iamRoleName,
86-
},
87-
callback
88-
);
54+
Then("the IAM role should exist", async function () {
55+
const { Role } = await this.iam.getRole({ RoleName: this.iamRoleName });
56+
this.assert.equal(Role.RoleName, this.iamRoleName);
8957
});

features/opsworks/opsworks.feature

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,12 @@ Feature: AWS OpsWorks
1313
Then the IAM user ARN should be in the result
1414
And the name should be equal to the IAM username
1515
And the SSH username should be equal to the IAM username
16-
And I delete the OpsWorks user profile
17-
And I delete the IAM user
1816

1917
Scenario: Error handling
2018
Given I have an IAM username ""
2119
And I create an OpsWorks user profile with the IAM user ARN
2220
Then the error code should be "ValidationException"
2321
Then the error message should be:
2422
"""
25-
Please provide user ARN
23+
IAM User does not exist
2624
"""
Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,47 @@
1-
const { Before, Given, Then } = require("@cucumber/cucumber");
1+
const { After, Before, Given, Then } = require("@cucumber/cucumber");
22

3-
Before({ tags: "@opsworks" }, function (scenario, callback) {
3+
Before({ tags: "@opsworks" }, function () {
44
const { IAM } = require("../../../clients/client-iam");
5-
this.iam = new IAM({ region: "us-west-2" });
65
const { OpsWorks } = require("../../../clients/client-opsworks");
7-
this.service = new OpsWorks({ region: "us-west-2" });
8-
callback();
6+
7+
this.iam = new IAM({});
8+
this.service = new OpsWorks({});
9+
});
10+
11+
After({ tags: "@opsworks" }, async function () {
12+
if (this.iamUser) {
13+
await this.iam.deleteUser({ UserName: this.iamUser });
14+
await this.service.deleteUserProfile({ IamUserArn: this.iamUserArn });
15+
this.iamUser = undefined;
16+
}
917
});
1018

11-
Given("I create an OpsWorks user profile with the IAM user ARN", function (callback) {
12-
const params = {
13-
IamUserArn: this.iamUserArn,
14-
};
15-
this.request(null, "createUserProfile", params, callback, false);
19+
Given("I create an OpsWorks user profile with the IAM user ARN", async function () {
20+
try {
21+
const params = { IamUserArn: this.iamUserArn };
22+
this.data = await this.service.createUserProfile(params);
23+
} catch (error) {
24+
this.error = error;
25+
}
1626
});
1727

18-
Given("the IAM user ARN is in the result", function (callback) {
28+
Given("the IAM user ARN is in the result", function () {
1929
this.assert.equal(this.data.IamUserArn, this.iamUserArn);
20-
callback();
2130
});
2231

23-
Given("I describe the OpsWorks user profiles", function (callback) {
24-
const params = {
25-
IamUserArns: [this.iamUserArn],
26-
};
27-
this.request(null, "describeUserProfiles", params, callback);
32+
Given("I describe the OpsWorks user profiles", async function () {
33+
const params = { IamUserArns: [this.iamUserArn] };
34+
this.data = await this.service.describeUserProfiles(params);
2835
});
2936

30-
Then("the IAM user ARN should be in the result", function (callback) {
37+
Then("the IAM user ARN should be in the result", function () {
3138
this.assert.equal(this.data.UserProfiles[0].IamUserArn, this.iamUserArn);
32-
callback();
3339
});
3440

35-
Then("the name should be equal to the IAM username", function (callback) {
41+
Then("the name should be equal to the IAM username", function () {
3642
this.assert.equal(this.data.UserProfiles[0].Name, this.iamUser);
37-
callback();
3843
});
3944

40-
Then("the SSH username should be equal to the IAM username", function (callback) {
45+
Then("the SSH username should be equal to the IAM username", function () {
4146
this.assert.equal(this.data.UserProfiles[0].SshUsername, this.iamUser);
42-
callback();
43-
});
44-
45-
Then("I delete the OpsWorks user profile", function (callback) {
46-
const params = {
47-
IamUserArn: this.iamUserArn,
48-
};
49-
this.request(null, "deleteUserProfile", params, callback, false);
5047
});

0 commit comments

Comments
 (0)