cfoundry 2.4.0 → 2.4.1.rc1

Sign up to get free protection for your applications and to get access to all the features.
@@ -15,7 +15,7 @@ module CFoundry
15
15
  :trace, :backtrace, :backtrace=, :log, :log=,
16
16
  :http_proxy, :http_proxy=, :https_proxy, :https_proxy=
17
17
 
18
- def initialize(target = "https://api.cloudfoundry.com", token = nil)
18
+ def initialize(target, token = nil)
19
19
  @rest_client = CFoundry::RestClient.new(target, token)
20
20
  self.trace = false
21
21
  self.backtrace = false
@@ -5,7 +5,7 @@ module CFoundry
5
5
  class UAAClient
6
6
  attr_accessor :target, :client_id, :token, :trace
7
7
 
8
- def initialize(target = "https://uaa.cloudfoundry.com", client_id = "cf")
8
+ def initialize(target, client_id = "cf")
9
9
  @target = target
10
10
  @client_id = client_id
11
11
  CF::UAA::Misc.symbolize_keys = true
@@ -24,6 +24,12 @@ module CFoundry
24
24
  end
25
25
  end
26
26
 
27
+ def user(guid)
28
+ wrap_uaa_errors do
29
+ scim.get(:user, guid)
30
+ end
31
+ end
32
+
27
33
  def users
28
34
  wrap_uaa_errors do
29
35
  scim.query(:user)
@@ -24,7 +24,7 @@ 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 = "http://api.cloudfoundry.com", token = nil)
27
+ def initialize(target, token = nil)
28
28
  @base = Base.new(target, token)
29
29
  end
30
30
 
@@ -11,6 +11,6 @@ module CFoundry::V2
11
11
 
12
12
  scoped_to_space
13
13
 
14
- queryable_by :name, :space_guid, :service_plan_guid, :service_binding_guid
14
+ queryable_by :name, :space_guid, :service_plan_guid, :service_binding_guid, :gateway_name
15
15
  end
16
16
  end
@@ -40,16 +40,23 @@ module CFoundry
40
40
  attr_accessor :emails, :name
41
41
 
42
42
  def email
43
+ # if the email collection is nil or empty? collect from UAA
44
+ get_meta_from_uaa if @emails.nil?
45
+
43
46
  return unless @emails && @emails.first
44
- @emails.first[:value]
47
+ @emails.first["value"]
45
48
  end
46
49
 
47
50
  def given_name
51
+ get_meta_from_uaa if @name.nil?
52
+
48
53
  return unless @name && @name[:givenName] != email
49
54
  @name[:givenName]
50
55
  end
51
56
 
52
57
  def family_name
58
+ get_meta_from_uaa if @name.nil?
59
+
53
60
  return unless @name && @name[:familyName] != email
54
61
  @name[:familyName]
55
62
  end
@@ -67,6 +74,20 @@ module CFoundry
67
74
  @client.base.uaa.delete_user(guid)
68
75
  true
69
76
  end
77
+
78
+ private
79
+
80
+ def get_meta_from_uaa
81
+ user = @client.base.uaa.user(guid)
82
+ return if user.nil?
83
+ return if not user['error'].nil?
84
+
85
+ @emails = user["emails"]
86
+ @name ||= {}
87
+ @name[:familyName] = user["name"]["familyname"]
88
+ @name[:givenName] = user["name"]["givenname"]
89
+ end
90
+
70
91
  end
71
92
  end
72
93
  end
@@ -1,4 +1,4 @@
1
1
  module CFoundry # :nodoc:
2
2
  # CFoundry library version number.
3
- VERSION = "2.4.0".freeze
3
+ VERSION = "2.4.1.rc1".freeze
4
4
  end
@@ -3,7 +3,7 @@ require 'net/http'
3
3
  require 'uri'
4
4
 
5
5
  describe CcApiStub::Organizations do
6
- let(:client) { CFoundry::V2::Client.new }
6
+ let(:client) { build(:client) }
7
7
 
8
8
  describe ".succeed_to_create" do
9
9
  let(:url) { "http://example.com/v2/organizations/" }
@@ -1,6 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe CFoundry::BaseClient do
4
+ subject(:client) { CFoundry::BaseClient.new("http://api.example.com") }
4
5
  describe "#request" do
5
6
  before do
6
7
  subject.stub(:handle_response).with(anything, anything, anything)
@@ -256,15 +257,15 @@ describe CFoundry::BaseClient do
256
257
  end
257
258
 
258
259
  describe "#target=" do
259
- let(:base_client) { CFoundry::BaseClient.new }
260
+ let(:base_client) { CFoundry::BaseClient.new("https://api.example.com") }
260
261
  let(:new_target) { "some-target-url.com"}
261
262
 
262
263
  it "sets a new target" do
263
- expect{base_client.target = new_target}.to change {base_client.target}.from("https://api.cloudfoundry.com").to(new_target)
264
+ expect{base_client.target = new_target}.to change {base_client.target}.from("https://api.example.com").to(new_target)
264
265
  end
265
266
 
266
267
  it "sets a new target on the rest client" do
267
- expect{base_client.target = new_target}.to change{base_client.rest_client.target}.from("https://api.cloudfoundry.com").to(new_target)
268
+ expect{base_client.target = new_target}.to change{base_client.rest_client.target}.from("https://api.example.com").to(new_target)
268
269
  end
269
270
  end
270
271
  end
@@ -21,7 +21,7 @@ describe 'Errors' do
21
21
  end
22
22
 
23
23
  describe CFoundry::APIError do
24
- let(:request) { { :method => "GET", :url => "http://api.cloudfoundry.com/foo", :headers => {} } }
24
+ let(:request) { { :method => "GET", :url => "http://api.example.com/foo", :headers => {} } }
25
25
  let(:response_body) { "NOT FOUND" }
26
26
  let(:response) { { :status => 404, :headers => {}, :body => response_body } }
27
27
 
@@ -2,7 +2,7 @@ require "spec_helper"
2
2
 
3
3
  describe CFoundry::RestClient do
4
4
  let(:token) { nil }
5
- let(:target) { "https://api.cloudfoundry.com" }
5
+ let(:target) { "https://api.example.com" }
6
6
  let(:rest_client) { CFoundry::RestClient.new(target, token) }
7
7
 
8
8
  describe '#request' do
@@ -81,7 +81,7 @@ describe CFoundry::RestClient do
81
81
  let(:options) { {:params => {}} }
82
82
 
83
83
  it "does not add a query string delimiter (the question mark)" do
84
- request_stub = stub_request(:get, "https://api.cloudfoundry.com/some-path")
84
+ request_stub = stub_request(:get, "https://api.example.com/some-path")
85
85
  subject
86
86
  expect(request_stub).to have_been_requested
87
87
  end
@@ -91,7 +91,7 @@ describe CFoundry::RestClient do
91
91
  let(:options) { {:params => {"key" => "value"}} }
92
92
 
93
93
  it "appends a query string and delimiter" do
94
- request_stub = stub_request(:get, "https://api.cloudfoundry.com/some-path?key=value")
94
+ request_stub = stub_request(:get, "https://api.example.com/some-path?key=value")
95
95
  subject
96
96
  expect(request_stub).to have_been_requested
97
97
  end
@@ -217,7 +217,7 @@ describe CFoundry::RestClient do
217
217
  let(:path) { "/some-path/some-segment" }
218
218
 
219
219
  it "doesn't add a double slash" do
220
- stub = stub_request(:get, "https://api.cloudfoundry.com/some-path/some-segment")
220
+ stub = stub_request(:get, "https://api.example.com/some-path/some-segment")
221
221
  subject
222
222
  expect(stub).to have_been_requested
223
223
  end
@@ -227,7 +227,7 @@ describe CFoundry::RestClient do
227
227
  let(:path) { "some-path/some-segment" }
228
228
 
229
229
  it "doesn't add a double slash" do
230
- stub = stub_request(:get, "https://api.cloudfoundry.com/some-path/some-segment")
230
+ stub = stub_request(:get, "https://api.example.com/some-path/some-segment")
231
231
  subject
232
232
  expect(stub).to have_been_requested
233
233
  end
@@ -258,7 +258,7 @@ describe CFoundry::RestClient do
258
258
  end
259
259
 
260
260
  it "prints the request and the response" do
261
- rest_client.should_receive(:print_request).with({:headers => {"Content-Length" => 0}, :url => "https://api.cloudfoundry.com/some-path", :method => "GET", :body => nil})
261
+ rest_client.should_receive(:print_request).with({:headers => {"Content-Length" => 0}, :url => "https://api.example.com/some-path", :method => "GET", :body => nil})
262
262
  rest_client.should_receive(:print_response).with({:status => "200", :headers => {"content-type" => "application/json"}, :body => '{"some": "json"}'})
263
263
  subject
264
264
  end
@@ -266,11 +266,11 @@ describe CFoundry::RestClient do
266
266
 
267
267
  describe "following redirects" do
268
268
  before do
269
- stub_request(:post, "https://api.cloudfoundry.com/apps").to_return(
269
+ stub_request(:post, "https://api.example.com/apps").to_return(
270
270
  :status => 301,
271
- :headers => {"location" => "https://api.cloudfoundry.com/apps/some-guid"}
271
+ :headers => {"location" => "https://api.example.com/apps/some-guid"}
272
272
  )
273
- stub_request(:get, "https://api.cloudfoundry.com/apps/some-guid").to_return(
273
+ stub_request(:get, "https://api.example.com/apps/some-guid").to_return(
274
274
  :status => 200,
275
275
  :body => '{"some": "json"}'
276
276
  )
@@ -291,7 +291,7 @@ describe CFoundry::RestClient do
291
291
  describe ".create" do
292
292
  let(:http_proxy) { '' }
293
293
  let(:https_proxy) { '' }
294
- let(:target_uri) { "http://cloudfoundry.com" }
294
+ let(:target_uri) { "http://api.example.com" }
295
295
 
296
296
  subject { CFoundry::RestClient::HTTPFactory.create(URI.parse(target_uri), http_proxy, https_proxy) }
297
297
 
@@ -304,7 +304,7 @@ describe CFoundry::RestClient do
304
304
  end
305
305
 
306
306
  context "when the target is an https URI" do
307
- let(:target_uri) { "https://cloudfoundry.com" }
307
+ let(:target_uri) { "https://example.com" }
308
308
  it "should return an instance of the plain Net:HTTP class with use_ssl" do
309
309
  expect(subject).to be_instance_of(Net::HTTP)
310
310
  expect(subject.use_ssl?).to be_true
@@ -333,7 +333,7 @@ describe CFoundry::RestClient do
333
333
  end
334
334
 
335
335
  context "when a https proxy URI is set and the target is an https URI" do
336
- let(:target_uri) { "https://cloudfoundry.com" }
336
+ let(:target_uri) { "https://example.com" }
337
337
  let(:https_proxy) { "http://exapmle.com:8080" }
338
338
 
339
339
  it "should return an instance of the proxy class" do
@@ -342,7 +342,7 @@ describe CFoundry::RestClient do
342
342
  end
343
343
 
344
344
  context "when a https proxy URI is set and the target is an http URI" do
345
- let(:target_uri) { "http://cloudfoundry.com" }
345
+ let(:target_uri) { "http://example.com" }
346
346
  let(:https_proxy) { "http://exapmle.com:8080" }
347
347
 
348
348
  it "should return an instance of the plain Net:HTTP class" do
@@ -351,7 +351,7 @@ describe CFoundry::RestClient do
351
351
  end
352
352
 
353
353
  context "when a http proxy URI is set and the target is an https URI" do
354
- let(:target_uri) { "https://cloudfoundry.com" }
354
+ let(:target_uri) { "https://example.com" }
355
355
  let(:http_proxy) { "http://exapmle.com:8080" }
356
356
 
357
357
  it "should return an instance of the plain Net:HTTP class" do
@@ -5,7 +5,7 @@ describe CFoundry::TraceHelpers do
5
5
  let(:request) do
6
6
  {
7
7
  :method => "GET",
8
- :url => "http://api.cloudfoundry.com/foo",
8
+ :url => "http://api.example.com/foo",
9
9
  :headers => { "bb-foo" => "bar", "accept" => "*/*" }
10
10
  }
11
11
  end
@@ -26,7 +26,7 @@ describe CFoundry::TraceHelpers do
26
26
  end
27
27
 
28
28
  describe "#request_trace" do
29
- let(:request_trace) { "REQUEST: GET http://api.cloudfoundry.com/foo" }
29
+ let(:request_trace) { "REQUEST: GET http://api.example.com/foo" }
30
30
  let(:header_trace) { "REQUEST_HEADERS:\n accept : */*\n bb-foo : bar" }
31
31
  let(:body_trace) { "" }
32
32
 
@@ -53,7 +53,7 @@ describe CFoundry::TraceHelpers do
53
53
  let(:request) do
54
54
  {
55
55
  :method => "GET",
56
- :url => "http://api.cloudfoundry.com/foo",
56
+ :url => "http://api.example.com/foo",
57
57
  :headers => { 'Authorization' => "SECRET STUFF" }
58
58
  }
59
59
  end
@@ -71,7 +71,7 @@ describe CFoundry::TraceHelpers do
71
71
  end
72
72
 
73
73
  context "with a JSON response body" do
74
- let(:response_body) { "{\"name\": \"vcap\",\"build\": 2222,\"support\": \"http://support.cloudfoundry.com\"}" }
74
+ let(:response_body) { "{\"name\": \"vcap\",\"build\": 2222,\"support\": \"http://support.example.com\"}" }
75
75
  let(:response_trace) { "RESPONSE: [404]\nRESPONSE_HEADERS:\n\nRESPONSE_BODY:\n#{MultiJson.dump(MultiJson.load(response_body), :pretty => true)}" }
76
76
 
77
77
  include_examples "response_trace tests"
@@ -68,7 +68,7 @@ EOF
68
68
  let(:password) { "test" }
69
69
  let(:creds) { {:username => username, :password => password} }
70
70
  let(:state) { 'somestate' }
71
- let(:redirect_uri) { 'https://uaa.cloudfoundry.com/redirect/cf' }
71
+ let(:redirect_uri) { 'https://uaa.example.com/redirect/cf' }
72
72
  let(:auth) { Object.new }
73
73
  let(:issuer) { Object.new }
74
74
 
@@ -1,7 +1,7 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe CFoundry::V2::Base do
4
- let(:target) { "https://api.cloudfoundry.com" }
4
+ let(:target) { "https://api.example.com" }
5
5
  let(:base) { CFoundry::V2::Base.new(target) }
6
6
 
7
7
  describe "helper methods for HTTP verbs" do
@@ -17,7 +17,7 @@ describe CFoundry::V2::Base do
17
17
  let(:options) { {:accept => :json} }
18
18
 
19
19
  it 'returns the parsed JSON' do
20
- stub_request(:any, 'https://api.cloudfoundry.com/some-path').to_return(:status => 200, :body => "{\"hello\": \"there\"}")
20
+ stub_request(:any, 'https://api.example.com/some-path').to_return(:status => 200, :body => "{\"hello\": \"there\"}")
21
21
  expect(subject).to eq(:hello => "there")
22
22
  end
23
23
  end
@@ -26,7 +26,7 @@ describe CFoundry::V2::Base do
26
26
  let(:options) { {:accept => :form} }
27
27
 
28
28
  it 'returns the body' do
29
- stub_request(:any, 'https://api.cloudfoundry.com/some-path').to_return :status => 200, :body => "body"
29
+ stub_request(:any, 'https://api.example.com/some-path').to_return :status => 200, :body => "body"
30
30
  expect(subject).to eq "body"
31
31
  end
32
32
  end
@@ -36,7 +36,7 @@ describe CFoundry::V2::Base do
36
36
  let(:response_code) { 404 }
37
37
 
38
38
  it 'raises the correct error if JSON is parsed successfully' do
39
- stub_request(:any, 'https://api.cloudfoundry.com/some-path').to_return(
39
+ stub_request(:any, 'https://api.example.com/some-path').to_return(
40
40
  :status => response_code,
41
41
  :body => "{\"code\": 111, \"description\": \"Something bad happened\"}"
42
42
  )
@@ -44,7 +44,7 @@ describe CFoundry::V2::Base do
44
44
  end
45
45
 
46
46
  it 'raises the correct error if code is missing from response' do
47
- stub_request(:any, 'https://api.cloudfoundry.com/some-path').to_return(
47
+ stub_request(:any, 'https://api.example.com/some-path').to_return(
48
48
  :status => response_code,
49
49
  :body => "{\"description\": \"Something bad happened\"}"
50
50
  )
@@ -52,7 +52,7 @@ describe CFoundry::V2::Base do
52
52
  end
53
53
 
54
54
  it 'raises the correct error if response body is not JSON' do
55
- stub_request(:any, 'https://api.cloudfoundry.com/some-path').to_return(
55
+ stub_request(:any, 'https://api.example.com/some-path').to_return(
56
56
  :status => response_code,
57
57
  :body => "Error happened"
58
58
  )
@@ -60,7 +60,7 @@ describe CFoundry::V2::Base do
60
60
  end
61
61
 
62
62
  it 'raises a generic APIError if code is not recognized' do
63
- stub_request(:any, 'https://api.cloudfoundry.com/some-path').to_return :status => response_code,
63
+ stub_request(:any, 'https://api.example.com/some-path').to_return :status => response_code,
64
64
  :body => "{\"code\": 6932, \"description\": \"Something bad happened\"}"
65
65
  expect {subject}.to raise_error CFoundry::APIError, "6932: Something bad happened"
66
66
  end
@@ -120,7 +120,7 @@ describe CFoundry::V2::Base do
120
120
  :headers => { "Content-Length" => 0 },
121
121
  :method => verb,
122
122
  :body => nil,
123
- :url => "https://api.cloudfoundry.com/some-path"
123
+ :url => "https://api.example.com/some-path"
124
124
  })
125
125
  end
126
126
  end
@@ -175,7 +175,7 @@ describe CFoundry::V2::Base do
175
175
  let(:request) do
176
176
  {
177
177
  :method => "GET",
178
- :url => "http://api.cloudfoundry.com/some-path",
178
+ :url => "http://api.example.com/some-path",
179
179
  :headers => { "some-header-key" => "some-header-value" },
180
180
  :body => "some-body"
181
181
  }
@@ -234,7 +234,7 @@ describe CFoundry::V2::Base do
234
234
  let(:fingerprints) { "some-fingerprints" }
235
235
 
236
236
  it "makes a PUT request to the resource_match endpoint with the correct payload" do
237
- stub = stub_request(:put, "https://api.cloudfoundry.com/v2/resource_match").
237
+ stub = stub_request(:put, "https://api.example.com/v2/resource_match").
238
238
  with(:body => fingerprints).
239
239
  to_return(:body => "{}")
240
240
  base.resource_match(fingerprints)
@@ -248,7 +248,7 @@ describe CFoundry::V2::Base do
248
248
  let(:fake_zipfile) { File.new("#{SPEC_ROOT}/fixtures/empty_file") }
249
249
 
250
250
  it "makes a PUT request to the app bits endpoint with the correct payload" do
251
- stub = stub_request(:put, "https://api.cloudfoundry.com/v2/apps/#{guid}/bits").to_return(:body => "{}")
251
+ stub = stub_request(:put, "https://api.example.com/v2/apps/#{guid}/bits").to_return(:body => "{}")
252
252
  base.upload_app(guid, fake_zipfile)
253
253
  expect(stub).to have_been_requested
254
254
  end
@@ -258,7 +258,7 @@ describe CFoundry::V2::Base do
258
258
  stub =
259
259
  stub_request(
260
260
  :put,
261
- "https://api.cloudfoundry.com/v2/apps/#{guid}/bits"
261
+ "https://api.example.com/v2/apps/#{guid}/bits"
262
262
  ).with { |request|
263
263
  request.body =~ /name="resources"/ &&
264
264
  request.body !~ /name="application"/
@@ -274,8 +274,8 @@ describe CFoundry::V2::Base do
274
274
  describe "#stream_file" do
275
275
  let(:app_guid) { "1234" }
276
276
  let(:instance_guid) { "3456" }
277
- let(:api_url) { "https://api.cloudfoundry.com/v2/apps/#{app_guid}/instances/#{instance_guid}/files/some/path/segments" }
278
- let(:file_url) { "http://api.cloudfoundry.com/static/path/to/some/file" }
277
+ let(:api_url) { "https://api.example.com/v2/apps/#{app_guid}/instances/#{instance_guid}/files/some/path/segments" }
278
+ let(:file_url) { "http://api.example.com/static/path/to/some/file" }
279
279
 
280
280
  before do
281
281
  base.stub(:token) { CFoundry::AuthToken.new("bearer foo") }
@@ -3,10 +3,10 @@ require "spec_helper"
3
3
  module CFoundry
4
4
  module V2
5
5
  describe Client do
6
- let(:client) { build(:client) }
6
+ subject(:client) { build(:client) }
7
7
 
8
8
  describe "#register" do
9
- let(:uaa) { UAAClient.new }
9
+ let(:uaa) { UAAClient.new('http://uaa.example.com') }
10
10
  let(:email) { "test@test.com" }
11
11
  let(:password) { "secret" }
12
12
 
@@ -77,11 +77,11 @@ module CFoundry
77
77
  let(:new_target) { "some-target-url.com"}
78
78
 
79
79
  it "sets a new target" do
80
- expect{client.target = new_target}.to change {client.target}.from("http://api.cloudfoundry.com").to(new_target)
80
+ expect{client.target = new_target}.to change {client.target}.from("http://api.example.com").to(new_target)
81
81
  end
82
82
 
83
83
  it "sets a new target on the base client" do
84
- expect{client.target = new_target}.to change{client.base.target}.from("http://api.cloudfoundry.com").to(new_target)
84
+ expect{client.target = new_target}.to change{client.base.target}.from("http://api.example.com").to(new_target)
85
85
  end
86
86
  end
87
87
  end
@@ -0,0 +1,66 @@
1
+ require "spec_helper"
2
+
3
+ module CFoundry
4
+ module V2
5
+ describe ServiceInstance do
6
+ let(:client) { build(:client) }
7
+ subject { build(:service_instance, :client => client) }
8
+
9
+ describe "space" do
10
+ let(:space) { build(:space) }
11
+
12
+ it "has a space" do
13
+ subject.space = space
14
+ expect(subject.space).to eq(space)
15
+ end
16
+
17
+ context "when an invalid value is assigned" do
18
+ it "raises a Mismatch exception" do
19
+ expect {
20
+ subject.space = [build(:organization)]
21
+ }.to raise_error(CFoundry::Mismatch)
22
+ end
23
+ end
24
+ end
25
+
26
+ describe "service_plan" do
27
+ let(:service_plan) { build(:service_plan) }
28
+
29
+ it "has a service plan" do
30
+ subject.service_plan = service_plan
31
+ expect(subject.service_plan).to eq(service_plan)
32
+ end
33
+
34
+ context "when an invalid value is assigned" do
35
+ it "raises a Mismatch exception" do
36
+ expect {
37
+ subject.space = [build(:organization)]
38
+ }.to raise_error(CFoundry::Mismatch)
39
+ end
40
+ end
41
+ end
42
+
43
+ describe 'query params' do
44
+ it 'allows query by name' do
45
+ client.should respond_to(:service_instance_by_name)
46
+ end
47
+
48
+ it 'allows query by space_guid' do
49
+ client.should respond_to(:service_instance_by_space_guid)
50
+ end
51
+
52
+ it 'allows query by gateway_name' do
53
+ client.should respond_to(:service_instance_by_gateway_name)
54
+ end
55
+
56
+ it 'allows query by service_plan_guid' do
57
+ client.should respond_to(:service_instance_by_service_plan_guid)
58
+ end
59
+
60
+ it 'allows query by service_binding_guid' do
61
+ client.should respond_to(:service_instance_by_service_binding_guid)
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
@@ -30,6 +30,177 @@ module CFoundry
30
30
  end
31
31
  end
32
32
  end
33
+
34
+ describe '#get_meta_from_uaa' do
35
+
36
+ let(:api_target) { 'http://api.example.com' }
37
+ let(:login_target) { 'https://login.example.com' }
38
+ let(:uaa_target) { 'https://uaa.example.com' }
39
+ let(:user_email) { 'test-user@example.com' }
40
+ let(:given_name) { 'John' }
41
+ let(:family_name) { 'Doe' }
42
+
43
+ before do
44
+
45
+ stub_request(:get, "#{api_target}/info").to_return :status => 200,
46
+ :headers => {'Content-Type' => 'application/json'},
47
+ :body => <<EOF
48
+ {
49
+ "name": "vcap",
50
+ "build": "2222",
51
+ "support": "http://support.example.com",
52
+ "version": 2,
53
+ "description": "Cloud Foundry sponsored by Pivotal",
54
+ "authorization_endpoint": "https://login.example.com",
55
+ "token_endpoint": "https://uaa.example.com",
56
+ "allow_debug": true,
57
+ "user": "00000000-0000-0000-0000-000000000000",
58
+ "limits": {
59
+ "memory": 2048,
60
+ "app_uris": 4,
61
+ "services": 16,
62
+ "apps": 20
63
+ },
64
+ "usage": {
65
+ "memory": 896,
66
+ "apps": 4,
67
+ "services": 6
68
+ }
69
+ }
70
+ EOF
71
+
72
+ stub_request(:get, "#{login_target}/login").to_return :status => 200,
73
+ :headers => {'Content-Type' => 'application/json'},
74
+ :body => <<EOF
75
+ {
76
+ "timestamp": "2013-06-12T22:32:57-0700",
77
+ "app": {
78
+ "artifact": "cloudfoundry-login-server",
79
+ "description": "Cloud Foundry Login App",
80
+ "name": "Cloud Foundry Login",
81
+ "version": "1.2.3"
82
+ },
83
+ "links": {
84
+ "register": "https://console.example.com/register",
85
+ "passwd": "https://console.example.com/password_resets/new",
86
+ "home": "https://console.example.com",
87
+ "login": "https://login.example.com",
88
+ "uaa": "https://uaa.example.com"
89
+ },
90
+ "analytics": {
91
+ "code": "UA-00000000-00",
92
+ "domain": "example.com"
93
+ },
94
+ "commit_id": "0000000",
95
+ "prompts": {
96
+ "username": [
97
+ "text",
98
+ "Email"
99
+ ],
100
+ "password": [
101
+ "password",
102
+ "Password"
103
+ ]
104
+ }
105
+ }
106
+ EOF
107
+
108
+ stub_request(:get, /#{uaa_target}\/Users\/user-guid-\d{1,2}/).to_return :status => 200,
109
+ :headers => {'Content-Type' => 'application/json'},
110
+ :body => <<EOF
111
+ {
112
+ "id": "00000000-0000-0000-0000-000000000000",
113
+ "meta": {
114
+ "version": 0,
115
+ "created": "2013-06-24T13:44:38.000Z",
116
+ "lastModified": "2013-06-24T13:44:38.000Z"
117
+ },
118
+ "userName": "#{user_email}",
119
+ "name": {
120
+ "familyName": "#{family_name}",
121
+ "givenName": "#{given_name}"
122
+ },
123
+ "emails": [
124
+ {
125
+ "value": "#{user_email}"
126
+ }
127
+ ],
128
+ "groups": [
129
+ {
130
+ "value": "00000000-0000-0000-0000-000000000000",
131
+ "display": "password.write",
132
+ "type": "DIRECT"
133
+ },
134
+ {
135
+ "value": "00000000-0000-0000-0000-000000000000",
136
+ "display": "openid",
137
+ "type": "DIRECT"
138
+ },
139
+ {
140
+ "value": "00000000-0000-0000-0000-000000000000",
141
+ "display": "uaa.user",
142
+ "type": "DIRECT"
143
+ },
144
+ {
145
+ "value": "00000000-0000-0000-0000-000000000000",
146
+ "display": "scim.userids",
147
+ "type": "DIRECT"
148
+ },
149
+ {
150
+ "value": "00000000-0000-0000-0000-000000000000",
151
+ "display": "approvals.me",
152
+ "type": "DIRECT"
153
+ },
154
+ {
155
+ "value": "00000000-0000-0000-0000-000000000000",
156
+ "display": "cloud_controller.write",
157
+ "type": "DIRECT"
158
+ },
159
+ {
160
+ "value": "00000000-0000-0000-0000-000000000000",
161
+ "display": "scim.me",
162
+ "type": "DIRECT"
163
+ },
164
+ {
165
+ "value": "00000000-0000-0000-0000-000000000000",
166
+ "display": "cloud_controller.read",
167
+ "type": "DIRECT"
168
+ }
169
+ ],
170
+ "approvals": [
171
+
172
+ ],
173
+ "active": true,
174
+ "schemas": [
175
+ "urn:scim:schemas:core:1.0"
176
+ ]
177
+ }
178
+ EOF
179
+ end
180
+
181
+ it "retrieves metadata from the UAA" do
182
+ subject.email.should == user_email
183
+ subject.given_name.should == given_name
184
+ subject.family_name.should == family_name
185
+ subject.full_name.should == "#{given_name} #{family_name}"
186
+ end
187
+
188
+ it "should be nil if user doesn't have permission to query uaa" do
189
+
190
+ stub_request(:get, /#{uaa_target}\/Users\/user-guid-\d{1,2}/).to_return :status => 200,
191
+ :headers => {'Content-Type' => 'application/json'},
192
+ :body => <<EOF
193
+ {
194
+ "error": "access_denied",
195
+ "error_description": "Access is denied"
196
+ }
197
+ EOF
198
+ subject.email.should == nil
199
+ subject.given_name.should == nil
200
+ subject.family_name.should == nil
201
+ end
202
+
203
+ end
33
204
  end
34
205
  end
35
206
  end
@@ -1,5 +1,7 @@
1
1
  FactoryGirl.define do
2
2
  factory :client, :class => CFoundry::V2::Client do
3
-
3
+ initialize_with do
4
+ new("http://api.example.com")
5
+ end
4
6
  end
5
7
  end
@@ -0,0 +1,10 @@
1
+ FactoryGirl.define do
2
+ factory :service_instance, :class => CFoundry::V2::ServiceInstance do
3
+ sequence(:guid) { |n| "service-instance-guid-#{n}" }
4
+ ignore do
5
+ client { FactoryGirl.build(:client) }
6
+ end
7
+
8
+ initialize_with { new(guid, client) }
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ FactoryGirl.define do
2
+ factory :service_plan, :class => CFoundry::V2::ServicePlan do
3
+ sequence(:guid) { |n| "service-plan-guid-#{n}" }
4
+ ignore do
5
+ client { FactoryGirl.build(:client) }
6
+ end
7
+
8
+ initialize_with { new(guid, client) }
9
+ end
10
+ end
@@ -6,10 +6,10 @@
6
6
  "guid":"application-id-1",
7
7
  "name":"application-name-1",
8
8
  "routes":[
9
- { "guid": "aa14f148-3d82-4db3-982e-fe0fd00582f4", "host": "app", "domain": { "name": "cloudfoundry.com"}}
9
+ { "guid": "aa14f148-3d82-4db3-982e-fe0fd00582f4", "host": "app", "domain": { "name": "example.com"}}
10
10
  ],
11
11
  "urls":[
12
- "app.cloudfoundry.com"
12
+ "app.example.com"
13
13
  ],
14
14
  "state":"STARTED",
15
15
  "memory":128,
@@ -25,12 +25,12 @@
25
25
  "guid":"application-id-2",
26
26
  "name":"application-name-2",
27
27
  "routes":[
28
- { "guid": "a14c5666-5354-49a7-8da8-2c29eaaaac18", "host": "app2-1", "domain": { "name": "cloudfoundry.com"}},
29
- { "guid": "7c183670-2e4b-4dd1-b2b5-d7ada5d470fb", "host": "app2-2", "domain": { "name": "cloudfoundry.com"}}
28
+ { "guid": "a14c5666-5354-49a7-8da8-2c29eaaaac18", "host": "app2-1", "domain": { "name": "example.com"}},
29
+ { "guid": "7c183670-2e4b-4dd1-b2b5-d7ada5d470fb", "host": "app2-2", "domain": { "name": "example.com"}}
30
30
  ],
31
31
  "urls":[
32
- "app2-1.cloudfoundry.com",
33
- "app2-2.cloudfoundry.com"
32
+ "app2-1.example.com",
33
+ "app2-2.example.com"
34
34
  ],
35
35
  "state":"STOPPED",
36
36
  "memory":256,
@@ -22,14 +22,14 @@ describe CFoundry::V2::Client do
22
22
  if ENV["CF_V2_RUN_INTEGRATION"]
23
23
  it "requires a re-login" do
24
24
  client = CFoundry::V2::Client.new("http://api." + a1_domain)
25
- client.login(ENV["CF_V2_TEST_USER"], ENV["CF_V2_TEST_PASSWORD"])
25
+ client.login({username: ENV["CF_V2_TEST_USER"], password: ENV["CF_V2_TEST_PASSWORD"]})
26
26
  client.quota_definitions # Getting quota definitions will always be the shortest request that requires auth
27
27
 
28
28
  client.target = nil
29
29
  client.target = "http://api." + a1_domain
30
30
  expect { client.quota_definitions }.to raise_error(CFoundry::InvalidAuthToken)
31
31
 
32
- client.login(ENV["CF_V2_TEST_USER"], ENV["CF_V2_TEST_PASSWORD"])
32
+ client.login({username: ENV["CF_V2_TEST_USER"], password: ENV["CF_V2_TEST_PASSWORD"]})
33
33
  client.quota_definitions
34
34
  end
35
35
  end
@@ -1,5 +1,5 @@
1
1
  shared_examples_for 'client login prompts' do
2
- let(:uaa) { CFoundry::UAAClient.new }
2
+ let(:uaa) { CFoundry::UAAClient.new('http://uaa.example.com') }
3
3
  let(:prompts) do
4
4
  {
5
5
  :user_id => ["text", "User ID"],
@@ -22,7 +22,7 @@ end
22
22
  shared_examples_for 'client login' do
23
23
  let(:email) { 'test@test.com' }
24
24
  let(:password) { 'secret' }
25
- let(:uaa) { CFoundry::UAAClient.new }
25
+ let(:uaa) { CFoundry::UAAClient.new('http://uaa.example.com') }
26
26
  let(:access_token) { "some-access-token" }
27
27
  let(:token_info) { CF::UAA::TokenInfo.new({ :access_token => access_token, :token_type => "bearer" }) }
28
28
 
metadata CHANGED
@@ -1,8 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cfoundry
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.0
5
- prerelease:
4
+ version: 2.4.1.rc1
5
+ prerelease: 6
6
6
  platform: ruby
7
7
  authors:
8
8
  - Cloud Foundry Team
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-07-12 00:00:00.000000000 Z
13
+ date: 2013-07-17 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activemodel
@@ -337,6 +337,7 @@ files:
337
337
  - spec/cfoundry/v2/organization_spec.rb
338
338
  - spec/cfoundry/v2/quota_definition_spec.rb
339
339
  - spec/cfoundry/v2/route_spec.rb
340
+ - spec/cfoundry/v2/service_instance_spec.rb
340
341
  - spec/cfoundry/v2/space_spec.rb
341
342
  - spec/cfoundry/v2/user_spec.rb
342
343
  - spec/cfoundry/validator_spec.rb
@@ -347,6 +348,8 @@ files:
347
348
  - spec/factories/organizations_factory.rb
348
349
  - spec/factories/quota_definitions_factory.rb
349
350
  - spec/factories/routes_factory.rb
351
+ - spec/factories/service_instances_factory.rb
352
+ - spec/factories/service_plans_factory.rb
350
353
  - spec/factories/spaces_factory.rb
351
354
  - spec/factories/users_factory.rb
352
355
  - spec/fixtures/apps/with_cfignore/ambiguous_ignored
@@ -416,16 +419,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
416
419
  version: '0'
417
420
  segments:
418
421
  - 0
419
- hash: -3185654219291849147
422
+ hash: -3405419350059499948
420
423
  required_rubygems_version: !ruby/object:Gem::Requirement
421
424
  none: false
422
425
  requirements:
423
- - - ! '>='
426
+ - - ! '>'
424
427
  - !ruby/object:Gem::Version
425
- version: '0'
426
- segments:
427
- - 0
428
- hash: -3185654219291849147
428
+ version: 1.3.1
429
429
  requirements: []
430
430
  rubyforge_project: cfoundry
431
431
  rubygems_version: 1.8.25
@@ -467,6 +467,7 @@ test_files:
467
467
  - spec/cfoundry/v2/organization_spec.rb
468
468
  - spec/cfoundry/v2/quota_definition_spec.rb
469
469
  - spec/cfoundry/v2/route_spec.rb
470
+ - spec/cfoundry/v2/service_instance_spec.rb
470
471
  - spec/cfoundry/v2/space_spec.rb
471
472
  - spec/cfoundry/v2/user_spec.rb
472
473
  - spec/cfoundry/validator_spec.rb
@@ -477,6 +478,8 @@ test_files:
477
478
  - spec/factories/organizations_factory.rb
478
479
  - spec/factories/quota_definitions_factory.rb
479
480
  - spec/factories/routes_factory.rb
481
+ - spec/factories/service_instances_factory.rb
482
+ - spec/factories/service_plans_factory.rb
480
483
  - spec/factories/spaces_factory.rb
481
484
  - spec/factories/users_factory.rb
482
485
  - spec/fixtures/apps/with_cfignore/ambiguous_ignored