diff --git a/lib/fog/aws/parsers/iam/get_user_policy.rb b/lib/fog/aws/parsers/iam/get_user_policy.rb index d6a9213d0..d3589abce 100644 --- a/lib/fog/aws/parsers/iam/get_user_policy.rb +++ b/lib/fog/aws/parsers/iam/get_user_policy.rb @@ -12,8 +12,14 @@ module Fog def end_element(name) case name - when 'UserName', 'PolicyName', 'PolicyDocument' + when 'UserName', 'PolicyName' @response[name] = value + when 'PolicyDocument' + @response[name] = if decoded_string = URI.decode(value) + Fog::JSON.decode(decoded_string) rescue value + else + value + end when 'RequestId' @response[name] = value end diff --git a/tests/aws/models/iam/policies_tests.rb b/tests/aws/models/iam/policies_tests.rb index a82ccb89d..3e847799e 100644 --- a/tests/aws/models/iam/policies_tests.rb +++ b/tests/aws/models/iam/policies_tests.rb @@ -12,12 +12,18 @@ Shindo.tests("Fog::Compute[:iam] | policies", ['aws','iam']) do @user.policies.empty? end - - tests('#create','a policy').succeeds do - policy = @user.policies.create(id: @policy_name, document: @policy_document) - policy.id == @policy_name - policy.username == @username - #policy.document == @policy_document # FIXME, the format isn't right + tests('#create') do + tests('a valid policy').succeeds do + policy = @user.policies.create(id: @policy_name, document: @policy_document) + policy.id == @policy_name + policy.username == @username + policy.document == @policy_document + end + + # The mocking doesn't validate the document policy + #tests('an invalid valid policy').succeeds do + # raises(Fog::AWS::IAM::Error) { @user.policies.create(id: 'non-valid-document', document: 'invalid json blob') } + #end end @user.policies.create(id: 'another-policy', document: {}) @@ -31,7 +37,7 @@ Shindo.tests("Fog::Compute[:iam] | policies", ['aws','iam']) do policy = @user.policies.get(@policy_name) policy.id == @polic_name policy.username == @username - #policy.document == @policy_document # FIXME, the format isn't right + policy.document == @policy_document end tests('an invalid policy').succeeds do