sepafm 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/lib/sepa/application_request.rb +29 -13
  3. data/lib/sepa/attribute_checks.rb +29 -29
  4. data/lib/sepa/banks/danske/danske_response.rb +49 -10
  5. data/lib/sepa/banks/danske/soap_danske.rb +7 -6
  6. data/lib/sepa/banks/nordea/nordea_response.rb +2 -4
  7. data/lib/sepa/client.rb +31 -11
  8. data/lib/sepa/error_messages.rb +2 -1
  9. data/lib/sepa/response.rb +18 -3
  10. data/lib/sepa/soap_builder.rb +52 -21
  11. data/lib/sepa/utilities.rb +4 -0
  12. data/lib/sepa/version.rb +1 -1
  13. data/lib/sepa/wsdl/wsdl_danske.xml +1 -1
  14. data/lib/sepa/xml_templates/application_request/download_file.xml +0 -1
  15. data/lib/sepa/xml_templates/application_request/download_file_list.xml +0 -1
  16. data/lib/sepa/xml_templates/application_request/upload_file.xml +0 -1
  17. data/lib/sepa/xml_templates/soap/download_file_list.xml +1 -1
  18. data/lib/sepa/xml_templates/soap/header.xml +6 -5
  19. data/lib/sepafm.rb +1 -0
  20. data/readme.md +3 -5
  21. data/sepafm.gemspec +5 -5
  22. data/test/sepa/banks/danske/danske_cert_response_test.rb +6 -6
  23. data/test/sepa/banks/danske/danske_cert_soap_builder_test.rb +16 -17
  24. data/test/sepa/banks/danske/danske_certificate_application_request_test.rb +16 -0
  25. data/test/sepa/banks/danske/danske_generic_soap_builder_test.rb +39 -43
  26. data/test/sepa/banks/nordea/nordea_application_request_test.rb +38 -18
  27. data/test/sepa/banks/nordea/nordea_cert_application_request_test.rb +12 -11
  28. data/test/sepa/banks/nordea/nordea_cert_request_soap_builder_test.rb +10 -10
  29. data/test/sepa/banks/nordea/nordea_generic_soap_builder_test.rb +14 -18
  30. data/test/sepa/banks/nordea/nordea_response_test.rb +1 -1
  31. data/test/sepa/client_test.rb +38 -25
  32. data/test/sepa/fixtures.rb +52 -22
  33. data/test/sepa/sepa_test.rb +1 -1
  34. metadata +27 -25
@@ -5,7 +5,6 @@
5
5
  <Timestamp></Timestamp>
6
6
  <Status></Status>
7
7
  <Environment></Environment>
8
- <TargetId></TargetId>
9
8
  <SoftwareId></SoftwareId>
10
9
  <FileType></FileType>
11
10
  <dsig:Signature xmlns:dsig="http://www.w3.org/2000/09/xmldsig#">
@@ -4,7 +4,6 @@
4
4
  <Command></Command>
5
5
  <Timestamp></Timestamp>
6
6
  <Environment></Environment>
7
- <TargetId></TargetId>
8
7
  <SoftwareId></SoftwareId>
9
8
  <FileType></FileType>
10
9
  <Content></Content>
@@ -4,7 +4,7 @@
4
4
  xmlns:cor="http://bxd.fi/CorporateFileService" xmlns:bxd="http://model.bxd.fi">
5
5
  <env:Body
6
6
  xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
7
- wsu:Id="sdf6sa7d86f87s6df786sd87f6s8fsda">
7
+ wsu:Id="">
8
8
  <cor:downloadFileListin xmlns:cor="http://bxd.fi/CorporateFileService">
9
9
  <bxd:RequestHeader xmlns:bxd="http://model.bxd.fi">
10
10
  <bxd:SenderId></bxd:SenderId>
@@ -10,19 +10,19 @@
10
10
  xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
11
11
  EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary"
12
12
  ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3"
13
- wsu:Id="sdgdsg76sdg78sdg78d6gs"></wsse:BinarySecurityToken>
13
+ wsu:Id=""></wsse:BinarySecurityToken>
14
14
  <dsig:Signature xmlns:dsig="http://www.w3.org/2000/09/xmldsig#">
15
15
  <dsig:SignedInfo>
16
16
  <dsig:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
17
17
  <dsig:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>
18
- <dsig:Reference URI="#dsfg8sdg87dsf678g6dsg6ds7fg">
18
+ <dsig:Reference URI="">
19
19
  <dsig:Transforms>
20
20
  <dsig:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
21
21
  </dsig:Transforms>
22
22
  <dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
23
23
  <dsig:DigestValue></dsig:DigestValue>
24
24
  </dsig:Reference>
25
- <dsig:Reference URI="#sdf6sa7d86f87s6df786sd87f6s8fsda">
25
+ <dsig:Reference URI="">
26
26
  <dsig:Transforms>
27
27
  <dsig:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
28
28
  </dsig:Transforms>
@@ -33,13 +33,14 @@
33
33
  <dsig:SignatureValue></dsig:SignatureValue>
34
34
  <dsig:KeyInfo>
35
35
  <wsse:SecurityTokenReference>
36
- <wsse:Reference URI="#sdgdsg76sdg78sdg78d6gs"/>
36
+ <wsse:Reference URI=""
37
+ ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3"/>
37
38
  </wsse:SecurityTokenReference>
38
39
  </dsig:KeyInfo>
39
40
  </dsig:Signature>
40
41
  <wsu:Timestamp
41
42
  xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
42
- wsu:Id="dsfg8sdg87dsf678g6dsg6ds7fg">
43
+ wsu:Id="">
43
44
  <wsu:Created></wsu:Created>
44
45
  <wsu:Expires></wsu:Expires>
45
46
  </wsu:Timestamp>
data/lib/sepafm.rb CHANGED
@@ -32,6 +32,7 @@ OASIS_UTILITY = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecur
32
32
  OASIS_SECEXT = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd'
33
33
  XML_DATA = 'http://bxd.fi/xmldata/'
34
34
  BXD = 'http://model.bxd.fi'
35
+ XMLENC = 'http://www.w3.org/2001/04/xmlenc#'
35
36
 
36
37
  # Nordea XML namespaces
37
38
  NORDEA_PKI = 'http://bxd.fi/CertificateService'
data/readme.md CHANGED
@@ -3,6 +3,7 @@
3
3
  [![Code Climate](https://codeclimate.com/github/devlab-oy/sepa.png)](https://codeclimate.com/github/devlab-oy/sepa)
4
4
  [![Code Climate](https://codeclimate.com/github/devlab-oy/sepa/coverage.png)](https://codeclimate.com/github/devlab-oy/sepa)
5
5
  [![Build Status](https://travis-ci.org/devlab-oy/sepa.svg?branch=master)](https://travis-ci.org/devlab-oy/sepa)
6
+ [![Gem Version](https://badge.fury.io/rb/sepafm.svg)](http://badge.fury.io/rb/sepafm)
6
7
 
7
8
  This project aims to create an open source implementation of SEPA Financial Messages using Web Services. Project implementation is done in Ruby.
8
9
 
@@ -155,7 +156,6 @@ params = {
155
156
  command: :create_certificate,
156
157
  customer_id: '360817',
157
158
  environment: 'customertest',
158
- key_generator_type: 'software',
159
159
  encryption_cert_pkcs10: danske_enc_cert_request,
160
160
  signing_cert_pkcs10: danske_signing_cert_request,
161
161
  pin: '1234'
@@ -197,10 +197,10 @@ response.ca_certificate
197
197
  * get_user_info
198
198
  * get_certificate
199
199
  * get_bank_certificate
200
- * **customer_id** - Your personal id with the bank.
200
+ * **customer_id** - Your customer id with the bank.
201
201
  * **environment** - Must be either PRODUCTION or TEST
202
202
  * **status** - For filtering stuff. Must be either NEW, DOWNLOADED or ALL
203
- * **target_id** - Some specification of the folder which to access in the bank.
203
+ * **target_id** - Some specification of the folder which to access in the bank (Nordea only)
204
204
  * **language** - Language must be either FI, EN or SV
205
205
  * **file_type** - File types to upload or download:
206
206
  * LMP300 = Laskujen maksupalvelu (lähtevä)
@@ -213,8 +213,6 @@ response.ca_certificate
213
213
  * **content** - The payload to send.
214
214
  * **file_reference** - File reference for :download_file command
215
215
  * **pin** - Your personal pin-code provided by the bank
216
- * **service** - For testing value is service, otherwise ISSUER
217
- * **bank_root_cert_serial** - Serial number for Danske bank certificate download (1111110002)
218
216
 
219
217
  ---
220
218
 
data/sepafm.gemspec CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
9
9
  spec.description = 'SEPA Financial Messages using Web Services'
10
10
  spec.homepage = 'https://github.com/devlab-oy/sepa'
11
11
  spec.license = 'MIT'
12
- spec.authors = ['Joni Kanerva', 'Mika Myllynen', 'Tommi Jarvinen']
12
+ spec.authors = ['Joni Kanerva', 'Mika Myllynen', 'Tommi Järvinen']
13
13
  spec.email = ['joni@devlab.fi']
14
14
  spec.files = `git ls-files`.split($/)
15
15
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
@@ -18,14 +18,14 @@ Gem::Specification.new do |spec|
18
18
 
19
19
  spec.required_ruby_version = '>= 2.0.0'
20
20
 
21
- spec.add_dependency 'savon', '~> 2.5'
22
- spec.add_dependency 'nokogiri', '~> 1.6'
23
21
  spec.add_dependency 'activemodel', '~> 4.1'
24
- spec.add_dependency 'minitest', '~> 5.3'
22
+ spec.add_dependency 'nokogiri', '~> 1.6'
23
+ spec.add_dependency 'savon', '~> 2.5'
25
24
 
26
25
  spec.add_development_dependency 'bundler', '~> 1.6'
27
- spec.add_development_dependency 'rake', '~> 10.3'
28
26
  spec.add_development_dependency 'codeclimate-test-reporter', '~> 0.3'
29
27
  spec.add_development_dependency 'dotenv', '~> 0.11'
28
+ spec.add_development_dependency 'minitest', '~> 5.3'
29
+ spec.add_development_dependency 'rake', '~> 10.3'
30
30
  spec.add_development_dependency 'rubyntlm', '~> 0.3'
31
31
  end
@@ -18,32 +18,32 @@ class DanskeCertResponseTest < ActiveSupport::TestCase
18
18
 
19
19
  # Tests for get bank certificate
20
20
  test 'should have correct bank signing cert with get_bank_certificate command' do
21
- bank_signing_cert = @get_bank_cert_response.bank_signing_cert
21
+ bank_signing_cert = @get_bank_cert_response.bank_signing_certificate
22
22
  refute_nil bank_signing_cert
23
23
  assert_equal bank_signing_cert.to_s, DANSKE_BANK_SIGNING_CERT
24
24
  end
25
25
 
26
26
  test 'should have corrent bank encryption cert with get bank certificate command' do
27
- bank_encryption_cert = @get_bank_cert_response.bank_encryption_cert
27
+ bank_encryption_cert = @get_bank_cert_response.bank_encryption_certificate
28
28
  refute_nil bank_encryption_cert
29
29
  assert_equal bank_encryption_cert.to_s, DANSKE_BANK_ENCRYPTION_CERT
30
30
  end
31
31
 
32
- test 'should have correct bank root cert with get bank certificate command' do
33
- bank_root_cert = @get_bank_cert_response.bank_root_cert
32
+ test 'should have correct bank root certificate with get bank certificate command' do
33
+ bank_root_cert = @get_bank_cert_response.bank_root_certificate
34
34
  refute_nil bank_root_cert
35
35
  assert_equal bank_root_cert.to_s, DANSKE_BANK_ROOT_CERT
36
36
  end
37
37
 
38
38
  # Tests for create certificate
39
39
  test 'should have own encryption certificate with create certificate command' do
40
- own_encryption_cert = @create_certificate_response.own_encryption_cert
40
+ own_encryption_cert = @create_certificate_response.own_encryption_certificate
41
41
  refute_nil own_encryption_cert
42
42
  assert own_encryption_cert.respond_to? :sign
43
43
  end
44
44
 
45
45
  test 'should have on signing certificate with create certificate command' do
46
- own_signing_cert = @create_certificate_response.own_signing_cert
46
+ own_signing_cert = @create_certificate_response.own_signing_certificate
47
47
  refute_nil own_signing_cert
48
48
  assert own_signing_cert.respond_to? :sign
49
49
  end
@@ -2,34 +2,33 @@ require 'test_helper'
2
2
 
3
3
  class DanskeCertSoapBuilderTest < ActiveSupport::TestCase
4
4
  def setup
5
- @create_cert_params = danske_create_cert_params
5
+ @danske_create_certificate_params = danske_create_certificate_params
6
6
 
7
- @cert_request = Sepa::SoapBuilder.new(@create_cert_params)
8
- @enc_private_key = OpenSSL::PKey::RSA.new File.read("#{DANSKE_TEST_KEYS_PATH}/enc_private_key.pem")
7
+ @cert_request = Sepa::SoapBuilder.new(@danske_create_certificate_params)
8
+ @enc_private_key = rsa_key File.read("#{DANSKE_TEST_KEYS_PATH}/enc_private_key.pem")
9
9
  @doc = Nokogiri::XML(@cert_request.to_xml)
10
10
 
11
11
  # Namespaces
12
12
  @pkif = 'http://danskebank.dk/PKI/PKIFactoryService'
13
13
  @dsig = 'http://www.w3.org/2000/09/xmldsig#'
14
- @xenc = 'http://www.w3.org/2001/04/xmlenc#'
15
14
  end
16
15
 
17
16
  def test_should_raise_error_if_command_missing
18
- @create_cert_params.delete(:command)
17
+ @danske_create_certificate_params.delete(:command)
19
18
 
20
19
  assert_raises(ArgumentError) do
21
- Sepa::SoapBuilder.new(@create_cert_params)
20
+ Sepa::SoapBuilder.new(@danske_create_certificate_params)
22
21
  end
23
22
  end
24
23
 
25
24
  def test_sender_id_is_properly_set
26
25
  sender_id = @doc.at("SenderId", "xmlns" => @pkif).content
27
- assert_equal sender_id, @create_cert_params[:customer_id]
26
+ assert_equal sender_id, @danske_create_certificate_params[:customer_id]
28
27
  end
29
28
 
30
29
  def test_customer_id_is_properly_set
31
30
  customer_id = @doc.at("CustomerId", "xmlns" => @pkif).content
32
- assert_equal customer_id, @create_cert_params[:customer_id]
31
+ assert_equal customer_id, @danske_create_certificate_params[:customer_id]
33
32
  end
34
33
 
35
34
  def test_request_id_is_properly_set
@@ -54,28 +53,28 @@ class DanskeCertSoapBuilderTest < ActiveSupport::TestCase
54
53
  end
55
54
 
56
55
  def test_certificate_is_added_properly
57
- embedded_cert = @doc.at("X509Certificate", 'xmlns' => @dsig).content.gsub(/\s+/, "")
56
+ embedded_certificate = @doc.at("X509Certificate", 'xmlns' => @dsig).content.gsub(/\s+/, "")
58
57
 
59
- actual_cert = @create_cert_params[:enc_cert]
60
- actual_cert = actual_cert.split('-----BEGIN CERTIFICATE-----')[1]
61
- actual_cert = actual_cert.split('-----END CERTIFICATE-----')[0]
62
- actual_cert.gsub!(/\s+/, "")
58
+ actual_certificate = @danske_create_certificate_params[:encryption_certificate]
59
+ actual_certificate = actual_certificate.split('-----BEGIN CERTIFICATE-----')[1]
60
+ actual_certificate = actual_certificate.split('-----END CERTIFICATE-----')[0]
61
+ actual_certificate.gsub!(/\s+/, "")
63
62
 
64
- assert_equal embedded_cert, actual_cert
63
+ assert_equal embedded_certificate, actual_certificate
65
64
  end
66
65
 
67
66
  def test_encrypted_key_is_added_properly_and_can_be_decrypted
68
- enc_key = @doc.css("CipherValue", 'xmlns' => @xenc)[0].content
67
+ enc_key = @doc.css("CipherValue", 'xmlns' => XMLENC)[0].content
69
68
  enc_key = decode enc_key
70
69
  assert @enc_private_key.private_decrypt(enc_key)
71
70
  end
72
71
 
73
72
  def test_encypted_data_is_added_properly_and_can_be_decrypted
74
- enc_key = @doc.css("CipherValue", 'xmlns' => @xenc)[0].content
73
+ enc_key = @doc.css("CipherValue", 'xmlns' => XMLENC)[0].content
75
74
  enc_key = decode enc_key
76
75
  key = @enc_private_key.private_decrypt(enc_key)
77
76
 
78
- encypted_data = @doc.css("CipherValue", 'xmlns' => @xenc)[1].content
77
+ encypted_data = @doc.css("CipherValue", 'xmlns' => XMLENC)[1].content
79
78
  encypted_data = decode encypted_data
80
79
  iv = encypted_data[0, 8]
81
80
  encypted_data = encypted_data[8, encypted_data.length]
@@ -0,0 +1,16 @@
1
+ require 'test_helper'
2
+
3
+ class DanskeCertificateApplicationRequestTest < ActiveSupport::TestCase
4
+ setup do
5
+ @danske_create_certificate_params = danske_create_certificate_params
6
+ @danske_create_certificate_params[:environment] = :test
7
+ @danske_create_certificate_application_request =
8
+ Sepa::ApplicationRequest.new @danske_create_certificate_params
9
+ end
10
+
11
+ test 'should set environment to customertest when test in parameters' do
12
+ environment_node =
13
+ @danske_create_certificate_application_request.to_nokogiri.at('tns|Environment')
14
+ assert_equal environment_node.content, 'customertest'
15
+ end
16
+ end
@@ -5,23 +5,23 @@ class DanskeGenericSoapBuilderTest < ActiveSupport::TestCase
5
5
  def setup
6
6
  keys_path = File.expand_path('../keys', __FILE__)
7
7
 
8
- private_key_path = "#{keys_path}/signing_private_key.pem"
9
- private_key = File.read private_key_path
8
+ signing_private_key_path = "#{keys_path}/signing_key.pem"
9
+ signing_private_key = File.read signing_private_key_path
10
10
 
11
- signing_cert_path = "#{keys_path}/own_signing_cert.pem"
12
- signing_cert = File.read signing_cert_path
11
+ signing_certificate_path = "#{keys_path}/own_signing_cert.pem"
12
+ signing_certificate = File.read signing_certificate_path
13
13
 
14
- enc_cert_path = "#{keys_path}/own_enc_cert.pem"
15
- enc_cert = File.read enc_cert_path
14
+ encryption_certificate_path = "#{keys_path}/own_enc_cert.pem"
15
+ encryption_certificate = File.read encryption_certificate_path
16
16
 
17
- @nordea_generic_params = {
17
+ @danske_generic_params = {
18
18
  bank: :danske,
19
- private_key: OpenSSL::PKey::RSA.new(private_key),
19
+ signing_private_key: rsa_key(signing_private_key),
20
20
  command: :upload_file,
21
21
  customer_id: '360817',
22
22
  environment: 'TEST',
23
- enc_cert: enc_cert,
24
- cert: signing_cert,
23
+ encryption_certificate: encryption_certificate,
24
+ signing_certificate: signing_certificate,
25
25
  language: 'EN',
26
26
  status: 'ALL',
27
27
  target_id: 'Danske FI',
@@ -30,7 +30,7 @@ class DanskeGenericSoapBuilderTest < ActiveSupport::TestCase
30
30
  file_reference: "11111111A12006030329501800000014",
31
31
  }
32
32
 
33
- @soap_request = Sepa::SoapBuilder.new(@nordea_generic_params)
33
+ @soap_request = Sepa::SoapBuilder.new(@danske_generic_params)
34
34
 
35
35
  @doc = Nokogiri::XML(@soap_request.to_xml)
36
36
 
@@ -39,55 +39,55 @@ class DanskeGenericSoapBuilderTest < ActiveSupport::TestCase
39
39
  end
40
40
 
41
41
  def test_should_initialize_request_with_proper_params
42
- assert Sepa::SoapBuilder.new(@nordea_generic_params).to_xml
42
+ assert Sepa::SoapBuilder.new(@danske_generic_params).to_xml
43
43
  end
44
44
 
45
45
  def test_should_get_error_if_command_missing
46
- @nordea_generic_params.delete(:command)
46
+ @danske_generic_params.delete(:command)
47
47
 
48
48
  assert_raises(ArgumentError) do
49
- Sepa::SoapBuilder.new(@nordea_generic_params)
49
+ Sepa::SoapBuilder.new(@danske_generic_params)
50
50
  end
51
51
  end
52
52
 
53
53
  def test_should_load_correct_template_with_download_file_list
54
- @nordea_generic_params[:command] = :download_file_list
55
- doc = Nokogiri::XML(Sepa::SoapBuilder.new(@nordea_generic_params).to_xml)
54
+ @danske_generic_params[:command] = :download_file_list
55
+ doc = Nokogiri::XML(Sepa::SoapBuilder.new(@danske_generic_params).to_xml)
56
56
 
57
57
  assert doc.at('//cor:downloadFileListin', 'cor' => 'http://bxd.fi/CorporateFileService')
58
58
  end
59
59
 
60
60
  def test_should_load_correct_template_with_get_user_info
61
- @nordea_generic_params[:command] = :get_user_info
62
- doc = Nokogiri::XML(Sepa::SoapBuilder.new(@nordea_generic_params).to_xml)
61
+ @danske_generic_params[:command] = :get_user_info
62
+ doc = Nokogiri::XML(Sepa::SoapBuilder.new(@danske_generic_params).to_xml)
63
63
 
64
64
  assert doc.at('//cor:getUserInfoin', 'cor' => 'http://bxd.fi/CorporateFileService')
65
65
  end
66
66
 
67
67
  def test_should_load_correct_template_with_download_file
68
- @nordea_generic_params[:command] = :download_file
69
- doc = Nokogiri::XML(Sepa::SoapBuilder.new(@nordea_generic_params).to_xml)
68
+ @danske_generic_params[:command] = :download_file
69
+ doc = Nokogiri::XML(Sepa::SoapBuilder.new(@danske_generic_params).to_xml)
70
70
 
71
71
  assert doc.at('//cor:downloadFilein', 'cor' => 'http://bxd.fi/CorporateFileService')
72
72
  end
73
73
 
74
74
  def test_should_load_correct_template_with_upload_file
75
- @nordea_generic_params[:command] = :upload_file
76
- doc = Nokogiri::XML(Sepa::SoapBuilder.new(@nordea_generic_params).to_xml)
75
+ @danske_generic_params[:command] = :upload_file
76
+ doc = Nokogiri::XML(Sepa::SoapBuilder.new(@danske_generic_params).to_xml)
77
77
 
78
78
  assert doc.at('//cor:uploadFilein', 'cor' => 'http://bxd.fi/CorporateFileService')
79
79
  end
80
80
 
81
81
  def test_should_raise_error_if_unrecognised_command
82
- @nordea_generic_params[:command] = :wrong_command
82
+ @danske_generic_params[:command] = :wrong_command
83
83
 
84
84
  assert_raises(ArgumentError) do
85
- soap = Sepa::SoapBuilder.new(@nordea_generic_params)
85
+ soap = Sepa::SoapBuilder.new(@danske_generic_params)
86
86
  end
87
87
  end
88
88
 
89
89
  def test_sender_id_is_properly_set
90
- assert_equal @nordea_generic_params[:customer_id],
90
+ assert_equal @danske_generic_params[:customer_id],
91
91
  @doc.at("//bxd:SenderId", 'bxd' => 'http://model.bxd.fi').content
92
92
  end
93
93
 
@@ -108,7 +108,7 @@ class DanskeGenericSoapBuilderTest < ActiveSupport::TestCase
108
108
  def test_language_is_set_correctly
109
109
  language_node = @doc.at("//bxd:Language", 'bxd' => 'http://model.bxd.fi')
110
110
 
111
- assert_equal language_node.content, @nordea_generic_params[:language]
111
+ assert_equal language_node.content, @danske_generic_params[:language]
112
112
  end
113
113
 
114
114
  def test_user_agent_is_set_correctly
@@ -120,35 +120,33 @@ class DanskeGenericSoapBuilderTest < ActiveSupport::TestCase
120
120
  def test_receiver_is_is_set_correctly
121
121
  receiver_id_node = @doc.at("//bxd:ReceiverId", 'bxd' => 'http://model.bxd.fi')
122
122
 
123
- assert_equal receiver_id_node.content, @nordea_generic_params[:target_id]
123
+ assert_equal 'DABAFIHH', receiver_id_node.content
124
124
  end
125
125
 
126
126
  def test_cert_is_added_correctly
127
127
  wsse = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd'
128
128
 
129
- added_cert = @doc.at(
129
+ added_certificate = @doc.at(
130
130
  "//wsse:BinarySecurityToken", 'wsse' => wsse
131
131
  ).content
132
132
 
133
- actual_cert = OpenSSL::X509::Certificate.new(
134
- @nordea_generic_params.fetch(:cert)
133
+ actual_certificate = OpenSSL::X509::Certificate.new(
134
+ @danske_generic_params.fetch(:signing_certificate)
135
135
  ).to_s
136
136
 
137
- actual_cert = actual_cert.split('-----BEGIN CERTIFICATE-----')[1]
138
- actual_cert = actual_cert.split('-----END CERTIFICATE-----')[0]
139
- actual_cert = actual_cert.gsub(/\s+/, "")
137
+ actual_certificate = actual_certificate.split('-----BEGIN CERTIFICATE-----')[1]
138
+ actual_certificate = actual_certificate.split('-----END CERTIFICATE-----')[0]
139
+ actual_certificate = actual_certificate.gsub(/\s+/, "")
140
140
 
141
- assert_equal added_cert, actual_cert
141
+ assert_equal added_certificate, actual_certificate
142
142
  end
143
143
 
144
144
  def test_body_digest_is_calculated_correctly
145
145
  sha1 = OpenSSL::Digest::SHA1.new
146
146
 
147
147
  # Digest which is calculated from the body and added to the header
148
- added_digest = @doc.at(
149
- "//dsig:Reference[@URI='#sdf6sa7d86f87s6df786sd87f6s8fsda']/dsig:DigestValue",
150
- 'dsig' => 'http://www.w3.org/2000/09/xmldsig#'
151
- ).content
148
+ reference_node = @doc.css('dsig|Reference')[1]
149
+ added_digest = reference_node.at('dsig|DigestValue').content
152
150
 
153
151
  body_node = @doc.at(
154
152
  "//env:Body", 'env' => 'http://schemas.xmlsoap.org/soap/envelope/'
@@ -192,10 +190,8 @@ class DanskeGenericSoapBuilderTest < ActiveSupport::TestCase
192
190
  def test_header_timestamps_digest_is_calculated_correctly
193
191
  sha1 = OpenSSL::Digest::SHA1.new
194
192
 
195
- added_digest = @doc.at(
196
- "//dsig:Reference[@URI='#dsfg8sdg87dsf678g6dsg6ds7fg']/dsig:DigestValue",
197
- 'dsig' => 'http://www.w3.org/2000/09/xmldsig#'
198
- ).content
193
+ reference_node = @doc.css('dsig|Reference')[0]
194
+ added_digest = reference_node.at('dsig|DigestValue').content
199
195
 
200
196
  wsu = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd'
201
197
 
@@ -216,7 +212,7 @@ class DanskeGenericSoapBuilderTest < ActiveSupport::TestCase
216
212
  def test_signature_is_calculated_correctly
217
213
  sha1 = OpenSSL::Digest::SHA1.new
218
214
 
219
- private_key = OpenSSL::PKey::RSA.new(@nordea_generic_params.fetch(:private_key))
215
+ private_key = rsa_key(@danske_generic_params.fetch(:signing_private_key))
220
216
 
221
217
  added_signature = @doc.at(
222
218
  "//dsig:SignatureValue",
@@ -6,8 +6,8 @@ class NordeaApplicationRequestTest < ActiveSupport::TestCase
6
6
 
7
7
  # Convert the keys here since the conversion is usually done by the client and these tests
8
8
  # bypass the client
9
- @nordea_generic_params[:private_key] = OpenSSL::PKey::RSA.new @nordea_generic_params[:private_key]
10
- @nordea_generic_params[:cert] = OpenSSL::X509::Certificate.new @nordea_generic_params[:cert]
9
+ @nordea_generic_params[:signing_private_key] = rsa_key @nordea_generic_params[:signing_private_key]
10
+ @nordea_generic_params[:signing_certificate] = OpenSSL::X509::Certificate.new @nordea_generic_params[:signing_certificate]
11
11
 
12
12
  ar_file = Sepa::SoapBuilder.new(@nordea_generic_params).application_request
13
13
 
@@ -89,10 +89,12 @@ class NordeaApplicationRequestTest < ActiveSupport::TestCase
89
89
  end
90
90
 
91
91
  def test_should_have_environment_set_with_all_commands
92
- assert_equal @doc_file.at_css("Environment").content, @nordea_generic_params[:environment]
93
- assert_equal @doc_get.at_css("Environment").content, @nordea_generic_params[:environment]
94
- assert_equal @doc_list.at_css("Environment").content, @nordea_generic_params[:environment]
95
- assert_equal @doc_up.at_css("Environment").content, @nordea_generic_params[:environment]
92
+ expected_environment = @nordea_generic_params[:environment].upcase
93
+
94
+ assert_equal @doc_file.at_css("Environment").content, expected_environment
95
+ assert_equal @doc_get.at_css("Environment").content, expected_environment
96
+ assert_equal @doc_list.at_css("Environment").content, expected_environment
97
+ assert_equal @doc_up.at_css("Environment").content, expected_environment
96
98
  end
97
99
 
98
100
  def test_should_have_software_id_set_with_all_commands
@@ -124,10 +126,6 @@ class NordeaApplicationRequestTest < ActiveSupport::TestCase
124
126
  assert_equal @doc_list.at_css("TargetId").content, @nordea_generic_params[:target_id]
125
127
  end
126
128
 
127
- def test_should_have_target_id_set_when_download_file
128
- assert_equal @doc_file.at_css("TargetId").content, @nordea_generic_params[:target_id]
129
- end
130
-
131
129
  def test_should_not_have_target_id_set_when_get_user_info
132
130
  refute @doc_get.at_css("TargetId")
133
131
  end
@@ -219,7 +217,7 @@ class NordeaApplicationRequestTest < ActiveSupport::TestCase
219
217
 
220
218
  # Calculate the actual signature
221
219
  keys_path = File.expand_path('../keys', __FILE__)
222
- private_key = OpenSSL::PKey::RSA.new(File.read("#{keys_path}/nordea.key"))
220
+ private_key = rsa_key(File.read("#{keys_path}/nordea.key"))
223
221
 
224
222
  sha1 = OpenSSL::Digest::SHA1.new
225
223
  actual_signature = encode(private_key.sign(
@@ -230,23 +228,45 @@ class NordeaApplicationRequestTest < ActiveSupport::TestCase
230
228
  end
231
229
 
232
230
  def test_certificate_is_added_correctly
233
- added_cert = @doc_file.at_css(
231
+ added_certificate = @doc_file.at_css(
234
232
  "dsig|X509Certificate", 'dsig' => 'http://www.w3.org/2000/09/xmldsig#'
235
233
  ).content
236
234
 
237
- actual_cert = @nordea_generic_params.fetch(:cert).to_s
238
- actual_cert = actual_cert.split('-----BEGIN CERTIFICATE-----')[1]
239
- actual_cert = actual_cert.split('-----END CERTIFICATE-----')[0]
240
- actual_cert.gsub!(/\s+/, "")
235
+ actual_certificate = @nordea_generic_params.fetch(:signing_certificate).to_s
236
+ actual_certificate = actual_certificate.split('-----BEGIN CERTIFICATE-----')[1]
237
+ actual_certificate = actual_certificate.split('-----END CERTIFICATE-----')[0]
238
+ actual_certificate.gsub!(/\s+/, "")
241
239
 
242
- assert_equal added_cert, actual_cert
240
+ assert_equal added_certificate, actual_certificate
243
241
  end
244
242
 
245
- def test_should_validate_against_schema
243
+ test 'download file should validate against schema' do
246
244
  Dir.chdir(SCHEMA_PATH) do
247
245
  xsd = Nokogiri::XML::Schema(IO.read('application_request.xsd'))
248
246
  assert xsd.valid?(@doc_file)
249
247
  end
250
248
  end
251
249
 
250
+ test 'upload file should validate against schema' do
251
+ Dir.chdir(SCHEMA_PATH) do
252
+ xsd = Nokogiri::XML::Schema(IO.read('application_request.xsd'))
253
+ xsd.validate(@doc_up).each do |error|
254
+ puts error
255
+ end
256
+ end
257
+ end
258
+
259
+ test 'download file list should validate against schema' do
260
+ Dir.chdir(SCHEMA_PATH) do
261
+ xsd = Nokogiri::XML::Schema(IO.read('application_request.xsd'))
262
+ assert xsd.valid?(@doc_list)
263
+ end
264
+ end
265
+
266
+ test 'get user info should validate against schema' do
267
+ Dir.chdir(SCHEMA_PATH) do
268
+ xsd = Nokogiri::XML::Schema(IO.read('application_request.xsd'))
269
+ assert xsd.valid?(@doc_get)
270
+ end
271
+ end
252
272
  end
@@ -4,8 +4,8 @@ class NordeaCertApplicationRequestTest < ActiveSupport::TestCase
4
4
  include Sepa::Utilities
5
5
 
6
6
  def setup
7
- @get_cert_params = nordea_cert_params
8
- ar_cert = Sepa::SoapBuilder.new(@get_cert_params).application_request
7
+ @nordea_get_certificate_params = nordea_get_certificate_params
8
+ ar_cert = Sepa::SoapBuilder.new(@nordea_get_certificate_params).application_request
9
9
  @xml = Nokogiri::XML(ar_cert.to_xml)
10
10
  end
11
11
 
@@ -17,19 +17,19 @@ class NordeaCertApplicationRequestTest < ActiveSupport::TestCase
17
17
  end
18
18
 
19
19
  def test_should_initialize_with_only_get_certificate_params
20
- assert Sepa::ApplicationRequest.new(@get_cert_params)
20
+ assert Sepa::ApplicationRequest.new(@nordea_get_certificate_params)
21
21
  end
22
22
 
23
23
  def test_should_get_argument_errors_unless_command_is_get_certificate
24
24
  assert_raises(ArgumentError) do
25
- @get_cert_params[:command] = :wrong_command
26
- ar = Sepa::ApplicationRequest.new(@get_cert_params)
25
+ @nordea_get_certificate_params[:command] = :wrong_command
26
+ ar = Sepa::ApplicationRequest.new(@nordea_get_certificate_params)
27
27
  ar.get_as_base64
28
28
  end
29
29
  end
30
30
 
31
31
  def test_should_have_customer_id_set
32
- assert_equal @xml.at_css("CustomerId").content, @get_cert_params[:customer_id]
32
+ assert_equal @xml.at_css("CustomerId").content, @nordea_get_certificate_params[:customer_id]
33
33
  end
34
34
 
35
35
  def test_should_have_timestamp_set_properly
@@ -41,8 +41,9 @@ class NordeaCertApplicationRequestTest < ActiveSupport::TestCase
41
41
  assert_equal @xml.at_css("Command").content, "GetCertificate"
42
42
  end
43
43
 
44
- def test_should_have_environment_set
45
- assert_equal @xml.at_css("Environment").content, @get_cert_params[:environment]
44
+ def test_should_have_environment_set_and_upcase
45
+ expected_environment = @nordea_get_certificate_params[:environment].upcase
46
+ assert_equal expected_environment, @xml.at_css("Environment").content
46
47
  end
47
48
 
48
49
  test 'should have software id set' do
@@ -50,16 +51,16 @@ class NordeaCertApplicationRequestTest < ActiveSupport::TestCase
50
51
  end
51
52
 
52
53
  test 'should have service set' do
53
- assert_equal @xml.at_css('Service').content, @get_cert_params[:service]
54
+ assert_equal @xml.at_css('Service').content, ''
54
55
  end
55
56
 
56
57
  test 'should have content set' do
57
- assert_equal @xml.at_css('Content').content, format_cert_request(@get_cert_params[:csr])
58
+ assert_equal @xml.at_css('Content').content, format_cert_request(@nordea_get_certificate_params[:signing_csr])
58
59
  end
59
60
 
60
61
  test 'should have hmac set' do
61
62
  assert_equal @xml.at_css('HMAC').content,
62
- hmac(@get_cert_params[:pin], csr_to_binary(@get_cert_params[:csr]))
63
+ hmac(@nordea_get_certificate_params[:pin], csr_to_binary(@nordea_get_certificate_params[:signing_csr]))
63
64
  end
64
65
 
65
66
  def test_should_validate_against_schema