Skip to content
Extraits de code Groupes Projets
Valider 65c40f23 rédigé par theworldbright's avatar theworldbright
Parcourir les fichiers

Load scopes from seeds

parent 99d6d7b3
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -4,8 +4,6 @@ module Api ...@@ -4,8 +4,6 @@ module Api
has_many :authorizations, through: :authorization_scopes has_many :authorizations, through: :authorization_scopes
validates :name, presence: true, uniqueness: true validates :name, presence: true, uniqueness: true
# TODO: Add constants so scopes can be referenced as OpenidConnect::Scope::Read
end end
end end
end end
Api::OpenidConnect::Scope.find_or_create_by!(name: "openid")
Api::OpenidConnect::Scope.find_or_create_by!(name: "read")
Api::OpenidConnect::Scope.find_or_create_by!(name: "write")
...@@ -23,7 +23,7 @@ module Api ...@@ -23,7 +23,7 @@ module Api
auth = Api::OpenidConnect::Authorization.with_redirect_uri(req.redirect_uri).use_code(req.code) auth = Api::OpenidConnect::Authorization.with_redirect_uri(req.redirect_uri).use_code(req.code)
req.invalid_grant! if auth.blank? req.invalid_grant! if auth.blank?
res.access_token = auth.create_access_token res.access_token = auth.create_access_token
if auth.accessible?(Api::OpenidConnect::Scope.find_by(name: "openid")) if auth.accessible?(Api::OpenidConnect::Scope.find_by!(name: "openid"))
id_token = auth.create_id_token id_token = auth.create_id_token
res.id_token = id_token.to_jwt(access_token: res.access_token) res.id_token = id_token.to_jwt(access_token: res.access_token)
end end
......
...@@ -15,7 +15,6 @@ describe Api::OpenidConnect::AuthorizationsController, type: :controller do ...@@ -15,7 +15,6 @@ describe Api::OpenidConnect::AuthorizationsController, type: :controller do
before do before do
sign_in :user, alice sign_in :user, alice
allow(@controller).to receive(:current_user).and_return(alice) allow(@controller).to receive(:current_user).and_return(alice)
Api::OpenidConnect::Scope.create!(name: "openid")
end end
describe "#new" do describe "#new" do
......
...@@ -8,8 +8,8 @@ describe Api::OpenidConnect::ProtectedResourceEndpoint, type: :request do ...@@ -8,8 +8,8 @@ describe Api::OpenidConnect::ProtectedResourceEndpoint, type: :request do
end end
let(:auth_with_read) do let(:auth_with_read) do
auth = Api::OpenidConnect::Authorization.create!(o_auth_application: client, user: alice) auth = Api::OpenidConnect::Authorization.create!(o_auth_application: client, user: alice)
auth.scopes << [Api::OpenidConnect::Scope.find_or_create_by(name: "openid"), auth.scopes << [Api::OpenidConnect::Scope.find_by!(name: "openid"),
Api::OpenidConnect::Scope.find_or_create_by(name: "read")] Api::OpenidConnect::Scope.find_by!(name: "read")]
auth auth
end end
let!(:access_token_with_read) { auth_with_read.create_access_token.to_s } let!(:access_token_with_read) { auth_with_read.create_access_token.to_s }
......
require "spec_helper" require "spec_helper"
describe Api::OpenidConnect::TokenEndpoint, type: :request do describe Api::OpenidConnect::TokenEndpoint, type: :request do
let!(:client) do let!(:client) do
Api::OpenidConnect::OAuthApplication.create!( Api::OpenidConnect::OAuthApplication.create!(
redirect_uris: ["http://localhost:3000/"], client_name: "diaspora client", redirect_uris: ["http://localhost:3000/"], client_name: "diaspora client",
ppid: true, sector_identifier_uri: "https://example.com/uri") ppid: true, sector_identifier_uri: "https://example.com/uri")
end end
let!(:auth) { let!(:auth) do
Api::OpenidConnect::Authorization.find_or_create_by( auth = Api::OpenidConnect::Authorization.find_or_create_by(
o_auth_application: client, user: bob, redirect_uri: "http://localhost:3000/") o_auth_application: client, user: bob, redirect_uri: "http://localhost:3000/")
} auth.scopes << [Api::OpenidConnect::Scope.find_by!(name: "openid")]
let!(:code) { auth.create_code } auth
before do
Api::OpenidConnect::Scope.find_or_create_by(name: "read")
end end
let!(:code) { auth.create_code }
describe "the authorization code grant type" do describe "the authorization code grant type" do
context "when the authorization code is valid" do context "when the authorization code is valid" do
......
...@@ -84,6 +84,7 @@ RSpec.configure do |config| ...@@ -84,6 +84,7 @@ RSpec.configure do |config|
$process_queue = false $process_queue = false
allow_any_instance_of(Postzord::Dispatcher::Public).to receive(:deliver_to_remote) allow_any_instance_of(Postzord::Dispatcher::Public).to receive(:deliver_to_remote)
allow_any_instance_of(Postzord::Dispatcher::Private).to receive(:deliver_to_remote) allow_any_instance_of(Postzord::Dispatcher::Private).to receive(:deliver_to_remote)
load "#{Rails.root}/db/seeds.rb"
end end
config.expect_with :rspec do |expect_config| config.expect_with :rspec do |expect_config|
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter