cfoundry 2.3.5 → 2.3.6.rc1
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/lib/cfoundry/rest_client.rb +8 -2
- data/lib/cfoundry/trace_helpers.rb +6 -1
- data/lib/cfoundry/v2/client.rb +1 -1
- data/lib/cfoundry/version.rb +1 -1
- data/spec/cfoundry/baseclient_spec.rb +14 -1
- data/spec/cfoundry/rest_client_spec.rb +14 -0
- data/spec/cfoundry/trace_helpers_spec.rb +12 -0
- data/spec/cfoundry/v2/client_spec.rb +21 -9
- data/spec/integration/client_spec.rb +37 -0
- metadata +8 -9
data/lib/cfoundry/rest_client.rb
CHANGED
@@ -48,8 +48,7 @@ module CFoundry
|
|
48
48
|
attr_reader :target
|
49
49
|
|
50
50
|
attr_accessor :trace, :backtrace, :log,
|
51
|
-
:request_id, :token, :
|
52
|
-
:http_proxy, :https_proxy
|
51
|
+
:request_id, :token, :http_proxy, :https_proxy
|
53
52
|
|
54
53
|
def initialize(target, token = nil)
|
55
54
|
@target = target
|
@@ -59,6 +58,13 @@ module CFoundry
|
|
59
58
|
@log = false
|
60
59
|
end
|
61
60
|
|
61
|
+
def target=(target)
|
62
|
+
return if target == @target
|
63
|
+
|
64
|
+
@target = target
|
65
|
+
@token = nil
|
66
|
+
end
|
67
|
+
|
62
68
|
def request(method, path, options = {})
|
63
69
|
request_uri(method, construct_url(path), DEFAULT_OPTIONS.merge(options))
|
64
70
|
end
|
@@ -3,6 +3,7 @@ require "multi_json"
|
|
3
3
|
|
4
4
|
module CFoundry
|
5
5
|
module TraceHelpers
|
6
|
+
PROTECTED_ATTRIBUTES = ['Authorization']
|
6
7
|
|
7
8
|
def request_trace(request)
|
8
9
|
return nil unless request
|
@@ -33,7 +34,11 @@ module CFoundry
|
|
33
34
|
|
34
35
|
def header_trace(headers)
|
35
36
|
headers.sort.map do |key, value|
|
36
|
-
|
37
|
+
unless PROTECTED_ATTRIBUTES.include?(key)
|
38
|
+
" #{key} : #{value}"
|
39
|
+
else
|
40
|
+
" #{key} : [PRIVATE DATA HIDDEN]"
|
41
|
+
end
|
37
42
|
end
|
38
43
|
end
|
39
44
|
end
|
data/lib/cfoundry/v2/client.rb
CHANGED
@@ -18,7 +18,7 @@ module CFoundry::V2
|
|
18
18
|
# [Space] Currently targeted space.
|
19
19
|
attr_accessor :current_space
|
20
20
|
|
21
|
-
def_delegators :@base, :target, :token, :token=, :http_proxy, :http_proxy=,
|
21
|
+
def_delegators :@base, :target, :target=, :token, :token=, :http_proxy, :http_proxy=,
|
22
22
|
:https_proxy, :https_proxy=, :trace, :trace=, :log, :log=, :info
|
23
23
|
|
24
24
|
# Create a new Client for interfacing with the given target.
|
data/lib/cfoundry/version.rb
CHANGED
@@ -80,7 +80,7 @@ describe CFoundry::BaseClient do
|
|
80
80
|
end
|
81
81
|
|
82
82
|
describe "#refresh_token!" do
|
83
|
-
let(:uaa) {
|
83
|
+
let(:uaa) { double }
|
84
84
|
let(:access_token) { Base64.encode64(%Q|{"algo": "h1234"}{"a":"b"}random-bytes|) }
|
85
85
|
let(:refresh_token) { "xyz" }
|
86
86
|
let(:new_access_token) { Base64.encode64(%Q|{"algo": "h1234"}{"a":"x"}random-bytes|) }
|
@@ -254,4 +254,17 @@ describe CFoundry::BaseClient do
|
|
254
254
|
}.to raise_error(CFoundry::BadResponse, /result/)
|
255
255
|
end
|
256
256
|
end
|
257
|
+
|
258
|
+
describe "#target=" do
|
259
|
+
let(:base_client) { CFoundry::BaseClient.new }
|
260
|
+
let(:new_target) { "some-target-url.com"}
|
261
|
+
|
262
|
+
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
|
+
end
|
265
|
+
|
266
|
+
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
|
+
end
|
269
|
+
end
|
257
270
|
end
|
@@ -368,4 +368,18 @@ describe CFoundry::RestClient do
|
|
368
368
|
end
|
369
369
|
end
|
370
370
|
end
|
371
|
+
|
372
|
+
describe "#target=" do
|
373
|
+
let(:token) { "some-token" }
|
374
|
+
|
375
|
+
it "invalidates the token if the target has changed" do
|
376
|
+
rest_client.target = "http://some-target.com"
|
377
|
+
expect(rest_client.token).to be_nil
|
378
|
+
end
|
379
|
+
|
380
|
+
it "does not invalidate the token if the target has not changed" do
|
381
|
+
rest_client.target = target
|
382
|
+
expect(rest_client.token).to eq token
|
383
|
+
end
|
384
|
+
end
|
371
385
|
end
|
@@ -47,6 +47,18 @@ describe CFoundry::TraceHelpers do
|
|
47
47
|
it "returns nil if request is nil" do
|
48
48
|
tracehelper_test_class.new.request_trace(nil).should == nil
|
49
49
|
end
|
50
|
+
|
51
|
+
context "with protected attributes" do
|
52
|
+
let(:header_trace) { "REQUEST_HEADERS:\n Authorization : [PRIVATE DATA HIDDEN]" }
|
53
|
+
let(:request) do
|
54
|
+
{
|
55
|
+
:method => "GET",
|
56
|
+
:url => "http://api.cloudfoundry.com/foo",
|
57
|
+
:headers => { 'Authorization' => "SECRET STUFF" }
|
58
|
+
}
|
59
|
+
end
|
60
|
+
include_examples "request_trace tests"
|
61
|
+
end
|
50
62
|
end
|
51
63
|
|
52
64
|
|
@@ -60,16 +60,28 @@ module CFoundry
|
|
60
60
|
end
|
61
61
|
|
62
62
|
describe "#login" do
|
63
|
-
include_examples "client login"
|
64
|
-
it 'sets the current organization to nil' do
|
65
|
-
client.current_organization = "org"
|
66
|
-
expect { subject }.to change { client.current_organization }.from("org").to(nil)
|
67
|
-
end
|
63
|
+
include_examples "client login"
|
68
64
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
65
|
+
it 'sets the current organization to nil' do
|
66
|
+
client.current_organization = "org"
|
67
|
+
expect { subject }.to change { client.current_organization }.from("org").to(nil)
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'sets the current space to nil' do
|
71
|
+
client.current_space = "space"
|
72
|
+
expect { subject }.to change { client.current_space }.from("space").to(nil)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe "#target=" do
|
77
|
+
let(:new_target) { "some-target-url.com"}
|
78
|
+
|
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)
|
81
|
+
end
|
82
|
+
|
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)
|
73
85
|
end
|
74
86
|
end
|
75
87
|
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe CFoundry::V2::Client do
|
4
|
+
before do
|
5
|
+
WebMock.allow_net_connect!
|
6
|
+
end
|
7
|
+
|
8
|
+
let(:a1_domain) { "a1.cf-app.com" }
|
9
|
+
let(:prod_domain) { "run.pivotal.io" }
|
10
|
+
|
11
|
+
describe "setting a new target" do
|
12
|
+
it "switches the target cc" do
|
13
|
+
client = CFoundry::V2::Client.new("http://api." + a1_domain)
|
14
|
+
auth_endpoint = client.info[:authorization_endpoint]
|
15
|
+
expect(auth_endpoint).to match a1_domain
|
16
|
+
|
17
|
+
client.target = "http://api." + prod_domain
|
18
|
+
auth_endpoint = client.info[:authorization_endpoint]
|
19
|
+
expect(auth_endpoint).to match prod_domain
|
20
|
+
end
|
21
|
+
|
22
|
+
if ENV["CF_V2_RUN_INTEGRATION"]
|
23
|
+
it "requires a re-login" do
|
24
|
+
client = CFoundry::V2::Client.new("http://api." + a1_domain)
|
25
|
+
client.login(ENV["CF_V2_TEST_USER"], ENV["CF_V2_TEST_PASSWORD"])
|
26
|
+
client.quota_definitions # Getting quota definitions will always be the shortest request that requires auth
|
27
|
+
|
28
|
+
client.target = nil
|
29
|
+
client.target = "http://api." + a1_domain
|
30
|
+
expect { client.quota_definitions }.to raise_error(CFoundry::InvalidAuthToken)
|
31
|
+
|
32
|
+
client.login(ENV["CF_V2_TEST_USER"], ENV["CF_V2_TEST_PASSWORD"])
|
33
|
+
client.quota_definitions
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
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.3.
|
5
|
-
prerelease:
|
4
|
+
version: 2.3.6.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-
|
13
|
+
date: 2013-07-10 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activemodel
|
@@ -395,6 +395,7 @@ files:
|
|
395
395
|
- spec/fixtures/fake_cc_user.json
|
396
396
|
- spec/fixtures/fake_cc_user_organizations.json
|
397
397
|
- spec/fixtures/fake_cc_user_with_managers.json
|
398
|
+
- spec/integration/client_spec.rb
|
398
399
|
- spec/spec_helper.rb
|
399
400
|
- spec/support/factory_girl.rb
|
400
401
|
- spec/support/shared_examples/cc_api_stub_request_examples.rb
|
@@ -415,16 +416,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
415
416
|
version: '0'
|
416
417
|
segments:
|
417
418
|
- 0
|
418
|
-
hash: -
|
419
|
+
hash: -59622661081407862
|
419
420
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
420
421
|
none: false
|
421
422
|
requirements:
|
422
|
-
- - ! '
|
423
|
+
- - ! '>'
|
423
424
|
- !ruby/object:Gem::Version
|
424
|
-
version:
|
425
|
-
segments:
|
426
|
-
- 0
|
427
|
-
hash: -3146471824032498517
|
425
|
+
version: 1.3.1
|
428
426
|
requirements: []
|
429
427
|
rubyforge_project: cfoundry
|
430
428
|
rubygems_version: 1.8.25
|
@@ -524,6 +522,7 @@ test_files:
|
|
524
522
|
- spec/fixtures/fake_cc_user.json
|
525
523
|
- spec/fixtures/fake_cc_user_organizations.json
|
526
524
|
- spec/fixtures/fake_cc_user_with_managers.json
|
525
|
+
- spec/integration/client_spec.rb
|
527
526
|
- spec/spec_helper.rb
|
528
527
|
- spec/support/factory_girl.rb
|
529
528
|
- spec/support/shared_examples/cc_api_stub_request_examples.rb
|