|  | 
| 2 | 2 | 
 | 
| 3 | 3 | describe Samlr::Tools::MetadataBuilder do | 
| 4 | 4 |   describe "#build" do | 
| 5 |  | -    before do | 
| 6 |  | -      @xml = Samlr::Tools::MetadataBuilder.build({ | 
|  | 5 | +    let(:options) do | 
|  | 6 | +      { | 
| 7 | 7 |         :entity_id            => "https://sp.example.com/saml2", | 
| 8 | 8 |         :name_identity_format => "identity_format", | 
| 9 | 9 |         :consumer_service_url => "https://support.sp.example.com/" | 
| 10 |  | -      }) | 
| 11 |  | - | 
| 12 |  | -      @doc = Nokogiri::XML(@xml) { |c| c.strict } | 
|  | 10 | +      } | 
| 13 | 11 |     end | 
|  | 12 | +    let(:xml) { Samlr::Tools::MetadataBuilder.build(options) } | 
|  | 13 | +    let(:doc) { Nokogiri::XML(xml) { |c| c.strict } } | 
| 14 | 14 | 
 | 
| 15 | 15 |     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 | 
| 18 | 18 |     end | 
| 19 | 19 | 
 | 
| 20 | 20 |     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) | 
| 22 | 22 |       assert result | 
| 23 | 23 |     end | 
| 24 | 24 | 
 | 
|  | 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 | 
| 25 | 38 |   end | 
| 26 | 39 | end | 
0 commit comments