parent
0bab7839b1
commit
dcdebf71ac
@ -0,0 +1,39 @@ |
||||
#-- encoding: UTF-8 |
||||
|
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2018 the OpenProject Foundation (OPF) |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
||||
# Copyright (C) 2006-2017 Jean-Philippe Lang |
||||
# Copyright (C) 2010-2013 the ChiliProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License |
||||
# as published by the Free Software Foundation; either version 2 |
||||
# of the License, or (at your option) any later version. |
||||
# |
||||
# This program is distributed in the hope that it will be useful, |
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
# GNU General Public License for more details. |
||||
# |
||||
# You should have received a copy of the GNU General Public License |
||||
# along with this program; if not, write to the Free Software |
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||
# |
||||
# See docs/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
module Bcf::API::V2_1 |
||||
class AuthAPI < ::API::OpenProjectAPI |
||||
resources :auth do |
||||
get do |
||||
::Bcf::API::V2_1::Auth::SingleRepresenter.new(nil) |
||||
end |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,56 @@ |
||||
#-- encoding: UTF-8 |
||||
|
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2018 the OpenProject Foundation (OPF) |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
||||
# Copyright (C) 2006-2017 Jean-Philippe Lang |
||||
# Copyright (C) 2010-2013 the ChiliProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License |
||||
# as published by the Free Software Foundation; either version 2 |
||||
# of the License, or (at your option) any later version. |
||||
# |
||||
# This program is distributed in the hope that it will be useful, |
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
# GNU General Public License for more details. |
||||
# |
||||
# You should have received a copy of the GNU General Public License |
||||
# along with this program; if not, write to the Free Software |
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||
# |
||||
# See docs/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
module Bcf::API::V2_1 |
||||
class Auth::SingleRepresenter < Roar::Decorator |
||||
include Representable::JSON |
||||
include OpenProject::StaticRouting::UrlHelpers |
||||
|
||||
property :oauth2_auth_url, |
||||
getter: ->(decorator:, **) { |
||||
"#{decorator.root_url}oauth/authorize" |
||||
} |
||||
|
||||
property :oauth2_token_url, |
||||
getter: ->(decorator:, **) { |
||||
"#{decorator.root_url}oauth/token" |
||||
} |
||||
|
||||
property :supported_oauth2_flows, |
||||
getter: ->(*) { |
||||
%w(authorization_code_grant client_credentials) |
||||
} |
||||
|
||||
property :http_basic_supported, |
||||
getter: ->(*) { |
||||
false |
||||
} |
||||
end |
||||
end |
@ -0,0 +1,74 @@ |
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2019 the OpenProject Foundation (OPF) |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
||||
# Copyright (C) 2006-2017 Jean-Philippe Lang |
||||
# Copyright (C) 2010-2013 the ChiliProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License |
||||
# as published by the Free Software Foundation; either version 2 |
||||
# of the License, or (at your option) any later version. |
||||
# |
||||
# This program is distributed in the hope that it will be useful, |
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
# GNU General Public License for more details. |
||||
# |
||||
# You should have received a copy of the GNU General Public License |
||||
# along with this program; if not, write to the Free Software |
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||
# |
||||
# See docs/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
require 'spec_helper' |
||||
|
||||
require_relative '../shared_examples' |
||||
|
||||
describe Bcf::API::V2_1::Auth::SingleRepresenter, 'rendering' do |
||||
let(:instance) { described_class.new(nil) } |
||||
include OpenProject::StaticRouting::UrlHelpers |
||||
|
||||
subject { instance.to_json } |
||||
|
||||
describe 'attributes' do |
||||
before do |
||||
allow(OpenProject::Configuration) |
||||
.to receive(:rails_relative_url_root) |
||||
.and_return('/blubs') |
||||
end |
||||
|
||||
context 'oauth2_auth_url' do |
||||
it_behaves_like 'attribute' do |
||||
let(:value) { "http://localhost:3000/blubs/oauth/authorize" } |
||||
let(:path) { 'oauth2_auth_url' } |
||||
end |
||||
end |
||||
|
||||
context 'oauth2_token_url' do |
||||
it_behaves_like 'attribute' do |
||||
let(:value) { "http://localhost:3000/blubs/oauth/token" } |
||||
let(:path) { 'oauth2_token_url' } |
||||
end |
||||
end |
||||
|
||||
context 'http_basic_supported' do |
||||
it_behaves_like 'attribute' do |
||||
let(:value) { false } |
||||
let(:path) { 'http_basic_supported' } |
||||
end |
||||
end |
||||
|
||||
context 'supported_oauth2_flows' do |
||||
it_behaves_like 'attribute' do |
||||
let(:value) { %w(authorization_code_grant client_credentials) } |
||||
let(:path) { 'supported_oauth2_flows' } |
||||
end |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,62 @@ |
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2019 the OpenProject Foundation (OPF) |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
||||
# Copyright (C) 2006-2017 Jean-Philippe Lang |
||||
# Copyright (C) 2010-2013 the ChiliProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License |
||||
# as published by the Free Software Foundation; either version 2 |
||||
# of the License, or (at your option) any later version. |
||||
# |
||||
# This program is distributed in the hope that it will be useful, |
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
# GNU General Public License for more details. |
||||
# |
||||
# You should have received a copy of the GNU General Public License |
||||
# along with this program; if not, write to the Free Software |
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||
# |
||||
# See docs/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
require 'spec_helper' |
||||
require 'rack/test' |
||||
|
||||
require_relative './shared_responses' |
||||
|
||||
describe 'BCF 2.1 auth resource', type: :request, content_type: :json do |
||||
include Rack::Test::Methods |
||||
|
||||
let(:current_user) do |
||||
FactoryBot.create(:user) |
||||
end |
||||
|
||||
subject(:response) { last_response } |
||||
|
||||
describe 'GET /api/bcf/2.1/auth' do |
||||
let(:path) { "/api/bcf/2.1/auth" } |
||||
|
||||
before do |
||||
login_as(current_user) |
||||
get path |
||||
end |
||||
|
||||
it_behaves_like 'bcf api successful response' do |
||||
let(:expected_body) do |
||||
{ |
||||
"oauth2_auth_url": "http://localhost:3000/oauth/authorize", |
||||
"oauth2_token_url": "http://localhost:3000/oauth/token", |
||||
"http_basic_supported": false, |
||||
"supported_oauth2_flows": %w(authorization_code_grant client_credentials) |
||||
} |
||||
end |
||||
end |
||||
end |
||||
end |
Loading…
Reference in new issue