openid_connect 0.0.13 → 0.0.14

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- openid_connect (0.0.12)
4
+ openid_connect (0.0.13)
5
5
  activemodel (>= 3)
6
6
  attr_required (>= 0.0.3)
7
7
  json (>= 1.4.3)
@@ -70,7 +70,7 @@ GEM
70
70
  validate_url (0.2.0)
71
71
  activemodel (>= 3.0.0)
72
72
  webmock (1.7.4)
73
- addressable (~> 2.2, > 2.2.5)
73
+ addressable (> 2.2.5, ~> 2.2)
74
74
  crack (>= 0.1.7)
75
75
 
76
76
  PLATFORMS
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.13
1
+ 0.0.14
@@ -5,8 +5,8 @@ module OpenIDConnect
5
5
  class Principal
6
6
  attr_reader :identifier, :host
7
7
 
8
- def initialize(identifier)
9
- raise InvalidIdentifier if identifier.blank?
8
+ def self.parse(identifier)
9
+ raise InvalidIdentifier.new('Identifier Required') if identifier.blank?
10
10
  type = case identifier
11
11
  when /^(=|@|!)/
12
12
  XRI
@@ -15,15 +15,13 @@ module OpenIDConnect
15
15
  else
16
16
  URI
17
17
  end
18
- principal = type.new identifier
19
- @identifier = principal.identifier
20
- @host = principal.host
18
+ type.new identifier
21
19
  end
22
20
 
23
21
  def discover!
24
22
  SWD.discover!(
25
23
  :principal => identifier,
26
- :service => 'http://openid.net/specs/connect/1.0/issuer',
24
+ :service => Provider::SERVICE_URI,
27
25
  :host => host
28
26
  )
29
27
  rescue SWD::Exception => e
@@ -11,13 +11,12 @@ module OpenIDConnect
11
11
  private
12
12
 
13
13
  def normalize(identifier)
14
+ identifier = "https://#{identifier}" unless identifier.include?('://')
14
15
  uri = ::URI.parse(identifier)
15
- if uri.host.blank?
16
- uri.host, uri.path = uri.path.split('/', 2)
17
- uri.path = File.join('/', uri.path)
18
- end
19
- uri.scheme ||= 'https'
16
+ uri.fragment = nil
20
17
  uri
18
+ rescue ::URI::Error => e
19
+ raise InvalidIdentifier.new('Invalid URI')
21
20
  end
22
21
  end
23
22
  end
@@ -5,6 +5,10 @@ module OpenIDConnect
5
5
  def initialize(identifier)
6
6
  @identifier = identifier
7
7
  end
8
+
9
+ def discover!
10
+ raise NotImplementedError.new('XRI is not supported yet')
11
+ end
8
12
  end
9
13
  end
10
14
  end
@@ -1,8 +1,10 @@
1
1
  module OpenIDConnect
2
2
  module Discovery
3
3
  module Provider
4
+ SERVICE_URI = 'http://openid.net/specs/connect/1.0/issuer'
5
+
4
6
  def self.discover!(identifier)
5
- Principal.new(identifier).discover!
7
+ Principal.parse(identifier).discover!
6
8
  end
7
9
  end
8
10
  end
@@ -0,0 +1,3 @@
1
+ {
2
+ "locations": ["https://server.example.com/authorize"]
3
+ }
@@ -1,5 +1,43 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe OpenIDConnect::Discovery::Principal::URI do
4
- it :TODO
4
+ subject { uri }
5
+ let(:uri) { OpenIDConnect::Discovery::Principal::URI.new identifier }
6
+
7
+ {
8
+ 'server.example.com' => 'https://server.example.com',
9
+ 'server.example.com/' => 'https://server.example.com/',
10
+ 'server.example.com/nov' => 'https://server.example.com/nov',
11
+ 'server.example.com/nov/' => 'https://server.example.com/nov/',
12
+ 'server.example.com/nov#id' => 'https://server.example.com/nov',
13
+ 'server.example.com/nov?k=v' => 'https://server.example.com/nov?k=v',
14
+ 'server.example.com/nov?k=v#id' => 'https://server.example.com/nov?k=v',
15
+ 'http://server.example.com' => 'http://server.example.com',
16
+ 'http://server.example.com/' => 'http://server.example.com/',
17
+ 'http://server.example.com/nov' => 'http://server.example.com/nov',
18
+ 'http://server.example.com/nov/' => 'http://server.example.com/nov/',
19
+ 'http://server.example.com/nov#id' => 'http://server.example.com/nov',
20
+ 'http://server.example.com/nov?k=v' => 'http://server.example.com/nov?k=v',
21
+ 'http://server.example.com/nov?k=v#id' => 'http://server.example.com/nov?k=v',
22
+ 'https://server.example.com' => 'https://server.example.com',
23
+ 'https://server.example.com/' => 'https://server.example.com/',
24
+ 'https://server.example.com/nov' => 'https://server.example.com/nov',
25
+ 'https://server.example.com/nov/' => 'https://server.example.com/nov/',
26
+ 'https://server.example.com/nov#id' => 'https://server.example.com/nov',
27
+ 'https://server.example.com/nov?k=v' => 'https://server.example.com/nov?k=v',
28
+ 'https://server.example.com/nov?k=v#id' => 'https://server.example.com/nov?k=v',
29
+ }.each do |input, output|
30
+ context "when '#{input}' is given" do
31
+ let(:identifier) { input }
32
+ its(:identifier) { should == output }
33
+ its(:host) { should == 'server.example.com' }
34
+ end
35
+ end
36
+
37
+ describe 'error handling' do
38
+ let(:identifier) { '**' }
39
+ it do
40
+ expect { uri }.should raise_error OpenIDConnect::Discovery::InvalidIdentifier
41
+ end
42
+ end
5
43
  end
@@ -1,5 +1,35 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe OpenIDConnect::Discovery::Principal do
4
- it :TODO
4
+ describe '.parse' do
5
+ {
6
+ 'server.example.com' => OpenIDConnect::Discovery::Principal::URI,
7
+ 'http://server.example.com' => OpenIDConnect::Discovery::Principal::URI,
8
+ 'nov@server.example.com' => OpenIDConnect::Discovery::Principal::Email,
9
+ '=nov' => OpenIDConnect::Discovery::Principal::XRI,
10
+ '@nov' => OpenIDConnect::Discovery::Principal::XRI
11
+ }.each do |input, klass|
12
+ describe input do
13
+ it do
14
+ OpenIDConnect::Discovery::Principal.parse(input).should be_a klass
15
+ end
16
+ end
17
+ end
18
+ end
19
+
20
+ describe '#discover!' do
21
+ let(:request) { OpenIDConnect::Discovery::Principal.new.discover! }
22
+
23
+ it 'should do SWD discovery' do
24
+ SWD.should_receive(:discover!)
25
+ request
26
+ end
27
+
28
+ context 'when discovery failed' do
29
+ it do
30
+ SWD.should_receive(:discover!).and_raise(SWD::Exception)
31
+ expect { request }.should raise_error OpenIDConnect::Discovery::DiscoveryFailed
32
+ end
33
+ end
34
+ end
5
35
  end
@@ -0,0 +1,59 @@
1
+ require 'spec_helper'
2
+
3
+ describe OpenIDConnect::Discovery::Provider do
4
+ let(:provider) { 'https://server.example.com/authorize' }
5
+ let(:discover) { OpenIDConnect::Discovery::Provider.discover! identifier }
6
+ let(:endpoint) { "https://#{host}/.well-known/simple-web-discovery" }
7
+ let(:query) do
8
+ {
9
+ :service => OpenIDConnect::Discovery::Provider::SERVICE_URI,
10
+ :principal => principal
11
+ }
12
+ end
13
+
14
+ shared_examples_for :discover_provider do
15
+ it "should succeed" do
16
+ mock_json :get, endpoint, 'discovery/swd', :params => query do
17
+ res = discover
18
+ res.should be_a SWD::Response
19
+ res.location.should == provider
20
+ end
21
+ end
22
+ end
23
+
24
+ describe '#discover!' do
25
+
26
+ context 'when URI is given' do
27
+ let(:principal) { identifier }
28
+
29
+ context 'when scheme included' do
30
+ let(:host) { URI.parse(identifier).host }
31
+
32
+ context 'when HTTPS' do
33
+ let(:identifier) { 'https://server.example.com' }
34
+ it_behaves_like :discover_provider
35
+ end
36
+
37
+ context 'otherwise' do
38
+ let(:identifier) { 'http://server.example.com' }
39
+ it_behaves_like :discover_provider
40
+ it 'should access to https://**' do
41
+ endpoint.should match /^https:\/\//
42
+ end
43
+ end
44
+ end
45
+
46
+ context 'when only host is given' do
47
+ let(:identifier) { 'server.example.com' }
48
+ let(:host) { identifier }
49
+ let(:principal) { "https://#{identifier}" }
50
+ it_behaves_like :discover_provider
51
+ end
52
+ end
53
+
54
+ context 'when Email is given' do
55
+ it :TODO
56
+ end
57
+
58
+ end
59
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: openid_connect
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.13
5
+ version: 0.0.14
6
6
  platform: ruby
7
7
  authors:
8
8
  - nov matake
@@ -198,6 +198,7 @@ files:
198
198
  - spec/mock_response/access_token/bearer.json
199
199
  - spec/mock_response/access_token/bearer_with_id_token.json
200
200
  - spec/mock_response/access_token/mac.json
201
+ - spec/mock_response/discovery/swd.json
201
202
  - spec/mock_response/errors/insufficient_scope.json
202
203
  - spec/mock_response/errors/invalid_access_token.json
203
204
  - spec/mock_response/errors/invalid_request.json
@@ -210,7 +211,7 @@ files:
210
211
  - spec/openid_connect/discovery/principal/uri_spec.rb
211
212
  - spec/openid_connect/discovery/principal/xri_spec.rb
212
213
  - spec/openid_connect/discovery/principal_spec.rb
213
- - spec/openid_connect/discovery_spec.rb
214
+ - spec/openid_connect/discovery/provider_spec.rb
214
215
  - spec/openid_connect/exception_spec.rb
215
216
  - spec/openid_connect/response_object/id_token_spec.rb
216
217
  - spec/openid_connect/response_object/user_info/open_id/address_spec.rb
@@ -254,6 +255,7 @@ test_files:
254
255
  - spec/mock_response/access_token/bearer.json
255
256
  - spec/mock_response/access_token/bearer_with_id_token.json
256
257
  - spec/mock_response/access_token/mac.json
258
+ - spec/mock_response/discovery/swd.json
257
259
  - spec/mock_response/errors/insufficient_scope.json
258
260
  - spec/mock_response/errors/invalid_access_token.json
259
261
  - spec/mock_response/errors/invalid_request.json
@@ -266,7 +268,7 @@ test_files:
266
268
  - spec/openid_connect/discovery/principal/uri_spec.rb
267
269
  - spec/openid_connect/discovery/principal/xri_spec.rb
268
270
  - spec/openid_connect/discovery/principal_spec.rb
269
- - spec/openid_connect/discovery_spec.rb
271
+ - spec/openid_connect/discovery/provider_spec.rb
270
272
  - spec/openid_connect/exception_spec.rb
271
273
  - spec/openid_connect/response_object/id_token_spec.rb
272
274
  - spec/openid_connect/response_object/user_info/open_id/address_spec.rb
@@ -1,5 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe OpenIDConnect::Discovery do
4
- it :TODO
5
- end