2017-02-01 21:27:10 +00:00
|
|
|
# author: Simon Varlow
|
|
|
|
require 'aws-sdk'
|
|
|
|
require 'helper'
|
|
|
|
|
|
|
|
require 'aws_iam_user'
|
|
|
|
|
|
|
|
class AwsIamUserTest < Minitest::Test
|
2017-06-13 05:36:43 +00:00
|
|
|
Username = "test"
|
2017-02-01 21:27:10 +00:00
|
|
|
|
|
|
|
def setup
|
2017-03-29 21:09:05 +00:00
|
|
|
@mock_user_provider = Minitest::Mock.new
|
2017-02-01 21:27:10 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_that_MFA_enable_returns_true_if_MFA_Enabled
|
2017-05-10 19:41:03 +00:00
|
|
|
@mock_user_provider.expect :user, {has_mfa_enabled?: true}, [Username]
|
2017-03-29 21:09:05 +00:00
|
|
|
assert AwsIamUser.new(Username, @mock_user_provider).has_mfa_enabled?
|
2017-02-01 21:27:10 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_that_MFA_enable_returns_false_if_MFA_is_not_Enabled
|
2017-05-10 19:41:03 +00:00
|
|
|
@mock_user_provider.expect :user, {has_mfa_enabled?: false}, [Username]
|
2017-06-13 05:36:43 +00:00
|
|
|
refute AwsIamUser.new(Username, @mock_user_provider).has_mfa_enabled?
|
2017-02-01 21:27:10 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_that_console_Password_returns_true_if_console_Password_has_been_set
|
2017-05-10 19:41:03 +00:00
|
|
|
@mock_user_provider.expect :user, {has_console_password?: true}, [Username]
|
2017-03-29 21:09:05 +00:00
|
|
|
assert AwsIamUser.new(Username, @mock_user_provider).has_console_password?
|
2017-02-01 21:27:10 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_that_console_Password_returns_false_if_console_Password_has_not_been_set
|
2017-05-10 19:41:03 +00:00
|
|
|
@mock_user_provider.expect :user, {has_console_password?: false}, [Username]
|
2017-06-13 05:36:43 +00:00
|
|
|
refute AwsIamUser.new(Username, @mock_user_provider).has_console_password?
|
2017-02-01 21:27:10 +00:00
|
|
|
end
|
2017-06-13 05:36:43 +00:00
|
|
|
|
|
|
|
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, {access_keys: [stub_aws_access_key]}, [Username]
|
|
|
|
mock_access_key_factory.expect :create_access_key, stub_access_key_resource, [stub_aws_access_key]
|
|
|
|
|
|
|
|
assert_equal(stub_access_key_resource,
|
|
|
|
AwsIamUser.new(Username, @mock_user_provider, mock_access_key_factory).access_keys[0])
|
|
|
|
|
|
|
|
mock_access_key_factory.verify
|
|
|
|
end
|
2017-06-28 12:46:59 +00:00
|
|
|
|
|
|
|
def test_to_s
|
|
|
|
@mock_user_provider.expect :user, {has_mfa_enabled?: true}, [Username]
|
|
|
|
expected = "IAM User test"
|
|
|
|
test = AwsIamUser.new(Username, @mock_user_provider).to_s
|
|
|
|
assert_equal expected, test
|
|
|
|
end
|
2017-06-13 05:36:43 +00:00
|
|
|
end
|