mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Merge pull request #2118 from gregburek/aws-getfedtoken-mocks
Add mocks for AWS STS GetFederationToken api call
This commit is contained in:
commit
f1323c1986
3 changed files with 43 additions and 4 deletions
|
@ -14,10 +14,8 @@ module Fog
|
|||
case name
|
||||
when 'SessionToken', 'SecretAccessKey', 'Expiration', 'AccessKeyId'
|
||||
@response[name] = @value.strip
|
||||
when 'Arn', 'FederatedUserId'
|
||||
when 'Arn', 'FederatedUserId', 'PackedPolicySize'
|
||||
@response[name] = @value.strip
|
||||
when 'PackedPolicySize'
|
||||
@response[name] = @value
|
||||
when 'RequestId'
|
||||
@response[name] = @value
|
||||
end
|
||||
|
|
|
@ -5,6 +5,31 @@ module Fog
|
|||
|
||||
require 'fog/aws/parsers/sts/get_session_token'
|
||||
|
||||
# Get federation token
|
||||
#
|
||||
# ==== Parameters
|
||||
# * name<~String>: The name of the federated user.
|
||||
# Minimum length of 2. Maximum length of 32.
|
||||
# * policy<~String>: Optional policy that specifies the permissions
|
||||
# that are granted to the federated user
|
||||
# Minimum length of 1. Maximum length of 2048.
|
||||
# * duration<~Integer>: Optional duration, in seconds, that the session
|
||||
# should last.
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'SessionToken'<~String> -
|
||||
# * 'SecretAccessKey'<~String> -
|
||||
# * 'Expiration'<~String> -
|
||||
# * 'AccessKeyId'<~String> -
|
||||
# * 'Arn'<~String> -
|
||||
# * 'FederatedUserId'<~String> -
|
||||
# * 'PackedPolicySize'<~String> -
|
||||
# * 'RequestId'<~String> - Id of the request
|
||||
#
|
||||
# ==== See Also
|
||||
# http://docs.aws.amazon.com/STS/latest/APIReference/API_GetFederationToken.html
|
||||
|
||||
def get_federation_token(name, policy, duration=43200)
|
||||
request({
|
||||
'Action' => 'GetFederationToken',
|
||||
|
@ -16,6 +41,23 @@ module Fog
|
|||
})
|
||||
end
|
||||
end
|
||||
class Mock
|
||||
def get_federation_token(name, policy, duration=43200)
|
||||
Excon::Response.new.tap do |response|
|
||||
response.status = 200
|
||||
response.body = {
|
||||
'SessionToken' => Fog::Mock.random_base64(580),
|
||||
'SecretAccessKey' => Fog::Mock.random_base64(40),
|
||||
'Expiration' => (DateTime.now + duration).strftime('%FT%TZ'),
|
||||
'AccessKeyId' => Fog::AWS::Mock.key_id(20),
|
||||
'Arn' => "arn:aws:sts::#{Fog::AWS::Mock.owner_id}:federated-user/#{name}",
|
||||
'FederatedUserId' => "#{Fog::AWS::Mock.owner_id}:#{name}",
|
||||
'PackedPolicySize' => Fog::Mock.random_numbers(2),
|
||||
'RequestId' => Fog::AWS::Mock.request_id
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -14,7 +14,6 @@ Shindo.tests('AWS::STS | session tokens', ['aws']) do
|
|||
}
|
||||
|
||||
tests("#get_federation_token('test@fog.io', #{@policy.inspect})").formats(@federation_format) do
|
||||
pending if Fog.mocking?
|
||||
Fog::AWS[:sts].get_federation_token("test@fog.io", @policy).body
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue