Skip to content

Commit

Permalink
Add institutions.saml_sp_entity_id
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Dolski committed Jan 19, 2024
1 parent f183ea5 commit a058b2d
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 4 deletions.
1 change: 1 addition & 0 deletions app/controllers/institutions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -953,6 +953,7 @@ def settings_params
:saml_idp_sso_post_service_url,
:saml_idp_sso_redirect_service_url,
:saml_last_name_attribute,
:saml_sp_entity_id,
:saml_sp_next_public_cert,
:saml_sp_private_key,
:saml_sp_public_cert,
Expand Down
10 changes: 9 additions & 1 deletion app/models/institution.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@
# * `saml_metadata_url` Caches the value entered into the URL
# field when supplying SAML metadata from
# A URL.
# * `saml_sp_entity_id` SAML SP entity ID.
# * `saml_sp_next_public_cert` SAML X.509 public certificate with a
# later expiration than
# {saml_sp_public_cert} to facilitate
Expand Down Expand Up @@ -463,6 +464,13 @@ def default_metadata_profile
self.metadata_profiles.where(institution_default: true).limit(1).first
end

##
# @return [String]
#
def default_saml_sp_entity_id
[scope_url, "entity"].join("/")
end

##
# @return [SubmissionProfile]
#
Expand Down Expand Up @@ -709,7 +717,7 @@ def required_elements
# @return [String]
#
def saml_sp_entity_id
[scope_url, "entity"].join("/")
read_attribute(:saml_sp_entity_id) || default_saml_sp_entity_id
end

##
Expand Down
3 changes: 3 additions & 0 deletions app/views/institutions/_saml_authentication_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
.row
.col-lg-6
%h5 Service Provider
.mb-3
= f.label :saml_sp_entity_id, "Entity ID"
= f.text_field :saml_sp_entity_id, class: "form-control"
.mb-3
= f.label :saml_sp_private_key, "Private Key"
= f.text_area :saml_sp_private_key, rows: 10, class: "form-control"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddInstitutionsSamlSpEntityIdColumn < ActiveRecord::Migration[7.1]
def change
add_column :institutions, :saml_sp_entity_id, :string
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.1].define(version: 2023_12_12_202706) do
ActiveRecord::Schema[7.1].define(version: 2024_01_19_023719) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
enable_extension "unaccent"
Expand Down Expand Up @@ -448,6 +448,7 @@
t.string "saml_idp_sso_redirect_service_url"
t.boolean "allow_user_registration", default: true, null: false
t.string "saml_metadata_url"
t.string "saml_sp_entity_id"
t.index ["fqdn"], name: "index_institutions_on_fqdn", unique: true
t.index ["incoming_message_queue"], name: "index_institutions_on_incoming_message_queue", unique: true
t.index ["key"], name: "index_institutions_on_key", unique: true
Expand Down
11 changes: 9 additions & 2 deletions test/models/institution_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,12 @@ class InstitutionTest < ActiveSupport::TestCase
assert @instance.default_metadata_profile.institution_default
end

# default_saml_sp_entity_id()

test "default_saml_sp_entity_id() returns a correct value" do
assert_equal "#{@instance.scope_url}/entity", @instance.default_saml_sp_entity_id
end

# default_submission_profile()

test "default_submission_profile() returns the default submission profile" do
Expand Down Expand Up @@ -981,8 +987,9 @@ class InstitutionTest < ActiveSupport::TestCase

# saml_sp_entity_id()

test "saml_sp_entity_id() returns a correct value" do
assert_equal "#{@instance.scope_url}/entity", @instance.saml_sp_entity_id
test "saml_sp_entity_id() returns the default entity ID when not set" do
assert_equal @instance.default_saml_sp_entity_id,
@instance.saml_sp_entity_id
end

# saml_sp_next_public_cert
Expand Down

0 comments on commit a058b2d

Please sign in to comment.