2015-01-02 12:34:40 -05:00
Shindo . tests ( 'AWS::IAM | user requests' , [ 'aws' ] ) do
2015-05-21 15:02:21 -04:00
service = Fog :: AWS [ :iam ]
2014-12-30 17:25:09 -05:00
2015-05-18 18:04:05 -04:00
begin
2015-05-21 15:02:21 -04:00
service . delete_group ( 'fog_user_tests' )
2015-05-18 18:04:05 -04:00
rescue Fog :: AWS :: IAM :: NotFound
end
2014-12-30 17:25:09 -05:00
2015-05-18 18:04:05 -04:00
begin
2015-05-21 15:02:21 -04:00
service . delete_user ( 'fog_user' ) . body
2015-05-18 18:04:05 -04:00
rescue Fog :: AWS :: IAM :: NotFound
end
2014-12-30 17:25:09 -05:00
2015-05-21 15:02:21 -04:00
username = 'fog_user'
2014-12-30 17:25:09 -05:00
2015-05-21 15:02:21 -04:00
service . create_group ( 'fog_user_tests' )
tests ( " # create_user(' #{ username } ') " ) . data_matches_schema ( AWS :: IAM :: Formats :: CREATE_USER ) do
service . create_user ( username ) . body
2015-05-18 18:04:05 -04:00
end
2014-12-30 17:25:09 -05:00
2015-05-18 18:04:05 -04:00
tests ( " # list_users " ) . data_matches_schema ( AWS :: IAM :: Formats :: LIST_USER ) do
2015-05-21 15:02:21 -04:00
service . list_users . body
2015-05-18 18:04:05 -04:00
end
2014-12-30 17:25:09 -05:00
2015-05-21 15:02:21 -04:00
tests ( " # get_user(' #{ username } ') " ) . data_matches_schema ( AWS :: IAM :: Formats :: GET_USER ) do
service . get_user ( username ) . body
2015-05-18 18:04:05 -04:00
end
2014-12-30 17:25:09 -05:00
2015-05-18 18:04:05 -04:00
tests ( " # get_user " ) . data_matches_schema ( AWS :: IAM :: Formats :: GET_CURRENT_USER ) do
2015-05-20 18:55:28 -04:00
body = Fog :: AWS [ :iam ] . get_user . body
if Fog . mocking?
tests ( " correct root arn " ) . returns ( true ) {
body [ " User " ] [ " Arn " ] . end_with? ( " :root " )
}
end
body
2015-05-18 18:04:05 -04:00
end
2014-12-30 17:25:09 -05:00
2015-05-21 15:02:21 -04:00
tests ( " # create_login_profile " ) do
service . create_login_profile ( username , SecureRandom . base64 ( 10 ) )
end
tests ( " # get_login_profile " ) do
service . get_login_profile ( username )
end
tests ( " # update_login_profile " ) do
# avoids Fog::AWS::IAM::Error: EntityTemporarilyUnmodifiable => Login Profile for User instance cannot be modified while login profile is being created.
if Fog . mocking?
service . update_login_profile ( username , SecureRandom . base64 ( 10 ) )
end
end
tests ( " # delete_login_profile " ) do
service . delete_login_profile ( username )
end
tests ( " # add_user_to_group('fog_user_tests', ' #{ username } ') " ) . data_matches_schema ( AWS :: IAM :: Formats :: BASIC ) do
service . add_user_to_group ( 'fog_user_tests' , username ) . body
2015-05-18 18:04:05 -04:00
end
2014-12-30 17:25:09 -05:00
2015-05-21 15:02:21 -04:00
tests ( " # list_groups_for_user(' #{ username } ') " ) . data_matches_schema ( AWS :: IAM :: Formats :: GROUPS ) do
service . list_groups_for_user ( username ) . body
2015-05-18 18:04:05 -04:00
end
2014-12-30 17:25:09 -05:00
2015-05-21 15:02:21 -04:00
tests ( " # remove_user_from_group('fog_user_tests', ' #{ username } ') " ) . data_matches_schema ( AWS :: IAM :: Formats :: BASIC ) do
service . remove_user_from_group ( 'fog_user_tests' , username ) . body
2014-12-30 17:25:09 -05:00
end
2015-05-21 15:02:21 -04:00
tests ( " # delete_user(' #{ username } ') " ) . data_matches_schema ( AWS :: IAM :: Formats :: BASIC ) do
service . delete_user ( username ) . body
2014-12-30 17:25:09 -05:00
end
2015-05-21 15:02:21 -04:00
service . delete_group ( 'fog_user_tests' )
2014-12-30 17:25:09 -05:00
end