Commit 67ecfd1
Changed files (11)
lib
spec
support
matchers
lib/xml/kit/templates/key_info.builder
@@ -2,9 +2,11 @@ xml.KeyInfo xmlns: ::Xml::Kit::Namespaces::XMLDSIG do
xml.KeyName key_name if key_name
render(key_value, xml: xml) if @key_value
render(retrieval_method, xml: xml) if @retrieval_method
- xml.X509Data do
- xml.X509SKI subject_key_identifier
- xml.X509Certificate ::Xml::Kit::Certificate.strip(x509_data.to_pem)
- end if x509_data
+ if x509_data
+ xml.X509Data do
+ xml.X509SKI subject_key_identifier
+ xml.X509Certificate ::Xml::Kit::Certificate.strip(x509_data.to_pem)
+ end
+ end
render(encrypted_key, xml: xml) if encrypted_key
end
lib/xml/kit/encrypted_key.rb
@@ -3,8 +3,8 @@ require 'xml/kit/templatable'
module Xml
module Kit
class EncryptedKey
- DEFAULT_ALGORITHM = ::Xml::Kit::Crypto::RsaCipher::ALGORITHM
include ::Xml::Kit::Templatable
+ DEFAULT_ALGORITHM = ::Xml::Kit::Crypto::RsaCipher::ALGORITHM
attr_reader :id, :algorithm
attr_reader :public_key, :key
lib/xml/kit/external_key_info.rb
@@ -1,4 +1,3 @@
-
# frozen_string_literal: true
module Xml
@@ -6,7 +5,7 @@ module Xml
class ExternalKeyInfo
attr_reader :uri, :type
- def initialize(uri:, type: "http://www.w3.org/2001/04/xmlenc#EncryptedKey")
+ def initialize(uri:, type: 'http://www.w3.org/2001/04/xmlenc#EncryptedKey')
@uri = uri
@type = type
end
lib/xml/kit/self_signed_certificate.rb
@@ -34,7 +34,7 @@ module Xml
extension_factory = OpenSSL::X509::ExtensionFactory.new
extension_factory.subject_certificate = certificate
extension_factory.issuer_certificate = certificate
- certificate.add_extension(extension_factory.create_extension("subjectKeyIdentifier", "hash", false))
+ certificate.add_extension(extension_factory.create_extension('subjectKeyIdentifier', 'hash', false))
certificate
end
lib/xml/kit/templatable.rb
@@ -23,7 +23,7 @@ module Xml
pretty ? Nokogiri::XML(result).to_xml(indent: 2) : result
end
- def encrypt_key_for(xml: , id: , public_key: , key: )
+ def encrypt_key_for(xml:, id:, public_key:, key:)
::Xml::Kit::EncryptedKey.new(id: id, public_key: public_key, key: key).to_xml(xml: xml)
end
spec/support/matchers/match_xsd.rb
@@ -14,4 +14,3 @@ RSpec::Matchers.define :match_xsd do |expected|
diffable
end
-
spec/xml/kit/encrypted_key_spec.rb
@@ -1,6 +1,7 @@
RSpec.describe ::Xml::Kit::EncryptedKey do
- describe "#to_xml" do
+ describe '#to_xml' do
subject { described_class.new(id: id, algorithm: algorithm, public_key: public_key, key: symmetric_key, key_info: key_info) }
+
let(:algorithm) { ::Xml::Kit::Crypto::RsaCipher::ALGORITHM }
let(:key_info) { ::Xml::Kit::KeyInfo.new }
let(:id) { ::Xml::Kit::Id.generate }
spec/xml/kit/external_key_info_spec.rb
@@ -1,15 +1,16 @@
RSpec.describe Xml::Kit::ExternalKeyInfo do
- describe "#to_xml" do
+ describe '#to_xml' do
subject { described_class.new(uri: uri, type: type) }
- let(:uri) { "#EK" }
- let(:type) { "http://www.w3.org/2001/04/xmlenc#EncryptedKey" }
+
+ let(:uri) { '#EK' }
+ let(:type) { 'http://www.w3.org/2001/04/xmlenc#EncryptedKey' }
let(:result) { Hash.from_xml(subject.to_xml) }
specify { expect(result['KeyInfo']).to be_present }
- specify { expect(result["KeyInfo"]["RetrievalMethod"]).to be_present }
- specify { expect(result["KeyInfo"]["RetrievalMethod"]["xmlns"]).to eql(::Xml::Kit::Namespaces::XMLDSIG) }
- specify { expect(result["KeyInfo"]["RetrievalMethod"]["URI"]).to eql(uri) }
- specify { expect(result["KeyInfo"]["RetrievalMethod"]["Type"]).to eql(type) }
- specify { expect(result["KeyInfo"]["EncryptedKey"]).to be_nil }
+ specify { expect(result['KeyInfo']['RetrievalMethod']).to be_present }
+ specify { expect(result['KeyInfo']['RetrievalMethod']['xmlns']).to eql(::Xml::Kit::Namespaces::XMLDSIG) }
+ specify { expect(result['KeyInfo']['RetrievalMethod']['URI']).to eql(uri) }
+ specify { expect(result['KeyInfo']['RetrievalMethod']['Type']).to eql(type) }
+ specify { expect(result['KeyInfo']['EncryptedKey']).to be_nil }
end
end
spec/xml/kit/key_info_spec.rb
@@ -1,8 +1,8 @@
RSpec.describe Xml::Kit::KeyInfo do
subject { described_class.new }
- describe "#to_xml" do
- context "with encrypted key" do
+ describe '#to_xml' do
+ context 'with encrypted key' do
let(:encrypted_key) { ::Xml::Kit::EncryptedKey.new(id: id, algorithm: algorithm, public_key: public_key, key: symmetric_key) }
let(:algorithm) { ::Xml::Kit::Crypto::RsaCipher::ALGORITHM }
let(:id) { ::Xml::Kit::Id.generate }
@@ -19,17 +19,17 @@ RSpec.describe Xml::Kit::KeyInfo do
specify { expect(private_key.private_decrypt(Base64.decode64(result['KeyInfo']['EncryptedKey']['CipherData']['CipherValue']))).to eql(symmetric_key) }
end
- context "with key name" do
+ context 'with key name' do
let(:result) { Hash.from_xml(subject.to_xml) }
before do
- subject.key_name = "samlkey"
+ subject.key_name = 'samlkey'
end
specify { expect(result['KeyInfo']['KeyName']).to eql('samlkey') }
end
- context "with key value" do
+ context 'with key value' do
let(:result) { Hash.from_xml(subject.to_xml) }
let(:modulus) { 'xA7SEU+e0yQH5rm9kbCDN9o3aPIo7HbP7tX6WOocLZAtNfyxSZDU16ksL6WjubafOqNEpcwR3RdFsT7bCqnXPBe5ELh5u4VEy19MzxkXRgrMvavzyBpVRgBUwUlV5foK5hhmbktQhyNdy/6LpQRhDUDsTvK+g9Ucj47es9AQJ3U=' }
let(:exponent) { 'AQAB' }
@@ -43,10 +43,10 @@ RSpec.describe Xml::Kit::KeyInfo do
specify { expect(result['KeyInfo']['KeyValue']['RSAKeyValue']['Exponent']).to eql(exponent) }
end
- context "with retrieval method" do
+ context 'with retrieval method' do
let(:result) { Hash.from_xml(subject.to_xml) }
let(:uri) { Xml::Kit::Id.generate }
- let(:type) { "http://www.w3.org/2001/04/xmlenc#EncryptedKey" }
+ let(:type) { 'http://www.w3.org/2001/04/xmlenc#EncryptedKey' }
before do
subject.retrieval_method.uri = uri
@@ -57,10 +57,10 @@ RSpec.describe Xml::Kit::KeyInfo do
specify { expect(result['KeyInfo']['RetrievalMethod']['Type']).to eql(type) }
end
- context "with x509 data" do
+ context 'with x509 data' do
let(:key_pair) { ::Xml::Kit::KeyPair.generate(use: :encryption) }
let(:x509_certificate) { key_pair.certificate.x509 }
- let(:subject_key_identifier) { x509_certificate.extensions.find { |x| x.oid == "subjectKeyIdentifier" }.value }
+ let(:subject_key_identifier) { x509_certificate.extensions.find { |x| x.oid == 'subjectKeyIdentifier' }.value }
let(:result) { Hash.from_xml(subject.to_xml) }
before do
spec/xml/kit/soap_spec.rb
@@ -1,6 +1,7 @@
-RSpec.describe "Soap Example" do
- describe "#to_xml" do
+RSpec.describe 'Soap Example' do
+ describe '#to_xml' do
subject { Soap.new }
+
let(:result) { Hash.from_xml(subject.to_xml) }
specify { expect(result['Envelope']).to be_present }
spec/xml/kit/templatable_spec.rb
@@ -96,7 +96,7 @@ RSpec.describe ::Xml::Kit::Templatable do
specify { expect(subject.to_xml).to match_xsd('item') }
- context "with the key extracted to the header" do
+ context 'with the key extracted to the header' do
let(:xml_hash) { Hash.from_xml(subject.to_xml) }
before do
@@ -104,11 +104,11 @@ RSpec.describe ::Xml::Kit::Templatable do
end
specify { expect(subject.to_xml).to match_xsd('item-extracted-key') }
- specify { expect(xml_hash["Item"]["Encrypted"]["EncryptedData"]["KeyInfo"]["RetrievalMethod"]).to be_present }
- specify { expect(xml_hash["Item"]["Encrypted"]["EncryptedData"]["KeyInfo"]["RetrievalMethod"]["xmlns"]).to eql(::Xml::Kit::Namespaces::XMLDSIG) }
- specify { expect(xml_hash["Item"]["Encrypted"]["EncryptedData"]["KeyInfo"]["RetrievalMethod"]["URI"]).to eql("#EK") }
- specify { expect(xml_hash["Item"]["Encrypted"]["EncryptedData"]["KeyInfo"]["RetrievalMethod"]["Type"]).to eql("http://www.w3.org/2001/04/xmlenc#EncryptedKey") }
- specify { expect(xml_hash["Item"]["Encrypted"]["EncryptedData"]["KeyInfo"]["EncryptedKey"]).to be_nil }
+ specify { expect(xml_hash['Item']['Encrypted']['EncryptedData']['KeyInfo']['RetrievalMethod']).to be_present }
+ specify { expect(xml_hash['Item']['Encrypted']['EncryptedData']['KeyInfo']['RetrievalMethod']['xmlns']).to eql(::Xml::Kit::Namespaces::XMLDSIG) }
+ specify { expect(xml_hash['Item']['Encrypted']['EncryptedData']['KeyInfo']['RetrievalMethod']['URI']).to eql('#EK') }
+ specify { expect(xml_hash['Item']['Encrypted']['EncryptedData']['KeyInfo']['RetrievalMethod']['Type']).to eql('http://www.w3.org/2001/04/xmlenc#EncryptedKey') }
+ specify { expect(xml_hash['Item']['Encrypted']['EncryptedData']['KeyInfo']['EncryptedKey']).to be_nil }
end
end
end