Commit fbfb862
Changed files (3)
spec
spec/fixtures/no_nameid.saml_response.erb
@@ -0,0 +1,25 @@
+<saml2p:Response xmlns:saml2p="urn:oasis:names:tc:SAML:2.0:protocol" xmlns:xsd="http://www.w3.org/2001/XMLSchema" Destination="<%= fetch(:destination, 'https://www.example.com/acs') %>" ID="_d2b481a92e895f1436189403b7d5ccd1" InResponseTo="<%= fetch(:in_response_to, "_4db60150-227a-439b-a686-e7c57a9b5f9a") %>" IssueInstant="<%= issue_instant.iso8601 %>" Version="2.0">
+ <saml2:Issuer xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion"><%= fetch(:issuer, 'https://www.example.com') %></saml2:Issuer>
+ <saml2p:Status>
+ <saml2p:StatusCode Value="urn:oasis:names:tc:SAML:2.0:status:Success"></saml2p:StatusCode>
+ </saml2p:Status>
+ <saml2:Assertion xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion" xmlns:xsd="http://www.w3.org/2001/XMLSchema" ID="_637d9c5c732418d7cef10586f21c21b0" IssueInstant="<%= issue_instant.iso8601 %>" Version="2.0">
+ <saml2:Issuer><%= fetch(:issuer, 'https://www.example.com') %></saml2:Issuer>
+ <saml2:Subject>
+ <saml2:SubjectConfirmation Method="urn:oasis:names:tc:SAML:2.0:cm:bearer">
+ <saml2:SubjectConfirmationData Address="10.38.131.134" InResponseTo="<%= fetch(:in_response_to, "_4db60150-227a-439b-a686-e7c57a9b5f9a") %>" NotOnOrAfter="<%= fetch(:not_on_or_after, Time.now).iso8601 %>" Recipient="<%= fetch(:recipient, 'https://www.example.com/') %>"></saml2:SubjectConfirmationData>
+ </saml2:SubjectConfirmation>
+ </saml2:Subject>
+ <saml2:Conditions NotBefore="<%= fetch(:not_before, Time.now).iso8601 %>" NotOnOrAfter="<%= fetch(:not_on_or_after, Time.now).iso8601 %>">
+ <saml2:AudienceRestriction>
+ <saml2:Audience><%= fetch(:audience, 'https://www.example.com') %></saml2:Audience>
+ </saml2:AudienceRestriction>
+ </saml2:Conditions>
+ <saml2:AuthnStatement AuthnInstant="<%= issue_instant.iso8601 %>" SessionIndex="_99d6ac14d6ad70a23c89f82ba75c4ae0">
+ <saml2:SubjectLocality Address="10.38.131.134"></saml2:SubjectLocality>
+ <saml2:AuthnContext>
+ <saml2:AuthnContextClassRef>urn:oasis:names:tc:SAML:2.0:ac:classes:Password</saml2:AuthnContextClassRef>
+ </saml2:AuthnContext>
+ </saml2:AuthnStatement>
+ </saml2:Assertion>
+</saml2p:Response>
spec/saml/kit/response_spec.rb
@@ -554,6 +554,12 @@ XML
subject = described_class.build(user, request)
expect(subject.attributes).to eql('name' => 'mo', 'age' => '33')
end
+
+ it 'can parse an assertion without a name id' do
+ xml = expand_template('no_nameid.saml_response', issue_instant: Time.now)
+ subject = described_class.new(xml)
+ expect(subject.name_id).to be_nil
+ end
end
describe '#build' do
spec/support/erb_templating.rb
@@ -0,0 +1,34 @@
+# frozen_string_literal: true
+
+module ErbTemplating
+ class Template
+ def initialize(template_name, data)
+ @erb = ERB.new(IO.read(File.join('spec/fixtures', "#{template_name}.erb")))
+ @data = data
+ end
+
+ def fetch(key, default)
+ @data.fetch(key, default)
+ end
+
+ def __expand
+ @erb.result(binding)
+ end
+
+ def method_missing(name, *args)
+ @data[name]
+ end
+
+ def respond_to_missing?(method, *)
+ @data.key?(method)
+ end
+ end
+
+ def expand_template(template_name, data = {})
+ Template.new(template_name, data).__expand
+ end
+end
+
+RSpec.configure do |config|
+ config.include ErbTemplating
+end