xmlenc 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 43a28e1294fa06dd78706f950aa952f66e846e5a
4
- data.tar.gz: 1a0ca77fe7935b3e60e2ec8ef32df91ef9c9717e
3
+ metadata.gz: 869074b32ca2144be9a0c5b4344e2a962b067096
4
+ data.tar.gz: e33dd060461d348bec6c2160ae83c7997341e572
5
5
  SHA512:
6
- metadata.gz: 425afdca319a8b8dfe4c39ef12002009f2943d3c9bf943b9d7dd7c1f0a6944e4610c0b6e7e2f81e695815842188e91ef4238f0b92a9d79c03479f4ab2b215b51
7
- data.tar.gz: cee795932daba6734ce9c6d70dff6d7ebbdeb3e5f616514bea6aad36df415a4e1afaf7a296ac6e04e2c02ed7ecf4e78d4b2442af45ad8448e72f4a0ae9dcdf86
6
+ metadata.gz: 3216e9fef6a70ed78735a8cc6587dd22e1a1c8ced0d6ef21ec125203e0778f2379374a3bbfa9a2f9b4ed962cb49146fd71d319f42ceda0f2e4319e2284b83cc6
7
+ data.tar.gz: 7e80bcaaa65527a1bea1b932ee159bcd225c5335bb58601239e8de4aa64ed6993c90987a9c884d60fc90292253f98da1cebf979fc45c36a9a7d1cd130e2d26b6
@@ -31,6 +31,8 @@ module Xmlenc
31
31
 
32
32
  module HappyMapperClassMethods
33
33
  def parse(xml, options = {})
34
+ raise Xmlenc::UnparseableMessage("Unable to parse nil document") if xml.nil?
35
+
34
36
  object = super
35
37
  if object.is_a?(Array)
36
38
  object.map { |x| x.from_xml = true }
@@ -23,6 +23,13 @@ module Xmlenc
23
23
  def set_encryption_method(attributes = {})
24
24
  self.encryption_method = EncryptionMethod.new(attributes)
25
25
  end
26
+
27
+ def set_key_name(key_name)
28
+ if key_name
29
+ self.key_info ||= KeyInfo.new
30
+ self.key_info.key_name = key_name
31
+ end
32
+ end
26
33
  end
27
34
  end
28
35
  end
@@ -1,3 +1,3 @@
1
1
  module Xmlenc
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -9,7 +9,7 @@ end
9
9
  describe BaseDummy do
10
10
  describe "parse override" do
11
11
  it "sets the from_xml flag" do
12
- BaseDummy.parse("<tag></tag>", :single => true).from_xml?.should be_true
12
+ BaseDummy.parse("<tag></tag>", :single => true).from_xml?.should be_truthy
13
13
  end
14
14
 
15
15
  it "raises an error if the message cannot be parsed" do
@@ -18,7 +18,8 @@ describe Xmlenc::Builder::ComplexTypes::EncryptedType do
18
18
 
19
19
  it "should check the presence of cipher data" do
20
20
  subject.cipher_data = nil
21
- expect(subject).to have(1).error_on :cipher_data
21
+ expect(subject).to_not be_valid
22
+ expect(subject.errors[:cipher_data].size).to eq(1)
22
23
  end
23
24
  end
24
25
 
@@ -35,6 +36,24 @@ describe Xmlenc::Builder::ComplexTypes::EncryptedType do
35
36
  end
36
37
  end
37
38
 
39
+ describe "#set_key_name" do
40
+ it "sets the key info with the key name" do
41
+ subject.set_key_name("key name")
42
+ expect(subject.key_info.key_name).to eq "key name"
43
+ end
44
+
45
+ it "does not override old key info data" do
46
+ subject.set_key_name("key name")
47
+ expect(subject.key_info.encrypted_key).not_to be_nil
48
+ end
49
+
50
+ it "does not set the key info element if the keyname is nil" do
51
+ subject.key_info = nil
52
+ subject.set_key_name(nil)
53
+ expect(subject.key_info).to be_nil
54
+ end
55
+ end
56
+
38
57
  describe "#parse" do
39
58
  describe "encryption method" do
40
59
  it "should create an EncryptionMethod element" do
@@ -12,7 +12,8 @@ describe Xmlenc::Builder::DigestMethod do
12
12
 
13
13
  it "raises error when no algorithm" do
14
14
  subject.algorithm = nil
15
- expect(subject).to have(1).error_on :algorithm
15
+ expect(subject).to_not be_valid
16
+ expect(subject.errors[:algorithm].size).to eq(1)
16
17
  end
17
18
  end
18
19
  end
@@ -12,7 +12,8 @@ describe Xmlenc::Builder::EncryptedData do
12
12
 
13
13
  it "should check the presence of cipher data" do
14
14
  subject.cipher_data = nil
15
- expect(subject).to have(1).error_on :cipher_data
15
+ expect(subject).to_not be_valid
16
+ expect(subject.errors[:cipher_data].size).to eq(1)
16
17
  end
17
18
  end
18
19
 
@@ -12,7 +12,8 @@ describe Xmlenc::Builder::EncryptedKey do
12
12
 
13
13
  it "should check the presence of cipher data" do
14
14
  subject.cipher_data = nil
15
- expect(subject).to have(1).error_on :cipher_data
15
+ expect(subject).to_not be_valid
16
+ expect(subject.errors[:cipher_data].size).to eq(1)
16
17
  end
17
18
  end
18
19
 
@@ -12,7 +12,8 @@ describe Xmlenc::Builder::EncryptionMethod do
12
12
 
13
13
  it "should check the presence of algorithm" do
14
14
  subject.algorithm = nil
15
- expect(subject).to have(1).error_on :algorithm
15
+ expect(subject).to_not be_valid
16
+ expect(subject.errors[:algorithm].size).to eq(1)
16
17
  end
17
18
  end
18
19
 
@@ -46,9 +46,10 @@ describe Xmlenc::EncryptedData do
46
46
 
47
47
  describe 'aes256-cbc' do
48
48
  it 'replaces returns the decrypted value' do
49
- encrypted_data_node.at_xpath('./xenc:EncryptionMethod', Xmlenc::NAMESPACES).replace <<-XML
50
- <EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes256-cbc"></EncryptionMethod>
49
+ fragment = <<-XML
50
+ <EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes256-cbc" xmlns="http://www.w3.org/2001/04/xmlenc#"></EncryptionMethod>
51
51
  XML
52
+ encrypted_data_node.at_xpath('./xenc:EncryptionMethod', Xmlenc::NAMESPACES).replace(Nokogiri::XML::DocumentFragment.parse(fragment))
52
53
  subject.stub(:cipher_value) { 'DpNYC0Np5hHaQAUyHWpM3MQ99wkDFtGRc7TywqxmhI4sJKDXM5SRjVlKf6st5wOz' }
53
54
  key = %w(b0621c35317af207b92e3a6b317a122a93772a7261e3f13a4297eb64a91af10a).pack('H*')
54
55
 
@@ -58,9 +59,11 @@ describe Xmlenc::EncryptedData do
58
59
 
59
60
  describe 'des3-cbc' do
60
61
  it 'replaces returns the decrypted value' do
61
- encrypted_data_node.at_xpath('./xenc:EncryptionMethod', Xmlenc::NAMESPACES).replace <<-XML
62
- <EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#tripledes-cbc"></EncryptionMethod>
62
+ fragment = <<-XML
63
+ <EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#tripledes-cbc" xmlns="http://www.w3.org/2001/04/xmlenc#"></EncryptionMethod>
63
64
  XML
65
+
66
+ encrypted_data_node.at_xpath('./xenc:EncryptionMethod', Xmlenc::NAMESPACES).replace(Nokogiri::XML::DocumentFragment.parse(fragment))
64
67
  subject.stub(:cipher_value) { 'kY6scZxpyRXQbaDZp+LbuvSFYgmI3pQrfsrCVt3/9sZzpeUTPXJEatQ5KPOXYpJC
65
68
  Gid01h/T8PIezic0Ooz/jU+r3kYMKesMYiXin4CXTZYcGhd0TjmOd4kg1vlhE8kt
66
69
  WLC7JDzFLPAqXbOug3ghmWunFiUETbGJaF5V4AHIoZrYP+RS3DTLgJcATuDeWyOd
@@ -31,7 +31,7 @@ describe Xmlenc::EncryptedDocument do
31
31
 
32
32
  it 'converts the elements to EncryptedKey' do
33
33
  all_converted = subject.encrypted_keys.all? { |ek| ek.is_a?(Xmlenc::EncryptedKey) }
34
- expect(all_converted).to be_true
34
+ expect(all_converted).to be_truthy
35
35
  end
36
36
  end
37
37
 
@@ -68,21 +68,24 @@ describe Xmlenc::EncryptedKey do
68
68
  SBMpGzkVfDuv8aAFXOtf+LV67Ov6hJAt7FB65tE9Hg==
69
69
  CV
70
70
 
71
- encrypted_key_node.at_xpath('./xenc:EncryptionMethod', Xmlenc::NAMESPACES).replace <<-XML
72
- <EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p">
71
+ fragment = <<-XML
72
+ <EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p" xmlns="http://www.w3.org/2001/04/xmlenc#">
73
73
  <ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" xmlns:ds="http://www.w3.org/2000/09/xmldsig#"/>
74
74
  </EncryptionMethod>
75
75
  XML
76
+ encrypted_key_node.at_xpath('./xenc:EncryptionMethod', Xmlenc::NAMESPACES).replace(Nokogiri::XML::DocumentFragment.parse(fragment))
76
77
  end
77
78
 
78
79
  describe 'with unsupported digest method' do
79
80
  it 'raises an unsupported error' do
80
- encrypted_key_node.at_xpath('./xenc:EncryptionMethod', Xmlenc::NAMESPACES).replace <<-XML
81
- <EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p">
81
+ fragment = <<-XML
82
+ <EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p" xmlns="http://www.w3.org/2001/04/xmlenc#">
82
83
  <ds:DigestMethod Algorithm="unsupported" xmlns:ds="http://www.w3.org/2000/09/xmldsig#"/>
83
84
  </EncryptionMethod>
84
85
  XML
85
86
 
87
+ encrypted_key_node.at_xpath('./xenc:EncryptionMethod', Xmlenc::NAMESPACES).replace(Nokogiri::XML::DocumentFragment.parse(fragment))
88
+
86
89
  expect {
87
90
  subject.decrypt(private_key)
88
91
  }.to raise_error(Xmlenc::UnsupportedError)
@@ -96,10 +99,12 @@ describe Xmlenc::EncryptedKey do
96
99
 
97
100
  describe 'with unsupported algorithm' do
98
101
  it 'raises an unsupported error' do
99
- encrypted_key_node.at_xpath('./xenc:EncryptionMethod', Xmlenc::NAMESPACES).replace <<-XML
100
- <EncryptionMethod Algorithm="unsupported"></EncryptionMethod>
102
+ fragment = <<-XML
103
+ <EncryptionMethod Algorithm="unsupported" xmlns="http://www.w3.org/2001/04/xmlenc#"></EncryptionMethod>
101
104
  XML
102
105
 
106
+ encrypted_key_node.at_xpath('./xenc:EncryptionMethod', Xmlenc::NAMESPACES).replace(Nokogiri::XML::DocumentFragment.parse(fragment))
107
+
103
108
  expect {
104
109
  subject.decrypt(private_key)
105
110
  }.to raise_error(Xmlenc::UnsupportedError)
@@ -84,7 +84,7 @@ describe 'Phaos compatibility tests' do
84
84
  result = cipher.update(data_cipher[cipher.iv_len..-1])
85
85
  result << cipher.final
86
86
 
87
- doc.at_xpath('//xenc:EncryptedData', Xmlenc::NAMESPACES).replace(result)
87
+ doc.at_xpath('//xenc:EncryptedData', Xmlenc::NAMESPACES).replace(Nokogiri::XML::DocumentFragment.parse(result))
88
88
  expect(doc.to_xml.chomp).to be == plain_xml
89
89
  end
90
90
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xmlenc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benoist
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-24 00:00:00.000000000 Z
11
+ date: 2015-10-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport