Skip to content

Commit bcdd21f

Browse files
refactor 6
1 parent a16c871 commit bcdd21f

File tree

5 files changed

+44
-62
lines changed

5 files changed

+44
-62
lines changed

tests/zenko_tests/node_tests/backbeat/tests/lifecycle/transition.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ testsToRun.forEach(test => {
131131
if (err || (!this.currentTest.isPending() && !this.currentTest.isPassed())) {
132132
const testName = this.currentTest.fullTitle();
133133
const retry = this.currentTest.currentRetry();
134+
// eslint-disable-next-line no-console
134135
console.log(` FAILED ${testName} [retry #${retry}] : ${srcBucket}`);
135136
}
136137
done(err);

tests/zenko_tests/node_tests/iam_policies/cloudserver/IAMUser.js

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,9 @@ const testAPIs = [
3333
},
3434
];
3535

36-
function checkResponseAsync(credentials, bucket, object) {
36+
function checkResponseAsync(checkResponseFn, credentials, bucket, object) {
3737
return new Promise((resolve, reject) => {
38-
// Use the appropriate test API based on current context
39-
const currentTestAPI = testAPIs.find(api => bucket.includes(api.API.toLowerCase()));
40-
if (!currentTestAPI) {
41-
reject(new Error('Could not determine test API'));
42-
return;
43-
}
44-
currentTestAPI.checkResponse(credentials, bucket, (err, res) => {
38+
checkResponseFn(credentials, bucket, (err, res) => {
4539
if (err) {
4640
reject(err);
4741
return;
@@ -91,7 +85,7 @@ testAPIs.forEach(testAPI => {
9185
it(
9286
`should not be able to ${testAPI.API} without the permission s3:${testAPI.API}`,
9387
async () => {
94-
const res = await checkResponseAsync(userCredentials, bucketName, objectName);
88+
const res = await checkResponseAsync(testAPI.checkResponse, userCredentials, bucketName, objectName);
9589
assert.strictEqual(res.statusCode, 403);
9690
assert.strictEqual(res.code, errors.AccessDenied.message);
9791
},
@@ -109,7 +103,7 @@ testAPIs.forEach(testAPI => {
109103
UserName: userName,
110104
PolicyArn: res.Policy.Arn,
111105
}));
112-
const res2 = await checkResponseAsync(userCredentials, bucketName, objectName);
106+
const res2 = await checkResponseAsync(testAPI.checkResponse, userCredentials, bucketName, objectName);
113107
if (testAPI.API === 'RestoreObject') {
114108
assert.strictEqual(res2.statusCode, 403);
115109
assert.strictEqual(res2.code, errors.InvalidObjectState.message);
@@ -138,14 +132,14 @@ testAPIs.forEach(testAPI => {
138132
}));
139133
policyArns.push(res.Policy.Arn);
140134
await iam.send(new AttachUserPolicyCommand({ UserName: userName, PolicyArn: res.Policy.Arn }));
141-
const res2 = await checkResponseAsync(userCredentials, bucketName, objectName);
135+
const res2 = await checkResponseAsync(testAPI.checkResponse, userCredentials, bucketName, objectName);
142136
if (testAPI.API === 'RestoreObject') {
143137
assert.strictEqual(res2.statusCode, 403);
144138
assert.strictEqual(res2.code, errors.InvalidObjectState.message);
145139
} else {
146140
assert.strictEqual(res2.statusCode, 200);
147141
}
148-
const res3 = await checkResponseAsync(userCredentials, bucketName2, objectName2);
142+
const res3 = await checkResponseAsync(testAPI.checkResponse, userCredentials, bucketName2, objectName2);
149143
assert.strictEqual(res3.statusCode, 403);
150144
assert.strictEqual(res3.code, errors.AccessDenied.message);
151145
} finally {
@@ -165,7 +159,7 @@ testAPIs.forEach(testAPI => {
165159
}));
166160
policyArns.push(res.Policy.Arn);
167161
await iam.send(new AttachUserPolicyCommand({ UserName: userName, PolicyArn: res.Policy.Arn }));
168-
const res2 = await checkResponseAsync(userCredentials, bucketName, objectName);
162+
const res2 = await checkResponseAsync(testAPI.checkResponse, userCredentials, bucketName, objectName);
169163
assert.strictEqual(res2.statusCode, 403);
170164
assert.strictEqual(res2.code, errors.AccessDenied.message);
171165
} finally {
@@ -195,10 +189,10 @@ testAPIs.forEach(testAPI => {
195189
}));
196190
policyArns.push(res2.Policy.Arn);
197191
await iam.send(new AttachUserPolicyCommand({ UserName: userName, PolicyArn: res2.Policy.Arn }));
198-
const res3 = await checkResponseAsync(userCredentials, bucketName, objectName);
192+
const res3 = await checkResponseAsync(testAPI.checkResponse, userCredentials, bucketName, objectName);
199193
assert.strictEqual(res3.statusCode, 403);
200194
assert.strictEqual(res3.code, errors.AccessDenied.message);
201-
const res4 = await checkResponseAsync(userCredentials, bucketName2, objectName2);
195+
const res4 = await checkResponseAsync(testAPI.checkResponse, userCredentials, bucketName2, objectName2);
202196
if (testAPI.API === 'RestoreObject') {
203197
assert.strictEqual(res4.statusCode, 403);
204198
assert.strictEqual(res4.code, errors.InvalidObjectState.message);

tests/zenko_tests/node_tests/init_test.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,6 @@ const bucket = `get-bucket-${uuidV4()}`;
1616
const key = `object-key-${uuidV4()}`;
1717
const body = 'testbody';
1818

19-
// todo : move to utils.request.js ?
20-
const streamToString = stream => new Promise((resolve, reject) => {
21-
const chunks = [];
22-
stream.on('data', chunk => chunks.push(chunk));
23-
stream.on('error', reject);
24-
stream.on('end', () => resolve(Buffer.concat(chunks).toString('utf-8')));
25-
});
26-
2719
describe('Test Configuration', () => {
2820
it('should create a bucket and upload an object', async () => {
2921
await s3.send(new CreateBucketCommand({
@@ -32,7 +24,6 @@ describe('Test Configuration', () => {
3224
LocationConstraint: 'us-east-1',
3325
},
3426
}));
35-
3627
const listBucketsRes = await s3.send(new ListBucketsCommand({}));
3728
assert.strictEqual(listBucketsRes.Buckets.length, 1);
3829
assert.strictEqual(listBucketsRes.Buckets[0].Name, bucket);
@@ -42,7 +33,12 @@ describe('Test Configuration', () => {
4233
const getObjectRes = await s3.send(new GetObjectCommand(
4334
{ Bucket: bucket, Key: key },
4435
));
45-
const resBody = await streamToString(getObjectRes.Body);
36+
const chunks = [];
37+
// eslint-disable-next-line no-restricted-syntax
38+
for await (const chunk of getObjectRes.Body) {
39+
chunks.push(chunk);
40+
}
41+
const resBody = Buffer.concat(chunks).toString('utf-8');
4642
assert.strictEqual(body, resBody);
4743
const listObjectsRes = await s3.send(new ListObjectsCommand({ Bucket: bucket }));
4844
assert.strictEqual(listObjectsRes.Contents.length, 1);
Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const async = require('async');
12
const VaultClient = require('../../VaultClient');
23

34
const clientAdmin = VaultClient.getAdminClient();
@@ -10,23 +11,21 @@ const accountInfo = {
1011
let iamClient = null;
1112

1213
describe('Accounts: ', () => {
13-
it('should be able create, generate credentials and delete an account', async () => {
14-
await new Promise((resolve, reject) => {
15-
clientAdmin.createAccount(accountName, accountInfo, err => {
16-
if (err) return reject(err);
17-
return resolve();
18-
});
19-
});
20-
21-
const res = await new Promise((resolve, reject) => {
22-
clientAdmin.generateAccountAccessKey(accountName, (err, result) => {
23-
if (err) return reject(err);
24-
return resolve(result);
25-
});
26-
});
27-
28-
iamClient = VaultClient.getIamClient(res.id, res.value);
29-
30-
await VaultClient.deleteVaultAccount(clientAdmin, iamClient, accountName);
14+
it('should be able create, generate credentials and delete an account', done => {
15+
async.series([
16+
next => clientAdmin.createAccount(accountName, accountInfo, next),
17+
next => clientAdmin.generateAccountAccessKey(accountName, (err, res) => {
18+
if (err) {
19+
return next(err);
20+
}
21+
iamClient = VaultClient.getIamClient(res.id, res.value);
22+
return next(null);
23+
}),
24+
next => {
25+
VaultClient.deleteVaultAccount(clientAdmin, iamClient, accountName)
26+
.then(() => next())
27+
.catch(next);
28+
},
29+
], done);
3130
});
3231
});

tests/zenko_tests/node_tests/smoke_tests/vault_admin_and_IAM_API_tests/iamApi.js

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -53,26 +53,18 @@ describe('IAM user - Access Keys: ', () => {
5353
let iamAccountClient = null;
5454
let keyPair = null;
5555

56-
beforeEach(async () => {
57-
await new Promise((resolve, reject) => {
58-
clientAdmin.createAccount(accountName, accountInfo, err => {
59-
if (err) {
60-
return reject(err);
61-
}
62-
return resolve();
63-
});
64-
});
65-
await new Promise((resolve, reject) => {
66-
clientAdmin.generateAccountAccessKey(accountName, err => {
67-
if (err) {
68-
return reject(err);
69-
}
70-
return resolve();
71-
}, { externalAccessKey, externalSecretKey });
72-
});
56+
beforeEach(done => async.series([
57+
next => clientAdmin.createAccount(accountName, accountInfo, next),
58+
next => clientAdmin.generateAccountAccessKey(accountName, next, { externalAccessKey, externalSecretKey }),
59+
], err => {
60+
if (err) {
61+
return done(err);
62+
}
7363
iamAccountClient = VaultClient.getIamClient(externalAccessKey, externalSecretKey);
74-
await iamAccountClient.send(new CreateUserCommand({ UserName: userName }));
75-
});
64+
return iamAccountClient.send(new CreateUserCommand({ UserName: userName }))
65+
.then(() => done())
66+
.catch(done);
67+
}));
7668

7769
afterEach(async () => {
7870
await iamAccountClient.send(new DeleteUserCommand({ UserName: userName }));

0 commit comments

Comments
 (0)