new_cfoundry 4.8.2 → 4.8.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitmodules +1 -1
- data/VERSION +1 -1
- data/cfoundry.gemspec +1 -0
- data/lib/cfoundry/auth_token.rb +4 -5
- data/lib/cfoundry/baseclient.rb +10 -2
- data/lib/cfoundry/uaaclient.rb +4 -3
- data/lib/cfoundry/v2/app.rb +10 -0
- data/lib/cfoundry/v2/base.rb +4 -0
- data/lib/cfoundry/v2/client.rb +2 -2
- data/lib/cfoundry/v2/managed_service_instance.rb +1 -0
- data/lib/cfoundry/v2/model_magic/to_many.rb +7 -0
- data/lib/cfoundry/v2/user.rb +4 -0
- data/lib/cfoundry/v2/user_provided_service_instance.rb +1 -0
- data/lib/cfoundry.rb +1 -0
- data/spec/cfoundry/auth_token_spec.rb +7 -8
- data/spec/cfoundry/v2/client_spec.rb +1 -1
- data/spec/cfoundry/v2/organization_spec.rb +147 -0
- data/spec/cfoundry/v2/space_spec.rb +139 -2
- metadata +126 -115
- data/vendor/errors/README.md +0 -4
- data/vendor/errors/v1.yml +0 -189
- data/vendor/errors/v2.yml +0 -384
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1db0e9895e11eccd067274b7989b8c7d630da182
|
4
|
+
data.tar.gz: 0777ad44dc209588fa57c28e48ac3aafbc82eb36
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8038fb2fd9388649c229c1c614b00a4f0bc52b019721e2128b17ee752be739f5f844351990c934a1d2e4c5636805db71f66da0611dc3941cc4fc80287cb48faf
|
7
|
+
data.tar.gz: d6eadc54a8ce1530182213597db2800b0f978942bee0c9d33521f29b38ca4f5bd79ba85215b952a25a12749b1c462872b3089928a46f91454a84c27922ea20ad
|
data/.gitmodules
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
4.8.
|
1
|
+
4.8.3
|
data/cfoundry.gemspec
CHANGED
@@ -20,6 +20,7 @@ Gem::Specification.new do |s|
|
|
20
20
|
|
21
21
|
s.add_dependency "activemodel", "<5.0.0", ">= 3.2.13"
|
22
22
|
s.add_dependency "cf-uaa-lib", "~> 2.0.0"
|
23
|
+
s.add_dependency "jwt", "~> 1.5"
|
23
24
|
s.add_dependency "multi_json", "~> 1.7"
|
24
25
|
s.add_dependency "multipart-post", "~> 1.1"
|
25
26
|
s.add_dependency "rubyzip", "~> 0.9"
|
data/lib/cfoundry/auth_token.rb
CHANGED
@@ -38,12 +38,11 @@ module CFoundry
|
|
38
38
|
return @token_data if @token_data
|
39
39
|
return {} unless @auth_header
|
40
40
|
|
41
|
-
|
42
|
-
data_json = json_hashes.sub(JSON_HASH, "")[JSON_HASH]
|
41
|
+
data_json = @auth_header.split(" ", 2).last
|
43
42
|
return {} unless data_json
|
44
43
|
|
45
|
-
@token_data =
|
46
|
-
rescue
|
44
|
+
@token_data = JWT.decode(data_json, nil, false)[0].symbolize_keys
|
45
|
+
rescue
|
47
46
|
{}
|
48
47
|
end
|
49
48
|
|
@@ -53,7 +52,7 @@ module CFoundry
|
|
53
52
|
end
|
54
53
|
|
55
54
|
def expiration
|
56
|
-
Time.at(token_data[:exp])
|
55
|
+
token_data[:exp].nil? ? Time.at(0) : Time.at(token_data[:exp])
|
57
56
|
end
|
58
57
|
|
59
58
|
def expires_soon?
|
data/lib/cfoundry/baseclient.rb
CHANGED
@@ -12,13 +12,18 @@ module CFoundry
|
|
12
12
|
extend Forwardable
|
13
13
|
|
14
14
|
attr_reader :rest_client
|
15
|
+
attr_accessor :client_id, :client_secret
|
15
16
|
|
16
17
|
def_delegators :rest_client, :target, :target=, :token,
|
17
18
|
:trace, :backtrace, :backtrace=, :log, :log=,
|
18
19
|
:http_proxy, :http_proxy=, :https_proxy, :https_proxy=
|
19
20
|
|
20
|
-
def initialize(target, token = nil)
|
21
|
+
def initialize(target, token = nil, options = {})
|
21
22
|
@rest_client = CFoundry::RestClient.new(target, token)
|
23
|
+
@rest_client.http_proxy = options[:http_proxy]
|
24
|
+
@rest_client.https_proxy = options[:https_proxy]
|
25
|
+
self.client_id = options[:client_id]
|
26
|
+
self.client_secret = options[:client_secret]
|
22
27
|
self.trace = false
|
23
28
|
self.backtrace = false
|
24
29
|
self.log = false
|
@@ -29,7 +34,10 @@ module CFoundry
|
|
29
34
|
endpoint = info[:authorization_endpoint]
|
30
35
|
|
31
36
|
if endpoint
|
32
|
-
uaa = CFoundry::UAAClient.new(endpoint,
|
37
|
+
uaa = CFoundry::UAAClient.new(endpoint,
|
38
|
+
client_id || "cf",
|
39
|
+
client_secret: client_secret,
|
40
|
+
http_proxy: http_proxy, https_proxy: https_proxy)
|
33
41
|
uaa.trace = trace
|
34
42
|
uaa.token = token
|
35
43
|
uaa
|
data/lib/cfoundry/uaaclient.rb
CHANGED
@@ -3,11 +3,12 @@ require "uaa"
|
|
3
3
|
|
4
4
|
module CFoundry
|
5
5
|
class UAAClient
|
6
|
-
attr_accessor :target, :client_id, :token, :trace, :http_proxy, :https_proxy
|
6
|
+
attr_accessor :target, :client_id, :client_secret, :token, :trace, :http_proxy, :https_proxy
|
7
7
|
|
8
8
|
def initialize(target, client_id = "cf", options = {})
|
9
9
|
@target = target
|
10
10
|
@client_id = client_id
|
11
|
+
@client_secret = options[:client_secret]
|
11
12
|
@http_proxy = options[:http_proxy]
|
12
13
|
@https_proxy = options[:https_proxy]
|
13
14
|
@uaa_info_client = uaa_info_client_for(target)
|
@@ -102,7 +103,7 @@ module CFoundry
|
|
102
103
|
end
|
103
104
|
|
104
105
|
def token_issuer
|
105
|
-
@token_issuer ||= CF::UAA::TokenIssuer.new(target, client_id,
|
106
|
+
@token_issuer ||= CF::UAA::TokenIssuer.new(target, client_id, client_secret,
|
106
107
|
:symbolize_keys => true,
|
107
108
|
:http_proxy => @http_proxy,
|
108
109
|
:https_proxy => @https_proxy
|
@@ -113,7 +114,7 @@ module CFoundry
|
|
113
114
|
|
114
115
|
def scim
|
115
116
|
auth_header = token && token.auth_header
|
116
|
-
scim = CF::UAA::Scim.new(uaa_url, auth_header, :symbolize_keys => true)
|
117
|
+
scim = CF::UAA::Scim.new(uaa_url, auth_header, :symbolize_keys => true, :http_proxy => @http_proxy, :https_proxy => @https_proxy)
|
117
118
|
scim.logger.level = @trace ? Logger::Severity::TRACE : 1
|
118
119
|
scim
|
119
120
|
end
|
data/lib/cfoundry/v2/app.rb
CHANGED
@@ -71,6 +71,16 @@ module CFoundry::V2
|
|
71
71
|
stats
|
72
72
|
end
|
73
73
|
|
74
|
+
def system_env
|
75
|
+
system_env = {}
|
76
|
+
|
77
|
+
@client.base.env(@guid).each do |idx, info|
|
78
|
+
system_env[idx.to_s] = info
|
79
|
+
end
|
80
|
+
|
81
|
+
system_env
|
82
|
+
end
|
83
|
+
|
74
84
|
def services
|
75
85
|
service_bindings.collect(&:service_instance)
|
76
86
|
end
|
data/lib/cfoundry/v2/base.rb
CHANGED
data/lib/cfoundry/v2/client.rb
CHANGED
@@ -24,8 +24,8 @@ module CFoundry::V2
|
|
24
24
|
# Create a new Client for interfacing with the given target.
|
25
25
|
#
|
26
26
|
# A token may also be provided to skip the login step.
|
27
|
-
def initialize(target, token = nil)
|
28
|
-
@base = Base.new(target, token)
|
27
|
+
def initialize(target, token = nil, options = {})
|
28
|
+
@base = Base.new(target, token, options)
|
29
29
|
end
|
30
30
|
|
31
31
|
def version
|
@@ -73,6 +73,13 @@ module CFoundry::V2::ModelMagic
|
|
73
73
|
@client.base.put("v2", plural_object_name, @guid, plural, x.guid, :accept => :json)
|
74
74
|
end
|
75
75
|
|
76
|
+
#
|
77
|
+
# def add_MODEL_by_username
|
78
|
+
#
|
79
|
+
define_method(:"add_#{singular}_by_username") do |username|
|
80
|
+
@client.base.put("v2", plural_object_name, @guid, plural, :accept => :json, :content => :json, :payload => {:username => username.to_s})
|
81
|
+
end
|
82
|
+
|
76
83
|
#
|
77
84
|
# def create_MODEL
|
78
85
|
#
|
data/lib/cfoundry/v2/user.rb
CHANGED
data/lib/cfoundry.rb
CHANGED
@@ -3,7 +3,7 @@ require "spec_helper"
|
|
3
3
|
|
4
4
|
describe CFoundry::AuthToken do
|
5
5
|
describe ".from_uaa_token_info" do
|
6
|
-
let(:access_token) {
|
6
|
+
let(:access_token) { JWT.encode({user_id: "a6", email: "a@b.com"}, nil, 'none') }
|
7
7
|
let(:info_hash) do
|
8
8
|
{
|
9
9
|
:token_type => "bearer",
|
@@ -70,16 +70,15 @@ describe CFoundry::AuthToken do
|
|
70
70
|
end
|
71
71
|
|
72
72
|
describe '#token_data' do
|
73
|
-
|
74
|
-
it { should eq({}) }
|
73
|
+
it { subject.token_data.should eq({}) }
|
75
74
|
end
|
76
75
|
end
|
77
76
|
end
|
78
77
|
end
|
79
78
|
|
80
79
|
describe ".from_hash(hash)" do
|
81
|
-
let(:token_data) {
|
82
|
-
let(:token) {
|
80
|
+
let(:token_data) { {baz:"buzz"} }
|
81
|
+
let(:token) { JWT.encode(token_data, nil, 'none') }
|
83
82
|
|
84
83
|
let(:hash) do
|
85
84
|
{
|
@@ -113,8 +112,8 @@ describe CFoundry::AuthToken do
|
|
113
112
|
end
|
114
113
|
|
115
114
|
describe "#auth_header=" do
|
116
|
-
let(:access_token) {
|
117
|
-
let(:other_access_token) {
|
115
|
+
let(:access_token) { JWT.encode({ user_id: "a6", email: "a@b.com" }, nil, 'none') }
|
116
|
+
let(:other_access_token) { JWT.encode({ user_id: "b6", email: "a@b.com"}, nil, 'none') }
|
118
117
|
|
119
118
|
subject { CFoundry::AuthToken.new("bearer #{access_token}") }
|
120
119
|
|
@@ -127,7 +126,7 @@ describe CFoundry::AuthToken do
|
|
127
126
|
end
|
128
127
|
|
129
128
|
describe "#expires_soon?" do
|
130
|
-
let(:access_token) {
|
129
|
+
let(:access_token) { JWT.encode({ exp: expiration.to_i }, nil, 'none') }
|
131
130
|
|
132
131
|
subject { CFoundry::AuthToken.new("bearer #{access_token}") }
|
133
132
|
|
@@ -40,7 +40,7 @@ module CFoundry
|
|
40
40
|
|
41
41
|
context "when there is access_token_data" do
|
42
42
|
let(:token_data) { {:user_id => "123", :email => "guy@example.com"} }
|
43
|
-
let(:auth_header) {
|
43
|
+
let(:auth_header) { JWT.encode(token_data, nil, false) }
|
44
44
|
let(:token) do
|
45
45
|
CFoundry::AuthToken.new("bearer #{auth_header}", "some-refresh-token")
|
46
46
|
end
|
@@ -130,6 +130,153 @@ json
|
|
130
130
|
expect(WebMock).to have_requested(:delete, "http://api.example.com/v2/spaces/#{space2.guid}/developers/#{user.guid}")
|
131
131
|
end
|
132
132
|
end
|
133
|
+
|
134
|
+
describe "#add_manager_by_username" do
|
135
|
+
let(:user) { build(:user) }
|
136
|
+
let(:organization) do
|
137
|
+
build(:organization, client: client, users: [],
|
138
|
+
managers: [], billing_managers: [], auditors: [])
|
139
|
+
end
|
140
|
+
|
141
|
+
let(:status) { 201 }
|
142
|
+
|
143
|
+
let(:add_manager_org_response) do
|
144
|
+
<<-json
|
145
|
+
{
|
146
|
+
"metadata": {
|
147
|
+
"guid": "8d2238e2-2fb3-4ede-b188-1fd3a533c4b4",
|
148
|
+
"url": "/v2/organizations/8d2238e2-2fb3-4ede-b188-1fd3a533c4b4",
|
149
|
+
"created_at": "2015-11-30T23:38:59Z",
|
150
|
+
"updated_at": null
|
151
|
+
},
|
152
|
+
"entity": {
|
153
|
+
"name": "name-2523",
|
154
|
+
"billing_enabled": false,
|
155
|
+
"quota_definition_guid": "0e36ae22-a752-4e37-9dbf-0bac5c1b93c1",
|
156
|
+
"status": "active",
|
157
|
+
"quota_definition_url": "/v2/quota_definitions/0e36ae22-a752-4e37-9dbf-0bac5c1b93c1",
|
158
|
+
"spaces_url": "/v2/organizations/8d2238e2-2fb3-4ede-b188-1fd3a533c4b4/spaces",
|
159
|
+
"domains_url": "/v2/organizations/8d2238e2-2fb3-4ede-b188-1fd3a533c4b4/domains",
|
160
|
+
"private_domains_url": "/v2/organizations/8d2238e2-2fb3-4ede-b188-1fd3a533c4b4/private_domains",
|
161
|
+
"users_url": "/v2/organizations/8d2238e2-2fb3-4ede-b188-1fd3a533c4b4/users",
|
162
|
+
"managers_url": "/v2/organizations/8d2238e2-2fb3-4ede-b188-1fd3a533c4b4/managers",
|
163
|
+
"billing_managers_url": "/v2/organizations/8d2238e2-2fb3-4ede-b188-1fd3a533c4b4/billing_managers",
|
164
|
+
"auditors_url": "/v2/organizations/8d2238e2-2fb3-4ede-b188-1fd3a533c4b4/auditors",
|
165
|
+
"app_events_url": "/v2/organizations/8d2238e2-2fb3-4ede-b188-1fd3a533c4b4/app_events",
|
166
|
+
"space_quota_definitions_url": "/v2/organizations/8d2238e2-2fb3-4ede-b188-1fd3a533c4b4/space_quota_definitions"
|
167
|
+
}
|
168
|
+
}
|
169
|
+
json
|
170
|
+
end
|
171
|
+
|
172
|
+
before do
|
173
|
+
allow(user).to receive(:username).and_return("user_1")
|
174
|
+
stub_request(:put, "http://api.example.com/v2/organizations/#{organization.guid}/managers").to_return(status: status, body: add_manager_org_response)
|
175
|
+
end
|
176
|
+
|
177
|
+
it "adds the given user to OrgManager in the org" do
|
178
|
+
organization.add_manager_by_username("user_1")
|
179
|
+
expect(WebMock).to have_requested(:put, "http://api.example.com/v2/organizations/#{organization.guid}/managers")
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
describe "#add_billing_manager_by_username" do
|
184
|
+
let(:user) { build(:user) }
|
185
|
+
let(:organization) do
|
186
|
+
build(:organization, client: client, users: [],
|
187
|
+
managers: [], billing_managers: [], auditors: [])
|
188
|
+
end
|
189
|
+
|
190
|
+
let(:status) { 201 }
|
191
|
+
|
192
|
+
let(:add_billing_manager_org_response) do
|
193
|
+
<<-json
|
194
|
+
{
|
195
|
+
"metadata": {
|
196
|
+
"guid": "c8d4f13c-8880-4859-8e03-fc690efd8f48",
|
197
|
+
"url": "/v2/organizations/c8d4f13c-8880-4859-8e03-fc690efd8f48",
|
198
|
+
"created_at": "2015-11-30T23:38:58Z",
|
199
|
+
"updated_at": null
|
200
|
+
},
|
201
|
+
"entity": {
|
202
|
+
"name": "name-2470",
|
203
|
+
"billing_enabled": false,
|
204
|
+
"quota_definition_guid": "4ad7378e-e90a-4714-b906-a451dd0d5507",
|
205
|
+
"status": "active",
|
206
|
+
"quota_definition_url": "/v2/quota_definitions/4ad7378e-e90a-4714-b906-a451dd0d5507",
|
207
|
+
"spaces_url": "/v2/organizations/c8d4f13c-8880-4859-8e03-fc690efd8f48/spaces",
|
208
|
+
"domains_url": "/v2/organizations/c8d4f13c-8880-4859-8e03-fc690efd8f48/domains",
|
209
|
+
"private_domains_url": "/v2/organizations/c8d4f13c-8880-4859-8e03-fc690efd8f48/private_domains",
|
210
|
+
"users_url": "/v2/organizations/c8d4f13c-8880-4859-8e03-fc690efd8f48/users",
|
211
|
+
"managers_url": "/v2/organizations/c8d4f13c-8880-4859-8e03-fc690efd8f48/managers",
|
212
|
+
"billing_managers_url": "/v2/organizations/c8d4f13c-8880-4859-8e03-fc690efd8f48/billing_managers",
|
213
|
+
"auditors_url": "/v2/organizations/c8d4f13c-8880-4859-8e03-fc690efd8f48/auditors",
|
214
|
+
"app_events_url": "/v2/organizations/c8d4f13c-8880-4859-8e03-fc690efd8f48/app_events",
|
215
|
+
"space_quota_definitions_url": "/v2/organizations/c8d4f13c-8880-4859-8e03-fc690efd8f48/space_quota_definitions"
|
216
|
+
}
|
217
|
+
}
|
218
|
+
json
|
219
|
+
end
|
220
|
+
|
221
|
+
before do
|
222
|
+
allow(user).to receive(:username).and_return("user_1")
|
223
|
+
stub_request(:put, "http://api.example.com/v2/organizations/#{organization.guid}/billing_managers").to_return(status: status, body: add_billing_manager_org_response)
|
224
|
+
end
|
225
|
+
|
226
|
+
it "adds the given user to OrgBillingMnager in the org" do
|
227
|
+
organization.add_billing_manager_by_username("user_1")
|
228
|
+
expect(WebMock).to have_requested(:put, "http://api.example.com/v2/organizations/#{organization.guid}/billing_managers")
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
describe "#add_auditor_by_username" do
|
233
|
+
let(:user) { build(:user) }
|
234
|
+
let(:organization) do
|
235
|
+
build(:organization, client: client, users: [],
|
236
|
+
managers: [], billing_managers: [], auditors: [])
|
237
|
+
end
|
238
|
+
|
239
|
+
let(:status) { 201 }
|
240
|
+
|
241
|
+
let(:add_auditor_org_response) do
|
242
|
+
<<-json
|
243
|
+
{
|
244
|
+
"metadata": {
|
245
|
+
"guid": "50dfb04d-cd49-477d-a54c-32e00e180022",
|
246
|
+
"url": "/v2/organizations/50dfb04d-cd49-477d-a54c-32e00e180022",
|
247
|
+
"created_at": "2015-11-30T23:38:58Z",
|
248
|
+
"updated_at": null
|
249
|
+
},
|
250
|
+
"entity": {
|
251
|
+
"name": "name-2476",
|
252
|
+
"billing_enabled": false,
|
253
|
+
"quota_definition_guid": "8de0754e-bb1e-4739-be6e-91104bbab281",
|
254
|
+
"status": "active",
|
255
|
+
"quota_definition_url": "/v2/quota_definitions/8de0754e-bb1e-4739-be6e-91104bbab281",
|
256
|
+
"spaces_url": "/v2/organizations/50dfb04d-cd49-477d-a54c-32e00e180022/spaces",
|
257
|
+
"domains_url": "/v2/organizations/50dfb04d-cd49-477d-a54c-32e00e180022/domains",
|
258
|
+
"private_domains_url": "/v2/organizations/50dfb04d-cd49-477d-a54c-32e00e180022/private_domains",
|
259
|
+
"users_url": "/v2/organizations/50dfb04d-cd49-477d-a54c-32e00e180022/users",
|
260
|
+
"managers_url": "/v2/organizations/50dfb04d-cd49-477d-a54c-32e00e180022/managers",
|
261
|
+
"billing_managers_url": "/v2/organizations/50dfb04d-cd49-477d-a54c-32e00e180022/billing_managers",
|
262
|
+
"auditors_url": "/v2/organizations/50dfb04d-cd49-477d-a54c-32e00e180022/auditors",
|
263
|
+
"app_events_url": "/v2/organizations/50dfb04d-cd49-477d-a54c-32e00e180022/app_events",
|
264
|
+
"space_quota_definitions_url": "/v2/organizations/50dfb04d-cd49-477d-a54c-32e00e180022/space_quota_definitions"
|
265
|
+
}
|
266
|
+
}
|
267
|
+
json
|
268
|
+
end
|
269
|
+
|
270
|
+
before do
|
271
|
+
allow(user).to receive(:username).and_return("user_1")
|
272
|
+
stub_request(:put, "http://api.example.com/v2/organizations/#{organization.guid}/auditors").to_return(status: status, body: add_auditor_org_response)
|
273
|
+
end
|
274
|
+
|
275
|
+
it "adds the given user to OrgAuditor in the org" do
|
276
|
+
organization.add_auditor_by_username("user_1")
|
277
|
+
expect(WebMock).to have_requested(:put, "http://api.example.com/v2/organizations/#{organization.guid}/auditors")
|
278
|
+
end
|
279
|
+
end
|
133
280
|
end
|
134
281
|
end
|
135
282
|
end
|
@@ -3,10 +3,147 @@ require "spec_helper"
|
|
3
3
|
module CFoundry
|
4
4
|
module V2
|
5
5
|
describe Space do
|
6
|
+
let(:client) { build(:client) }
|
7
|
+
let(:space) { build(:space, :client => client) }
|
8
|
+
|
6
9
|
it_behaves_like "a summarizeable model" do
|
10
|
+
subject { space }
|
7
11
|
let(:summary_attributes) { {:name => "fizzbuzz"} }
|
8
|
-
|
9
|
-
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "#add_manager_by_username" do
|
15
|
+
let(:user) { build(:user) }
|
16
|
+
let(:status) { 201 }
|
17
|
+
|
18
|
+
let(:add_manager_space_response) do
|
19
|
+
<<-json
|
20
|
+
{
|
21
|
+
"metadata": {
|
22
|
+
"guid": "4351f97b-3485-4738-821b-5bf77bed44eb",
|
23
|
+
"url": "/v2/spaces/4351f97b-3485-4738-821b-5bf77bed44eb",
|
24
|
+
"created_at": "2015-11-30T23:38:28Z",
|
25
|
+
"updated_at": null
|
26
|
+
},
|
27
|
+
"entity": {
|
28
|
+
"name": "name-98",
|
29
|
+
"organization_guid": "a488910d-2d69-46a2-bf6e-319248e03705",
|
30
|
+
"space_quota_definition_guid": null,
|
31
|
+
"allow_ssh": true,
|
32
|
+
"organization_url": "/v2/organizations/a488910d-2d69-46a2-bf6e-319248e03705",
|
33
|
+
"developers_url": "/v2/spaces/4351f97b-3485-4738-821b-5bf77bed44eb/developers",
|
34
|
+
"managers_url": "/v2/spaces/4351f97b-3485-4738-821b-5bf77bed44eb/managers",
|
35
|
+
"auditors_url": "/v2/spaces/4351f97b-3485-4738-821b-5bf77bed44eb/auditors",
|
36
|
+
"apps_url": "/v2/spaces/4351f97b-3485-4738-821b-5bf77bed44eb/apps",
|
37
|
+
"routes_url": "/v2/spaces/4351f97b-3485-4738-821b-5bf77bed44eb/routes",
|
38
|
+
"domains_url": "/v2/spaces/4351f97b-3485-4738-821b-5bf77bed44eb/domains",
|
39
|
+
"service_instances_url": "/v2/spaces/4351f97b-3485-4738-821b-5bf77bed44eb/service_instances",
|
40
|
+
"app_events_url": "/v2/spaces/4351f97b-3485-4738-821b-5bf77bed44eb/app_events",
|
41
|
+
"events_url": "/v2/spaces/4351f97b-3485-4738-821b-5bf77bed44eb/events",
|
42
|
+
"security_groups_url": "/v2/spaces/4351f97b-3485-4738-821b-5bf77bed44eb/security_groups"
|
43
|
+
}
|
44
|
+
}
|
45
|
+
json
|
46
|
+
end
|
47
|
+
|
48
|
+
before do
|
49
|
+
allow(user).to receive(:username).and_return("user_1")
|
50
|
+
stub_request(:put, "http://api.example.com/v2/spaces/#{space.guid}/managers").to_return(status: status, body: add_manager_space_response)
|
51
|
+
end
|
52
|
+
|
53
|
+
it "adds the given user to SpaceManager in the space" do
|
54
|
+
space.add_manager_by_username("user_1")
|
55
|
+
expect(WebMock).to have_requested(:put, "http://api.example.com/v2/spaces/#{space.guid}/managers")
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "#add_auditor_by_username" do
|
60
|
+
let(:user) { build(:user) }
|
61
|
+
let(:status) { 201 }
|
62
|
+
|
63
|
+
let(:add_auditor_space_response) do
|
64
|
+
<<-json
|
65
|
+
{
|
66
|
+
"metadata": {
|
67
|
+
"guid": "873193ee-878c-436f-80bd-10d68927937d",
|
68
|
+
"url": "/v2/spaces/873193ee-878c-436f-80bd-10d68927937d",
|
69
|
+
"created_at": "2015-11-30T23:38:28Z",
|
70
|
+
"updated_at": null
|
71
|
+
},
|
72
|
+
"entity": {
|
73
|
+
"name": "name-101",
|
74
|
+
"organization_guid": "5fddaf61-092d-4b33-9490-8350963db89e",
|
75
|
+
"space_quota_definition_guid": null,
|
76
|
+
"allow_ssh": true,
|
77
|
+
"organization_url": "/v2/organizations/5fddaf61-092d-4b33-9490-8350963db89e",
|
78
|
+
"developers_url": "/v2/spaces/873193ee-878c-436f-80bd-10d68927937d/developers",
|
79
|
+
"managers_url": "/v2/spaces/873193ee-878c-436f-80bd-10d68927937d/managers",
|
80
|
+
"auditors_url": "/v2/spaces/873193ee-878c-436f-80bd-10d68927937d/auditors",
|
81
|
+
"apps_url": "/v2/spaces/873193ee-878c-436f-80bd-10d68927937d/apps",
|
82
|
+
"routes_url": "/v2/spaces/873193ee-878c-436f-80bd-10d68927937d/routes",
|
83
|
+
"domains_url": "/v2/spaces/873193ee-878c-436f-80bd-10d68927937d/domains",
|
84
|
+
"service_instances_url": "/v2/spaces/873193ee-878c-436f-80bd-10d68927937d/service_instances",
|
85
|
+
"app_events_url": "/v2/spaces/873193ee-878c-436f-80bd-10d68927937d/app_events",
|
86
|
+
"events_url": "/v2/spaces/873193ee-878c-436f-80bd-10d68927937d/events",
|
87
|
+
"security_groups_url": "/v2/spaces/873193ee-878c-436f-80bd-10d68927937d/security_groups"
|
88
|
+
}
|
89
|
+
}
|
90
|
+
json
|
91
|
+
end
|
92
|
+
|
93
|
+
before do
|
94
|
+
allow(user).to receive(:username).and_return("user_1")
|
95
|
+
stub_request(:put, "http://api.example.com/v2/spaces/#{space.guid}/auditors").to_return(status: status, body: add_auditor_space_response)
|
96
|
+
end
|
97
|
+
|
98
|
+
it "adds the given user to SpaceAuditor in the space" do
|
99
|
+
space.add_auditor_by_username("user_1")
|
100
|
+
expect(WebMock).to have_requested(:put, "http://api.example.com/v2/spaces/#{space.guid}/auditors")
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
describe "#add_developer_by_username" do
|
105
|
+
let(:user) { build(:user) }
|
106
|
+
let(:status) { 201 }
|
107
|
+
|
108
|
+
let(:add_developer_space_response) do
|
109
|
+
<<-json
|
110
|
+
{
|
111
|
+
"metadata": {
|
112
|
+
"guid": "b6d11f17-1cea-4c00-a951-fef3223b8c84",
|
113
|
+
"url": "/v2/spaces/b6d11f17-1cea-4c00-a951-fef3223b8c84",
|
114
|
+
"created_at": "2015-11-30T23:38:27Z",
|
115
|
+
"updated_at": null
|
116
|
+
},
|
117
|
+
"entity": {
|
118
|
+
"name": "name-58",
|
119
|
+
"organization_guid": "b13bbebe-427e-424d-8820-2937f7e218d5",
|
120
|
+
"space_quota_definition_guid": null,
|
121
|
+
"allow_ssh": true,
|
122
|
+
"organization_url": "/v2/organizations/b13bbebe-427e-424d-8820-2937f7e218d5",
|
123
|
+
"developers_url": "/v2/spaces/b6d11f17-1cea-4c00-a951-fef3223b8c84/developers",
|
124
|
+
"managers_url": "/v2/spaces/b6d11f17-1cea-4c00-a951-fef3223b8c84/managers",
|
125
|
+
"auditors_url": "/v2/spaces/b6d11f17-1cea-4c00-a951-fef3223b8c84/auditors",
|
126
|
+
"apps_url": "/v2/spaces/b6d11f17-1cea-4c00-a951-fef3223b8c84/apps",
|
127
|
+
"routes_url": "/v2/spaces/b6d11f17-1cea-4c00-a951-fef3223b8c84/routes",
|
128
|
+
"domains_url": "/v2/spaces/b6d11f17-1cea-4c00-a951-fef3223b8c84/domains",
|
129
|
+
"service_instances_url": "/v2/spaces/b6d11f17-1cea-4c00-a951-fef3223b8c84/service_instances",
|
130
|
+
"app_events_url": "/v2/spaces/b6d11f17-1cea-4c00-a951-fef3223b8c84/app_events",
|
131
|
+
"events_url": "/v2/spaces/b6d11f17-1cea-4c00-a951-fef3223b8c84/events",
|
132
|
+
"security_groups_url": "/v2/spaces/b6d11f17-1cea-4c00-a951-fef3223b8c84/security_groups"
|
133
|
+
}
|
134
|
+
}
|
135
|
+
json
|
136
|
+
end
|
137
|
+
|
138
|
+
before do
|
139
|
+
allow(user).to receive(:username).and_return("user_1")
|
140
|
+
stub_request(:put, "http://api.example.com/v2/spaces/#{space.guid}/developers").to_return(status: status, body: add_developer_space_response)
|
141
|
+
end
|
142
|
+
|
143
|
+
it "adds the given user to SpaceDeveloper in the space" do
|
144
|
+
space.add_developer_by_username("user_1")
|
145
|
+
expect(WebMock).to have_requested(:put, "http://api.example.com/v2/spaces/#{space.guid}/developers")
|
146
|
+
end
|
10
147
|
end
|
11
148
|
end
|
12
149
|
end
|