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üntherdd65ef439ca6
diff --git a/modules/auth_saml/app/contracts/saml/providers/base_contract.rb b/modules/auth_saml/app/contracts/saml/providers/base_contract.rb
index 3450597c6f1..c0d018638b9 100644
--- a/modules/auth_saml/app/contracts/saml/providers/base_contract.rb
+++ b/modules/auth_saml/app/contracts/saml/providers/base_contract.rb
@@ -34,6 +34,9 @@ module Saml
Saml::Provider
end
+ attribute :type
+ validate :type_is_saml_provider
+
attribute :display_name
attribute :slug
attribute :options
@@ -59,16 +62,22 @@ module Saml
if: -> { model.idp_cert_changed? && model.idp_cert.present? }
attribute :authn_requests_signed
- validate :authn_requests_signed_requires_cert
+ validate :valid_certificate_key_pair
%i[mapping_mail mapping_login mapping_firstname mapping_lastname].each do |attr|
attribute attr
validates_presence_of attr, if: -> { model.public_send(:"#{attr}_changed?") }
end
+ def type_is_saml_provider
+ unless model.type == Saml::Provider.name
+ errors.add(:type, :inclusion)
+ end
+ end
+
def idp_cert_not_expired
unless model.idp_certificate_expired?
- errors.add :certificate, :certificate_expired
+ errors.add :idp_cert, :certificate_expired
end
rescue OpenSSL::X509::CertificateError => e
errors.add :idp_cert, :invalid_certificate, additional_message: e.message
@@ -94,7 +103,7 @@ module Saml
errors.add :private_key, :invalid_private_key, additional_message: e.message
end
- def authn_requests_signed_requires_cert
+ def valid_certificate_key_pair
return unless should_test_certificate?
return if certificate_invalid?
@@ -114,10 +123,9 @@ module Saml
end
def should_test_certificate?
- return false unless model.authn_requests_signed
- return false unless model.authn_requests_signed_changed? || model.certificate_changed? || model.private_key_changed?
+ return false unless model.certificate_changed? || model.private_key_changed?
- model.certificate.present? && model.private_key.present?
+ model.certificate.present? || model.private_key.present?
end
end
end
diff --git a/modules/auth_saml/app/contracts/saml/providers/create_contract.rb b/modules/auth_saml/app/contracts/saml/providers/create_contract.rb
index 2115bc482b3..555aeac3604 100644
--- a/modules/auth_saml/app/contracts/saml/providers/create_contract.rb
+++ b/modules/auth_saml/app/contracts/saml/providers/create_contract.rb
@@ -28,7 +28,6 @@
module Saml
module Providers
class CreateContract < BaseContract
- attribute :type
end
end
end
diff --git a/modules/auth_saml/app/models/saml/provider/hash_builder.rb b/modules/auth_saml/app/models/saml/provider/hash_builder.rb
index 522183b29b8..cc02b2c8361 100644
--- a/modules/auth_saml/app/models/saml/provider/hash_builder.rb
+++ b/modules/auth_saml/app/models/saml/provider/hash_builder.rb
@@ -52,9 +52,9 @@ module Saml
check_idp_cert_expiration: false, # done in contract
check_sp_cert_expiration: false, # done in contract
metadata_signed: certificate.present? && private_key.present?,
- authn_requests_signed:,
- want_assertions_signed:,
- want_assertions_encrypted:,
+ authn_requests_signed: !!authn_requests_signed,
+ want_assertions_signed: !!want_assertions_signed,
+ want_assertions_encrypted: !!want_assertions_encrypted,
digest_method:,
signature_method:
}.compact
diff --git a/modules/auth_saml/app/seeders/env_data/saml/provider_seeder.rb b/modules/auth_saml/app/seeders/env_data/saml/provider_seeder.rb
index 4c68fdad45e..134ed8a94ff 100644
--- a/modules/auth_saml/app/seeders/env_data/saml/provider_seeder.rb
+++ b/modules/auth_saml/app/seeders/env_data/saml/provider_seeder.rb
@@ -61,7 +61,7 @@ module EnvData
if deprecated_settings.exist?
Rails.logger.info do
<<~WARNING
- Loading SAML configuration from deprecated location #{deprecated_path}.
+ Loading SAML configuration from deprecated location #{deprecated_settings}.
Please use ENV variables or UI configuration instead.
For more information, see our guide on how to configure SAML.
diff --git a/modules/auth_saml/app/services/saml/providers/set_attributes_service.rb b/modules/auth_saml/app/services/saml/providers/set_attributes_service.rb
index a70be4d9fc7..322072a72ba 100644
--- a/modules/auth_saml/app/services/saml/providers/set_attributes_service.rb
+++ b/modules/auth_saml/app/services/saml/providers/set_attributes_service.rb
@@ -45,7 +45,7 @@ module Saml
end
end
- def update_options(options)
+ def update_options(options) # rubocop:disable Metrics/AbcSize
update_idp_cert(options.delete(:idp_cert)) if options.key?(:idp_cert)
update_certificate(options.delete(:certificate)) if options.key?(:certificate)
update_private_key(options.delete(:private_key)) if options.key?(:private_key)
@@ -67,11 +67,18 @@ module Saml
set_issuer
set_name_identifier_format
set_default_digest
+ set_default_encryption
end
end
+ def set_default_encryption
+ model.authn_requests_signed = false if model.authn_requests_signed.nil?
+ model.want_assertions_signed = false if model.want_assertions_signed.nil?
+ model.want_assertions_encrypted = false if model.want_assertions_encrypted.nil?
+ end
+
def set_slug
- model.slug ||= "#{model.class.slug_fragment}-#{model.display_name.to_url}"
+ model.slug ||= "#{model.class.slug_fragment}-#{model.display_name.to_url}" if model.display_name
end
def set_default_digest
@@ -107,14 +114,14 @@ module Saml
##
# Clean up provided mapping, reducing whitespace
def update_mapping(params)
- %i[mapping_mail mapping_login mapping_firstname mapping_lastname].each do |attr|
+ %i[mapping_mail mapping_login mapping_firstname mapping_lastname mapping_uid].each do |attr|
next unless params.key?(attr)
- mapping = params.delete(attr)
- mapping.gsub!("\r\n", "\n")
- mapping.gsub!(/^\s*(.+?)\s*$/, '\1')
+ parsed = params.delete(attr)
+ .gsub("\r\n", "\n")
+ .gsub!(/^\s*(.+?)\s*$/, '\1')
- model.public_send(:"#{attr}=", mapping)
+ model.public_send(:"#{attr}=", parsed)
end
end
diff --git a/modules/auth_saml/lib/open_project/auth_saml/engine.rb b/modules/auth_saml/lib/open_project/auth_saml/engine.rb
index 5477eb21da9..41cf1c3a9ee 100644
--- a/modules/auth_saml/lib/open_project/auth_saml/engine.rb
+++ b/modules/auth_saml/lib/open_project/auth_saml/engine.rb
@@ -6,7 +6,7 @@ module OpenProject
OpenProject::Cache.fetch(providers.cache_key) do
providers.each_with_object({}) do |provider, hash|
- hash[provider.slug] = provider.to_h
+ hash[provider.slug.to_sym] = provider.to_h
end
end
end
diff --git a/modules/auth_saml/spec/factories/saml_provider_factory.rb b/modules/auth_saml/spec/factories/saml_provider_factory.rb
index 51ebdd6ac4f..d0daf5f25fb 100644
--- a/modules/auth_saml/spec/factories/saml_provider_factory.rb
+++ b/modules/auth_saml/spec/factories/saml_provider_factory.rb
@@ -26,8 +26,21 @@
# See COPYRIGHT and LICENSE files for more details.
#++
+require_relative "../support/certificate_helper"
+
FactoryBot.define do
factory(:saml_provider, class: "Saml::Provider") do
sequence(:display_name) { |n| "Saml Provider #{n}" }
+ creator factory: :user
+ available { true }
+ idp_cert { CertificateHelper.valid_certificate.to_pem }
+
+ idp_sso_service_url { "https://example.com/sso" }
+ idp_slo_service_url { "https://example.com/slo" }
+
+ mapping_login { Saml::Defaults::MAIL_MAPPING }
+ mapping_mail { Saml::Defaults::MAIL_MAPPING }
+ mapping_firstname { Saml::Defaults::FIRSTNAME_MAPPING }
+ mapping_lastname { Saml::Defaults::LASTNAME_MAPPING }
end
end
diff --git a/modules/auth_saml/spec/lib/open_project/auth_saml_spec.rb b/modules/auth_saml/spec/lib/open_project/auth_saml_spec.rb
index 4aff710610e..263cd698e03 100644
--- a/modules/auth_saml/spec/lib/open_project/auth_saml_spec.rb
+++ b/modules/auth_saml/spec/lib/open_project/auth_saml_spec.rb
@@ -1,66 +1,34 @@
-require File.dirname(__FILE__) + "/../../spec_helper"
+require "#{File.dirname(__FILE__)}/../../spec_helper"
require "open_project/auth_saml"
RSpec.describe OpenProject::AuthSaml do
- before do
- OpenProject::AuthSaml.reload_configuration!
- end
-
- after do
- OpenProject::AuthSaml.reload_configuration!
- end
-
describe ".configuration" do
- let(:config) do
- # the `configuration` method is cached to avoid
- # loading the SAML file more than once
- # thus remove any cached value here
- OpenProject::AuthSaml.remove_instance_variable(:@saml_settings)
- OpenProject::AuthSaml.configuration
- end
+ let!(:provider) { create(:saml_provider, display_name: "My SSO", slug: "my-saml") }
+
+ subject { described_class.configuration[:"my-saml"] }
- context(
- "with configuration",
- with_config: {
- saml: {
- my_saml: {
- name: "saml",
- display_name: "My SSO"
- }
- }
- }
- ) do
- it "contains the configuration from OpenProject::Configuration (or settings.yml) by default" do
- expect(config[:my_saml][:name]).to eq "saml"
- expect(config[:my_saml][:display_name]).to eq "My SSO"
- end
+ it "contains the configuration from OpenProject::Configuration (or settings.yml) by default",
+ :aggregate_failures do
+ expect(subject[:name]).to eq "my-saml"
+ expect(subject[:display_name]).to eq "My SSO"
+ expect(subject[:idp_cert].strip).to eq provider.idp_cert.strip
+ expect(subject[:assertion_consumer_service_url]).to eq "http://#{Setting.host_name}/auth/my-saml/callback"
+ expect(subject[:idp_sso_service_url]).to eq "https://example.com/sso"
+ expect(subject[:idp_slo_service_url]).to eq "https://example.com/slo"
- context(
- "with settings override from database",
- with_settings: {
- plugin_openproject_auth_saml: {
- providers: {
- my_saml: {
- display_name: "Your SSO"
- },
- new_saml: {
- name: "new_saml",
- display_name: "Another SAML"
- }
- }
- }
- }
- ) do
- it "overrides the existing configuration where defined" do
- expect(config[:my_saml][:name]).to eq "saml"
- expect(config[:my_saml][:display_name]).to eq "Your SSO"
- end
+ attributes = subject[:attribute_statements]
+ expect(attributes[:email]).to eq Saml::Defaults::MAIL_MAPPING.split("\n")
+ expect(attributes[:login]).to eq Saml::Defaults::MAIL_MAPPING.split("\n")
+ expect(attributes[:first_name]).to eq Saml::Defaults::FIRSTNAME_MAPPING.split("\n")
+ expect(attributes[:last_name]).to eq Saml::Defaults::LASTNAME_MAPPING.split("\n")
- it "defines new providers if given" do
- expect(config[:new_saml][:name]).to eq "new_saml"
- expect(config[:new_saml][:display_name]).to eq "Another SAML"
- end
- end
+ security = subject[:security]
+ expect(security[:check_idp_cert_expiration]).to be false
+ expect(security[:check_sp_cert_expiration]).to be false
+ expect(security[:metadata_signed]).to be false
+ expect(security[:authn_requests_signed]).to be false
+ expect(security[:want_assertions_signed]).to be false
+ expect(security[:want_assertions_encrypted]).to be false
end
end
end
diff --git a/modules/auth_saml/spec/seeders/env_data/saml/provider_seeder_spec.rb b/modules/auth_saml/spec/seeders/env_data/saml/provider_seeder_spec.rb
index 57b10da5fe0..23f1681f67f 100644
--- a/modules/auth_saml/spec/seeders/env_data/saml/provider_seeder_spec.rb
+++ b/modules/auth_saml/spec/seeders/env_data/saml/provider_seeder_spec.rb
@@ -69,9 +69,9 @@ RSpec.describe EnvData::Saml::ProviderSeeder, :settings_reset do
expect { seeder.seed! }.to change(Saml::Provider, :count).by(1)
provider = Saml::Provider.last
+ expect(provider.seeded_from_env?).to be true
expect(provider.slug).to eq "saml"
expect(provider.display_name).to eq "Test SAML"
- expect(provider.seeded_from_env).to be true
expect(provider.sp_entity_id).to eq "http://localhost:3000"
expect(provider.assertion_consumer_service_url).to eq "http://localhost:3000/auth/saml/callback"
@@ -86,14 +86,12 @@ RSpec.describe EnvData::Saml::ProviderSeeder, :settings_reset do
context "when provider already exists with that name" do
it "updates the provider" do
provider = Saml::Provider.create!(display_name: "Something", slug: "saml", mapping_mail: "old", creator: User.system)
- expect(provider.seeded_from_env).to be_nil
-
expect { seeder.seed! }.not_to change(Saml::Provider, :count)
provider.reload
expect(provider.display_name).to eq "Test SAML"
- expect(provider.seeded_from_env).to be true
+ expect(provider.seeded_from_env?).to be true
expect(provider.mapping_mail).to eq "mail\nurn:oid:2.5.4.42\nhttp://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress"
end
end
diff --git a/modules/auth_saml/spec/services/saml/providers/create_service_spec.rb b/modules/auth_saml/spec/services/saml/providers/create_service_spec.rb
new file mode 100644
index 00000000000..a148565c492
--- /dev/null
+++ b/modules/auth_saml/spec/services/saml/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 Saml::Providers::CreateService, type: :model do
+ it_behaves_like "BaseServices create service" do
+ let(:factory) { :saml_provider }
+ end
+end
diff --git a/modules/auth_saml/spec/services/saml/providers/set_attributes_service_spec.rb b/modules/auth_saml/spec/services/saml/providers/set_attributes_service_spec.rb
new file mode 100644
index 00000000000..7dc74db109b
--- /dev/null
+++ b/modules/auth_saml/spec/services/saml/providers/set_attributes_service_spec.rb
@@ -0,0 +1,276 @@
+# 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_relative "../../../support/certificate_helper"
+require_module_spec_helper
+
+RSpec.describe Saml::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(:params) do
+ { options: }
+ end
+ let(:call) { instance.call(params) }
+
+ subject { call.result }
+
+ describe "new instance" do
+ let(:model_instance) { Saml::Provider.new(display_name: "foo") }
+ let(:contract_class) { Saml::Providers::CreateContract }
+
+ describe "default attributes" do
+ let(:options) { {} }
+
+ it "sets all default attributes", :aggregate_failures do
+ expect(subject.display_name).to eq "foo"
+ expect(subject.slug).to eq "saml-foo"
+ expect(subject.creator).to eq(current_user)
+ expect(subject.sp_entity_id).to eq(OpenProject::StaticRouting::StaticUrlHelpers.new.root_url)
+ expect(subject.name_identifier_format).to eq("urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress")
+ expect(subject.signature_method).to eq(Saml::Defaults::SIGNATURE_METHODS["RSA SHA-1"])
+ expect(subject.digest_method).to eq(Saml::Defaults::DIGEST_METHODS["SHA-1"])
+
+ expect(subject.mapping_mail).to eq Saml::Defaults::MAIL_MAPPING
+ expect(subject.mapping_firstname).to eq Saml::Defaults::FIRSTNAME_MAPPING
+ expect(subject.mapping_lastname).to eq Saml::Defaults::LASTNAME_MAPPING
+ expect(subject.mapping_uid).to be_blank
+ expect(subject.mapping_login).to eq Saml::Defaults::MAIL_MAPPING
+
+ expect(subject.requested_login_attribute).to eq "mail"
+ expect(subject.requested_mail_attribute).to eq "mail"
+ expect(subject.requested_firstname_attribute).to eq "givenName"
+ expect(subject.requested_lastname_attribute).to eq "sn"
+
+ expect(subject.requested_login_format).to eq "urn:oasis:names:tc:SAML:2.0:attrname-format:basic"
+ expect(subject.requested_mail_format).to eq "urn:oasis:names:tc:SAML:2.0:attrname-format:basic"
+ expect(subject.requested_firstname_format).to eq "urn:oasis:names:tc:SAML:2.0:attrname-format:basic"
+ expect(subject.requested_lastname_format).to eq "urn:oasis:names:tc:SAML:2.0:attrname-format:basic"
+ end
+ end
+
+ describe "IDP certificate" do
+ let(:options) do
+ {
+ idp_cert: certificate
+ }
+ end
+
+ context "with a valid certificate" do
+ let(:certificate) { CertificateHelper.valid_certificate.to_pem }
+
+ it "assigns the certificate" do
+ expect(call).to be_success
+ expect(call.errors).to be_empty
+
+ expect(subject.idp_cert).to eq CertificateHelper.valid_certificate.to_pem
+ end
+ end
+
+ context "with a valid certificate, not in pem format" do
+ let(:certificate) { CertificateHelper.valid_certificate.to_pem.lines[1...-1].join }
+
+ it "assigns the certificate" do
+ expect(call).to be_success
+ expect(call.errors).to be_empty
+
+ expect(subject.idp_cert).to eq CertificateHelper.valid_certificate.to_pem.strip
+ end
+ end
+
+ context "with two certificates, one expired" do
+ let(:certificate) do
+ "#{CertificateHelper.valid_certificate.to_pem}\n#{CertificateHelper.expired_certificate.to_pem}"
+ end
+
+ it "assigns the certificate" do
+ expect(call).to be_success
+ expect(call.errors).to be_empty
+
+ expect(subject.idp_cert).to eq certificate
+ end
+ end
+
+ context "with an invalid certificate" do
+ let(:certificate) { CertificateHelper.expired_certificate.to_pem }
+
+ it "assigns the certificate" do
+ expect(call).not_to be_success
+ expect(call.errors.details[:idp_cert]).to contain_exactly({ error: :certificate_expired })
+ end
+ end
+ end
+
+ describe "certificate and private key" do
+ let(:options) do
+ {
+ certificate: given_certificate,
+ private_key: given_private_key
+ }
+ end
+
+ context "with a valid certificate pair" do
+ let(:given_certificate) { CertificateHelper.valid_certificate.to_pem }
+ let(:given_private_key) { CertificateHelper.private_key.private_to_pem }
+
+ it "assigns the certificate" do
+ expect(call).to be_success
+ expect(call.errors).to be_empty
+
+ expect(subject.certificate).to eq given_certificate.strip
+ expect(subject.private_key).to eq given_private_key.strip
+ end
+ end
+
+ context "with an invalid certificate" do
+ let(:given_certificate) { CertificateHelper.expired_certificate.to_pem }
+ let(:given_private_key) { nil }
+
+ it "results in an error" do
+ expect(call).not_to be_success
+ expect(call.errors.details[:certificate]).to contain_exactly({ error: :certificate_expired })
+ expect(call.errors.details[:private_key]).to contain_exactly({ error: :blank })
+ end
+ end
+
+ context "with a mismatched certificate" do
+ let(:given_certificate) { CertificateHelper.mismatched_certificate.to_pem }
+ let(:given_private_key) { CertificateHelper.private_key.private_to_pem }
+
+ it "results in an error" do
+ expect(call).not_to be_success
+ expect(call.errors.details[:private_key]).to contain_exactly({ error: :unmatched_private_key })
+ end
+ end
+ end
+
+ describe "mapping" do
+ let(:options) do
+ {
+ mapping_mail: "mail\n whitespace \nfoo",
+ mapping_firstname: "name\nsn",
+ mapping_lastname: "hello ",
+ mapping_uid: "something"
+ }
+ end
+
+ it "assigns the given and default values", :aggregate_failures do
+ expect(call).to be_success
+ expect(call.errors).to be_empty
+
+ expect(subject.mapping_mail).to eq "mail\nwhitespace\nfoo"
+ expect(subject.mapping_firstname).to eq "name\nsn"
+ expect(subject.mapping_lastname).to eq "hello"
+ expect(subject.mapping_uid).to eq "something"
+
+ expect(subject.mapping_login).to eq Saml::Defaults::MAIL_MAPPING
+ end
+ end
+
+ describe "want_assertions_signed" do
+ context "when provided" do
+ let(:options) { { want_assertions_signed: true } }
+
+ it "assigns the value" do
+ expect(call).to be_success
+ expect(call.errors).to be_empty
+
+ expect(subject.want_assertions_signed).to be true
+ end
+ end
+
+ context "when not provided" do
+ let(:options) { {} }
+
+ it "assigns the default value" do
+ expect(call).to be_success
+ expect(call.errors).to be_empty
+
+ expect(subject.want_assertions_signed).to be false
+ end
+ end
+ end
+
+ describe "want_assertions_encrypted" do
+ context "when provided" do
+ let(:options) { { want_assertions_encrypted: true } }
+
+ it "assigns the value" do
+ expect(call).to be_success
+ expect(call.errors).to be_empty
+
+ expect(subject.want_assertions_encrypted).to be true
+ end
+ end
+
+ context "when not provided" do
+ let(:options) { {} }
+
+ it "assigns the default value" do
+ expect(call).to be_success
+ expect(call.errors).to be_empty
+
+ expect(subject.want_assertions_encrypted).to be false
+ end
+ end
+ end
+
+ describe "authn_requests_signed" do
+ context "when provided" do
+ let(:options) { { authn_requests_signed: true } }
+
+ it "assigns the value" do
+ expect(call).to be_success
+ expect(call.errors).to be_empty
+
+ expect(subject.authn_requests_signed).to be true
+ end
+ end
+
+ context "when not provided" do
+ let(:options) { {} }
+
+ it "assigns the default value" do
+ expect(call).to be_success
+ expect(call.errors).to be_empty
+
+ expect(subject.authn_requests_signed).to be false
+ end
+ end
+ end
+ end
+end
diff --git a/modules/auth_saml/spec/services/saml/providers/update_service_spec.rb b/modules/auth_saml/spec/services/saml/providers/update_service_spec.rb
new file mode 100644
index 00000000000..bd0b8df595d
--- /dev/null
+++ b/modules/auth_saml/spec/services/saml/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 Saml::Providers::UpdateService, type: :model do
+ it_behaves_like "BaseServices update service" do
+ let(:factory) { :saml_provider }
+ end
+end
diff --git a/modules/auth_saml/spec/support/certificate_helper.rb b/modules/auth_saml/spec/support/certificate_helper.rb
new file mode 100644
index 00000000000..1574c8e5cdb
--- /dev/null
+++ b/modules/auth_saml/spec/support/certificate_helper.rb
@@ -0,0 +1,56 @@
+module CertificateHelper
+ module_function
+
+ def private_key
+ @private_key ||= OpenSSL::PKey::RSA.new(1024)
+ end
+
+ def valid_certificate
+ @valid_certificate ||= begin
+ name = OpenSSL::X509::Name.parse "/CN=valid-testing"
+ cert = OpenSSL::X509::Certificate.new
+ cert.version = 2
+ cert.serial = 1234
+
+ cert.not_before = Time.now
+ cert.not_after = Time.now + 606024364.251
+ cert.public_key = private_key.public_key
+ cert.subject = name
+ cert.issuer = name
+ cert.sign private_key, OpenSSL::Digest.new("SHA1")
+ end
+ end
+
+ def expired_certificate
+ @expired_certificate ||= begin
+ name = OpenSSL::X509::Name.parse "/CN=expired-testing"
+ cert = OpenSSL::X509::Certificate.new
+ cert.version = 2
+ cert.serial = 1234
+
+ cert.not_before = Time.now - 2.years
+ cert.not_after = Time.now - 30.days
+ cert.public_key = private_key.public_key
+ cert.subject = name
+ cert.issuer = name
+ cert.sign private_key, OpenSSL::Digest.new("SHA1")
+ end
+ end
+
+ def mismatched_certificate
+ @mismatched_certificate ||= begin
+ name = OpenSSL::X509::Name.parse "/CN=mismatched-testing"
+ cert = OpenSSL::X509::Certificate.new
+ cert.version = 2
+ cert.serial = 1234
+
+ key = OpenSSL::PKey::RSA.new(1024)
+ cert.not_before = Time.now
+ cert.not_after = Time.now + 606024364.251
+ cert.public_key = key.public_key
+ cert.subject = name
+ cert.issuer = name
+ cert.sign key, OpenSSL::Digest.new("SHA1")
+ end
+ end
+end