cf-uaa-lib 3.2.4 → 3.2.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f1a44d84d9da8b6a573137d39cff8f0a8272f21d
4
- data.tar.gz: 50590e8f0a93d17739478de139c72a744ce1417a
3
+ metadata.gz: 22244230c33436d1113ddefaa82fd4e8f68f611b
4
+ data.tar.gz: 67c4faa41e5dabcd57944e634dc1d7689ff63402
5
5
  SHA512:
6
- metadata.gz: 01b0f6577fad7197cd957c55f4f7b7cf781a6d79f160de5cba31a523708da721396cbf48261f9d8da61e59b704672f4b3d3fa0c7f08ccc349c3171ec98478e1f
7
- data.tar.gz: 723f1a40f353d5b70bf8ee778dc1ec32f7c1e10729a82444281fa96e7f17a5b5eb0c0a10ff160ef149f9017f2bd2aae236ffb7a72accf016664788d8c947e17f
6
+ metadata.gz: 08a6c3960dfd815606d99b477450068c1350f8ecfca4617f2bd9401faa594565290aa4c1c191fc48254a25b27b629701525bee4192cc23df8a1c835b791257b5
7
+ data.tar.gz: be6448d4cc5dddb693a122b7cf86062c62f950163dbb648cb0c03cee05899f74b47081e7b1e85aef9f95973fa995c5b52f004bd152c401050713ee2a44eb12b1
@@ -50,7 +50,7 @@ module Http
50
50
 
51
51
  def self.included(base)
52
52
  base.class_eval do
53
- attr_accessor :http_proxy, :https_proxy, :skip_ssl_validation, :ssl_ca_file
53
+ attr_accessor :http_proxy, :https_proxy, :skip_ssl_validation, :ssl_ca_file, :ssl_cert_store, :zone
54
54
  end
55
55
  end
56
56
 
@@ -128,8 +128,10 @@ module Http
128
128
  def http_put(target, path, body, headers = {}) request(target, :put, path, body, headers) end
129
129
  def http_patch(target, path, body, headers = {}) request(target, :patch, path, body, headers) end
130
130
 
131
- def http_delete(target, path, authorization)
132
- status = request(target, :delete, path, nil, "authorization" => authorization)[0]
131
+ def http_delete(target, path, authorization, zone = nil)
132
+ hdrs = { "authorization" => authorization }
133
+ hdrs['X-Identity-Zone-Subdomain'] = zone if zone
134
+ status = request(target, :delete, path, nil, hdrs)[0]
133
135
  unless [200, 204].include?(status)
134
136
  raise (status == 404 ? NotFound : BadResponse), "invalid response from #{path}: #{status}"
135
137
  end
@@ -188,6 +190,9 @@ module Http
188
190
  elsif ssl_ca_file
189
191
  http.ca_file = File.expand_path(ssl_ca_file)
190
192
  http.verify_mode = OpenSSL::SSL::VERIFY_PEER
193
+ elsif ssl_cert_store
194
+ http.cert_store = ssl_cert_store
195
+ http.verify_mode = OpenSSL::SSL::VERIFY_PEER
191
196
  end
192
197
  end
193
198
 
@@ -33,6 +33,7 @@ class Info
33
33
  self.target = target
34
34
  self.skip_ssl_validation = options[:skip_ssl_validation]
35
35
  self.ssl_ca_file = options[:ssl_ca_file]
36
+ self.ssl_cert_store = options[:ssl_cert_store]
36
37
  self.symbolize_keys = options[:symbolize_keys]
37
38
  self.http_proxy = options[:http_proxy]
38
39
  self.https_proxy = options[:https_proxy]
@@ -55,6 +55,12 @@ class Scim
55
55
  kc || kd
56
56
  end
57
57
 
58
+ def headers()
59
+ hdrs = { 'authorization' => @auth_header }
60
+ hdrs['X-Identity-Zone-Subdomain'] = @zone if @zone
61
+ hdrs
62
+ end
63
+
58
64
  # This is very inefficient and should be unnecessary. SCIM (1.1 and early
59
65
  # 2.0 drafts) specify that attribute names are case insensitive. However
60
66
  # in the UAA attribute names are currently case sensitive. This hack takes
@@ -102,8 +108,10 @@ class Scim
102
108
  @key_style = options[:symbolize_keys] ? :downsym : :down
103
109
  self.skip_ssl_validation = options[:skip_ssl_validation]
104
110
  self.ssl_ca_file = options[:ssl_ca_file]
111
+ self.ssl_cert_store = options[:ssl_cert_store]
105
112
  self.http_proxy = options[:http_proxy]
106
113
  self.https_proxy = options[:https_proxy]
114
+ @zone = options[:zone]
107
115
  end
108
116
 
109
117
  # Convenience method to get the naming attribute, e.g. userName for user,
@@ -120,7 +128,7 @@ class Scim
120
128
  def add(type, info)
121
129
  path, info = type_info(type, :path), force_case(info)
122
130
  reply = json_parse_reply(@key_style, *json_post(@target, path, info,
123
- "authorization" => @auth_header))
131
+ headers))
124
132
  fake_client_id(reply) if type == :client # hide client reply, not quite scim
125
133
  reply
126
134
  end
@@ -130,7 +138,7 @@ class Scim
130
138
  # @param [String] id the id attribute of the SCIM object
131
139
  # @return [nil]
132
140
  def delete(type, id)
133
- http_delete @target, "#{type_info(type, :path)}/#{URI.encode(id)}", @auth_header
141
+ http_delete @target, "#{type_info(type, :path)}/#{URI.encode(id)}", @auth_header, @zone
134
142
  end
135
143
 
136
144
  # Replaces the contents of a SCIM object.
@@ -140,7 +148,7 @@ class Scim
140
148
  path, info = type_info(type, :path), force_case(info)
141
149
  ida = type == :client ? 'client_id' : 'id'
142
150
  raise ArgumentError, "info must include #{ida}" unless id = info[ida]
143
- hdrs = {'authorization' => @auth_header}
151
+ hdrs = headers
144
152
  if info && info['meta'] && (etag = info['meta']['version'])
145
153
  hdrs.merge!('if-match' => etag)
146
154
  end
@@ -158,7 +166,7 @@ class Scim
158
166
  path, info = type_info(type, :path), force_case(info)
159
167
  ida = type == :client ? 'client_id' : 'id'
160
168
  raise ArgumentError, "info must include #{ida}" unless id = info[ida]
161
- hdrs = {'authorization' => @auth_header}
169
+ hdrs = headers
162
170
  if info && info['meta'] && (etag = info['meta']['version'])
163
171
  hdrs.merge!('if-match' => etag)
164
172
  end
@@ -189,7 +197,7 @@ class Scim
189
197
  end
190
198
  qstr = query.empty?? '': "?#{Util.encode_form(query)}"
191
199
  info = json_get(@target, "#{type_info(type, :path)}#{qstr}",
192
- @key_style, 'authorization' => @auth_header)
200
+ @key_style, headers)
193
201
  unless info.is_a?(Hash) && info[rk = jkey(:resources)].is_a?(Array)
194
202
 
195
203
  # hide client endpoints that are not yet scim compatible
@@ -212,7 +220,7 @@ class Scim
212
220
  # @return (see #add)
213
221
  def get(type, id)
214
222
  info = json_get(@target, "#{type_info(type, :path)}/#{URI.encode(id)}",
215
- @key_style, 'authorization' => @auth_header)
223
+ @key_style, headers)
216
224
 
217
225
  fake_client_id(info) if type == :client # hide client reply, not quite scim
218
226
  info
@@ -288,8 +296,7 @@ class Scim
288
296
  req = {"password" => new_password}
289
297
  req["oldPassword"] = old_password if old_password
290
298
  json_parse_reply(@key_style, *json_put(@target,
291
- "#{type_info(:user, :path)}/#{URI.encode(user_id)}/password", req,
292
- 'authorization' => @auth_header))
299
+ "#{type_info(:user, :path)}/#{URI.encode(user_id)}/password", req, headers))
293
300
  end
294
301
 
295
302
  # Change client secret.
@@ -305,8 +312,7 @@ class Scim
305
312
  req = {"secret" => new_secret }
306
313
  req["oldSecret"] = old_secret if old_secret
307
314
  json_parse_reply(@key_style, *json_put(@target,
308
- "#{type_info(:client, :path)}/#{URI.encode(client_id)}/secret", req,
309
- 'authorization' => @auth_header))
315
+ "#{type_info(:client, :path)}/#{URI.encode(client_id)}/secret", req, headers))
310
316
  end
311
317
 
312
318
  def map_group(group, is_id, external_group)
@@ -314,19 +320,18 @@ class Scim
314
320
  request = {key_name => group, :externalGroup => external_group, :schemas => ["urn:scim:schemas:core:1.0"] }
315
321
  result = json_parse_reply(@key_style, *json_post(@target,
316
322
  "#{type_info(:group_mapping, :path)}", request,
317
- 'authorization' => @auth_header))
323
+ headers))
318
324
  result
319
325
  end
320
326
 
321
327
  def unmap_group(group_id, external_group)
322
328
  http_delete(@target, "#{type_info(:group_mapping, :path)}/id/#{group_id}/#{URI.encode(external_group)}",
323
- @auth_header)
329
+ @auth_header, @zone)
324
330
  end
325
331
 
326
332
  def list_group_mappings(start = nil, count = nil)
327
- json_get(@target, "#{type_info(:group_mapping, :path)}/list?startIndex=#{start}&count=#{count}", @key_style, 'authorization' => @auth_header)
333
+ json_get(@target, "#{type_info(:group_mapping, :path)}/list?startIndex=#{start}&count=#{count}", @key_style, headers)
328
334
  end
329
335
  end
330
336
 
331
337
  end
332
-
@@ -111,6 +111,7 @@ class TokenIssuer
111
111
  @key_style = options[:symbolize_keys] ? :sym : nil
112
112
  self.skip_ssl_validation = options[:skip_ssl_validation]
113
113
  self.ssl_ca_file = options[:ssl_ca_file]
114
+ self.ssl_cert_store = options[:ssl_cert_store]
114
115
  self.http_proxy = options[:http_proxy]
115
116
  self.https_proxy = options[:https_proxy]
116
117
  end
@@ -14,6 +14,6 @@
14
14
  # Cloud Foundry namespace
15
15
  module CF
16
16
  module UAA
17
- VERSION = "3.2.4"
17
+ VERSION = "3.2.5"
18
18
  end
19
19
  end
@@ -80,6 +80,18 @@ describe Http do
80
80
  expect(http_double).to have_received(:ca_file=).with("/fake-ca-file")
81
81
  expect(http_double).to have_received(:verify_mode=).with(OpenSSL::SSL::VERIFY_PEER)
82
82
  end
83
+
84
+ it "passes ssl cert store if provided" do
85
+ http_double = double('http').as_null_object
86
+ cert_store = double('OpenSSL::X509::Store')
87
+ Net::HTTP.stub(:new).and_return(http_double)
88
+
89
+ http_instance.ssl_cert_store = cert_store
90
+ http_instance.http_get("https://uncached.example.com")
91
+
92
+ expect(http_double).to have_received(:cert_store=).with(cert_store)
93
+ expect(http_double).to have_received(:verify_mode=).with(OpenSSL::SSL::VERIFY_PEER)
94
+ end
83
95
  end
84
96
 
85
97
  end
@@ -29,12 +29,13 @@ describe Scim do
29
29
 
30
30
  subject { @scim }
31
31
 
32
- def check_headers(headers, content, accept)
32
+ def check_headers(headers, content, accept, zone)
33
33
  headers["content-type"].should =~ /application\/json/ if content == :json
34
34
  headers["content-type"].should be_nil unless content
35
35
  headers["accept"].should =~ /application\/json/ if accept == :json
36
36
  headers["accept"].should be_nil unless accept
37
37
  headers["authorization"].should =~ /^(?i:bearer)\s+xyz$/
38
+ headers["X-Identity-Zone-Subdomain"].should eq zone
38
39
  end
39
40
 
40
41
  describe "initialize" do
@@ -54,7 +55,7 @@ describe Scim do
54
55
  subject.set_request_handler do |url, method, body, headers|
55
56
  url.should == "#{@target}/Users"
56
57
  method.should == :post
57
- check_headers(headers, :json, :json)
58
+ check_headers(headers, :json, :json, nil)
58
59
  [200, '{"ID":"id12345"}', {"content-type" => "application/json"}]
59
60
  end
60
61
  result = subject.add(:user, :hair => "brown", :shoe_size => "large",
@@ -68,7 +69,7 @@ describe Scim do
68
69
  subject.set_request_handler do |url, method, body, headers|
69
70
  url.should == "#{@target}/Users/id12345"
70
71
  method.should == :put
71
- check_headers(headers, :json, :json)
72
+ check_headers(headers, :json, :json, nil)
72
73
  headers["if-match"].should == "v567"
73
74
  [200, '{"ID":"id12345"}', {"content-type" => "application/json"}]
74
75
  end
@@ -82,7 +83,7 @@ describe Scim do
82
83
  subject.set_request_handler do |url, method, body, headers|
83
84
  url.should == "#{@target}/Users/id12345"
84
85
  method.should == :patch
85
- check_headers(headers, :json, :json)
86
+ check_headers(headers, :json, :json, nil)
86
87
  headers["if-match"].should == "v567"
87
88
  [200, '{"ID":"id12345"}', {"content-type" => "application/json"}]
88
89
  end
@@ -94,7 +95,7 @@ describe Scim do
94
95
  subject.set_request_handler do |url, method, body, headers|
95
96
  url.should == "#{@target}/Users/id12345"
96
97
  method.should == :get
97
- check_headers(headers, nil, :json)
98
+ check_headers(headers, nil, :json, nil)
98
99
  [200, '{"id":"id12345"}', {"content-type" => "application/json"}]
99
100
  end
100
101
  result = subject.get(:user, "id12345")
@@ -107,7 +108,7 @@ describe Scim do
107
108
  url.should =~ %r{[\?&]attributes=id(&|$)}
108
109
  url.should =~ %r{[\?&]startIndex=[12](&|$)}
109
110
  method.should == :get
110
- check_headers(headers, nil, :json)
111
+ check_headers(headers, nil, :json, nil)
111
112
  reply = url =~ /startIndex=1/ ?
112
113
  '{"TotalResults":2,"ItemsPerPage":1,"StartIndex":1,"RESOURCES":[{"id":"id12345"}]}' :
113
114
  '{"TotalResults":2,"ItemsPerPage":1,"StartIndex":2,"RESOURCES":[{"id":"id67890"}]}'
@@ -121,7 +122,7 @@ describe Scim do
121
122
  subject.set_request_handler do |url, method, body, headers|
122
123
  url.should == "#{@target}/Users/id12345/password"
123
124
  method.should == :put
124
- check_headers(headers, :json, :json)
125
+ check_headers(headers, :json, :json, nil)
125
126
  body.should include('"password":"newpwd"', '"oldPassword":"oldpwd"')
126
127
  [200, '{"id":"id12345"}', {"content-type" => "application/json"}]
127
128
  end
@@ -133,7 +134,7 @@ describe Scim do
133
134
  subject.set_request_handler do |url, method, body, headers|
134
135
  url.should == "#{@target}/Users/id12345/password"
135
136
  method.should == :put
136
- check_headers(headers, :json, :json)
137
+ check_headers(headers, :json, :json, nil)
137
138
  [400, '{"error":"invalid_password","message":"Your new password cannot be the same as the old password."}', {"content-type" => "application/json"}]
138
139
  end
139
140
  expect {subject.change_password("id12345", "oldpwd", "oldpwd")}.to raise_error(error=TargetError)
@@ -143,7 +144,7 @@ describe Scim do
143
144
  subject.set_request_handler do |url, method, body, headers|
144
145
  url.should == "#{@target}/oauth/clients/id12345/secret"
145
146
  method.should == :put
146
- check_headers(headers, :json, :json)
147
+ check_headers(headers, :json, :json, nil)
147
148
  body.should include('"secret":"newpwd"', '"oldSecret":"oldpwd"')
148
149
  [200, '{"id":"id12345"}', {"content-type" => "application/json"}]
149
150
  end
@@ -155,7 +156,7 @@ describe Scim do
155
156
  subject.set_request_handler do |url, method, body, headers|
156
157
  url.should == "#{@target}/Groups/External"
157
158
  method.should == :post
158
- check_headers(headers, :json, :json)
159
+ check_headers(headers, :json, :json, nil)
159
160
  body.should include('"displayName":"uaa-scope-name"', '"externalGroup":"external-group-name"', '"schemas":["urn:scim:schemas:core:1.0"]')
160
161
  [201, '{"displayName":"uaa-scope-name", "externalGroup": "external-group-name"}', {"content-type" => "application/json"}]
161
162
  end
@@ -168,19 +169,35 @@ describe Scim do
168
169
  subject.set_request_handler do |url, method, body, headers|
169
170
  url.should == "#{@target}/Groups/External/id/uaa-group-id/external%20group%20name"
170
171
  method.should == :delete
171
- check_headers(headers, nil, nil)
172
+ check_headers(headers, nil, nil, nil)
172
173
 
173
174
  [200, '{"displayName":"uaa-scope-name", "groupId": "uaa-group-id", "externalGroup": "external-group-name"}', {"content-type" => "application/json"}]
174
175
  end
175
176
  subject.unmap_group("uaa-group-id", "external group name")
176
177
  end
177
178
 
179
+ describe "users in a zone" do
180
+ let(:options) { {:http_proxy => 'http-proxy.com', :https_proxy => 'https-proxy.com', :skip_ssl_validation => true, :zone => 'derpzone'} }
181
+
182
+ it "sends zone header" do
183
+ subject.set_request_handler do |url, method, body, headers|
184
+ url.should == "#{@target}/Users"
185
+ method.should == :post
186
+ check_headers(headers, :json, :json, 'derpzone')
187
+ [200, '{"ID":"id12345"}', {"content-type" => "application/json"}]
188
+ end
189
+ result = subject.add(:user, :hair => "brown", :shoe_size => "large",
190
+ :eye_color => ["blue", "green"], :name => "fred")
191
+ result["id"].should == "id12345"
192
+ end
193
+ end
194
+
178
195
  describe "#list_group_mappings" do
179
196
  it "lists all the external group mappings with default pagination" do
180
197
  subject.set_request_handler do |url, method, body, headers|
181
198
  url.should start_with("#{@target}/Groups/External/list")
182
199
  method.should == :get
183
- check_headers(headers, nil, :json)
200
+ check_headers(headers, nil, :json, nil)
184
201
 
185
202
  [
186
203
  200,
@@ -198,7 +215,7 @@ describe Scim do
198
215
  subject.set_request_handler do |url, method, body, headers|
199
216
  url.should start_with("#{@target}/Groups/External/list")
200
217
  method.should == :get
201
- check_headers(headers, nil, :json)
218
+ check_headers(headers, nil, :json, nil)
202
219
 
203
220
  query_params = CGI::parse(URI.parse(url).query)
204
221
  start_index = query_params["startIndex"].first
@@ -216,6 +233,8 @@ describe Scim do
216
233
 
217
234
  subject.list_group_mappings(3, 10)
218
235
  end
236
+
237
+
219
238
  end
220
239
  end
221
240
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cf-uaa-lib
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.4
4
+ version: 3.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dave Syer
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2015-09-22 00:00:00.000000000 Z
15
+ date: 2015-12-01 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: multi_json