Commit 1e2105b

mokha <mokha@cisco.com>
2018-03-06 00:01:55
add a spec for a valid xmldsig.
1 parent 1a2ff7c
Changed files (2)
lib
spec
saml
lib/saml/kit/cli/signature_report.rb
@@ -4,21 +4,22 @@ module Saml
   module Kit
     module Cli
       class SignatureReport
-        attr_reader :content, :format
+        attr_reader :content, :format, :path
 
-        def initialize(file, format:)
+        def initialize(path, format:)
           @format = format
-          if File.exist?(File.expand_path(file))
-            @content = IO.read(File.expand_path(file))
+          @path = path
+          if File.exist?(File.expand_path(path))
+            @content = IO.read(File.expand_path(path))
           else
-            uri = URI.parse(file)
+            uri = URI.parse(path)
             @content = Net::HTTP.get_response(uri).body.chomp
           end
         end
 
         def print(shell)
-          shell.say to_xml(pretty: true)
-          return shell.say_status :success, "#{file} is valid", :green if valid?
+          shell.say to_xml
+          return shell.say_status :success, "#{path} is valid", :green if valid?
           errors.each { |error| shell.say_status(:error, error, :red) }
           return unless full?
           invalid_signatures.each { |x| shell.say(x.to_xml(indent: 2), :red) }
spec/saml/kit/cli/commands/xml_digital_signature_spec.rb
@@ -0,0 +1,23 @@
+RSpec.describe Saml::Kit::Cli::Commands::Certificate do
+  describe "#verify" do
+    let(:command) { "xmldsig verify #{tempfile}" }
+    let(:tempfile) { Tempfile.new('saml-kit').path }
+    let(:configuration) do
+      Saml::Kit::Configuration.new do |config|
+        config.generate_key_pair_for(use: :signing)
+      end
+    end
+
+    before { IO.write(tempfile, xml) }
+    after { File.unlink(tempfile) }
+
+    context "file is valid" do
+      let(:document) { Saml::Kit::AuthenticationRequest.build(configuration: configuration) }
+      let(:xml) { document.to_xml }
+
+      specify { expect(status).to be_success }
+      specify { expect(output).to include(document.to_xml(pretty: true)) }
+      specify { expect(output).to include("success  #{tempfile} is valid") }
+    end
+  end
+end