|
26 | 26 | end |
27 | 27 | end |
28 | 28 |
|
| 29 | + describe "#signature" do |
| 30 | + let(:metadata_doc) do |
| 31 | + Nokogiri::XML( |
| 32 | + Samlr::Tools::MetadataBuilder.build( |
| 33 | + :entity_id => "https://sp.example.com/saml2", |
| 34 | + :name_identity_format => "identity_format", |
| 35 | + :consumer_service_url => "https://support.sp.example.com/", |
| 36 | + :sign_metadata => true, |
| 37 | + :certificate => TEST_CERTIFICATE |
| 38 | + ) |
| 39 | + ) |
| 40 | + end |
| 41 | + |
| 42 | + it "is associated to the response" do |
| 43 | + assert subject.signature.present? |
| 44 | + end |
| 45 | + |
| 46 | + describe "when response envelops a signature" do |
| 47 | + let(:fingerprint) { Samlr::Certificate.new(TEST_CERTIFICATE.x509).fingerprint.value } |
| 48 | + let(:saml_response) { Samlr::Response.new(xml_response_doc, fingerprint: fingerprint) } |
| 49 | + |
| 50 | + describe "referencing other response" do |
| 51 | + let(:xml_response_doc) { Base64.encode64(File.read(File.join('.', 'test', 'fixtures', 'multiple_responses.xml'))) } |
| 52 | + |
| 53 | + it "does not associate it with the response" do |
| 54 | + assert saml_response.signature.missing? |
| 55 | + end |
| 56 | + end |
| 57 | + |
| 58 | + describe "referencing other element" do |
| 59 | + let(:xml_response_doc) { Base64.encode64(File.read(File.join('.', 'test', 'fixtures', 'response_signature_wrapping.xml'))) } |
| 60 | + |
| 61 | + it "does not associate it with the response" do |
| 62 | + assert saml_response.signature.missing? |
| 63 | + end |
| 64 | + end |
| 65 | + end |
| 66 | + end |
| 67 | + |
29 | 68 | describe "XSW attack" do |
30 | 69 | it "should not validate if SAML response is hacked" do |
31 | 70 | document = saml_response_document(:certificate => TEST_CERTIFICATE) |
|
85 | 124 | let(:saml_resp) { Samlr::Response.new(saml_response_doc, fingerprint: Samlr::FingerprintSHA256.x509(TEST_CERTIFICATE.x509)) } |
86 | 125 |
|
87 | 126 | it "validates the saml response" do |
88 | | - assert_match /[email protected]<!---->.evil.com/, saml_response_doc |
| 127 | + assert_match %r{[email protected]<!---->.evil.com}, saml_response_doc |
89 | 128 | assert saml_resp.verify! |
90 | 129 | end |
91 | 130 |
|
92 | 131 | it "ignores the comment and parses the name_id XML node correctly" do |
93 | | - assert_match /[email protected]<!---->.evil.com/, saml_response_doc |
| 132 | + assert_match %r{[email protected]<!---->.evil.com}, saml_response_doc |
94 | 133 | assert_equal "[email protected]", saml_resp.name_id |
95 | 134 | end |
96 | 135 | end |
|
0 commit comments