mirror of
https://github.com/inspec/inspec
synced 2024-11-27 15:10:44 +00:00
commit
aff0185f48
2 changed files with 78 additions and 0 deletions
52
libraries/iam_password_policy.rb
Normal file
52
libraries/iam_password_policy.rb
Normal file
|
@ -0,0 +1,52 @@
|
|||
# author: Viktor Yakovlyev
|
||||
|
||||
require 'aws_conn'
|
||||
|
||||
class IamPasswordPolicy < Inspec.resource(1)
|
||||
name 'iam_password_policy'
|
||||
desc 'Verifies iam password policy'
|
||||
|
||||
example "
|
||||
describe iam_password_policy('i-123456') do
|
||||
its('requires_lowercase_letters?') { should be true }
|
||||
end
|
||||
|
||||
describe iam_password_policy('i-123456') do
|
||||
its('requires_uppercase_letters?') { should be true }
|
||||
end
|
||||
"
|
||||
|
||||
def initialize(conn = AWSConnection.new)
|
||||
@policy = conn.iam_resource.account_password_policy
|
||||
rescue Aws::IAM::Errors::NoSuchEntity
|
||||
@policy = nil
|
||||
end
|
||||
|
||||
def exists?
|
||||
!@policy.nil?
|
||||
end
|
||||
|
||||
def requires_lowercase_characters?
|
||||
@policy.require_lowercase_characters
|
||||
end
|
||||
|
||||
def requires_uppercase_characters?
|
||||
@policy.require_uppercase_characters
|
||||
end
|
||||
|
||||
def minimum_password_length
|
||||
@policy.minimum_password_length
|
||||
end
|
||||
|
||||
def requires_numbers?
|
||||
@policy.require_numbers
|
||||
end
|
||||
|
||||
def requires_symbols?
|
||||
@policy.require_symbols
|
||||
end
|
||||
|
||||
def allows_users_to_change_password?
|
||||
@policy.allow_users_to_change_password
|
||||
end
|
||||
end
|
26
test/unit/resources/iam_password_policy_test.rb
Normal file
26
test/unit/resources/iam_password_policy_test.rb
Normal file
|
@ -0,0 +1,26 @@
|
|||
require 'helper'
|
||||
require 'iam_password_policy'
|
||||
require 'aws-sdk'
|
||||
require 'json'
|
||||
|
||||
class IamPasswordPolicyTest < Minitest::Test
|
||||
def setup
|
||||
@mockConn = Minitest::Mock.new
|
||||
end
|
||||
|
||||
def test_policy_exists_when_policy_exists
|
||||
@mockResource = Minitest::Mock.new
|
||||
@mockResource.expect :account_password_policy, true
|
||||
@mockConn.expect :iam_resource, @mockResource
|
||||
assert_equal true, IamPasswordPolicy.new(@mockConn).exists?
|
||||
end
|
||||
|
||||
def test_policy_does_not_exists_when_no_policy
|
||||
@mockResource = Minitest::Mock.new
|
||||
@mockResource.expect :account_password_policy, nil do |args|
|
||||
raise Aws::IAM::Errors::NoSuchEntity.new nil, nil
|
||||
end
|
||||
@mockConn.expect :iam_resource, @mockResource
|
||||
assert_equal false, IamPasswordPolicy.new(@mockConn).exists?
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue