forked from nov/openid_connect
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
213 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--color | ||
--format=documentation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
require 'webmock/rspec' | ||
|
||
module WebMockHelper | ||
def mock_json(method, endpoint, response_file, options = {}) | ||
stub_request(method, endpoint).with( | ||
request_for(method, options) | ||
).to_return( | ||
response_for(response_file, options) | ||
) | ||
yield | ||
a_request(method, endpoint).with( | ||
request_for(method, options) | ||
).should have_been_made.once | ||
end | ||
|
||
private | ||
|
||
def request_for(method, options = {}) | ||
request = {} | ||
if options[:params] | ||
case method | ||
when :post, :put | ||
request[:body] = options[:params] | ||
else | ||
request[:query] = options[:params] | ||
end | ||
end | ||
request | ||
end | ||
|
||
def response_for(response_file, options = {}) | ||
response = {} | ||
response[:body] = File.new(File.join(File.dirname(__FILE__), '../mock_response', "#{response_file}.#{options[:format] || :json}")) | ||
if options[:status] | ||
response[:status] = options[:status] | ||
end | ||
response | ||
end | ||
end | ||
|
||
include WebMockHelper | ||
WebMock.disable_net_connect! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"access_token":"access_token", | ||
"refresh_token":"refresh_token", | ||
"token_type":"bearer", | ||
"expires_in":3600 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"token_type": "mac", | ||
"mac_algorithm": "hmac-sha-256", | ||
"expires_in": 3600, | ||
"mac_key": "secret", | ||
"refresh_token": "refresh_token", | ||
"access_token": "access_token" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"error": "insufficient_scope" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"error": "invalid_access_token" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"error": "invalid_request" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Fuckin Unknown Error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"iss": "http://server.example.com", | ||
"client_id": "http://client.example.com", | ||
"aud": "http://client.example.com", | ||
"user_id": "user_328723", | ||
"exp": 1303852880 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"id": "90125", | ||
"name": "Jonathan Q. Doe", | ||
"given_name": "Jonathan", | ||
"middle_name": "Q.", | ||
"family_name": "Doe", | ||
"nickname": "John", | ||
"email": "[email protected]", | ||
"verified": true, | ||
"profile": "http://example.com/johndoe/", | ||
"picture": "http://example.com/johndoe/me.jpg", | ||
"website": "http://john.doe.blogs.example.net/", | ||
"gender": "male", | ||
"birthday": "05/02/0000", | ||
"zoneinfo": "America/Los_Angeles", | ||
"locale": "en_US", | ||
"phone_number": "+1 (425) 555-1212", | ||
"address": { | ||
"region": "WA", | ||
"country": "United States" | ||
}, | ||
"last_updated": "2011-06-29T21:10:22+0000" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,68 @@ | ||
require 'spec_helper' | ||
|
||
describe OpenIDConnect::AccessToken do | ||
subject { token } | ||
let :client do | ||
OpenIDConnect::Client.new( | ||
:identifier => 'client_id', | ||
:host => 'server.example.com' | ||
) | ||
end | ||
let :token do | ||
OpenIDConnect::AccessToken.new( | ||
:access_token => 'access_token', | ||
:client => client | ||
) | ||
end | ||
its(:token_type) { should == :bearer } | ||
|
||
describe '#user_info!' do | ||
it :TODO | ||
it 'should return OpenIDConnect::ResponseObject::UserInfo::OpenID' do | ||
mock_json :get, client.user_info_uri, 'user_info/openid', :HTTP_AUTHORIZATION => 'Bearer access_token' do | ||
token.user_info!.should be_a OpenIDConnect::ResponseObject::UserInfo::OpenID | ||
end | ||
end | ||
|
||
describe 'error handling' do | ||
context 'when bad_request' do | ||
it 'should raise OpenIDConnect::Forbidden' do | ||
mock_json :get, client.user_info_uri, 'errors/invalid_request', :HTTP_AUTHORIZATION => 'Bearer access_token', :status => 400 do | ||
expect { token.user_info! }.should raise_error OpenIDConnect::BadRequest | ||
end | ||
end | ||
end | ||
|
||
context 'when unauthorized' do | ||
it 'should raise OpenIDConnect::Unauthorized' do | ||
mock_json :get, client.user_info_uri, 'errors/invalid_access_token', :HTTP_AUTHORIZATION => 'Bearer access_token', :status => 401 do | ||
expect { token.user_info! }.should raise_error OpenIDConnect::Unauthorized | ||
end | ||
end | ||
end | ||
|
||
context 'when forbidden' do | ||
it 'should raise OpenIDConnect::Forbidden' do | ||
mock_json :get, client.user_info_uri, 'errors/insufficient_scope', :HTTP_AUTHORIZATION => 'Bearer access_token', :status => 403 do | ||
expect { token.user_info! }.should raise_error OpenIDConnect::Forbidden | ||
end | ||
end | ||
end | ||
|
||
context 'when unknown' do | ||
it 'should raise OpenIDConnect::HttpError' do | ||
mock_json :get, client.user_info_uri, 'errors/unknown', :HTTP_AUTHORIZATION => 'Bearer access_token', :status => 500 do | ||
expect { token.user_info! }.should raise_error OpenIDConnect::HttpError | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
describe '#id_token!' do | ||
it :TODO | ||
it 'should return OpenIDConnect::ResponseObject::IdToken' do | ||
mock_json :get, client.introspection_uri, 'id_token', :HTTP_AUTHORIZATION => 'Bearer access_token' do | ||
token.id_token!.should be_a OpenIDConnect::ResponseObject::IdToken | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
require 'rspec' | ||
require 'openid_connect' | ||
|
||
require 'helpers/webmock_helper' |