cloudfoundry-client 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.travis.yml +12 -0
- data/.yardopts +9 -0
- data/CHANGELOG.md +6 -0
- data/Gemfile +3 -0
- data/LICENSE +20 -0
- data/README.md +122 -0
- data/Rakefile +28 -0
- data/cloudfoundry.gemspec +29 -0
- data/lib/cloudfoundry.rb +34 -0
- data/lib/cloudfoundry/client.rb +93 -0
- data/lib/cloudfoundry/client/apps.rb +192 -0
- data/lib/cloudfoundry/client/info.rb +29 -0
- data/lib/cloudfoundry/client/request.rb +89 -0
- data/lib/cloudfoundry/client/resources.rb +16 -0
- data/lib/cloudfoundry/client/response.rb +68 -0
- data/lib/cloudfoundry/client/services.rb +122 -0
- data/lib/cloudfoundry/client/users.rb +121 -0
- data/lib/cloudfoundry/constants.rb +30 -0
- data/lib/cloudfoundry/exception.rb +24 -0
- data/lib/cloudfoundry/version.rb +27 -0
- data/spec/client/apps_spec.rb +423 -0
- data/spec/client/info_spec.rb +92 -0
- data/spec/client/resources_spec.rb +52 -0
- data/spec/client/services_spec.rb +230 -0
- data/spec/client/users_spec.rb +367 -0
- data/spec/client_spec.rb +110 -0
- data/spec/cloudfoundry_spec.rb +62 -0
- data/spec/fixtures/admin_logged/client.yml +85 -0
- data/spec/fixtures/admin_logged/users.yml +363 -0
- data/spec/fixtures/admin_logged/users_create_action.yml +36 -0
- data/spec/fixtures/admin_logged/users_proxy_action.yml +46 -0
- data/spec/fixtures/admin_logged/users_proxy_nouser_action.yml +44 -0
- data/spec/fixtures/admin_logged/users_unproxy_action.yml +44 -0
- data/spec/fixtures/app.js +16 -0
- data/spec/fixtures/app.zip +0 -0
- data/spec/fixtures/client.yml +151 -0
- data/spec/fixtures/client_invalid.yml +85 -0
- data/spec/fixtures/cloudfoundry.yml +124 -0
- data/spec/fixtures/cloudfoundry_vs_client.yml +159 -0
- data/spec/fixtures/no_logged/apps.yml +42 -0
- data/spec/fixtures/no_logged/client.yml +42 -0
- data/spec/fixtures/no_logged/info.yml +81 -0
- data/spec/fixtures/no_logged/resources.yml +42 -0
- data/spec/fixtures/no_logged/services.yml +42 -0
- data/spec/fixtures/no_logged/users.yml +108 -0
- data/spec/fixtures/no_logged/users_login_action.yml +81 -0
- data/spec/fixtures/no_logged/users_proxy_action.yml +42 -0
- data/spec/fixtures/no_logged/users_unproxy_action.yml +42 -0
- data/spec/fixtures/user_logged/apps.yml +828 -0
- data/spec/fixtures/user_logged/apps_create_action.yml +42 -0
- data/spec/fixtures/user_logged/apps_directory_action.yml +48 -0
- data/spec/fixtures/user_logged/apps_download_action.yml +55 -0
- data/spec/fixtures/user_logged/apps_file_action.yml +54 -0
- data/spec/fixtures/user_logged/apps_start_action.yml +81 -0
- data/spec/fixtures/user_logged/apps_stats_action.yml +44 -0
- data/spec/fixtures/user_logged/apps_update_info_action.yml +44 -0
- data/spec/fixtures/user_logged/apps_upload_filename_action.yml +62 -0
- data/spec/fixtures/user_logged/apps_upload_zipfile_action.yml +62 -0
- data/spec/fixtures/user_logged/client.yml +85 -0
- data/spec/fixtures/user_logged/info.yml +126 -0
- data/spec/fixtures/user_logged/resources.yml +44 -0
- data/spec/fixtures/user_logged/resources_check_action.yml +42 -0
- data/spec/fixtures/user_logged/services.yml +354 -0
- data/spec/fixtures/user_logged/services_bind_action.yml +161 -0
- data/spec/fixtures/user_logged/services_create_action.yml +83 -0
- data/spec/fixtures/user_logged/services_unbind_action.yml +122 -0
- data/spec/fixtures/user_logged/services_unbind_fail_action.yml +122 -0
- data/spec/fixtures/user_logged/users.yml +299 -0
- data/spec/fixtures/user_logged/users_proxy_action.yml +44 -0
- data/spec/fixtures/user_logged/users_unproxy_action.yml +44 -0
- data/spec/spec_helper.rb +29 -0
- data/spec/support/cf_connection_helper.rb +26 -0
- data/spec/support/vcr.rb +8 -0
- metadata +235 -0
@@ -0,0 +1,92 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe "Cloudfoundry::Client::Info" do
|
4
|
+
include CfConnectionHelper
|
5
|
+
|
6
|
+
context "without a user logged in" do
|
7
|
+
before(:all) do
|
8
|
+
VCR.use_cassette("no_logged/client", :record => :new_episodes) do
|
9
|
+
@cf_client = client_no_logged()
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
use_vcr_cassette "no_logged/info", :record => :new_episodes
|
14
|
+
|
15
|
+
it "should properly get basic information from target cloud" do
|
16
|
+
cloud_info = @cf_client.cloud_info()
|
17
|
+
cloud_info.should have_key :name
|
18
|
+
cloud_info.should have_key :build
|
19
|
+
cloud_info.should have_key :support
|
20
|
+
cloud_info.should have_key :version
|
21
|
+
cloud_info.should have_key :description
|
22
|
+
cloud_info.should have_key :allow_debug
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should not return user account information from target cloud" do
|
26
|
+
cloud_info = @cf_client.cloud_info()
|
27
|
+
cloud_info.should_not have_key :user
|
28
|
+
cloud_info.should_not have_key :usage
|
29
|
+
cloud_info.should_not have_key :limits
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should get a proper list of runtimes available at target cloud" do
|
33
|
+
cloud_runtimes_info = @cf_client.cloud_runtimes_info()
|
34
|
+
cloud_runtimes_info.should have_at_least(1).items
|
35
|
+
runtime_info = cloud_runtimes_info.first[1]
|
36
|
+
runtime_info.should have_key :version
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should raise an AuthError exception when requesting system services" do
|
40
|
+
expect {
|
41
|
+
cloud_services_info = @cf_client.cloud_services_info()
|
42
|
+
}.to raise_exception(CloudFoundry::Client::Exception::AuthError)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context "with a user logged in" do
|
47
|
+
before(:all) do
|
48
|
+
VCR.use_cassette("user_logged/client", :record => :new_episodes) do
|
49
|
+
@cf_client = client_user_logged()
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
use_vcr_cassette "user_logged/info", :record => :new_episodes
|
54
|
+
|
55
|
+
it "should properly get basic account information from target cloud" do
|
56
|
+
cloud_info = @cf_client.cloud_info()
|
57
|
+
cloud_info.should have_key :name
|
58
|
+
cloud_info.should have_key :build
|
59
|
+
cloud_info.should have_key :support
|
60
|
+
cloud_info.should have_key :version
|
61
|
+
cloud_info.should have_key :description
|
62
|
+
cloud_info.should have_key :allow_debug
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should properly get user account information from target cloud" do
|
66
|
+
cloud_info = @cf_client.cloud_info()
|
67
|
+
cloud_info.should have_key :user
|
68
|
+
cloud_info.should have_key :usage
|
69
|
+
cloud_info.should have_key :limits
|
70
|
+
cloud_info[:user].should eql(@user)
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should get a proper list of runtimes available at target cloud" do
|
74
|
+
cloud_runtimes_info = @cf_client.cloud_runtimes_info()
|
75
|
+
cloud_runtimes_info.should have_at_least(1).items
|
76
|
+
runtime_info = cloud_runtimes_info.first[1]
|
77
|
+
runtime_info.should have_key :version
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should get a proper list of system services available at target cloud" do
|
81
|
+
cloud_services_info = @cf_client.cloud_services_info()
|
82
|
+
cloud_services_info.should have_at_least(1).items
|
83
|
+
system_service_info = cloud_services_info.first[1].values[0].first[1]
|
84
|
+
system_service_info.should have_key :id
|
85
|
+
system_service_info.should have_key :type
|
86
|
+
system_service_info.should have_key :vendor
|
87
|
+
system_service_info.should have_key :version
|
88
|
+
system_service_info.should have_key :description
|
89
|
+
system_service_info.should have_key :tiers
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe "Cloudfoundry::Client::Resources" do
|
4
|
+
include CfConnectionHelper
|
5
|
+
|
6
|
+
context "without a user logged in" do
|
7
|
+
before(:all) do
|
8
|
+
VCR.use_cassette("no_logged/client", :record => :new_episodes) do
|
9
|
+
@cf_client = client_no_logged()
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
use_vcr_cassette "no_logged/resources", :record => :new_episodes
|
14
|
+
|
15
|
+
it "should raise an AuthError exception when checking resources at target cloud" do
|
16
|
+
expect {
|
17
|
+
resources = []
|
18
|
+
resources_manifest = @cf_client.check_resources(resources)
|
19
|
+
}.to raise_exception(CloudFoundry::Client::Exception::AuthError)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context "with a user logged in" do
|
24
|
+
before(:all) do
|
25
|
+
VCR.use_cassette("user_logged/client", :record => :new_episodes) do
|
26
|
+
@cf_client = client_user_logged()
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
use_vcr_cassette "user_logged/resources", :record => :new_episodes
|
31
|
+
|
32
|
+
it "should properly get an empty resources manifest file from target cloud" do
|
33
|
+
resources = []
|
34
|
+
resources_manifest = @cf_client.check_resources(resources)
|
35
|
+
resources_manifest.should be_empty
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should properly get a resources manifest file from target cloud" do
|
39
|
+
VCR.use_cassette("user_logged/resources_check_action", :record => :new_episodes, :exclusive => true) do
|
40
|
+
resources = []
|
41
|
+
filename = spec_fixture("app.js")
|
42
|
+
resources << {
|
43
|
+
:size => File.size(filename),
|
44
|
+
:sha1 => Digest::SHA1.file(filename).hexdigest,
|
45
|
+
:fn => filename
|
46
|
+
}
|
47
|
+
resources_manifest = @cf_client.check_resources(resources)
|
48
|
+
resources_manifest.should eql(resources)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,230 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe "Cloudfoundry::Client::Services" do
|
4
|
+
include CfConnectionHelper
|
5
|
+
|
6
|
+
context "without a user logged in" do
|
7
|
+
before(:all) do
|
8
|
+
VCR.use_cassette("no_logged/client", :record => :new_episodes) do
|
9
|
+
@cf_client = client_no_logged()
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
use_vcr_cassette "no_logged/services", :record => :new_episodes
|
14
|
+
|
15
|
+
it "should raise an AuthError exception when creating a provisioned service" do
|
16
|
+
expect {
|
17
|
+
created = @cf_client.create_service("redis", "redis-mock")
|
18
|
+
}.to raise_exception(CloudFoundry::Client::Exception::AuthError)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should raise an AuthError exception when listing provisioned services at target cloud" do
|
22
|
+
expect {
|
23
|
+
services = @cf_client.list_services()
|
24
|
+
}.to raise_exception(CloudFoundry::Client::Exception::AuthError)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should raise an AuthError exception when retrieving provisioned service information from target cloud" do
|
28
|
+
expect {
|
29
|
+
service_info = @cf_client.service_info("redis-mock")
|
30
|
+
}.to raise_exception(CloudFoundry::Client::Exception::AuthError)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should raise an AuthError exception when binding a provisioned service to an application at target cloud" do
|
34
|
+
expect {
|
35
|
+
binded = @cf_client.bind_service("redis-mock", "newapp")
|
36
|
+
}.to raise_exception(CloudFoundry::Client::Exception::AuthError)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should raise an AuthError exception when unbinding a provisioned service to an application at target cloud" do
|
40
|
+
expect {
|
41
|
+
unbinded = @cf_client.unbind_service("redis-mock", "newapp")
|
42
|
+
}.to raise_exception(CloudFoundry::Client::Exception::AuthError)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should raise an AuthError exception when deleting a provisioned service at target cloud" do
|
46
|
+
expect {
|
47
|
+
deleted = @cf_client.delete_service("redis-mock")
|
48
|
+
}.to raise_exception(CloudFoundry::Client::Exception::AuthError)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context "with a user logged in" do
|
53
|
+
before(:all) do
|
54
|
+
VCR.use_cassette("user_logged/client", :record => :new_episodes) do
|
55
|
+
@cf_client = client_user_logged()
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
use_vcr_cassette "user_logged/services", :record => :new_episodes
|
60
|
+
|
61
|
+
it "should raise a BadParams exception when creating a provisioned service with a blank system service" do
|
62
|
+
expect {
|
63
|
+
created = @cf_client.create_service("", "redis-mock")
|
64
|
+
}.to raise_exception(CloudFoundry::Client::Exception::BadParams)
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should raise a BadParams exception when creating a provisioned service with a blank name" do
|
68
|
+
expect {
|
69
|
+
created = @cf_client.create_service("redis", "")
|
70
|
+
}.to raise_exception(CloudFoundry::Client::Exception::BadParams)
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should raise a BadParams exception when creating a provisioned service with an invalid system service" do
|
74
|
+
expect {
|
75
|
+
created = @cf_client.create_service("noservice", "redis-mock")
|
76
|
+
}.to raise_exception(CloudFoundry::Client::Exception::BadParams)
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should return true if a new provisioned service is created at target cloud" do
|
80
|
+
VCR.use_cassette("user_logged/services_create_action", :record => :new_episodes, :exclusive => true) do
|
81
|
+
created = @cf_client.create_service("redis", "redis-mock")
|
82
|
+
created.should be_true
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should raise a BadRequest exception when creating a provisioned service that already exists at target cloud" do
|
87
|
+
expect {
|
88
|
+
created = @cf_client.create_service("redis", "redis-mock")
|
89
|
+
}.to raise_exception(CloudFoundry::Client::Exception::BadRequest)
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should get a proper list of provisioned services at target cloud" do
|
93
|
+
services = @cf_client.list_services()
|
94
|
+
services.should have_at_least(1).items
|
95
|
+
service_info = services.first
|
96
|
+
service_info.should have_key :type
|
97
|
+
service_info.should have_key :vendor
|
98
|
+
service_info.should have_key :name
|
99
|
+
service_info.should have_key :version
|
100
|
+
service_info.should have_key :tier
|
101
|
+
service_info.should have_key :meta
|
102
|
+
service_info.should have_key :properties
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should raise a BadParams exception when retrieving information about a provisioned service with a blank name" do
|
106
|
+
expect {
|
107
|
+
service_info = @cf_client.service_info("")
|
108
|
+
}.to raise_exception(CloudFoundry::Client::Exception::BadParams)
|
109
|
+
end
|
110
|
+
|
111
|
+
it "should raise a NotFound exception when retrieving information about a provisioned service that does not exists at target cloud" do
|
112
|
+
expect {
|
113
|
+
service_info = @cf_client.service_info("noservice")
|
114
|
+
}.to raise_exception(CloudFoundry::Client::Exception::NotFound)
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should properly get provisioned service information from target cloud" do
|
118
|
+
service_info = @cf_client.service_info("redis-mock")
|
119
|
+
service_info.should have_key :type
|
120
|
+
service_info.should have_key :vendor
|
121
|
+
service_info.should have_key :name
|
122
|
+
service_info.should have_key :version
|
123
|
+
service_info.should have_key :tier
|
124
|
+
service_info.should have_key :meta
|
125
|
+
service_info.should have_key :properties
|
126
|
+
end
|
127
|
+
|
128
|
+
it "should raise a BadParams exception when binding to an application a provisioned service with a blank name" do
|
129
|
+
expect {
|
130
|
+
binded = @cf_client.bind_service("", "appname")
|
131
|
+
}.to raise_exception(CloudFoundry::Client::Exception::BadParams)
|
132
|
+
end
|
133
|
+
|
134
|
+
it "should raise a BadParams exception when binding a provisioned service to an application with a blank name" do
|
135
|
+
expect {
|
136
|
+
binded = @cf_client.bind_service("redis-mock", "")
|
137
|
+
}.to raise_exception(CloudFoundry::Client::Exception::BadParams)
|
138
|
+
end
|
139
|
+
|
140
|
+
it "should raise a NotFound exception when binding to an application a provisioned service that does not exists" do
|
141
|
+
expect {
|
142
|
+
binded = @cf_client.bind_service("noservice", "appname")
|
143
|
+
}.to raise_exception(CloudFoundry::Client::Exception::NotFound)
|
144
|
+
end
|
145
|
+
|
146
|
+
it "should raise a NotFound exception when binding a provisioned service to an application that does not exists" do
|
147
|
+
expect {
|
148
|
+
binded = @cf_client.bind_service("redis-mock", "appname")
|
149
|
+
}.to raise_exception(CloudFoundry::Client::Exception::NotFound)
|
150
|
+
end
|
151
|
+
|
152
|
+
it "should return true if a provisioned service is binded to an application at target cloud" do
|
153
|
+
VCR.use_cassette("user_logged/services_bind_action", :record => :new_episodes, :exclusive => true) do
|
154
|
+
manifest = {
|
155
|
+
:name => "newapp",
|
156
|
+
:uris => ["newapp.vcap.me"],
|
157
|
+
:instances => 1,
|
158
|
+
:staging => {:model => "node"},
|
159
|
+
:resources => {:memory => 64}
|
160
|
+
}
|
161
|
+
created = @cf_client.create_app("newapp", manifest)
|
162
|
+
binded = @cf_client.bind_service("redis-mock", "newapp")
|
163
|
+
binded.should be_true
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
it "should raise a BadParams exception when binding a provisioned service to an application already binded" do
|
168
|
+
expect {
|
169
|
+
binded = @cf_client.bind_service("redis-mock", "newapp")
|
170
|
+
}.to raise_exception(CloudFoundry::Client::Exception::BadParams)
|
171
|
+
end
|
172
|
+
|
173
|
+
it "should raise a BadParams exception when unbinding from an application a provisioned service with a blank name" do
|
174
|
+
expect {
|
175
|
+
unbinded = @cf_client.unbind_service("", "appname")
|
176
|
+
}.to raise_exception(CloudFoundry::Client::Exception::BadParams)
|
177
|
+
end
|
178
|
+
|
179
|
+
it "should raise a BadParams exception when unbinding a provisioned service from an application with a blank name" do
|
180
|
+
expect {
|
181
|
+
unbinded = @cf_client.unbind_service("redis-mock", "")
|
182
|
+
}.to raise_exception(CloudFoundry::Client::Exception::BadParams)
|
183
|
+
end
|
184
|
+
|
185
|
+
it "should raise a NotFound exception when unbinding a provisioned service that does not exists from an application" do
|
186
|
+
expect {
|
187
|
+
unbinded = @cf_client.unbind_service("noservice", "appname")
|
188
|
+
}.to raise_exception(CloudFoundry::Client::Exception::NotFound)
|
189
|
+
end
|
190
|
+
|
191
|
+
it "should raise a NotFound exception when unbinding a provisioned service from an application that does not exists" do
|
192
|
+
expect {
|
193
|
+
unbinded = @cf_client.unbind_service("redis-mock", "appname")
|
194
|
+
}.to raise_exception(CloudFoundry::Client::Exception::NotFound)
|
195
|
+
end
|
196
|
+
|
197
|
+
it "should return true if a provisioned service is binded to an application at target cloud" do
|
198
|
+
VCR.use_cassette("user_logged/services_unbind_action", :record => :new_episodes, :exclusive => true) do
|
199
|
+
unbinded = @cf_client.unbind_service("redis-mock", "newapp")
|
200
|
+
unbinded.should be_true
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
it "should raise a BadParams exception when unbinding a provisioned service from an application that is not binded" do
|
205
|
+
VCR.use_cassette("user_logged/services_unbind_fail_action", :record => :new_episodes, :exclusive => true) do
|
206
|
+
expect {
|
207
|
+
unbinded = @cf_client.unbind_service("redis-mock", "newapp")
|
208
|
+
}.to raise_exception(CloudFoundry::Client::Exception::BadParams)
|
209
|
+
deleted = @cf_client.delete_app("newapp")
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
it "should raise a BadParams exception when deleting a provisioned service with a blank name" do
|
214
|
+
expect {
|
215
|
+
deleted = @cf_client.delete_service("")
|
216
|
+
}.to raise_exception(CloudFoundry::Client::Exception::BadParams)
|
217
|
+
end
|
218
|
+
|
219
|
+
it "should raise a NotFound exception when deleting a provisioned service that does not exists at target cloud" do
|
220
|
+
expect {
|
221
|
+
deleted = @cf_client.delete_service("noservice")
|
222
|
+
}.to raise_exception(CloudFoundry::Client::Exception::NotFound)
|
223
|
+
end
|
224
|
+
|
225
|
+
it "should return true if a provisioned service is deleted at target cloud" do
|
226
|
+
deleted = @cf_client.delete_service("redis-mock")
|
227
|
+
deleted.should be_true
|
228
|
+
end
|
229
|
+
end
|
230
|
+
end
|
@@ -0,0 +1,367 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe "Cloudfoundry::Client::Users" do
|
4
|
+
include CfConnectionHelper
|
5
|
+
|
6
|
+
context "without a user logged in" do
|
7
|
+
before(:all) do
|
8
|
+
VCR.use_cassette("no_logged/client", :record => :new_episodes) do
|
9
|
+
@cf_client = client_no_logged()
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
use_vcr_cassette "no_logged/users", :record => :new_episodes
|
14
|
+
|
15
|
+
it "should return true if a new user is created at target cloud" do
|
16
|
+
created = @cf_client.create_user("fakeuser1@vcap.me", "foobar")
|
17
|
+
created.should be_true
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should raise an AuthError exception when listing all users at target cloud" do
|
21
|
+
expect {
|
22
|
+
users = @cf_client.list_users()
|
23
|
+
}.to raise_exception(CloudFoundry::Client::Exception::AuthError)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should raise an AuthError exception when retrieving user information from target cloud" do
|
27
|
+
expect {
|
28
|
+
user_info = @cf_client.user_info("user@vcap.me")
|
29
|
+
}.to raise_exception(CloudFoundry::Client::Exception::AuthError)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should raise an AuthError exception when updating a user at target cloud" do
|
33
|
+
expect {
|
34
|
+
updated = @cf_client.update_user("user@vcap.me", "foobar")
|
35
|
+
}.to raise_exception(CloudFoundry::Client::Exception::AuthError)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should raise an AuthError exception when deleting a user at target cloud" do
|
39
|
+
expect {
|
40
|
+
deleted = @cf_client.delete_user("user@vcap.me")
|
41
|
+
}.to raise_exception(CloudFoundry::Client::Exception::AuthError)
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should allow to proxy a user" do
|
45
|
+
proxied_user = @cf_client.set_proxy_user("user@vcap.me")
|
46
|
+
proxied_user.should eql("user@vcap.me")
|
47
|
+
proxied_user.should eql(@cf_client.proxy_user)
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should raise a Forbidden exception when retrieving proxy user account information from target cloud" do
|
51
|
+
VCR.use_cassette("no_logged/users_proxy_action", :record => :new_episodes, :exclusive => true) do
|
52
|
+
expect {
|
53
|
+
proxied_user = @cf_client.set_proxy_user("user@vcap.me")
|
54
|
+
cloud_info = @cf_client.cloud_info()
|
55
|
+
}.to raise_exception(CloudFoundry::Client::Exception::Forbidden)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should allow to unproxy a user" do
|
60
|
+
proxied_user = @cf_client.unset_proxy_user()
|
61
|
+
proxied_user.should be_nil
|
62
|
+
@cf_client.proxy_user.should be_nil
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should not get user account information from target cloud" do
|
66
|
+
VCR.use_cassette("no_logged/users_unproxy_action", :record => :new_episodes, :exclusive => true) do
|
67
|
+
proxied_user = @cf_client.unset_proxy_user()
|
68
|
+
cloud_info = @cf_client.cloud_info()
|
69
|
+
cloud_info.should_not have_key :user
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should raise a BadParams exception when login with a blank email" do
|
74
|
+
expect {
|
75
|
+
@cf_client.login("", "foobar")
|
76
|
+
}.to raise_exception(CloudFoundry::Client::Exception::BadParams)
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should raise a BadParams exception when login with a blank password" do
|
80
|
+
expect {
|
81
|
+
@cf_client.login("user@vcap.me", "")
|
82
|
+
}.to raise_exception(CloudFoundry::Client::Exception::BadParams)
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should raise a Forbidden exception if login to the target cloud fails" do
|
86
|
+
expect {
|
87
|
+
@cf_client.login("user@vcap.me", "password")
|
88
|
+
}.to raise_exception(CloudFoundry::Client::Exception::Forbidden)
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should return false if user is not logged in at target cloud" do
|
92
|
+
@cf_client.logged_in?.should be_false
|
93
|
+
@cf_client.user.should be_nil
|
94
|
+
@cf_client.auth_token.should be_nil
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should allow to login correctly at target cloud and return an auth_token" do
|
98
|
+
VCR.use_cassette("no_logged/users_login_action", :record => :new_episodes, :exclusive => true) do
|
99
|
+
auth_token = @cf_client.login("user@vcap.me", "foobar")
|
100
|
+
@cf_client.user.should_not be_nil
|
101
|
+
@cf_client.user.should eql("user@vcap.me")
|
102
|
+
@cf_client.auth_token.should_not be_nil
|
103
|
+
@cf_client.auth_token.should eql(auth_token)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
it "should return true if user is logged in at target cloud" do
|
108
|
+
VCR.use_cassette("no_logged/users_login_action", :record => :new_episodes, :exclusive => true) do
|
109
|
+
@cf_client.logged_in?.should be_true
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
context "with a user logged in" do
|
115
|
+
before(:all) do
|
116
|
+
VCR.use_cassette("user_logged/client", :record => :new_episodes) do
|
117
|
+
@cf_client = client_user_logged()
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
use_vcr_cassette "user_logged/users", :record => :new_episodes
|
122
|
+
|
123
|
+
it "should return true if a new user is created at target cloud" do
|
124
|
+
created = @cf_client.create_user("fakeuser2@vcap.me", "foobar")
|
125
|
+
created.should be_true
|
126
|
+
end
|
127
|
+
|
128
|
+
it "should raise a Forbidden exception when listing all users at target cloud" do
|
129
|
+
expect {
|
130
|
+
users = @cf_client.list_users()
|
131
|
+
}.to raise_exception(CloudFoundry::Client::Exception::Forbidden)
|
132
|
+
end
|
133
|
+
|
134
|
+
it "should raise an Forbidden exception when retrieving not own user information from target cloud" do
|
135
|
+
expect {
|
136
|
+
user_info = @cf_client.user_info("fakeuser1@vcap.me")
|
137
|
+
}.to raise_exception(CloudFoundry::Client::Exception::Forbidden)
|
138
|
+
end
|
139
|
+
|
140
|
+
it "should properly get basic user information from target cloud" do
|
141
|
+
user_info = @cf_client.user_info("user@vcap.me")
|
142
|
+
user_info.should have_key :email
|
143
|
+
end
|
144
|
+
|
145
|
+
it "should raise a Forbidden exception when updating not own user at target cloud" do
|
146
|
+
expect {
|
147
|
+
updated = @cf_client.update_user("fakeuser1@vcap.me", "foobar")
|
148
|
+
}.to raise_exception(CloudFoundry::Client::Exception::Forbidden)
|
149
|
+
end
|
150
|
+
|
151
|
+
it "should return true if a user is updated at target cloud" do
|
152
|
+
updated = @cf_client.update_user("user@vcap.me", "foobar")
|
153
|
+
updated.should be_true
|
154
|
+
end
|
155
|
+
|
156
|
+
it "should raise a Forbidden exception when deleting not now user at target cloud" do
|
157
|
+
expect {
|
158
|
+
deleted = @cf_client.delete_user("fakeuser1@vcap.me")
|
159
|
+
}.to raise_exception(CloudFoundry::Client::Exception::Forbidden)
|
160
|
+
end
|
161
|
+
|
162
|
+
it "should raise a Forbidden exception when deleting a user at target cloud" do
|
163
|
+
expect {
|
164
|
+
deleted = @cf_client.delete_user("user@vcap.me")
|
165
|
+
}.to raise_exception(CloudFoundry::Client::Exception::Forbidden)
|
166
|
+
end
|
167
|
+
|
168
|
+
it "should allow to proxy a user" do
|
169
|
+
proxied_user = @cf_client.set_proxy_user("fakeuser1@vcap.me")
|
170
|
+
proxied_user.should eql("fakeuser1@vcap.me")
|
171
|
+
proxied_user.should eql(@cf_client.proxy_user)
|
172
|
+
end
|
173
|
+
|
174
|
+
it "should raise a Forbidden exception when retrieving proxy user account information from target cloud" do
|
175
|
+
VCR.use_cassette("user_logged/users_proxy_action", :record => :new_episodes, :exclusive => true) do
|
176
|
+
expect {
|
177
|
+
proxied_user = @cf_client.set_proxy_user("fakeuser1@vcap.me")
|
178
|
+
cloud_info = @cf_client.cloud_info()
|
179
|
+
}.to raise_exception(CloudFoundry::Client::Exception::Forbidden)
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
it "should allow to unproxy a user" do
|
184
|
+
proxied_user = @cf_client.unset_proxy_user()
|
185
|
+
proxied_user.should be_nil
|
186
|
+
@cf_client.proxy_user.should be_nil
|
187
|
+
end
|
188
|
+
|
189
|
+
it "should properly get current user account information from target cloud" do
|
190
|
+
VCR.use_cassette("user_logged/users_unproxy_action", :record => :new_episodes, :exclusive => true) do
|
191
|
+
proxied_user = @cf_client.unset_proxy_user()
|
192
|
+
cloud_info = @cf_client.cloud_info()
|
193
|
+
cloud_info[:user].should eql(@user)
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
it "should return true if user is logged in at target cloud" do
|
198
|
+
@cf_client.logged_in?.should be_true
|
199
|
+
@cf_client.user.should_not be_nil
|
200
|
+
@cf_client.user.should eql(@user)
|
201
|
+
@cf_client.auth_token.should_not be_nil
|
202
|
+
@cf_client.auth_token.should eql(@auth_token)
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
context "with an admin user logged in" do
|
207
|
+
before(:all) do
|
208
|
+
VCR.use_cassette("admin_logged/client", :record => :new_episodes) do
|
209
|
+
@cf_client = client_admin_logged()
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
use_vcr_cassette "admin_logged/users", :record => :new_episodes
|
214
|
+
|
215
|
+
it "should raise a BadParams exception when creating a user with a blank email" do
|
216
|
+
expect {
|
217
|
+
created = @cf_client.create_user("", "foobar")
|
218
|
+
}.to raise_exception(CloudFoundry::Client::Exception::BadParams)
|
219
|
+
end
|
220
|
+
|
221
|
+
it "should raise a BadParams exception when creating a user with a blank password" do
|
222
|
+
expect {
|
223
|
+
created = @cf_client.create_user("fakeuser@vcap.me", "")
|
224
|
+
}.to raise_exception(CloudFoundry::Client::Exception::BadParams)
|
225
|
+
end
|
226
|
+
|
227
|
+
it "should raise a BadRequest exception when creating a user that already exists at target cloud" do
|
228
|
+
expect {
|
229
|
+
created = @cf_client.create_user("user@vcap.me", "foobar")
|
230
|
+
}.to raise_exception(CloudFoundry::Client::Exception::BadRequest)
|
231
|
+
end
|
232
|
+
|
233
|
+
it "should return true if a new user is created at target cloud" do
|
234
|
+
VCR.use_cassette("admin_logged/users_create_action", :record => :new_episodes, :exclusive => true) do
|
235
|
+
created = @cf_client.create_user("fakeuser@vcap.me", "foobar")
|
236
|
+
created.should be_true
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
240
|
+
it "should get a proper list of users at target cloud" do
|
241
|
+
users = @cf_client.list_users()
|
242
|
+
users.should have_at_least(1).items
|
243
|
+
user_info = users.first
|
244
|
+
user_info.should have_key :email
|
245
|
+
user_info.should have_key :admin
|
246
|
+
user_info.should have_key :apps
|
247
|
+
end
|
248
|
+
|
249
|
+
it "should raise a BadParams exception when retrieving information about a user with a blank email" do
|
250
|
+
expect {
|
251
|
+
user_info = @cf_client.user_info("")
|
252
|
+
}.to raise_exception(CloudFoundry::Client::Exception::BadParams)
|
253
|
+
end
|
254
|
+
|
255
|
+
it "should raise a Forbidden exception when retrieving information about a user that does not exists at target cloud" do
|
256
|
+
expect {
|
257
|
+
user_info = @cf_client.user_info("nouser@vcap.me")
|
258
|
+
}.to raise_exception(CloudFoundry::Client::Exception::Forbidden)
|
259
|
+
end
|
260
|
+
|
261
|
+
it "should properly get basic user information from target cloud" do
|
262
|
+
user_info = @cf_client.user_info("fakeuser@vcap.me")
|
263
|
+
user_info.should have_key :email
|
264
|
+
end
|
265
|
+
|
266
|
+
it "should raise a BadParams exception when updating a user with a blank email" do
|
267
|
+
expect {
|
268
|
+
created = @cf_client.update_user("", "foobar")
|
269
|
+
}.to raise_exception(CloudFoundry::Client::Exception::BadParams)
|
270
|
+
end
|
271
|
+
|
272
|
+
it "should raise a BadParams exception when updating a user with a blank password" do
|
273
|
+
expect {
|
274
|
+
created = @cf_client.update_user("fakeuser@vcap.me", "")
|
275
|
+
}.to raise_exception(CloudFoundry::Client::Exception::BadParams)
|
276
|
+
end
|
277
|
+
|
278
|
+
it "should raise a Forbidden exception when updating a user that does not exists at target cloud" do
|
279
|
+
expect {
|
280
|
+
updated = @cf_client.update_user("nouser@vcap.me", "foobar")
|
281
|
+
}.to raise_exception(CloudFoundry::Client::Exception::Forbidden)
|
282
|
+
end
|
283
|
+
|
284
|
+
it "should return true if a user is updated at target cloud" do
|
285
|
+
updated = @cf_client.update_user("fakeuser@vcap.me", "foobar")
|
286
|
+
updated.should be_true
|
287
|
+
end
|
288
|
+
|
289
|
+
it "should raise a BadParams exception when deleting a user with a blank email" do
|
290
|
+
expect {
|
291
|
+
created = @cf_client.delete_user("")
|
292
|
+
}.to raise_exception(CloudFoundry::Client::Exception::BadParams)
|
293
|
+
end
|
294
|
+
|
295
|
+
it "should raise a Forbidden exception when deleting a user that does not exists at target cloud" do
|
296
|
+
expect {
|
297
|
+
deleted = @cf_client.delete_user("nouser@vcap.me")
|
298
|
+
}.to raise_exception(CloudFoundry::Client::Exception::Forbidden)
|
299
|
+
end
|
300
|
+
|
301
|
+
it "should return true if a user is deleted at target cloud" do
|
302
|
+
deleted = @cf_client.delete_user("fakeuser@vcap.me")
|
303
|
+
deleted.should be_true
|
304
|
+
end
|
305
|
+
|
306
|
+
it "should return true if a user is deleted at target cloud" do
|
307
|
+
deleted = @cf_client.delete_user("fakeuser1@vcap.me")
|
308
|
+
deleted.should be_true
|
309
|
+
end
|
310
|
+
|
311
|
+
it "should return true if a user is deleted at target cloud" do
|
312
|
+
deleted = @cf_client.delete_user("fakeuser2@vcap.me")
|
313
|
+
deleted.should be_true
|
314
|
+
end
|
315
|
+
|
316
|
+
it "should allow to proxy a user" do
|
317
|
+
proxied_user = @cf_client.set_proxy_user("user@vcap.me")
|
318
|
+
proxied_user.should eql("user@vcap.me")
|
319
|
+
proxied_user.should eql(@cf_client.proxy_user)
|
320
|
+
end
|
321
|
+
|
322
|
+
it "should properly get proxy user account information from target cloud" do
|
323
|
+
VCR.use_cassette("admin_logged/users_proxy_action", :record => :new_episodes, :exclusive => true) do
|
324
|
+
proxied_user = @cf_client.set_proxy_user("user@vcap.me")
|
325
|
+
cloud_info = @cf_client.cloud_info()
|
326
|
+
cloud_info[:user].should eql("user@vcap.me")
|
327
|
+
cloud_info[:user].should eql(@cf_client.proxy_user)
|
328
|
+
end
|
329
|
+
end
|
330
|
+
|
331
|
+
it "should allow to proxy a user that does not exists at target cloud" do
|
332
|
+
proxied_user = @cf_client.set_proxy_user("nouser@vcap.me")
|
333
|
+
proxied_user.should eql("nouser@vcap.me")
|
334
|
+
proxied_user.should eql(@cf_client.proxy_user)
|
335
|
+
end
|
336
|
+
|
337
|
+
it "should raise a Forbidden exception when retrieving proxy user account information that does not exists at target cloud" do
|
338
|
+
VCR.use_cassette("admin_logged/users_proxy_nouser_action", :record => :new_episodes, :exclusive => true) do
|
339
|
+
expect {
|
340
|
+
proxied_user = @cf_client.set_proxy_user("nouser@vcap.me")
|
341
|
+
cloud_info = @cf_client.cloud_info()
|
342
|
+
}.to raise_exception(CloudFoundry::Client::Exception::Forbidden)
|
343
|
+
end
|
344
|
+
end
|
345
|
+
|
346
|
+
it "should allow to unproxy a user" do
|
347
|
+
proxied_user = @cf_client.unset_proxy_user()
|
348
|
+
proxied_user.should be_nil
|
349
|
+
@cf_client.proxy_user.should be_nil
|
350
|
+
end
|
351
|
+
|
352
|
+
it "should properly get current user account information from target cloud" do
|
353
|
+
VCR.use_cassette("admin_logged/users_unproxy_action", :record => :new_episodes, :exclusive => true) do
|
354
|
+
proxied_user = @cf_client.unset_proxy_user()
|
355
|
+
cloud_info = @cf_client.cloud_info()
|
356
|
+
cloud_info[:user].should eql(@user)
|
357
|
+
end
|
358
|
+
end
|
359
|
+
|
360
|
+
it "should return true if user is logged in at target cloud" do
|
361
|
+
@cf_client.logged_in?.should be_true
|
362
|
+
@cf_client.user.should_not be_nil
|
363
|
+
@cf_client.user.should eql(@user)
|
364
|
+
@cf_client.auth_token.should eql(@auth_token)
|
365
|
+
end
|
366
|
+
end
|
367
|
+
end
|