mirror of
https://github.com/inspec/inspec
synced 2024-11-23 21:23:29 +00:00
1a31425e81
* Initial Commit Signed-off-by: sfreeman <Steffanie.Freeman@d2l.com> * aws_iam_user uses lazy loading Signed-off-by: sfreeman <Steffanie.Freeman@d2l.com> * Disassociates convert call from list_users Signed-off-by: sfreeman <Steffanie.Freeman@d2l.com> * A real-world working AwsIamUsers (#71) * Add aws_iam_users Signed-off-by: Chris Redekop <chris.redekop@d2l.com> * Adding Filter table and Collect User Details to aws_iam_users.rb Signed-off-by: Chris Redekop <chris.redekop@d2l.com> * Adding Filter table and Collect User Details to aws_iam_users.rb Signed-off-by: Chris Redekop <chris.redekop@d2l.com> * Adding Filter table and Collect User Details to aws_iam_users.rb Signed-off-by: Chris Redekop <chris.redekop@d2l.com> * Get an aws_iam_users integration test to pass Signed-off-by: Chris Redekop <chris.redekop@d2l.com> * Fix RuboCop issues and tests Signed-off-by: Chris Redekop <chris.redekop@d2l.com> * Improving code based on PR feedback Signed-off-by: Chris Redekop <chris.redekop@d2l.com> * AWS IAM Users unit tests work with new lazy loading feature Signed-off-by: sfreeman <Steffanie.Freeman@d2l.com> * Fixes tests Signed-off-by: aduric <adnan.duric@d2l.com> * Users should only hold the returned user references, transfering responsibility to each user to fetch any details Signed-off-by: aduric <adnan.duric@d2l.com> * Create user details provider class Signed-off-by: sfreeman <Steffanie.Freeman@d2l.com> * Using details provider factory to delegate creation of detail providers, and updates tests Signed-off-by: aduric <adnan.duric@d2l.com> * Rubocop fixes Signed-off-by: aduric <adnan.duric@d2l.com> * Rename user details provider factory to initializer, and remove unnecessary instance variables Signed-off-by: sfreeman <Steffanie.Freeman@d2l.com>
100 lines
3.1 KiB
Ruby
100 lines
3.1 KiB
Ruby
# author: Simon Varlow
|
|
require 'aws-sdk'
|
|
require 'helper'
|
|
require 'aws_iam_user'
|
|
|
|
class AwsIamUserTest < Minitest::Test
|
|
Username = 'test'.freeze
|
|
|
|
def setup
|
|
@mock_user_provider = Minitest::Mock.new
|
|
@mock_dets_provider = Minitest::Mock.new
|
|
@mock_dets_prov_ini = Minitest::Mock.new
|
|
@mock_user = { name: Username }
|
|
end
|
|
|
|
def test_that_mfa_enable_returns_true_if_mfa_enabled
|
|
@mock_user_provider.expect :user, @mock_user, [Username]
|
|
@mock_dets_provider.expect :has_mfa_enabled?, true
|
|
@mock_dets_prov_ini.expect :create, @mock_dets_provider, [@mock_user]
|
|
assert AwsIamUser.new(
|
|
@mock_user,
|
|
@mock_user_provider,
|
|
@mock_dets_prov_ini,
|
|
).has_mfa_enabled?
|
|
end
|
|
|
|
def test_that_mfa_enable_returns_false_if_mfa_is_not_enabled
|
|
@mock_user_provider.expect :user, @mock_user, [Username]
|
|
@mock_dets_provider.expect :has_mfa_enabled?, false
|
|
@mock_dets_prov_ini.expect :create, @mock_dets_provider, [@mock_user]
|
|
refute AwsIamUser.new(
|
|
@mock_user,
|
|
@mock_user_provider,
|
|
@mock_dets_prov_ini,
|
|
).has_mfa_enabled?
|
|
end
|
|
|
|
def test_that_console_password_returns_true_if_console_password_set
|
|
@mock_user_provider.expect :user, @mock_user, [Username]
|
|
@mock_dets_provider.expect :has_console_password?, true
|
|
@mock_dets_prov_ini.expect :create, @mock_dets_provider, [@mock_user]
|
|
assert AwsIamUser.new(
|
|
@mock_user,
|
|
@mock_user_provider,
|
|
@mock_dets_prov_ini,
|
|
).has_console_password?
|
|
end
|
|
|
|
def test_that_console_password_returns_false_if_console_password_not_set
|
|
@mock_user_provider.expect :user, @mock_user, [Username]
|
|
@mock_dets_provider.expect :has_console_password?, false
|
|
@mock_dets_prov_ini.expect :create, @mock_dets_provider, [@mock_user]
|
|
refute AwsIamUser.new(
|
|
@mock_user,
|
|
@mock_user_provider,
|
|
@mock_dets_prov_ini,
|
|
).has_console_password?
|
|
end
|
|
|
|
def test_that_access_keys_returns_aws_iam_access_key_resources
|
|
stub_aws_access_key = Object.new
|
|
stub_access_key_resource = Object.new
|
|
mock_access_key_factory = Minitest::Mock.new
|
|
|
|
@mock_user_provider.expect :user, @mock_user, [Username]
|
|
@mock_dets_provider.expect :access_keys, [stub_aws_access_key]
|
|
@mock_dets_prov_ini.expect :create, @mock_dets_provider, [@mock_user]
|
|
mock_access_key_factory.expect(
|
|
:create_access_key,
|
|
stub_access_key_resource,
|
|
[stub_aws_access_key],
|
|
)
|
|
|
|
assert_equal(
|
|
stub_access_key_resource,
|
|
AwsIamUser.new(
|
|
@mock_user,
|
|
@mock_user_provider,
|
|
@mock_dets_prov_ini,
|
|
mock_access_key_factory,
|
|
).access_keys[0],
|
|
)
|
|
|
|
mock_access_key_factory.verify
|
|
end
|
|
|
|
def test_to_s
|
|
test_user = { name: Username, has_mfa_enabled?: true }
|
|
@mock_user_provider.expect :user, test_user, [Username]
|
|
@mock_dets_provider.expect :name, Username
|
|
@mock_dets_prov_ini.expect :create, @mock_dets_provider, [test_user]
|
|
expected = "IAM User #{Username}"
|
|
test = AwsIamUser.new(
|
|
{ name: Username },
|
|
@mock_user_provider,
|
|
@mock_dets_prov_ini,
|
|
).to_s
|
|
assert_equal expected, test
|
|
end
|
|
end
|