Sha256: f455ab84e21bf61857f3f13067e896e9bf5a4ca099173d6eea382a46b0041903
Contents?: true
Size: 1.57 KB
Versions: 2
Compression:
Stored size: 1.57 KB
Contents
require 'spec_helper' describe Xmlenc::EncryptedDocument do let(:plain_xml) { File.read('spec/fixtures/phaos/payment.xml') } let(:encrypted_xml) { File.read('spec/fixtures/encrypted_document.xml') } let(:private_key) { OpenSSL::PKey::RSA.new(File.read('spec/fixtures/phaos/rsa-priv-key.pem')) } subject { described_class.new(encrypted_xml) } describe 'document' do it 'returns the nokogiri document' do expect(subject.document).to be_a(Nokogiri::XML::Document) end it 'raises on badly formed XML' do badly_formed = <<-EOXML <root> <open>foo <closed>bar</closed> </root> EOXML expect { described_class.new(badly_formed).document }.to raise_error end end describe 'encrypted_keys' do it 'returns the encrypted keys' do expect(subject.encrypted_keys.count).to be == 1 end it 'converts the elements to EncryptedKey' do all_converted = subject.encrypted_keys.all? { |ek| ek.is_a?(Xmlenc::EncryptedKey) } expect(all_converted).to be_truthy end end describe 'decrypt' do it 'replaces the encrypted data with the unencrypted elements' do expect(subject.decrypt(private_key).chomp).to be == plain_xml end context 'when encryption key is missing encryption data' do let(:encrypted_xml) { File.read('spec/fixtures/encrypted_document_without_data.xml') } it 'raises an error if the encrypted data cannot be found' do expect { subject.decrypt(private_key).chomp }.to raise_error(Xmlenc::EncryptedDataNotFound) end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
xmlenc-0.6.0 | spec/lib/xmlenc/encrypted_document_spec.rb |
xmlenc-0.5.0 | spec/lib/xmlenc/encrypted_document_spec.rb |