Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Service specs

Oliver Günther2f3e7daef8ce
diff --git a/modules/openid_connect/app/services/openid_connect/providers/update_service.rb b/modules/openid_connect/app/services/openid_connect/providers/update_service.rb
index 689f73bae2f..68b366a15d1 100644
--- a/modules/openid_connect/app/services/openid_connect/providers/update_service.rb
+++ b/modules/openid_connect/app/services/openid_connect/providers/update_service.rb
@@ -45,12 +45,15 @@ module OpenIDConnect
metadata_url = get_metadata_url(model)
return call if metadata_url.blank?
+ extract_metadata(call, metadata_url, model)
+ end
+
+ def extract_metadata(call, metadata_url, model) # rubocop:disable Metrics/AbcSize
case (response = OpenProject.httpx.get(metadata_url))
in {status: 200..299}
json = begin
response.json
rescue HTTPX::Error
- binding.pry
call.errors.add(:metadata_url, :response_is_not_json)
call.success = false
end
diff --git a/modules/openid_connect/spec/factories/oidc_provider_factory.rb b/modules/openid_connect/spec/factories/oidc_provider_factory.rb
index bc5502c8dbf..069df379891 100644
--- a/modules/openid_connect/spec/factories/oidc_provider_factory.rb
+++ b/modules/openid_connect/spec/factories/oidc_provider_factory.rb
@@ -11,7 +11,6 @@ FactoryBot.define do
"jwks_uri" => "https://keycloak.local/realms/master/protocol/openid-connect/certs",
"client_id" => "https://openproject.local",
"client_secret" => "9AWjVC3A4U1HLrZuSP4xiwHfw6zmgECn",
- "metadata_url" => "https://keycloak.local/realms/master/.well-known/openid-configuration",
"oidc_provider" => "custom",
"token_endpoint" => "https://keycloak.local/realms/master/protocol/openid-connect/token",
"userinfo_endpoint" => "https://keycloak.local/realms/master/protocol/openid-connect/userinfo",
diff --git a/modules/openid_connect/spec/services/openid_connect/providers/create_service_spec.rb b/modules/openid_connect/spec/services/openid_connect/providers/create_service_spec.rb
new file mode 100644
index 00000000000..79f9518b4bb
--- /dev/null
+++ b/modules/openid_connect/spec/services/openid_connect/providers/create_service_spec.rb
@@ -0,0 +1,36 @@
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) the OpenProject GmbH
+#
+# 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-2013 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 COPYRIGHT and LICENSE files for more details.
+#++
+
+require "spec_helper"
+require "services/base_services/behaves_like_create_service"
+
+RSpec.describe OpenIDConnect::Providers::CreateService, type: :model do
+ it_behaves_like "BaseServices create service" do
+ let(:factory) { :oidc_provider }
+ end
+end
diff --git a/modules/openid_connect/spec/services/openid_connect/providers/set_attributes_service_spec.rb b/modules/openid_connect/spec/services/openid_connect/providers/set_attributes_service_spec.rb
new file mode 100644
index 00000000000..d348a60394b
--- /dev/null
+++ b/modules/openid_connect/spec/services/openid_connect/providers/set_attributes_service_spec.rb
@@ -0,0 +1,130 @@
+# frozen_string_literal: true
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) the OpenProject GmbH
+#
+# 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-2013 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 COPYRIGHT and LICENSE files for more details.
+#++
+
+require "spec_helper"
+require_module_spec_helper
+
+RSpec.describe OpenIDConnect::Providers::SetAttributesService, type: :model do
+ let(:current_user) { build_stubbed(:admin) }
+
+ let(:instance) do
+ described_class.new(user: current_user,
+ model: model_instance,
+ contract_class:,
+ contract_options: {})
+ end
+
+ let(:call) { instance.call(params) }
+
+ subject { call.result }
+
+ describe "new instance" do
+ let(:model_instance) { OpenIDConnect::Provider.new(oidc_provider: 'custom', display_name: "foo") }
+ let(:contract_class) { OpenIDConnect::Providers::CreateContract }
+
+ describe "default attributes" do
+ let(:params) { {} }
+
+ it "sets all default attributes", :aggregate_failures do
+ expect(subject.display_name).to eq "foo"
+ expect(subject.slug).to eq "oidc-foo"
+ expect(subject.creator).to eq(current_user)
+
+ expect(subject.mapping_email).to be_blank
+ expect(subject.mapping_first_name).to be_blank
+ expect(subject.mapping_last_name).to be_blank
+ expect(subject.mapping_login).to be_blank
+ end
+ end
+
+ %i[token_endpoint metadata_url jwks_uri userinfo_endpoint end_session_endpoint].each do |url_attr|
+ describe "setting #{url_attr}" do
+ let(:params) do
+ {
+ url_attr => value
+ }
+ end
+
+ context "when nil" do
+ let(:value) { nil }
+
+ it "is valid" do
+ expect(call).to be_success
+ expect(call.errors).to be_empty
+
+ expect(subject.public_send(url_attr)).to be_nil
+ end
+ end
+
+ context "when blank" do
+ let(:value) { "" }
+
+ it "is valid" do
+ expect(call).to be_success
+ expect(call.errors).to be_empty
+
+ expect(subject.public_send(url_attr)).to eq ""
+ end
+ end
+
+ context "when not a URL" do
+ let(:value) { "foo!" }
+
+ it "is valid" do
+ expect(call).not_to be_success
+ expect(call.errors.details[url_attr])
+ .to contain_exactly({ error: :url, value: })
+ end
+ end
+
+ context "when invalid scheme" do
+ let(:value) { "urn:some:info" }
+
+ it "is valid" do
+ expect(call).not_to be_success
+ expect(call.errors.details[url_attr])
+ .to contain_exactly({ error: :url, value: })
+ end
+ end
+
+ context "when valid" do
+ let(:value) { "https://foobar.example.com/slo" }
+
+ it "is valid" do
+ expect(call).to be_success
+ expect(call.errors).to be_empty
+
+ expect(subject.public_send(url_attr)).to eq value
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/modules/openid_connect/spec/services/openid_connect/providers/update_service_spec.rb b/modules/openid_connect/spec/services/openid_connect/providers/update_service_spec.rb
new file mode 100644
index 00000000000..7acd051a899
--- /dev/null
+++ b/modules/openid_connect/spec/services/openid_connect/providers/update_service_spec.rb
@@ -0,0 +1,36 @@
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) the OpenProject GmbH
+#
+# 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-2013 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 COPYRIGHT and LICENSE files for more details.
+#++
+
+require "spec_helper"
+require "services/base_services/behaves_like_update_service"
+
+RSpec.describe OpenIDConnect::Providers::UpdateService, type: :model do
+ it_behaves_like "BaseServices update service" do
+ let(:factory) { :oidc_provider }
+ end
+end