inspec/test/unit/resources/aws_iam_user_test.rb

123 lines
3.8 KiB
Ruby
Raw Normal View History

# author: Simon Varlow
require 'helper'
require 'aws_iam_user'
# rubocop:disable Metrics/ClassLength
class AwsIamUserTest < Minitest::Test
Username = 'test'.freeze
def setup
@mock_user_provider = Minitest::Mock.new
Issue #46 Lazily load attributes in aws_iam_users (#89) * 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>
2017-10-26 19:22:15 +00:00
@mock_dets_provider = Minitest::Mock.new
@mock_dets_prov_ini = Minitest::Mock.new
@mock_user = { name: Username }
end
def test_that_exists_returns_true_if_user_exists
@mock_user_provider.expect :user, @mock_user, [Username]
@mock_dets_provider.expect :exists?, true
@mock_dets_prov_ini.expect :create, @mock_dets_provider, [@mock_user]
assert AwsIamUser.new(
@mock_user,
@mock_user_provider,
@mock_dets_prov_ini,
).exists?
end
def test_that_exists_returns_false_if_user_does_not_exist
@mock_user_provider.expect :user, @mock_user, [Username]
@mock_dets_provider.expect :exists?, false
@mock_dets_prov_ini.expect :create, @mock_dets_provider, [@mock_user]
refute AwsIamUser.new(
@mock_user,
@mock_user_provider,
@mock_dets_prov_ini,
).exists?
end
Issue #46 Lazily load attributes in aws_iam_users (#89) * 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>
2017-10-26 19:22:15 +00:00
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
Issue #46 Lazily load attributes in aws_iam_users (#89) * 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>
2017-10-26 19:22:15 +00:00
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
Issue #46 Lazily load attributes in aws_iam_users (#89) * 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>
2017-10-26 19:22:15 +00:00
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
Issue #46 Lazily load attributes in aws_iam_users (#89) * 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>
2017-10-26 19:22:15 +00:00
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
Issue #46 Lazily load attributes in aws_iam_users (#89) * 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>
2017-10-26 19:22:15 +00:00
@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(
Issue #46 Lazily load attributes in aws_iam_users (#89) * 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>
2017-10-26 19:22:15 +00:00
@mock_user,
@mock_user_provider,
Issue #46 Lazily load attributes in aws_iam_users (#89) * 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>
2017-10-26 19:22:15 +00:00
@mock_dets_prov_ini,
mock_access_key_factory,
).access_keys[0],
)
mock_access_key_factory.verify
end
def test_to_s
Issue #46 Lazily load attributes in aws_iam_users (#89) * 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>
2017-10-26 19:22:15 +00:00
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}"
Issue #46 Lazily load attributes in aws_iam_users (#89) * 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>
2017-10-26 19:22:15 +00:00
test = AwsIamUser.new(
{ name: Username },
@mock_user_provider,
@mock_dets_prov_ini,
).to_s
assert_equal expected, test
end
end