File: users_tests.rb

package info (click to toggle)
ruby-fog-aws 3.18.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 8,140 kB
  • sloc: ruby: 73,328; javascript: 14; makefile: 9; sh: 4
file content (119 lines) | stat: -rw-r--r-- 3,006 bytes parent folder | download | duplicates (5)
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
109
110
111
112
113
114
115
116
117
118
119
Shindo.tests("Fog::Compute[:iam] | users", ['aws','iam']) do

  iam = Fog::AWS[:iam]

  user_one_name   = 'fake_user_one'
  user_two_name   = 'fake_user_two'
  user_three_name = 'fake_user_three'
  user_three_path = '/path/to/fake_user_three/'
  user_four_name  = 'fake_user_four'

  def all_users
    Fog::AWS[:iam].users.all.select{|user| user.id =~ /^fake_user/ }
  end

  tests('#create').succeeds do
    user_one = iam.users.create(:id => user_one_name)
    user_one.id == user_one_name
  end

  tests('#all','there is only one user').succeeds do
    all_users.size == 1
  end

  tests('#all','the only user should match').succeeds do
    all_users.first.id == user_one_name
  end

  tests('#create','a second user').succeeds do
    user_two = iam.users.create(:id => user_two_name)
    user_two.id == user_two_name
  end

  tests('#all','there are two users').succeeds do
    all_users.size == 2
  end

  user = iam.users.get(user_one_name)

  tests('#get','an existing user').succeeds do
    user.id == user_one_name
  end

  tests('#current').succeeds do
    iam.users.current
  end

  tests('#get',"returns nil if the user doesn't exists").succeeds do
    iam.users.get('non-exists') == nil
  end

  tests('#policies','it has no policies').succeeds do
    user.policies.empty?
  end

  tests('#access_keys','it has no keys').succeeds do
    user.access_keys.empty?
  end

  # test that users create in mock and be signed in via access key and share data
  if Fog.mocking?
    tests("mocking access key usage") do
      access_key = user.access_keys.create

      user_client = Fog::AWS::IAM.new(
        :aws_access_key_id     => access_key.identity,
        :aws_secret_access_key => access_key.secret_access_key
      )

      tests("sets correct data").succeeds do
        user_client.users.size > 1
      end

      tests("set current user name").succeeds do
        user_client.current_user_name == user.identity
      end
    end
  end

  tests('#password=nil', 'without a password').succeeds do
    user.password = nil
    user.password_created_at.nil?
  end

  tests('#password=(password)').succeeds do
    user.password = SecureRandom.base64(10)

    user.password_created_at.is_a?(Time)
  end

  tests('#password=(update_password)').succeeds do
    user.password = SecureRandom.base64(10)

    user.password_created_at.is_a?(Time)
  end

  tests('#password=nil', 'with a password').succeeds do
    user.password = nil
    user.password_created_at.nil?
  end

  tests('#create', 'assigns path').succeeds do
    user_three = iam.users.create(:id => user_three_name, :path => user_three_path)
    user_three.path == user_three_path
  end

  tests('#create', 'defaults path to /').succeeds do
    user_four = iam.users.create(:id => user_four_name)
    user_four.path == '/'
  end

  tests('#destroy','an existing user').succeeds do
    iam.users.get(user_one_name).destroy
  end

  tests('#destroy','clean up remaining user').succeeds do
    iam.users.get(user_two_name).destroy
  end

end