forked from doorkeeper-gem/doorkeeper-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.
chore: Use Doorkeeper helper in UserinfoController, add specs
- Loading branch information
Showing
2 changed files
with
40 additions
and
10 deletions.
There are no files selected for viewing
14 changes: 4 additions & 10 deletions
14
app/controllers/doorkeeper/openid_connect/userinfo_controller.rb
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
36 changes: 36 additions & 0 deletions
36
spec/controllers/doorkeeper/openid_connect/userinfo_controller_spec.rb
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,36 @@ | ||
require 'rails_helper' | ||
|
||
describe Doorkeeper::OpenidConnect::UserinfoController, type: :controller do | ||
let(:client) { create :application } | ||
let(:user) { User.create! name: 'Joe', password: 'sekret' } | ||
let(:token) { create :access_token, application: client, resource_owner_id: user.id } | ||
|
||
describe '#show' do | ||
context 'with a valid access token authorized for the openid scope' do | ||
let(:token) { create :access_token, application: client, resource_owner_id: user.id, scopes: 'openid' } | ||
|
||
it 'returns the user information as JSON' do | ||
get :show, access_token: token.token | ||
|
||
expect(response.status).to eq 200 | ||
expect(response.body).to eq %Q{{"sub":"#{user.id}"}} | ||
end | ||
end | ||
|
||
context 'with a valid access token not authorized for the openid scope' do | ||
it 'returns an error' do | ||
get :show, access_token: token.token | ||
|
||
expect(response.status).to eq 403 | ||
end | ||
end | ||
|
||
context 'without a valid access token' do | ||
it 'returns an error' do | ||
get :show, access_token: 'foobar' | ||
|
||
expect(response.status).to eq 401 | ||
end | ||
end | ||
end | ||
end |