Sha256: 2078a2d416d59c9b095912ed9b400ca76402dae7dd226bed1bf54a8ff46b7c1f

Contents?: true

Size: 1.79 KB

Versions: 1

Compression:

Stored size: 1.79 KB

Contents

require 'spec_helper'

describe Xmldsig_fiscalizer do
  let(:private_key) { OpenSSL::PKey::RSA.new(File.read("spec/fixtures/key.pem")) }
  let(:certificate) { OpenSSL::X509::Certificate.new(File.read("spec/fixtures/certificate.cer")) }

  describe "Sign unsigned documents" do
    Dir["spec/fixtures/unsigned/*.xml"].each do |document|
      describe "#{document}" do
        let(:unsigned_xml) { File.read(document) }
        let(:unsigned_document) { Xmldsig_fiscalizer::SignedDocument.new(unsigned_xml) }
        let(:signed_document) { unsigned_document.sign(private_key) }

        it "should be signable an validateable" do
          Xmldsig_fiscalizer::SignedDocument.new(signed_document).validate(certificate).should be_true
        end

        it 'should have a signature element' do
          Xmldsig_fiscalizer::SignedDocument.new(signed_document).signatures.count.should == 1
        end

        # TODO: remove this verification step when library matures
        #it 'matches the result from xmlsec1' do
        #  result = `xmlsec1 --sign --id-attr:ID http://example.com/foo#:Foo --privkey-pem spec/fixtures/key.pem #{document}`
        #  result.gsub!("\n", '')
        #  signed_document.gsub!("\n", '')
        #  result.should == signed_document
        #end
      end
    end
  end

  describe "Verify signed documents" do
    Dir["spec/fixtures/signed/*.txt"].each do |document|
      describe "#{document}" do
        let(:signed_xml) { Base64.decode64(File.read(document)) }
        let(:signed_document) { Xmldsig_fiscalizer::SignedDocument.new(signed_xml) }
        let(:certificate) { OpenSSL::X509::Certificate.new(File.read(document.gsub('.txt', '.cert'))) }

        it "should be validateable" do
          signed_document.validate(certificate).should be_true
        end
      end
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
xmldsig-fiscalizer-0.2.5 spec/lib/xmldsig_spec.rb