Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion app/controllers/concerns/saml_idp_auth_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,12 @@ def saml_response_signature_options

def saml_request_service_provider
return @saml_request_service_provider if defined?(@saml_request_service_provider)
@saml_request_service_provider = ServiceProvider.find_by(issuer: current_issuer)
@saml_request_service_provider =
if current_issuer.blank?
nil
else
ServiceProvider.find_by(issuer: current_issuer)
end
Comment on lines 240 to 245
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically we could make this a single if without the else and have this assign as nil with working memoization, though I think maybe this a good instance of being overly explicit due to how confusing the conditional assignment can be in Ruby.

    @saml_request_service_provider =
      if current_issuer.present?
        ServiceProvider.find_by(issuer: current_issuer)
      end

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, you're right, that hadn't occurred to me. I kind of prefer the explicitness though.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i have a slight preference for the explicitness as well!

end

def current_issuer
Expand Down
7 changes: 6 additions & 1 deletion app/forms/openid_connect_authorize_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,12 @@ def cannot_validate_redirect_uri?

def service_provider
return @service_provider if defined?(@service_provider)
@service_provider = ServiceProvider.find_by(issuer: client_id)
@service_provider =
if client_id.blank?
nil
else
ServiceProvider.find_by(issuer: client_id)
end
end

def link_identity_to_service_provider(
Expand Down
3 changes: 2 additions & 1 deletion app/services/saml_request_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

class SamlRequestParser
URI_PATTERN = Saml::Idp::Constants::REQUESTED_ATTRIBUTES_CLASSREF
ESCAPED_URI_PATTERN = /#{Regexp.escape(URI_PATTERN)}/

def initialize(request)
@request = request
Expand All @@ -24,7 +25,7 @@ def authn_context_attr_nodes
samlp: Saml::XML::Namespaces::PROTOCOL,
saml: Saml::XML::Namespaces::ASSERTION,
).select do |node|
node.content =~ /#{Regexp.escape(URI_PATTERN)}/
node.content =~ ESCAPED_URI_PATTERN
end
end
end
Expand Down
12 changes: 12 additions & 0 deletions spec/forms/openid_connect_authorize_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -784,4 +784,16 @@
end
end
end

describe '#service_provider' do
context 'empty client_id' do
let(:client_id) { '' }

it 'does not query the database' do
expect(ServiceProvider).to_not receive(:find_by)

expect(form.service_provider).to be_nil
end
end
end
end