Commit 3c4ebdb
Changed files (7)
lib
xml
kit
templates
spec
lib/xml/kit/templates/encrypted_key.builder
@@ -0,0 +1,3 @@
+xml.EncryptedKey Id: id, xmlns: ::Xml::Kit::Namespaces::XMLENC do
+
+end
lib/xml/kit/encrypted_key.rb
@@ -0,0 +1,15 @@
+require 'xml/kit/templatable'
+
+module Xml
+ module Kit
+ class EncryptedKey
+ include ::Xml::Kit::Templatable
+
+ attr_reader :id
+
+ def initialize(id:)
+ @id = id
+ end
+ end
+ end
+end
lib/xml/kit.rb
@@ -19,6 +19,7 @@ require 'xml/kit/crypto'
require 'xml/kit/decryption'
require 'xml/kit/decryption_error'
require 'xml/kit/document'
+require 'xml/kit/encrypted_key'
require 'xml/kit/encryption'
require 'xml/kit/external_key_info'
require 'xml/kit/fingerprint'
spec/fixtures/soap.builder
@@ -5,7 +5,16 @@ xml.Envelope xmlns: "http://schemas.xmlsoap.org/soap/envelope/" do
xml.Security mustUnderstand: '1' do
xml.EncryptedKey xmlns: 'http://www.w3.org/2001/04/xmlenc#', Id: key_id do
xml.EncryptionMethod Algorithm: 'http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p' do
- render header_key_info, xml: xml
+ xml.KeyInfo xmlns: '' do
+ xml.SecurityTokenReference do
+ xml.x509Data do
+ xml.x509IssuerSerial do
+ xml.x509IssuerName ''
+ xml.x509IssuerNumber ''
+ end
+ end
+ end
+ end
xml.CipherData do
xml.CipherValue ''
end
@@ -14,6 +23,8 @@ xml.Envelope xmlns: "http://schemas.xmlsoap.org/soap/envelope/" do
end
end
end
+ #encrypt_key_for(xml: xml, id: body_key_info.uri) do |xml|
+ #end
xml.BinarySecurityToken ''
end
end
spec/fixtures/soap_header_key_info.builder
@@ -1,10 +0,0 @@
-xml.KeyInfo xmlns: '' do
- xml.SecurityTokenReference do
- xml.x509Data do
- xml.x509IssuerSerial do
- xml.x509IssuerName ''
- xml.x509IssuerNumber ''
- end
- end
- end
-end
spec/support/soap.rb
@@ -1,15 +1,6 @@
# frozen_string_literal: true
class Soap
- class HeaderKeyInfo
- include ::Xml::Kit::Templatable
- attr_accessor :template_path
-
- def initialize(uri:)
- @template_path = File.join(__dir__, '../fixtures/soap_header_key_info.builder')
- end
- end
-
include ::Xml::Kit::Templatable
attr_reader :id, :signing_key_pair, :encryption_key_pair
@@ -29,10 +20,6 @@ class Soap
'EK-E2C32E59F27A1320A215468956686717'
end
- def header_key_info
- HeaderKeyInfo.new(uri: key_id)
- end
-
def body_key_info
::Xml::Kit::ExternalKeyInfo.new(uri: key_id)
end
spec/xml/kit/encrypted_key_spec.rb
@@ -0,0 +1,15 @@
+RSpec.describe ::Xml::Kit::EncryptedKey do
+ describe "#to_xml" do
+ subject { described_class.new(id: id) }
+ let(:id) { ::Xml::Kit::Id.generate }
+ let(:result) { Hash.from_xml(subject.to_xml) }
+
+ before do
+ puts subject.to_xml
+ end
+
+ specify { expect(result.key?('EncryptedKey')).to be_present }
+ specify { expect(result['EncryptedKey']['Id']).to eql(id) }
+ specify { expect(result['EncryptedKey']['xmlns']).to eql(::Xml::Kit::Namespaces::XMLENC) }
+ end
+end