Sha256: afe91872ddfec2ae9e5b5eb50992d4fcfe3c536c35f151f7ce26c93ca7e5db3d
Contents?: true
Size: 1.99 KB
Versions: 4
Compression:
Stored size: 1.99 KB
Contents
require 'spec_helper' describe "encryption and decryption:" do subject do Nokogiri::XML(fixture('sign2-doc.xml')) end [ 'aes128-cbc', 'aes192-cbc', 'aes256-cbc', 'tripledes-cbc' ].each do |block_encryption| [ 'rsa-1_5', 'rsa-oaep-mgf1p' ].each do |key_transport| describe "encrypting with an RSA public key with #{block_encryption} #{key_transport}" do before do @original = subject.to_s subject.encrypt!( key: fixture('rsa.pub'), name: 'test', block_encryption: block_encryption, key_transport: key_transport) end # it generates a new key every time so will never match the fixture specify { expect(subject.to_s == @original).to be_falsey } specify { expect(subject.to_s =~ /Hello.*World/i).to be_falsey } # specify { subject.to_s.should == fixture('encrypt2-result.xml') } describe 'decrypting with the RSA private key' do before do subject.decrypt! key: fixture('rsa.pem') end specify { expect(subject.to_s == fixture('sign2-doc.xml')).to be_truthy } end end end end it "encrypts a single element" do doc = subject original = doc.to_s node = doc.at_xpath('env:Envelope/env:Data', 'env' => 'urn:envelope') node.encrypt_with(key: fixture('rsa.pub'), block_encryption: 'aes128-cbc', key_transport: 'rsa-1_5') expect(doc.root.name).to eq 'Envelope' expect(doc.root.element_children.first.name).to eq 'EncryptedData' encrypted_data = doc.root.element_children.first encrypted_data.decrypt_with(key: fixture('rsa.pem')) expect(doc.to_s).to eq original end it "inserts a certificate" do doc = subject doc.encrypt!(key: fixture('cert/server.key.decrypted'), cert: fixture('cert/server.crt'), block_encryption: 'aes128-cbc', key_transport: 'rsa-1_5') expect(doc.to_s).to match(/X509Data/) expect(doc.to_s).not_to match(/X509Data></) end end
Version data entries
4 entries across 4 versions & 1 rubygems