File: security_group_tests.rb

package info (click to toggle)
ruby-fog-aws 3.33.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,180 kB
  • sloc: ruby: 75,405; javascript: 14; makefile: 9; sh: 4
file content (108 lines) | stat: -rw-r--r-- 3,655 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
Shindo.tests('AWS::Elasticache | security group requests', ['aws', 'elasticache']) do

  tests('success') do

    name = 'fog-test'
    description = 'Fog Test Security Group'

    tests(
    '#create_cache_security_group'
    ).formats(AWS::Elasticache::Formats::SINGLE_SECURITY_GROUP) do
      body = Fog::AWS[:elasticache].create_cache_security_group(name, description).body
      group = body['CacheSecurityGroup']
      returns(name)        { group['CacheSecurityGroupName'] }
      returns(description) { group['Description'] }
      returns([], "no authorized security group") { group['EC2SecurityGroups'] }
      body
    end

    tests(
    '#describe_cache_security_groups without options'
    ).formats(AWS::Elasticache::Formats::DESCRIBE_SECURITY_GROUPS) do
      body = Fog::AWS[:elasticache].describe_cache_security_groups.body
      returns(true, "has #{name}") do
        body['CacheSecurityGroups'].any? do |group|
          group['CacheSecurityGroupName'] == name
        end
      end
      body
    end

    tests(
    '#describe_cache_security_groups with name'
    ).formats(AWS::Elasticache::Formats::DESCRIBE_SECURITY_GROUPS) do
      body = Fog::AWS[:elasticache].describe_cache_security_groups(name).body
      returns(1, "size of 1") { body['CacheSecurityGroups'].size }
      returns(name, "has #{name}") do
        body['CacheSecurityGroups'].first['CacheSecurityGroupName']
      end
      body
    end

    tests('authorization') do
      ec2_group = Fog::Compute.new(:provider => 'AWS').security_groups.create(
        :name => 'fog-test-elasticache', :description => 'Fog Test Elasticache'
      )
      # Reload to get the owner_id
      ec2_group.reload

      tests(
      '#authorize_cache_security_group_ingress'
      ).formats(AWS::Elasticache::Formats::SINGLE_SECURITY_GROUP) do
        body = Fog::AWS[:elasticache].authorize_cache_security_group_ingress(
          name, ec2_group.name, ec2_group.owner_id
        ).body
        group = body['CacheSecurityGroup']
        expected_ec2_groups = [{
          'Status' => 'authorizing', 'EC2SecurityGroupName' => ec2_group.name,
          'EC2SecurityGroupOwnerId' => ec2_group.owner_id
        }]
        returns(expected_ec2_groups, 'has correct EC2 groups') do
          group['EC2SecurityGroups']
        end
        body
      end

      # Wait for the state to be active
      Fog.wait_for do
        response = Fog::AWS[:elasticache].describe_cache_security_groups(name)
        group = response.body['CacheSecurityGroups'].first
        group['EC2SecurityGroups'].all? {|ec2| ec2['Status'] == 'authorized'}
      end

      tests(
      '#revoke_cache_security_group_ingress'
      ).formats(AWS::Elasticache::Formats::SINGLE_SECURITY_GROUP) do
        pending if Fog.mocking?

        body = Fog::AWS[:elasticache].revoke_cache_security_group_ingress(
          name, ec2_group.name, ec2_group.owner_id
        ).body
        group = body['CacheSecurityGroup']
        expected_ec2_groups = [{
          'Status' => 'revoking', 'EC2SecurityGroupName' => ec2_group.name,
          'EC2SecurityGroupOwnerId' => ec2_group.owner_id
        }]
        returns(expected_ec2_groups, 'has correct EC2 groups') do
          group['EC2SecurityGroups']
        end
        body
      end

      ec2_group.destroy
    end

    tests(
    '#delete_cache_security_group'
    ).formats(AWS::Elasticache::Formats::BASIC) do
      body = Fog::AWS[:elasticache].delete_cache_security_group(name).body
    end
  end

  tests('failure') do
    # TODO:
    # Create a duplicate security group
    # List a missing security group
    # Delete a missing security group
  end
end