forked from aquasecurity/cloudsploit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/plugin/iam user admins (aquasecurity#223)
* add min and max admins * added spec file for testing * add extra expect * add additional tests * fix missing default * allow 0 for min/max values in settings Co-authored-by: robertramsey117 <[email protected]> Co-authored-by: Joel Haubold <[email protected]>
- Loading branch information
1 parent
d6e37a2
commit e215595
Showing
2 changed files
with
152 additions
and
15 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
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,126 @@ | ||
var assert = require('assert'); | ||
var expect = require('chai').expect; | ||
var iamUserAdmins = require('./iamUserAdmins'); | ||
|
||
const cache = { | ||
"iam": { | ||
"listUsers": { | ||
"us-east-1": { | ||
"data": [ | ||
{ | ||
"UserName": "[email protected]", | ||
}, | ||
{ | ||
"UserName": "[email protected]", | ||
}, | ||
] | ||
} | ||
}, | ||
"listAttachedUserPolicies": { | ||
"us-east-1": { | ||
"[email protected]": { | ||
"data": { | ||
"AttachedPolicies": [{"PolicyArn":"arn:aws:iam::aws:policy/AdministratorAccess"}], | ||
} | ||
}, | ||
"[email protected]": { | ||
"data": { | ||
"AttachedPolicies": [{"PolicyArn":"arn:aws:iam::aws:policy/AdministratorAccess"}], | ||
} | ||
}, | ||
} | ||
}, | ||
"listUserPolicies": { | ||
"us-east-1": { | ||
"[email protected]": { | ||
"data": { | ||
"PolicyNames": [], | ||
} | ||
}, | ||
"[email protected]": { | ||
"data": { | ||
"PolicyNames": [], | ||
} | ||
}, | ||
} | ||
}, | ||
"listGroupsForUser": { | ||
"us-east-1": { | ||
"[email protected]": { | ||
"data": { | ||
"Groups": [], | ||
} | ||
}, | ||
"[email protected]": { | ||
"data": { | ||
"Groups": [], | ||
} | ||
}, | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
describe('iamUserAdmins', function () { | ||
describe('run', function () { | ||
it('should FAIL when no users are found', function (done) { | ||
const settings = { | ||
iam_admin_count_minimum: 2, | ||
iam_admin_count_maximum: 2 | ||
} | ||
|
||
const cache = [{}]; | ||
|
||
|
||
const callback = (err, results) => { | ||
expect(results.length).to.equal(0) | ||
done() | ||
} | ||
|
||
iamUserAdmins.run(cache, settings, callback) | ||
}) | ||
|
||
it('should FAIL when there are not enough users', function (done) { | ||
const settings = { | ||
iam_admin_count_minimum: 3, | ||
iam_admin_count_maximum: 3 | ||
} | ||
|
||
const callback = (err, results) => { | ||
expect(results[0].status).to.equal(1) | ||
done() | ||
} | ||
|
||
iamUserAdmins.run(cache, settings, callback) | ||
}) | ||
|
||
it('should FAIL when there are too many users', function (done) { | ||
const settings = { | ||
iam_admin_count_minimum: 0, | ||
iam_admin_count_maximum: 0 | ||
} | ||
|
||
const callback = (err, results) => { | ||
expect(results[0].status).to.equal(2) | ||
done() | ||
} | ||
|
||
iamUserAdmins.run(cache, settings, callback) | ||
}) | ||
|
||
it('should PASS when users are found and fit within range', function (done) { | ||
const settings = { | ||
iam_admin_count_minimum: 1, | ||
iam_admin_count_maximum: 8 | ||
} | ||
|
||
const callback = (err, results) => { | ||
expect(results[0].status).to.equal(0) | ||
done() | ||
} | ||
|
||
iamUserAdmins.run(cache, settings, callback) | ||
}) | ||
}) | ||
}) |