cf-uaa-lib 2.1.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9bf9b6c77939ea097c5e4e04bb84b56fcc2ee251
4
+ data.tar.gz: 3363c83dc1fa3b1b946296b492f8652f2190cd2f
5
+ SHA512:
6
+ metadata.gz: a6be5ce23db43f6dd8e30f4ea127239abd1b77145d3ead280530e2c11a30ee693a40c18c5ff1f3387c7fd98d904b080f381cef5913e9227bc813263c006513a2
7
+ data.tar.gz: 9bacf86eea0a2215a87131aacabe7c48d7967419a0e2e8ae407ebf67b10b1baefa46c3f88898c58aaf7f9f7a4ebe7926d6e800578753bd599bd4608c89c0b374
data/cf-uaa-lib.gemspec CHANGED
@@ -36,11 +36,11 @@ Gem::Specification.new do |s|
36
36
  s.add_dependency "multi_json"
37
37
 
38
38
  s.add_development_dependency "bundler"
39
- s.add_development_dependency "rake"
40
- s.add_development_dependency "rspec"
41
- s.add_development_dependency "simplecov"
42
- s.add_development_dependency "simplecov-rcov"
43
- s.add_development_dependency "ci_reporter"
44
- s.add_development_dependency "json_pure"
39
+ s.add_development_dependency "rake", "~> 10.3.2"
40
+ s.add_development_dependency "rspec", "~> 2.14.1"
41
+ s.add_development_dependency "simplecov", "~> 0.8.2"
42
+ s.add_development_dependency "simplecov-rcov", "~> 0.2.3"
43
+ s.add_development_dependency "ci_reporter", "~> 1.9.2"
44
+ s.add_development_dependency "json_pure", "~> 1.8.1"
45
45
 
46
46
  end
data/lib/uaa/http.rb CHANGED
@@ -21,6 +21,9 @@ module CF::UAA
21
21
  # Indicates URL for the target is bad or not accessible.
22
22
  class BadTarget < UAAError; end
23
23
 
24
+ # Indicates invalid SSL Certification for the target.
25
+ class SSLException < UAAError; end
26
+
24
27
  # Indicates the resource within the target server was not found.
25
28
  class NotFound < UAAError; end
26
29
 
@@ -47,7 +50,7 @@ module Http
47
50
 
48
51
  def self.included(base)
49
52
  base.class_eval do
50
- attr_accessor :http_proxy, :https_proxy
53
+ attr_accessor :http_proxy, :https_proxy, :skip_ssl_validation
51
54
  end
52
55
  end
53
56
 
@@ -97,6 +100,10 @@ module Http
97
100
  http_put(target, path, Util.json(body), headers.merge("content-type" => JSON_UTF8))
98
101
  end
99
102
 
103
+ def json_patch(target, path, body, headers = {})
104
+ http_patch(target, path, Util.json(body), headers.merge("content-type" => JSON_UTF8))
105
+ end
106
+
100
107
  def json_parse_reply(style, status, body, headers)
101
108
  raise ArgumentError unless style.nil? || style.is_a?(Symbol)
102
109
  unless [200, 201, 204, 400, 401, 403, 409].include? status
@@ -119,6 +126,7 @@ module Http
119
126
  def http_get(target, path = nil, headers = {}) request(target, :get, path, nil, headers) end
120
127
  def http_post(target, path, body, headers = {}) request(target, :post, path, body, headers) end
121
128
  def http_put(target, path, body, headers = {}) request(target, :put, path, body, headers) end
129
+ def http_patch(target, path, body, headers = {}) request(target, :patch, path, body, headers) end
122
130
 
123
131
  def http_delete(target, path, authorization)
124
132
  status = request(target, :delete, path, nil, "authorization" => authorization)[0]
@@ -147,7 +155,7 @@ module Http
147
155
 
148
156
  def net_http_request(url, method, body, headers)
149
157
  raise ArgumentError unless reqtype = {:delete => Net::HTTP::Delete,
150
- :get => Net::HTTP::Get, :post => Net::HTTP::Post, :put => Net::HTTP::Put}[method]
158
+ :get => Net::HTTP::Get, :post => Net::HTTP::Post, :put => Net::HTTP::Put, :patch => Net::HTTP::Patch}[method]
151
159
  headers["content-length"] = body.length if body
152
160
  uri = URI.parse(url)
153
161
  req = reqtype.new(uri.request_uri)
@@ -157,6 +165,8 @@ module Http
157
165
  reply.each_header { |k, v| outhdrs[k] = v }
158
166
  [reply.code.to_i, reply.body, outhdrs]
159
167
 
168
+ rescue OpenSSL::SSL::SSLError => e
169
+ raise SSLException, "Invalid SSL Cert for #{url}. Use '--skip-ssl-validation' to continue with an insecure target"
160
170
  rescue URI::Error, SocketError, SystemCallError => e
161
171
  raise BadTarget, "error: #{e.message}"
162
172
  rescue Net::HTTPBadResponse => e
@@ -172,7 +182,7 @@ module Http
172
182
 
173
183
  if uri.is_a?(URI::HTTPS)
174
184
  http.use_ssl = true
175
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE
185
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE if skip_ssl_validation
176
186
  end
177
187
 
178
188
  @http_cache[cache_key] = http
data/lib/uaa/info.rb CHANGED
@@ -31,6 +31,7 @@ class Info
31
31
  # string keys are returned.
32
32
  def initialize(target, options = {})
33
33
  self.target = target
34
+ self.skip_ssl_validation = options[:skip_ssl_validation]
34
35
  self.symbolize_keys = options[:symbolize_keys]
35
36
  self.http_proxy = options[:http_proxy]
36
37
  self.https_proxy = options[:https_proxy]
data/lib/uaa/scim.rb CHANGED
@@ -99,6 +99,7 @@ class Scim
99
99
  def initialize(target, auth_header, options = {})
100
100
  @target, @auth_header = target, auth_header
101
101
  @key_style = options[:symbolize_keys] ? :downsym : :down
102
+ self.skip_ssl_validation = options[:skip_ssl_validation]
102
103
  self.http_proxy = options[:http_proxy]
103
104
  self.https_proxy = options[:https_proxy]
104
105
  end
@@ -148,6 +149,24 @@ class Scim
148
149
  type == :client && !reply ? get(type, info['client_id']): reply
149
150
  end
150
151
 
152
+ # Modifies the contents of a SCIM object.
153
+ # @param (see #add)
154
+ # @return (see #add)
155
+ def patch(type, info)
156
+ path, info = type_info(type, :path), force_case(info)
157
+ ida = type == :client ? 'client_id' : 'id'
158
+ raise ArgumentError, "info must include #{ida}" unless id = info[ida]
159
+ hdrs = {'authorization' => @auth_header}
160
+ if info && info['meta'] && (etag = info['meta']['version'])
161
+ hdrs.merge!('if-match' => etag)
162
+ end
163
+ reply = json_parse_reply(@key_style,
164
+ *json_patch(@target, "#{path}/#{URI.encode(id)}", info, hdrs))
165
+
166
+ # hide client endpoints that are not quite scim compatible
167
+ type == :client && !reply ? get(type, info['client_id']): reply
168
+ end
169
+
151
170
  # Gets a set of attributes for each object that matches a given filter.
152
171
  # @param (see #add)
153
172
  # @param [Hash] query may contain the following keys:
@@ -109,6 +109,7 @@ class TokenIssuer
109
109
  @target, @client_id, @client_secret = target, client_id, client_secret
110
110
  @token_target = options[:token_target] || target
111
111
  @key_style = options[:symbolize_keys] ? :sym : nil
112
+ self.skip_ssl_validation = options[:skip_ssl_validation]
112
113
  self.http_proxy = options[:http_proxy]
113
114
  self.https_proxy = options[:https_proxy]
114
115
  end
data/lib/uaa/version.rb CHANGED
@@ -14,6 +14,6 @@
14
14
  # Cloud Foundry namespace
15
15
  module CF
16
16
  module UAA
17
- VERSION = "2.1.0"
17
+ VERSION = "3.0.0"
18
18
  end
19
19
  end
data/spec/http_spec.rb CHANGED
@@ -49,6 +49,26 @@ describe Http do
49
49
  expect(Net::HTTP).to have_received(:new).with(anything, anything, 'http-proxy.example.com', 1234, 'user', 'password')
50
50
  end
51
51
 
52
+ it "raises an SSLException when the certificate is not valid" do
53
+ http_double = double('http').as_null_object
54
+ Net::HTTP.stub(:new).and_return(http_double)
55
+ http_double.stub(:request).and_raise(OpenSSL::SSL::SSLError)
56
+
57
+ expect { http_instance.http_get("https://example.com") }.to raise_error(CF::UAA::SSLException)
58
+ end
59
+
60
+ it "skips ssl validation if requested" do
61
+ http_double = double('http').as_null_object
62
+ Net::HTTP.stub(:new).and_return(http_double)
63
+ http_double.stub(:verify_mode=)
64
+
65
+ http_instance.http_get("https://example.com")
66
+ expect(http_double).not_to have_received(:verify_mode=)
67
+
68
+ http_instance.skip_ssl_validation = true
69
+ http_instance.http_get("https://uncached.example.com")
70
+ expect(http_double).to have_received(:verify_mode=).with(OpenSSL::SSL::VERIFY_NONE)
71
+ end
52
72
  end
53
73
 
54
74
  end
data/spec/info_spec.rb CHANGED
@@ -34,11 +34,12 @@ module CF::UAA
34
34
  end
35
35
 
36
36
  describe "initialize" do
37
- let(:options) { {:http_proxy => 'http-proxy.com', :https_proxy => 'https-proxy.com'} }
37
+ let(:options) { {:http_proxy => 'http-proxy.com', :https_proxy => 'https-proxy.com', :skip_ssl_validation => true} }
38
38
 
39
39
  it "sets proxy information" do
40
40
  uaa_info.http_proxy.should == 'http-proxy.com'
41
41
  uaa_info.https_proxy.should == 'https-proxy.com'
42
+ uaa_info.skip_ssl_validation == true
42
43
  end
43
44
  end
44
45
 
data/spec/scim_spec.rb CHANGED
@@ -36,12 +36,16 @@ describe Scim do
36
36
  end
37
37
 
38
38
  describe "initialize" do
39
- let(:options) { {:http_proxy => 'http-proxy.com', :https_proxy => 'https-proxy.com'} }
39
+ let(:options) { {:http_proxy => 'http-proxy.com', :https_proxy => 'https-proxy.com', :skip_ssl_validation => true} }
40
40
 
41
41
  it "sets proxy information" do
42
42
  subject.http_proxy.should == 'http-proxy.com'
43
43
  subject.https_proxy.should == 'https-proxy.com'
44
44
  end
45
+
46
+ it "sets skip_ssl_validation" do
47
+ subject.skip_ssl_validation == true
48
+ end
45
49
  end
46
50
 
47
51
  it "adds an object" do
@@ -70,6 +74,20 @@ describe Scim do
70
74
  result["id"].should == "id12345"
71
75
  end
72
76
 
77
+ it "modifies an object" do
78
+ obj = {:hair => "black", :shoe_size => "medium", :eye_color => ["hazel", "brown"],
79
+ :name => "fredrick", :meta => {:version => 'v567'}, :id => "id12345"}
80
+ subject.set_request_handler do |url, method, body, headers|
81
+ url.should == "#{@target}/Users/id12345"
82
+ method.should == :patch
83
+ check_headers(headers, :json, :json)
84
+ headers["if-match"].should == "v567"
85
+ [200, '{"ID":"id12345"}', {"content-type" => "application/json"}]
86
+ end
87
+ result = subject.patch(:user, obj)
88
+ result["id"].should == "id12345"
89
+ end
90
+
73
91
  it "gets an object" do
74
92
  subject.set_request_handler do |url, method, body, headers|
75
93
  url.should == "#{@target}/Users/id12345"
@@ -29,12 +29,16 @@ describe TokenIssuer do
29
29
  subject { @issuer }
30
30
 
31
31
  describe "initialize" do
32
- let(:options) { {:http_proxy => 'http-proxy.com', :https_proxy => 'https-proxy.com'} }
32
+ let(:options) { {:http_proxy => 'http-proxy.com', :https_proxy => 'https-proxy.com', :skip_ssl_validation => true} }
33
33
 
34
34
  it "sets proxy information" do
35
35
  subject.http_proxy.should == 'http-proxy.com'
36
36
  subject.https_proxy.should == 'https-proxy.com'
37
37
  end
38
+
39
+ it "sets skip_ssl_validation" do
40
+ subject.skip_ssl_validation == true
41
+ end
38
42
  end
39
43
 
40
44
  context "with client credentials grant" do
metadata CHANGED
@@ -1,15 +1,9 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: cf-uaa-lib
3
- version: !ruby/object:Gem::Version
4
- hash: 11
5
- prerelease:
6
- segments:
7
- - 2
8
- - 1
9
- - 0
10
- version: 2.1.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 3.0.0
11
5
  platform: ruby
12
- authors:
6
+ authors:
13
7
  - Dave Syer
14
8
  - Dale Olds
15
9
  - Joel D'sa
@@ -18,138 +12,138 @@ authors:
18
12
  autorequire:
19
13
  bindir: bin
20
14
  cert_chain: []
21
-
22
- date: 2014-04-15 00:00:00 Z
23
- dependencies:
24
- - !ruby/object:Gem::Dependency
15
+ date: 2014-08-06 00:00:00.000000000 Z
16
+ dependencies:
17
+ - !ruby/object:Gem::Dependency
25
18
  name: multi_json
26
- prerelease: false
27
- requirement: &id001 !ruby/object:Gem::Requirement
28
- none: false
29
- requirements:
19
+ requirement: !ruby/object:Gem::Requirement
20
+ requirements:
30
21
  - - ">="
31
- - !ruby/object:Gem::Version
32
- hash: 3
33
- segments:
34
- - 0
35
- version: "0"
22
+ - !ruby/object:Gem::Version
23
+ version: '0'
36
24
  type: :runtime
37
- version_requirements: *id001
38
- - !ruby/object:Gem::Dependency
39
- name: bundler
40
25
  prerelease: false
41
- requirement: &id002 !ruby/object:Gem::Requirement
42
- none: false
43
- requirements:
26
+ version_requirements: !ruby/object:Gem::Requirement
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ version: '0'
31
+ - !ruby/object:Gem::Dependency
32
+ name: bundler
33
+ requirement: !ruby/object:Gem::Requirement
34
+ requirements:
44
35
  - - ">="
45
- - !ruby/object:Gem::Version
46
- hash: 3
47
- segments:
48
- - 0
49
- version: "0"
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
50
38
  type: :development
51
- version_requirements: *id002
52
- - !ruby/object:Gem::Dependency
53
- name: rake
54
39
  prerelease: false
55
- requirement: &id003 !ruby/object:Gem::Requirement
56
- none: false
57
- requirements:
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ requirements:
58
42
  - - ">="
59
- - !ruby/object:Gem::Version
60
- hash: 3
61
- segments:
62
- - 0
63
- version: "0"
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ - !ruby/object:Gem::Dependency
46
+ name: rake
47
+ requirement: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - "~>"
50
+ - !ruby/object:Gem::Version
51
+ version: 10.3.2
64
52
  type: :development
65
- version_requirements: *id003
66
- - !ruby/object:Gem::Dependency
67
- name: rspec
68
53
  prerelease: false
69
- requirement: &id004 !ruby/object:Gem::Requirement
70
- none: false
71
- requirements:
72
- - - ">="
73
- - !ruby/object:Gem::Version
74
- hash: 3
75
- segments:
76
- - 0
77
- version: "0"
54
+ version_requirements: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - "~>"
57
+ - !ruby/object:Gem::Version
58
+ version: 10.3.2
59
+ - !ruby/object:Gem::Dependency
60
+ name: rspec
61
+ requirement: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - "~>"
64
+ - !ruby/object:Gem::Version
65
+ version: 2.14.1
78
66
  type: :development
79
- version_requirements: *id004
80
- - !ruby/object:Gem::Dependency
81
- name: simplecov
82
67
  prerelease: false
83
- requirement: &id005 !ruby/object:Gem::Requirement
84
- none: false
85
- requirements:
86
- - - ">="
87
- - !ruby/object:Gem::Version
88
- hash: 3
89
- segments:
90
- - 0
91
- version: "0"
68
+ version_requirements: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - "~>"
71
+ - !ruby/object:Gem::Version
72
+ version: 2.14.1
73
+ - !ruby/object:Gem::Dependency
74
+ name: simplecov
75
+ requirement: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - "~>"
78
+ - !ruby/object:Gem::Version
79
+ version: 0.8.2
92
80
  type: :development
93
- version_requirements: *id005
94
- - !ruby/object:Gem::Dependency
95
- name: simplecov-rcov
96
81
  prerelease: false
97
- requirement: &id006 !ruby/object:Gem::Requirement
98
- none: false
99
- requirements:
100
- - - ">="
101
- - !ruby/object:Gem::Version
102
- hash: 3
103
- segments:
104
- - 0
105
- version: "0"
82
+ version_requirements: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - "~>"
85
+ - !ruby/object:Gem::Version
86
+ version: 0.8.2
87
+ - !ruby/object:Gem::Dependency
88
+ name: simplecov-rcov
89
+ requirement: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - "~>"
92
+ - !ruby/object:Gem::Version
93
+ version: 0.2.3
106
94
  type: :development
107
- version_requirements: *id006
108
- - !ruby/object:Gem::Dependency
109
- name: ci_reporter
110
95
  prerelease: false
111
- requirement: &id007 !ruby/object:Gem::Requirement
112
- none: false
113
- requirements:
114
- - - ">="
115
- - !ruby/object:Gem::Version
116
- hash: 3
117
- segments:
118
- - 0
119
- version: "0"
96
+ version_requirements: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - "~>"
99
+ - !ruby/object:Gem::Version
100
+ version: 0.2.3
101
+ - !ruby/object:Gem::Dependency
102
+ name: ci_reporter
103
+ requirement: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - "~>"
106
+ - !ruby/object:Gem::Version
107
+ version: 1.9.2
120
108
  type: :development
121
- version_requirements: *id007
122
- - !ruby/object:Gem::Dependency
123
- name: json_pure
124
109
  prerelease: false
125
- requirement: &id008 !ruby/object:Gem::Requirement
126
- none: false
127
- requirements:
128
- - - ">="
129
- - !ruby/object:Gem::Version
130
- hash: 3
131
- segments:
132
- - 0
133
- version: "0"
110
+ version_requirements: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - "~>"
113
+ - !ruby/object:Gem::Version
114
+ version: 1.9.2
115
+ - !ruby/object:Gem::Dependency
116
+ name: json_pure
117
+ requirement: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - "~>"
120
+ - !ruby/object:Gem::Version
121
+ version: 1.8.1
134
122
  type: :development
135
- version_requirements: *id008
136
- description: Client library for interacting with the CloudFoundry User Account and Authorization (UAA) server. The UAA is an OAuth2 Authorization Server so it can be used by webapps and command line apps to obtain access tokens to act on behalf of users. The tokens can then be used to access protected resources in a Resource Server. This library is for use by UAA client applications or resource servers.
137
- email:
123
+ prerelease: false
124
+ version_requirements: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - "~>"
127
+ - !ruby/object:Gem::Version
128
+ version: 1.8.1
129
+ description: Client library for interacting with the CloudFoundry User Account and
130
+ Authorization (UAA) server. The UAA is an OAuth2 Authorization Server so it can
131
+ be used by webapps and command line apps to obtain access tokens to act on behalf
132
+ of users. The tokens can then be used to access protected resources in a Resource
133
+ Server. This library is for use by UAA client applications or resource servers.
134
+ email:
138
135
  - dsyer@vmware.com
139
136
  - olds@vmware.com
140
137
  - jdsa@vmware.com
141
138
  - vidya@vmware.com
142
139
  - ltaylor@vmware.com
143
140
  executables: []
144
-
145
141
  extensions: []
146
-
147
142
  extra_rdoc_files: []
148
-
149
- files:
150
- - .gitignore
151
- - .travis.yml
152
- - .yardopts
143
+ files:
144
+ - ".gitignore"
145
+ - ".travis.yml"
146
+ - ".yardopts"
153
147
  - CHANGELOG.md
154
148
  - Gemfile
155
149
  - LICENSE.TXT
@@ -174,37 +168,34 @@ files:
174
168
  - spec/token_coder_spec.rb
175
169
  - spec/token_issuer_spec.rb
176
170
  homepage: https://github.com/cloudfoundry/cf-uaa-lib
177
- licenses:
171
+ licenses:
178
172
  - Apache 2.0
173
+ metadata: {}
179
174
  post_install_message:
180
175
  rdoc_options: []
181
-
182
- require_paths:
176
+ require_paths:
183
177
  - lib
184
- required_ruby_version: !ruby/object:Gem::Requirement
185
- none: false
186
- requirements:
178
+ required_ruby_version: !ruby/object:Gem::Requirement
179
+ requirements:
187
180
  - - ">="
188
- - !ruby/object:Gem::Version
189
- hash: 3
190
- segments:
191
- - 0
192
- version: "0"
193
- required_rubygems_version: !ruby/object:Gem::Requirement
194
- none: false
195
- requirements:
181
+ - !ruby/object:Gem::Version
182
+ version: '0'
183
+ required_rubygems_version: !ruby/object:Gem::Requirement
184
+ requirements:
196
185
  - - ">="
197
- - !ruby/object:Gem::Version
198
- hash: 3
199
- segments:
200
- - 0
201
- version: "0"
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
202
188
  requirements: []
203
-
204
189
  rubyforge_project: cf-uaa-lib
205
- rubygems_version: 1.8.15
190
+ rubygems_version: 2.2.2
206
191
  signing_key:
207
- specification_version: 3
192
+ specification_version: 4
208
193
  summary: Client library for CloudFoundry UAA
209
- test_files: []
210
-
194
+ test_files:
195
+ - spec/http_spec.rb
196
+ - spec/info_spec.rb
197
+ - spec/integration_spec.rb
198
+ - spec/scim_spec.rb
199
+ - spec/spec_helper.rb
200
+ - spec/token_coder_spec.rb
201
+ - spec/token_issuer_spec.rb