sepafm 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +14 -30
  3. data/.ruby-version +1 -1
  4. data/.travis.yml +15 -0
  5. data/Gemfile +1 -1
  6. data/LICENSE +16 -4
  7. data/README.md +180 -319
  8. data/Rakefile +7 -2
  9. data/lib/sepa/application_request.rb +100 -131
  10. data/lib/sepa/application_response.rb +28 -84
  11. data/lib/sepa/attribute_checks.rb +169 -0
  12. data/lib/sepa/banks/danske/danske_response.rb +19 -0
  13. data/lib/sepa/banks/danske/soap_danske.rb +132 -0
  14. data/lib/sepa/banks/nordea/nordea_response.rb +20 -0
  15. data/lib/sepa/banks/nordea/soap_nordea.rb +51 -0
  16. data/lib/sepa/client.rb +72 -60
  17. data/lib/sepa/error_messages.rb +15 -0
  18. data/lib/sepa/response.rb +88 -85
  19. data/lib/sepa/soap_builder.rb +51 -341
  20. data/lib/sepa/utilities.rb +132 -0
  21. data/lib/sepa/version.rb +1 -1
  22. data/lib/sepa/xml_schemas/PKIFactory.xsd +334 -0
  23. data/lib/sepa/xml_schemas/xml_id.xsd +9 -0
  24. data/lib/sepa/xml_templates/application_request/create_certificate.xml +15 -10
  25. data/lib/sepa/xml_templates/application_request/danske_get_bank_certificate.xml +13 -9
  26. data/lib/sepa/xml_templates/application_request/download_file.xml +32 -30
  27. data/lib/sepa/xml_templates/application_request/download_file_list.xml +29 -27
  28. data/lib/sepa/xml_templates/application_request/encrypted_request.xml +22 -0
  29. data/lib/sepa/xml_templates/application_request/get_certificate.xml +9 -8
  30. data/lib/sepa/xml_templates/application_request/get_user_info.xml +26 -24
  31. data/lib/sepa/xml_templates/application_request/upload_file.xml +29 -27
  32. data/lib/sepa/xml_templates/soap/create_certificate.xml +17 -15
  33. data/lib/sepa/xml_templates/soap/danske_get_bank_certificate.xml +15 -13
  34. data/lib/sepa/xml_templates/soap/download_file.xml +19 -15
  35. data/lib/sepa/xml_templates/soap/download_file_list.xml +19 -15
  36. data/lib/sepa/xml_templates/soap/get_certificate.xml +2 -1
  37. data/lib/sepa/xml_templates/soap/get_user_info.xml +19 -15
  38. data/lib/sepa/xml_templates/soap/header.xml +48 -37
  39. data/lib/sepa/xml_templates/soap/upload_file.xml +19 -15
  40. data/lib/sepafm.rb +20 -18
  41. data/{sepa.gemspec → sepafm.gemspec} +10 -9
  42. data/test/sepa/banks/danske/danske_cert_response_test.rb +52 -0
  43. data/test/sepa/banks/danske/danske_cert_soap_builder_test.rb +100 -0
  44. data/test/sepa/banks/danske/danske_generic_soap_builder_test.rb +278 -0
  45. data/test/sepa/banks/danske/danske_get_bank_cert_test.rb +111 -0
  46. data/{lib/sepa/danske_testing/keys/danske_encryption.crt → test/sepa/banks/danske/keys/bank_encryption_cert.pem} +0 -0
  47. data/test/sepa/{danske_test_keys/danskeroot.pem → banks/danske/keys/bank_root_cert.pem} +1 -1
  48. data/test/sepa/banks/danske/keys/bank_signing_cert.pem +24 -0
  49. data/test/sepa/banks/danske/keys/danske_encryption.crt +24 -0
  50. data/test/sepa/banks/danske/keys/enc_private_key.pem +27 -0
  51. data/test/sepa/{danske_test_keys → banks/danske/keys}/encryption_pkcs.csr +0 -0
  52. data/test/sepa/banks/danske/keys/own_enc_cert.pem +21 -0
  53. data/test/sepa/banks/danske/keys/own_signing_cert.pem +22 -0
  54. data/test/sepa/{danske_test_keys → banks/danske/keys}/signing_key.pem +0 -0
  55. data/test/sepa/{danske_test_keys → banks/danske/keys}/signing_pkcs.csr +0 -0
  56. data/test/sepa/banks/danske/keys/signing_private_key.pem +27 -0
  57. data/test/sepa/banks/danske/responses/create_cert.xml +38 -0
  58. data/test/sepa/banks/danske/responses/get_bank_cert.xml +37 -0
  59. data/{lib/sepa/nordea_testing → test/sepa/banks/nordea}/keys/nordea.crt +0 -4
  60. data/test/sepa/{nordea_test_keys → banks/nordea/keys}/nordea.key +0 -3
  61. data/test/sepa/{nordea_test_keys → banks/nordea/keys}/root_cert.cer +0 -0
  62. data/test/sepa/{nordea_test_keys → banks/nordea/keys}/testcert.csr +0 -0
  63. data/test/sepa/banks/nordea/nordea_application_request_test.rb +252 -0
  64. data/test/sepa/{application_response_test.rb → banks/nordea/nordea_application_response_test.rb} +40 -46
  65. data/test/sepa/banks/nordea/nordea_cert_application_request_test.rb +72 -0
  66. data/test/sepa/banks/nordea/nordea_cert_request_soap_builder_test.rb +65 -0
  67. data/test/sepa/banks/nordea/nordea_generic_soap_builder_test.rb +280 -0
  68. data/test/sepa/banks/nordea/nordea_response_test.rb +116 -0
  69. data/test/sepa/banks/nordea/responses/df_ktl.xml +45 -0
  70. data/test/sepa/{test_files/test_responses/df.xml → banks/nordea/responses/df_tito.xml} +1 -1
  71. data/test/sepa/{test_files/test_responses → banks/nordea/responses}/dfl.xml +0 -0
  72. data/test/sepa/banks/nordea/responses/gbc.xml +15 -0
  73. data/test/sepa/banks/nordea/responses/gc.xml +49 -0
  74. data/test/sepa/{test_files/test_responses → banks/nordea/responses}/gui.xml +0 -0
  75. data/test/sepa/{test_files/test_responses → banks/nordea/responses}/uf.xml +0 -0
  76. data/test/sepa/client_test.rb +156 -302
  77. data/test/sepa/fixtures.rb +214 -0
  78. data/test/sepa/sepa_test.rb +3 -13
  79. data/test/sepa/test_files/{invalid.wsdl → invalid_wsdl.wsdl} +0 -0
  80. data/test/test_helper.rb +29 -3
  81. metadata +140 -116
  82. data/lib/danske_get_bank_certificate_test.rb +0 -15
  83. data/lib/sepa/custom_exceptions.rb +0 -2
  84. data/lib/sepa/filedescriptor.rb +0 -7
  85. data/lib/sepa/filetypeservice.rb +0 -6
  86. data/lib/sepa/nordea_testing/keys/CSR.csr +0 -0
  87. data/lib/sepa/nordea_testing/keys/nordea.key +0 -19
  88. data/lib/sepa/nordea_testing/response/content_053.xml +0 -998
  89. data/lib/sepa/nordea_testing/response/content_054.xml +0 -1
  90. data/lib/sepa/nordea_testing/response/download_file_response.xml +0 -14
  91. data/lib/sepa/nordea_testing/response/download_filelist_response.xml +0 -14
  92. data/lib/sepa/nordea_testing/response/get_user_info_response.xml +0 -14
  93. data/lib/sepa/nordea_testing/response/upload_file_response.xml +0 -14
  94. data/lib/sepa/payload.rb +0 -109
  95. data/lib/sepa/payment.rb +0 -97
  96. data/lib/sepa/sender_verifier.rb +0 -15
  97. data/lib/sepa/signature.rb +0 -7
  98. data/lib/sepa/soap_danske.rb +0 -47
  99. data/lib/sepa/soap_nordea.rb +0 -68
  100. data/lib/sepa/transaction.rb +0 -178
  101. data/lib/sepa/userfiletype.rb +0 -16
  102. data/lib/sepa/xml_parser.rb +0 -291
  103. data/lib/sepa_client_testing_mika.rb +0 -32
  104. data/lib/sepa_client_testing_tiere.rb +0 -257
  105. data/test/sepa/application_request_test.rb +0 -423
  106. data/test/sepa/cert_application_request_test.rb +0 -99
  107. data/test/sepa/nordea_cert_request_soap_builder_test.rb +0 -112
  108. data/test/sepa/nordea_generic_soap_builder_test.rb +0 -427
  109. data/test/sepa/nordea_test_keys/nordea.crt +0 -27
  110. data/test/sepa/payload_test.rb +0 -297
  111. data/test/sepa/payment_test.rb +0 -198
  112. data/test/sepa/response_test.rb +0 -269
  113. data/test/sepa/transaction_test.rb +0 -362
  114. data/test/sepa/user_file_type_test.rb +0 -21
  115. data/test/sepa/xml_parser_test.rb +0 -73
@@ -1,7 +1,3 @@
1
- Bag Attributes
2
- localKeyID: 4B 45 59 35 31 38 32 35 62 36 35 30 30 30 30 31 32 35 32 00
3
- subject=/C=FI/CN=Nordea Demo Certificate/serialNumber=5780860238
4
- issuer=/C=SE/O=Nordea Bank AB (publ)/CN=Nordea Corporate CA 01/serialNumber=516406-0120
5
1
  -----BEGIN CERTIFICATE-----
6
2
  MIIDwTCCAqmgAwIBAgIEAX1JuTANBgkqhkiG9w0BAQUFADBkMQswCQYDVQQGEwJT
7
3
  RTEeMBwGA1UEChMVTm9yZGVhIEJhbmsgQUIgKHB1YmwpMR8wHQYDVQQDExZOb3Jk
@@ -1,6 +1,3 @@
1
- Bag Attributes
2
- localKeyID: 4B 45 59 35 31 38 32 35 62 36 35 30 30 30 30 31 32 35 32 00
3
- Key Attributes: <No Attributes>
4
1
  -----BEGIN PRIVATE KEY-----
5
2
  MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAMLRRHwLWybhs0MM
6
3
  EbpmZL2IdgYxmFbADFHoirTp3t22UnorHwqvk16i9YCPS6H8ngEPSP7A5urS/NMq
@@ -0,0 +1,252 @@
1
+ require 'test_helper'
2
+
3
+ class NordeaApplicationRequestTest < ActiveSupport::TestCase
4
+ def setup
5
+ @nordea_generic_params = nordea_generic_params
6
+
7
+ # Convert the keys here since the conversion is usually done by the client and these tests
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]
11
+
12
+ ar_file = Sepa::SoapBuilder.new(@nordea_generic_params).ar
13
+
14
+ @nordea_generic_params[:command] = :get_user_info
15
+ ar_get = Sepa::SoapBuilder.new(@nordea_generic_params).ar
16
+
17
+ @nordea_generic_params[:command] = :download_file_list
18
+ ar_list = Sepa::SoapBuilder.new(@nordea_generic_params).ar
19
+
20
+ @nordea_generic_params[:command] = :upload_file
21
+ ar_up = Sepa::SoapBuilder.new(@nordea_generic_params).ar
22
+
23
+ @doc_file = Nokogiri::XML(ar_file.to_xml)
24
+ @doc_get = Nokogiri::XML(ar_get.to_xml)
25
+ @doc_list = Nokogiri::XML(ar_list.to_xml)
26
+ @doc_up = Nokogiri::XML(ar_up.to_xml)
27
+ end
28
+
29
+ def test_schemas_are_unmodified
30
+ sha1 = OpenSSL::Digest::SHA1.new
31
+
32
+ ar_schema = File.read("#{SCHEMA_PATH}/application_request.xsd")
33
+ xmldsig_schema = File.read("#{SCHEMA_PATH}/xmldsig-core-schema.xsd")
34
+ ar_schema_digest = sha1.digest(ar_schema)
35
+
36
+ sha1.reset
37
+
38
+ xmldsig_schema_digest = sha1.digest(xmldsig_schema)
39
+ assert_equal Base64.encode64(ar_schema_digest).strip, "1O24A7+/6S7CFYVlhH1jEZh1ARs="
40
+ assert_equal Base64.encode64(xmldsig_schema_digest).strip, "bmG0+2KykgkLeWsXsl6CFbyo4Yc="
41
+ end
42
+
43
+ def test_ar_should_initialize_with_proper_params
44
+ assert Sepa::SoapBuilder.new(@nordea_generic_params)
45
+ end
46
+
47
+ def test_should_get_key_error_if_command_missing
48
+ @nordea_generic_params.delete(:command)
49
+
50
+ assert_raises(ArgumentError) do
51
+ Sepa::SoapBuilder.new(@nordea_generic_params)
52
+ end
53
+ end
54
+
55
+ def test_should_have_customer_id_set_in_with_all_commands
56
+ assert_equal @doc_file.at_css("CustomerId").content, @nordea_generic_params[:customer_id]
57
+ assert_equal @doc_get.at_css("CustomerId").content, @nordea_generic_params[:customer_id]
58
+ assert_equal @doc_list.at_css("CustomerId").content, @nordea_generic_params[:customer_id]
59
+ assert_equal @doc_up.at_css("CustomerId").content, @nordea_generic_params[:customer_id]
60
+ end
61
+
62
+ def test_should_have_timestamp_set_properly_with_all_commands
63
+ timestamp_file = Time.strptime(@doc_file.at_css("Timestamp").content, '%Y-%m-%dT%H:%M:%S%z')
64
+ timestamp_get = Time.strptime(@doc_get.at_css("Timestamp").content, '%Y-%m-%dT%H:%M:%S%z')
65
+ timestamp_list = Time.strptime(@doc_list.at_css("Timestamp").content, '%Y-%m-%dT%H:%M:%S%z')
66
+ timestamp_up = Time.strptime(@doc_up.at_css("Timestamp").content, '%Y-%m-%dT%H:%M:%S%z')
67
+
68
+ ts_error = "Timestamp was not set correctly"
69
+ assert timestamp_file <= Time.now && timestamp_file > (Time.now - 60), ts_error
70
+ assert timestamp_get <= Time.now && timestamp_get > (Time.now - 60), ts_error
71
+ assert timestamp_list <= Time.now && timestamp_list > (Time.now - 60), ts_error
72
+ assert timestamp_up <= Time.now && timestamp_up > (Time.now - 60), ts_error
73
+ end
74
+
75
+ def test_should_have_command_set_when_get_user_info
76
+ assert_equal @doc_get.at_css("Command").content, "GetUserInfo"
77
+ end
78
+
79
+ def test_should_have_command_set_when_download_file_list
80
+ assert_equal @doc_list.at_css("Command").content, "DownloadFileList"
81
+ end
82
+
83
+ def test_should_have_command_set_when_download_file
84
+ assert_equal @doc_file.at_css("Command").content, "DownloadFile"
85
+ end
86
+
87
+ def test_should_have_command_set_when_upload_file
88
+ assert_equal @doc_up.at_css("Command").content, "UploadFile"
89
+ end
90
+
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]
96
+ end
97
+
98
+ def test_should_have_software_id_set_with_all_commands
99
+ string = "Sepa Transfer Library version #{Sepa::VERSION}"
100
+
101
+ assert_equal @doc_file.at_css("SoftwareId").content, string
102
+ assert_equal @doc_get.at_css("SoftwareId").content, string
103
+ assert_equal @doc_list.at_css("SoftwareId").content, string
104
+ assert_equal @doc_up.at_css("SoftwareId").content, string
105
+ end
106
+
107
+ def test_should_have_status_set_when_download_file_list
108
+ assert_equal @doc_list.at_css("Status").content, @nordea_generic_params[:status]
109
+ end
110
+
111
+ def test_should_have_status_set_when_download_file
112
+ assert_equal @doc_file.at_css("Status").content, @nordea_generic_params[:status]
113
+ end
114
+
115
+ def test_should_not_have_status_set_when_get_user_info
116
+ refute @doc_get.at_css("Status")
117
+ end
118
+
119
+ def test_should_not_have_status_set_when_upload_file
120
+ refute @doc_up.at_css("Status")
121
+ end
122
+
123
+ def test_should_have_target_id_set_when_download_file_list
124
+ assert_equal @doc_list.at_css("TargetId").content, @nordea_generic_params[:target_id]
125
+ end
126
+
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
+ def test_should_not_have_target_id_set_when_get_user_info
132
+ refute @doc_get.at_css("TargetId")
133
+ end
134
+
135
+ def test_should_have_file_type_set_when_download_file_list
136
+ assert_equal @doc_list.at_css("FileType").content, @nordea_generic_params[:file_type]
137
+ end
138
+
139
+ def test_should_have_file_type_set_when_download_file
140
+ assert_equal @doc_file.at_css("FileType").content, @nordea_generic_params[:file_type]
141
+ end
142
+
143
+ def test_should_have_file_type_set_when_upload_file
144
+ assert_equal @doc_up.at_css("FileType").content, @nordea_generic_params[:file_type]
145
+ end
146
+
147
+ def test_should_not_have_file_type_set_when_get_user_info
148
+ refute @doc_get.at_css("FileType")
149
+ end
150
+
151
+ def test_should_have_file_reference_set_when_download_file
152
+ assert_equal @doc_file.at_css("FileReference").content, @nordea_generic_params[:file_reference]
153
+ end
154
+
155
+ def test_should_not_have_file_ref_when_download_file_list
156
+ refute @doc_list.at_css("FileReference")
157
+ end
158
+
159
+ def test_should_not_have_file_ref_when_get_user_info
160
+ refute @doc_get.at_css("FileReference")
161
+ end
162
+
163
+ def test_should_not_have_file_ref_when_upload_file
164
+ refute @doc_up.at_css("FileReference")
165
+ end
166
+
167
+ def test_should_have_content_when_upload_file
168
+ assert_equal @doc_up.at_css("Content").content, Base64.encode64(@nordea_generic_params[:content])
169
+ end
170
+
171
+ def test_should_not_have_content_when_download_file_list
172
+ refute @doc_list.at_css("Content")
173
+ end
174
+
175
+ def test_should_not_have_content_when_download_file
176
+ refute @doc_file.at_css("Content")
177
+ end
178
+
179
+ def test_should_not_have_content_when_get_user_info
180
+ refute @doc_get.at_css("Content")
181
+ end
182
+
183
+ def test_should_raise_argument_error_with_invalid_command
184
+ assert_raises(ArgumentError) do
185
+ @nordea_generic_params[:command] = :wrong_kind_of_command
186
+ ar = Sepa::ApplicationRequest.new(@nordea_generic_params)
187
+ doc = ar.get_as_base64
188
+ end
189
+ end
190
+
191
+ def test_digest_is_calculatd_correctly
192
+ calculated_digest = @doc_file.at_css(
193
+ "dsig|DigestValue", 'dsig' => 'http://www.w3.org/2000/09/xmldsig#'
194
+ ).content
195
+
196
+ # Remove signature for calculating digest
197
+ @doc_file.at_css(
198
+ "dsig|Signature", 'dsig' => 'http://www.w3.org/2000/09/xmldsig#'
199
+ ).remove
200
+
201
+ # Calculate digest
202
+ sha1 = OpenSSL::Digest::SHA1.new
203
+ actual_digest = Base64.encode64(sha1.digest(@doc_file.canonicalize))
204
+
205
+ # And then make sure the two are equal
206
+ assert_equal calculated_digest.strip, actual_digest.strip
207
+ end
208
+
209
+ def test_signature_is_constructed_correctly
210
+ #private_key = @params.fetch(:private_key)
211
+
212
+ signed_info_node = @doc_file.at_css(
213
+ "dsig|SignedInfo", 'dsig' => 'http://www.w3.org/2000/09/xmldsig#')
214
+
215
+ # The value of the signature node in the constructed ar
216
+ calculated_signature = @doc_file.at_css(
217
+ "dsig|SignatureValue", 'dsig' => 'http://www.w3.org/2000/09/xmldsig#'
218
+ ).content
219
+
220
+ # Calculate the actual signature
221
+ keys_path = File.expand_path('../keys', __FILE__)
222
+ private_key = OpenSSL::PKey::RSA.new(File.read("#{keys_path}/nordea.key"))
223
+
224
+ sha1 = OpenSSL::Digest::SHA1.new
225
+ actual_signature = Base64.encode64(private_key.sign(
226
+ sha1, signed_info_node.canonicalize))
227
+
228
+ # And then of course assert the two are equal
229
+ assert_equal calculated_signature, actual_signature
230
+ end
231
+
232
+ def test_certificate_is_added_correctly
233
+ added_cert = @doc_file.at_css(
234
+ "dsig|X509Certificate", 'dsig' => 'http://www.w3.org/2000/09/xmldsig#'
235
+ ).content
236
+
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+/, "")
241
+
242
+ assert_equal added_cert, actual_cert
243
+ end
244
+
245
+ def test_should_validate_against_schema
246
+ Dir.chdir(SCHEMA_PATH) do
247
+ xsd = Nokogiri::XML::Schema(IO.read('application_request.xsd'))
248
+ assert xsd.valid?(@doc_file)
249
+ end
250
+ end
251
+
252
+ end
@@ -1,52 +1,45 @@
1
- require File.expand_path('../../test_helper.rb', __FILE__)
1
+ require 'test_helper'
2
2
 
3
- class ApplicationResponseTest < MiniTest::Test
4
- def setup
5
- keys_path = File.expand_path('../nordea_test_keys', __FILE__)
6
-
7
- @root_cert = OpenSSL::X509::Certificate.new File.read(
8
- "#{keys_path}/root_cert.cer"
9
- )
10
-
11
- @not_root_cert = OpenSSL::X509::Certificate.new File.read(
12
- "#{keys_path}/nordea.crt"
13
- )
3
+ class NordeaApplicationResponseTest < ActiveSupport::TestCase
14
4
 
15
- responses_path = File.expand_path('../test_files/test_responses', __FILE__)
5
+ def setup
6
+ keys_path = File.expand_path('../keys', __FILE__)
7
+ @root_cert = OpenSSL::X509::Certificate.new File.read("#{keys_path}/root_cert.cer")
8
+ @not_root_cert = OpenSSL::X509::Certificate.new File.read("#{keys_path}/nordea.crt")
16
9
 
17
- @dfl = Nokogiri::XML(File.read("#{responses_path}/dfl.xml"))
18
- @dfl = Sepa::Response.new(@dfl).application_response
10
+ @dfl = Nokogiri::XML(File.read("#{NORDEA_TEST_RESPONSE_PATH}/dfl.xml"))
11
+ @dfl = Sepa::Response.new(@dfl, command: :download_file_list).application_response
19
12
 
20
- @uf = Nokogiri::XML(File.read("#{responses_path}/uf.xml"))
21
- @uf = Sepa::Response.new(@uf).application_response
13
+ @uf = Nokogiri::XML(File.read("#{NORDEA_TEST_RESPONSE_PATH}/uf.xml"))
14
+ @uf = Sepa::Response.new(@uf, command: :upload_file).application_response
22
15
 
23
- @df = Nokogiri::XML(File.read("#{responses_path}/df.xml"))
24
- @df = Sepa::Response.new(@df).application_response
16
+ @df_tito = Nokogiri::XML(File.read("#{NORDEA_TEST_RESPONSE_PATH}/df_tito.xml"))
17
+ @df_tito = Sepa::Response.new(@df_tito, command: :download_file).application_response
25
18
 
26
- @gui = Nokogiri::XML(File.read("#{responses_path}/gui.xml"))
27
- @gui = Sepa::Response.new(@gui).application_response
19
+ @gui = Nokogiri::XML(File.read("#{NORDEA_TEST_RESPONSE_PATH}/gui.xml"))
20
+ @gui = Sepa::Response.new(@gui, command: :get_user_info).application_response
28
21
 
29
22
  @dfl_ar = Sepa::ApplicationResponse.new(@dfl)
30
23
  @uf_ar = Sepa::ApplicationResponse.new(@uf)
31
- @df_ar = Sepa::ApplicationResponse.new(@df)
24
+ @df_ar = Sepa::ApplicationResponse.new(@df_tito)
32
25
  @gui_ar = Sepa::ApplicationResponse.new(@gui)
33
26
  end
34
27
 
35
- def test_should_initialize_with_proper_params
36
- assert Sepa::ApplicationResponse.new(@dfl)
37
- assert Sepa::ApplicationResponse.new(@uf)
38
- assert Sepa::ApplicationResponse.new(@df)
39
- assert Sepa::ApplicationResponse.new(@gui)
28
+ def test_templates_valid
29
+ assert @dfl_ar.valid?
30
+ assert @uf_ar.valid?
31
+ assert @df_ar.valid?
32
+ assert @gui_ar.valid?
40
33
  end
41
34
 
42
- def test_should_complain_if_initialized_with_something_not_nokogiri_xml
43
- assert_raises(ArgumentError) { Sepa::ApplicationResponse.new("Jees") }
35
+ def test_should_fail_if_initialized_with_not_nokogiri_xml
36
+ as = Sepa::ApplicationResponse.new("Jees")
37
+ refute as.valid?
44
38
  end
45
39
 
46
40
  def test_should_complain_if_ar_not_valid_against_schema
47
- assert_raises(ArgumentError) do
48
- Sepa::ApplicationResponse.new(Nokogiri::XML("<ar>text</ar>"))
49
- end
41
+ as = Sepa::ApplicationResponse.new(Nokogiri::XML("<ar>text</ar>"))
42
+ refute as.valid?
50
43
  end
51
44
 
52
45
  def test_proper_dfl_hash_check_should_verify
@@ -80,14 +73,14 @@ class ApplicationResponseTest < MiniTest::Test
80
73
  end
81
74
 
82
75
  def test_invalid_df_hash_check_should_not_verify
83
- digest_value_node = @df.at_css(
76
+ digest_value_node = @df_tito.at_css(
84
77
  'xmlns|DigestValue',
85
78
  'xmlns' => 'http://www.w3.org/2000/09/xmldsig#'
86
79
  )
87
80
 
88
81
  digest_value_node.content = digest_value_node.content[4..-1]
89
82
 
90
- refute Sepa::ApplicationResponse.new(@df).hashes_match?
83
+ refute Sepa::ApplicationResponse.new(@df_tito).hashes_match?
91
84
  end
92
85
 
93
86
  def test_invalid_gui_hash_check_should_not_verify
@@ -140,14 +133,14 @@ class ApplicationResponseTest < MiniTest::Test
140
133
  end
141
134
 
142
135
  def test_corrupted_signature_in_df_should_fail_signature_verification
143
- signature_node = @df.at_css(
136
+ signature_node = @df_tito.at_css(
144
137
  'xmlns|SignatureValue',
145
138
  'xmlns' => 'http://www.w3.org/2000/09/xmldsig#'
146
139
  )
147
140
 
148
141
  signature_node.content = 'a' + signature_node.content[1..-1]
149
142
 
150
- refute Sepa::ApplicationResponse.new(@df).signature_is_valid?
143
+ refute Sepa::ApplicationResponse.new(@df_tito).signature_is_valid?
151
144
  end
152
145
 
153
146
  def test_corrupted_signature_in_gui_should_fail_signature_verification
@@ -188,7 +181,7 @@ class ApplicationResponseTest < MiniTest::Test
188
181
  end
189
182
 
190
183
  def test_should_raise_error_if_certificate_corrupted_in_df
191
- cert_node = @df.at_css(
184
+ cert_node = @df_tito.at_css(
192
185
  'xmlns|X509Certificate',
193
186
  'xmlns' => 'http://www.w3.org/2000/09/xmldsig#'
194
187
  )
@@ -196,7 +189,7 @@ class ApplicationResponseTest < MiniTest::Test
196
189
  cert_node.content = "n5iw#{cert_node.content}"
197
190
 
198
191
  assert_raises(OpenSSL::X509::CertificateError) do
199
- Sepa::ApplicationResponse.new(@df).certificate
192
+ Sepa::ApplicationResponse.new(@df_tito).certificate
200
193
  end
201
194
  end
202
195
 
@@ -214,25 +207,26 @@ class ApplicationResponseTest < MiniTest::Test
214
207
  end
215
208
 
216
209
  def test_cert_should_be_trusted_with_correct_root_cert
217
- assert @dfl_ar.cert_is_trusted?(@root_cert)
218
- assert @uf_ar.cert_is_trusted?(@root_cert)
219
- assert @df_ar.cert_is_trusted?(@root_cert)
220
- assert @gui_ar.cert_is_trusted?(@root_cert)
210
+ assert @dfl_ar.cert_is_trusted(@root_cert)
211
+ assert @uf_ar.cert_is_trusted(@root_cert)
212
+ assert @df_ar.cert_is_trusted(@root_cert)
213
+ assert @gui_ar.cert_is_trusted(@root_cert)
221
214
  end
222
215
 
223
216
  def test_dfl_should_fail_if_wrong_root_cert
224
- assert_raises(SecurityError) { @dfl_ar.cert_is_trusted?(@not_root_cert) }
217
+ assert_raises(SecurityError) { @dfl_ar.cert_is_trusted(@not_root_cert) }
225
218
  end
226
219
 
227
220
  def test_uf_should_fail_if_wrong_root_cert
228
- assert_raises(SecurityError) { @uf_ar.cert_is_trusted?(@not_root_cert) }
221
+ assert_raises(SecurityError) { @uf_ar.cert_is_trusted(@not_root_cert) }
229
222
  end
230
223
 
231
224
  def test_df_should_fail_if_wrong_root_cert
232
- assert_raises(SecurityError) { @df_ar.cert_is_trusted?(@not_root_cert) }
225
+ assert_raises(SecurityError) { @df_ar.cert_is_trusted(@not_root_cert) }
233
226
  end
234
227
 
235
228
  def test_gui_should_fail_if_wrong_root_cert
236
- assert_raises(SecurityError) { @gui_ar.cert_is_trusted?(@not_root_cert) }
229
+ assert_raises(SecurityError) { @gui_ar.cert_is_trusted(@not_root_cert) }
237
230
  end
231
+
238
232
  end
@@ -0,0 +1,72 @@
1
+ require 'test_helper'
2
+
3
+ class NordeaCertApplicationRequestTest < ActiveSupport::TestCase
4
+ include Sepa::Utilities
5
+
6
+ def setup
7
+ @get_cert_params = nordea_cert_params
8
+ ar_cert = Sepa::SoapBuilder.new(@get_cert_params).ar
9
+ @xml = Nokogiri::XML(ar_cert.to_xml)
10
+ end
11
+
12
+ def test_schemas_are_unmodified
13
+ sha1 = OpenSSL::Digest::SHA1.new
14
+ cert_schema = File.read("#{SCHEMA_PATH}/cert_application_request.xsd")
15
+ cert_digest = sha1.digest(cert_schema)
16
+ assert_equal Base64.encode64(cert_digest).strip, "sFwy9Tj+cERTdcmaGhm8WpmJBH4="
17
+ end
18
+
19
+ def test_should_initialize_with_only_get_certificate_params
20
+ assert Sepa::ApplicationRequest.new(@get_cert_params)
21
+ end
22
+
23
+ def test_should_get_argument_errors_unless_command_is_get_certificate
24
+ assert_raises(ArgumentError) do
25
+ @get_cert_params[:command] = :wrong_command
26
+ ar = Sepa::ApplicationRequest.new(@get_cert_params)
27
+ ar.get_as_base64
28
+ end
29
+ end
30
+
31
+ def test_should_have_customer_id_set
32
+ assert_equal @xml.at_css("CustomerId").content, @get_cert_params[:customer_id]
33
+ end
34
+
35
+ def test_should_have_timestamp_set_properly
36
+ timestamp = Time.strptime(@xml.at_css("Timestamp").content, '%Y-%m-%dT%H:%M:%S%z')
37
+ assert timestamp <= Time.now && timestamp > (Time.now - 60), "Timestamp was not set correctly"
38
+ end
39
+
40
+ def test_should_have_command_set_when_get_certificate
41
+ assert_equal @xml.at_css("Command").content, "GetCertificate"
42
+ end
43
+
44
+ def test_should_have_environment_set
45
+ assert_equal @xml.at_css("Environment").content, @get_cert_params[:environment]
46
+ end
47
+
48
+ test 'should have software id set' do
49
+ assert_equal @xml.at_css("SoftwareId").content, "Sepa Transfer Library version #{Sepa::VERSION}"
50
+ end
51
+
52
+ test 'should have service set' do
53
+ assert_equal @xml.at_css('Service').content, @get_cert_params[:service]
54
+ end
55
+
56
+ test 'should have content set' do
57
+ assert_equal @xml.at_css('Content').content, format_cert_request(@get_cert_params[:csr])
58
+ end
59
+
60
+ test 'should have hmac set' do
61
+ assert_equal @xml.at_css('HMAC').content,
62
+ hmac(@get_cert_params[:pin], csr_to_binary(@get_cert_params[:csr]))
63
+ end
64
+
65
+ def test_should_validate_against_schema
66
+ Dir.chdir(SCHEMA_PATH) do
67
+ xsd = Nokogiri::XML::Schema(IO.read('cert_application_request.xsd'))
68
+ assert xsd.valid?(@xml)
69
+ end
70
+ end
71
+
72
+ end
@@ -0,0 +1,65 @@
1
+ require 'test_helper'
2
+
3
+ class NordeaCertRequestSoapBuilderTest < ActiveSupport::TestCase
4
+
5
+ def setup
6
+ @nordea_generic_params = nordea_cert_params
7
+ @certrequest = Sepa::SoapBuilder.new(@nordea_generic_params)
8
+ @xml = Nokogiri::XML(@certrequest.to_xml)
9
+ end
10
+
11
+ def test_should_initialize_with_proper_params
12
+ assert Sepa::SoapBuilder.new(@nordea_generic_params)
13
+ end
14
+
15
+ def test_should_get_error_if_command_missing
16
+ @nordea_generic_params.delete(:command)
17
+
18
+ assert_raises(ArgumentError) do
19
+ Sepa::SoapBuilder.new(@nordea_generic_params)
20
+ end
21
+ end
22
+
23
+ def test_should_load_correct_template_with_get_certificate
24
+ @nordea_generic_params[:command] = :get_certificate
25
+ xml = Nokogiri::XML(Sepa::SoapBuilder.new(@nordea_generic_params).to_xml)
26
+
27
+ assert xml.xpath('//cer:getCertificatein', 'cer' => 'http://bxd.fi/CertificateService').first
28
+ end
29
+
30
+ def test_should_raise_error_if_command_not_correct
31
+ @nordea_generic_params[:command] = :wrong_command
32
+ assert_raises(ArgumentError) do
33
+ soap = Sepa::SoapBuilder.new(@nordea_generic_params).to_xml
34
+ end
35
+ end
36
+
37
+ def test_timestamp_is_set_correctly
38
+ timestamp_node = @xml.xpath(
39
+ "//cer:Timestamp", 'cer' => 'http://bxd.fi/CertificateService'
40
+ ).first
41
+
42
+ timestamp = Time.strptime(timestamp_node.content, '%Y-%m-%dT%H:%M:%S%z')
43
+
44
+ assert timestamp <= Time.now && timestamp > (Time.now - 60)
45
+ end
46
+
47
+ def test_application_request_should_be_inserted_properly
48
+ ar_node = @xml.xpath(
49
+ "//cer:ApplicationRequest", 'cer' => 'http://bxd.fi/CertificateService'
50
+ ).first
51
+
52
+ ar_doc = Nokogiri::XML(Base64.decode64(ar_node.content))
53
+
54
+ assert ar_doc.respond_to?(:canonicalize)
55
+ assert_equal ar_doc.at_css("CustomerId").content, @nordea_generic_params[:customer_id]
56
+ end
57
+
58
+ def test_should_validate_against_schema
59
+ Dir.chdir(SCHEMA_PATH) do
60
+ xsd = Nokogiri::XML::Schema(IO.read('soap.xsd'))
61
+ assert xsd.valid?(@xml)
62
+ end
63
+ end
64
+
65
+ end