Skip to content

Commit 5379215

Browse files
add tests for signing metadata
1 parent bf6ee3c commit 5379215

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

test/unit/test_response_signature_wrapping_attack.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@
5959
# According to SAML schema, the <Signature> needs to be placed after <Issuer>.
6060
metadata_signature_doc = metadata_doc.xpath("md:EntityDescriptor/ds:Signature", Samlr::NS_MAP).first
6161
response_doc.at("/samlp:Response/saml:Issuer", Samlr::NS_MAP).add_next_sibling(metadata_signature_doc.dup)
62-
6362
crafted_saml_response = Samlr::Response.new(Base64.encode64(response_doc.to_xml), fingerprint: fingerprint)
6463

6564
# Checks for duplicate values of the ID attribute.

test/unit/tools/test_metadata_builder.rb

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,38 @@
22

33
describe Samlr::Tools::MetadataBuilder do
44
describe "#build" do
5-
before do
6-
@xml = Samlr::Tools::MetadataBuilder.build({
5+
let(:options) do
6+
{
77
:entity_id => "https://sp.example.com/saml2",
88
:name_identity_format => "identity_format",
99
:consumer_service_url => "https://support.sp.example.com/"
10-
})
11-
12-
@doc = Nokogiri::XML(@xml) { |c| c.strict }
10+
}
1311
end
12+
let(:xml) { Samlr::Tools::MetadataBuilder.build(options) }
13+
let(:doc) { Nokogiri::XML(xml) { |c| c.strict } }
1414

1515
it "generates a metadata document" do
16-
assert_equal "EntityDescriptor", @doc.root.name
17-
assert_equal "identity_format", @doc.at("//md:NameIDFormat", { "md" => Samlr::NS_MAP["md"] }).text
16+
assert_equal "EntityDescriptor", doc.root.name
17+
assert_equal "identity_format", doc.at("//md:NameIDFormat", { "md" => Samlr::NS_MAP["md"] }).text
1818
end
1919

2020
it "validates against schemas" do
21-
result = Samlr::Tools.validate(:document => @xml, :schema => Samlr::META_SCHEMA)
21+
result = Samlr::Tools.validate(:document => xml, :schema => Samlr::META_SCHEMA)
2222
assert result
2323
end
2424

25+
it "does not sign metadata by default" do
26+
assert_nil doc.xpath("md:EntityDescriptor/ds:Signature", Samlr::NS_MAP).first
27+
end
28+
29+
describe "when prompted to add a signature" do
30+
before do
31+
options[:sign_metadata] = true
32+
end
33+
34+
it "signs metadata" do
35+
refute_nil doc.xpath("md:EntityDescriptor/ds:Signature", Samlr::NS_MAP).first
36+
end
37+
end
2538
end
2639
end

0 commit comments

Comments
 (0)