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,423 +0,0 @@
1
- require File.expand_path('../../test_helper.rb', __FILE__)
2
-
3
- class TestApplicationRequest < MiniTest::Test
4
- def setup
5
- keys_path = File.expand_path('../nordea_test_keys', __FILE__)
6
-
7
- @xml_templates_path = File.expand_path(
8
- '../../../lib/sepa/xml_templates/application_request', __FILE__
9
- )
10
-
11
- @schemas_path = File.expand_path('../../../lib/sepa/xml_schemas',__FILE__)
12
-
13
- @private_key = OpenSSL::PKey::RSA.new(File.read("#{keys_path}/nordea.key"))
14
- @cert = OpenSSL::X509::Certificate.new(File.read("#{keys_path}/nordea.crt"))
15
- certplain = "-----BEGIN CERTIFICATE-----
16
- MIIDwTCCAqmgAwIBAgIEAX1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SdGB36K1DfSi9AFEQDC1
50
- fwPAbTwTv6mFFPAiYxLiRZXxVPtW+QtjMXH4ymh2V4y/+GnCqbZyLwJBAJQSDAME
51
- Sn4Uz7Zjk3UrBIbMYEv0u2mcCypwsb0nGE5/gzDPjGE9cxWW+rXARIs+sNQVClnh
52
- 45nhdfYxOjgYff0=
53
- -----END PRIVATE KEY-----"
54
- @params = {
55
- bank: :nordea,
56
- private_key_plain: pkeyplain,
57
- cert_plain: certplain,
58
- command: :download_file,
59
- customer_id: '11111111',
60
- environment: 'PRODUCTION',
61
- status: 'NEW',
62
- target_id: '11111111A1',
63
- language: 'FI',
64
- file_type: 'TITO',
65
- content: Base64.encode64("haisuli"),
66
- file_reference: "11111111A12006030329501800000014"
67
- }
68
-
69
- #@ar_file = Sepa::ApplicationRequest.new(@params)
70
- @ar_file = Sepa::SoapBuilder.new(@params).get_ar_as_base64
71
-
72
- @params[:command] = :get_user_info
73
- #@ar_get = Sepa::ApplicationRequest.new(@params)
74
- @ar_get = Sepa::SoapBuilder.new(@params).get_ar_as_base64
75
-
76
- @params[:command] = :download_file_list
77
- #@ar_list = Sepa::ApplicationRequest.new(@params)
78
- @ar_list = Sepa::SoapBuilder.new(@params).get_ar_as_base64
79
-
80
- @params[:command] = :upload_file
81
- #@ar_up = Sepa::ApplicationRequest.new(@params)
82
- @ar_up = Sepa::SoapBuilder.new(@params).get_ar_as_base64
83
-
84
- @doc_file = Nokogiri::XML(Base64.decode64(@ar_file))
85
- @doc_get = Nokogiri::XML(Base64.decode64(@ar_get))
86
- @doc_list = Nokogiri::XML(Base64.decode64(@ar_list))
87
- @doc_up = Nokogiri::XML(Base64.decode64(@ar_up))
88
- end
89
-
90
- # Just to make sure that the xml templates are unmodified because
91
- # the application logic is designed for exactly these templates
92
- def test_xml_templates_are_unmodified
93
- sha1 = OpenSSL::Digest::SHA1.new
94
-
95
- get_user_info_template = File.read(
96
- "#{@xml_templates_path}/get_user_info.xml"
97
- )
98
-
99
- download_file_list_template = File.read(
100
- "#{@xml_templates_path}/download_file_list.xml"
101
- )
102
-
103
- download_file_template = File.read(
104
- "#{@xml_templates_path}/download_file.xml"
105
- )
106
-
107
- upload_file_template = File.read(
108
- "#{@xml_templates_path}/upload_file.xml"
109
- )
110
-
111
- get_user_info_digest = Base64.encode64(
112
- sha1.digest(get_user_info_template)
113
- ).strip
114
-
115
- sha1.reset
116
-
117
- download_file_list_digest = Base64.encode64(
118
- sha1.digest(download_file_list_template)
119
- ).strip
120
-
121
- sha1.reset
122
-
123
- download_file_digest = sha1.digest(download_file_template)
124
-
125
- sha1.reset
126
-
127
- upload_file_digest = sha1.digest(upload_file_template)
128
-
129
- assert_equal get_user_info_digest, "LW5J5R7SnPFPurAa2pM7weTWL1Y="
130
-
131
- assert_equal download_file_list_digest.strip,
132
- "dYtf4lOP1TXfXPVjYLvaTozhVrg="
133
-
134
- assert_equal Base64.encode64(download_file_digest).strip,
135
- "lY+8u+BhXlQmUyQiOiXcUfCUikc="
136
-
137
- assert_equal Base64.encode64(upload_file_digest).strip,
138
- "zRQTrNHkq4OLSX3u3ogxU05RJsI="
139
- end
140
-
141
- def test_schemas_are_unmodified
142
- sha1 = OpenSSL::Digest::SHA1.new
143
-
144
- ar_schema = File.read(
145
- "#{@schemas_path}/application_request.xsd"
146
- )
147
-
148
- xmldsig_schema = File.read(
149
- "#{@schemas_path}/xmldsig-core-schema.xsd"
150
- )
151
-
152
- ar_schema_digest = sha1.digest(ar_schema)
153
-
154
- sha1.reset
155
-
156
- xmldsig_schema_digest = sha1.digest(xmldsig_schema)
157
-
158
- assert_equal Base64.encode64(ar_schema_digest).strip,
159
- "1O24A7+/6S7CFYVlhH1jEZh1ARs="
160
-
161
- assert_equal Base64.encode64(xmldsig_schema_digest).strip,
162
- "bmG0+2KykgkLeWsXsl6CFbyo4Yc="
163
- end
164
-
165
- def test_ar_should_initialize_with_proper_params
166
- assert Sepa::SoapBuilder.new(@params)
167
- end
168
-
169
- def test_should_get_key_error_if_private_key_plain_missing
170
- @params.delete(:private_key_plain)
171
-
172
- assert_raises(ArgumentError) do
173
- Sepa::SoapBuilder.new(@params)
174
- end
175
- end
176
-
177
- def test_should_get_key_error_if_cert_plain_missing
178
- @params.delete(:cert_plain)
179
-
180
- assert_raises(ArgumentError) do
181
- Sepa::SoapBuilder.new(@params)
182
- end
183
- end
184
-
185
- def test_should_get_key_error_if_command_missing
186
- @params.delete(:command)
187
-
188
- assert_raises(ArgumentError) do
189
- Sepa::SoapBuilder.new(@params)
190
- end
191
- end
192
-
193
- def test_should_get_key_error_if_customer_id_missing
194
- @params.delete(:customer_id)
195
-
196
- assert_raises(ArgumentError) do
197
- Sepa::SoapBuilder.new(@params)
198
- end
199
- end
200
-
201
- def test_should_get_key_error_if_environment_missing
202
- @params.delete(:environment)
203
-
204
- assert_raises(ArgumentError) do
205
- Sepa::SoapBuilder.new(@params)
206
- end
207
- end
208
-
209
- def test_should_have_customer_id_set_in_with_all_commands
210
- assert_equal @doc_file.at_css("CustomerId").content, @params[:customer_id]
211
- assert_equal @doc_get.at_css("CustomerId").content, @params[:customer_id]
212
- assert_equal @doc_list.at_css("CustomerId").content, @params[:customer_id]
213
- assert_equal @doc_up.at_css("CustomerId").content, @params[:customer_id]
214
- end
215
-
216
- def test_should_have_timestamp_set_properly_with_all_commands
217
- timestamp_file = Time.strptime(@doc_file.at_css("Timestamp").content,
218
- '%Y-%m-%dT%H:%M:%S%z')
219
-
220
- timestamp_get = Time.strptime(@doc_get.at_css("Timestamp").content,
221
- '%Y-%m-%dT%H:%M:%S%z')
222
-
223
- timestamp_list = Time.strptime(@doc_list.at_css("Timestamp").content,
224
- '%Y-%m-%dT%H:%M:%S%z')
225
-
226
- timestamp_up = Time.strptime(@doc_up.at_css("Timestamp").content,
227
- '%Y-%m-%dT%H:%M:%S%z')
228
-
229
- assert timestamp_file <= Time.now && timestamp_file > (Time.now - 60),
230
- "Timestamp was not set correctly"
231
-
232
- assert timestamp_get <= Time.now && timestamp_get > (Time.now - 60),
233
- "Timestamp was not set correctly"
234
-
235
- assert timestamp_list <= Time.now && timestamp_list > (Time.now - 60),
236
- "Timestamp was not set correctly"
237
-
238
- assert timestamp_up <= Time.now && timestamp_up > (Time.now - 60),
239
- "Timestamp was not set correctly"
240
- end
241
-
242
- def test_should_have_command_set_when_get_user_info
243
-
244
- assert_equal @doc_get.at_css("Command").content, "GetUserInfo"
245
- end
246
-
247
- def test_should_have_command_set_when_download_file_list
248
- assert_equal @doc_list.at_css("Command").content, "DownloadFileList"
249
- end
250
-
251
- def test_should_have_command_set_when_download_file
252
- assert_equal @doc_file.at_css("Command").content, "DownloadFile"
253
- end
254
-
255
- def test_should_have_command_set_when_upload_file
256
- assert_equal @doc_up.at_css("Command").content, "UploadFile"
257
- end
258
-
259
- def test_should_have_environment_set_with_all_commands
260
- assert_equal @doc_file.at_css("Environment").content, @params[:environment]
261
- assert_equal @doc_get.at_css("Environment").content, @params[:environment]
262
- assert_equal @doc_list.at_css("Environment").content, @params[:environment]
263
- assert_equal @doc_up.at_css("Environment").content, @params[:environment]
264
- end
265
-
266
- def test_should_have_software_id_set_with_all_commands
267
- assert_equal @doc_file.at_css("SoftwareId").content,
268
- "Sepa Transfer Library version " + Sepa::VERSION
269
-
270
- assert_equal @doc_get.at_css("SoftwareId").content,
271
- "Sepa Transfer Library version " + Sepa::VERSION
272
-
273
- assert_equal @doc_list.at_css("SoftwareId").content,
274
- "Sepa Transfer Library version " + Sepa::VERSION
275
-
276
- assert_equal @doc_up.at_css("SoftwareId").content,
277
- "Sepa Transfer Library version " + Sepa::VERSION
278
- end
279
-
280
- def test_should_have_status_set_when_download_file_list
281
- assert_equal @doc_list.at_css("Status").content, @params[:status]
282
- end
283
-
284
- def test_should_have_status_set_when_download_file
285
- assert_equal @doc_file.at_css("Status").content, @params[:status]
286
- end
287
-
288
- def test_should_not_have_status_set_when_get_user_info
289
- refute @doc_get.at_css("Status")
290
- end
291
-
292
- def test_should_not_have_status_set_when_upload_file
293
- refute @doc_up.at_css("Status")
294
- end
295
-
296
- def test_should_have_target_id_set_when_download_file_list
297
- assert_equal @doc_list.at_css("TargetId").content, @params[:target_id]
298
- end
299
-
300
- def test_should_have_target_id_set_when_download_file
301
- assert_equal @doc_file.at_css("TargetId").content, @params[:target_id]
302
- end
303
-
304
- def test_should_not_have_target_id_set_when_get_user_info
305
- refute @doc_get.at_css("TargetId")
306
- end
307
-
308
- def test_should_have_file_type_set_when_download_file_list
309
- assert_equal @doc_list.at_css("FileType").content, @params[:file_type]
310
- end
311
-
312
- def test_should_have_file_type_set_when_download_file
313
- assert_equal @doc_file.at_css("FileType").content, @params[:file_type]
314
- end
315
-
316
- def test_should_have_file_type_set_when_upload_file
317
- assert_equal @doc_up.at_css("FileType").content, @params[:file_type]
318
- end
319
-
320
- def test_should_not_have_file_type_set_when_get_user_info
321
- refute @doc_get.at_css("FileType")
322
- end
323
-
324
- def test_should_have_file_reference_set_when_download_file
325
- assert_equal @doc_file.at_css("FileReference").content,
326
- @params[:file_reference]
327
- end
328
-
329
- def test_should_not_have_file_ref_when_download_file_list
330
- refute @doc_list.at_css("FileReference")
331
- end
332
-
333
- def test_should_not_have_file_ref_when_get_user_info
334
- refute @doc_get.at_css("FileReference")
335
- end
336
-
337
- def test_should_not_have_file_ref_when_upload_file
338
- refute @doc_up.at_css("FileReference")
339
- end
340
-
341
- def test_should_have_content_when_upload_file
342
- assert_equal @doc_up.at_css("Content").content,
343
- Base64.encode64(@params[:content])
344
- end
345
-
346
- def test_should_not_have_content_when_download_file_list
347
- refute @doc_list.at_css("Content")
348
- end
349
-
350
- def test_should_not_have_content_when_download_file
351
- refute @doc_file.at_css("Content")
352
- end
353
-
354
- def test_should_not_have_content_when_get_user_info
355
- refute @doc_get.at_css("Content")
356
- end
357
-
358
- def test_should_raise_argument_error_with_invalid_command
359
- assert_raises(ArgumentError) do
360
- @params[:command] = :wrong_kind_of_command
361
- ar = Sepa::ApplicationRequest.new(@params)
362
- doc = ar.get_as_base64
363
- end
364
- end
365
-
366
- def test_digest_is_calculatd_correctly
367
- calculated_digest = @doc_file.at_css(
368
- "dsig|DigestValue", 'dsig' => 'http://www.w3.org/2000/09/xmldsig#'
369
- ).content
370
-
371
- # Remove signature for calculating digest
372
- @doc_file.at_css(
373
- "dsig|Signature", 'dsig' => 'http://www.w3.org/2000/09/xmldsig#'
374
- ).remove
375
-
376
- # Calculate digest
377
- sha1 = OpenSSL::Digest::SHA1.new
378
- actual_digest = Base64.encode64(sha1.digest(@doc_file.canonicalize))
379
-
380
- # And then make sure the two are equal
381
- assert_equal calculated_digest.strip, actual_digest.strip
382
- end
383
-
384
- def test_signature_is_constructed_correctly
385
- #private_key = @params.fetch(:private_key)
386
-
387
- signed_info_node = @doc_file.at_css(
388
- "dsig|SignedInfo", 'dsig' => 'http://www.w3.org/2000/09/xmldsig#')
389
-
390
- # The value of the signature node in the constructed ar
391
- calculated_signature = @doc_file.at_css(
392
- "dsig|SignatureValue", 'dsig' => 'http://www.w3.org/2000/09/xmldsig#'
393
- ).content
394
-
395
- # Calculate the actual signature
396
- sha1 = OpenSSL::Digest::SHA1.new
397
- actual_signature = Base64.encode64(@private_key.sign(
398
- sha1, signed_info_node.canonicalize))
399
-
400
- # And then of course assert the two are equal
401
- assert_equal calculated_signature, actual_signature
402
- end
403
-
404
- def test_certificate_is_added_correctly
405
- added_cert = @doc_file.at_css(
406
- "dsig|X509Certificate", 'dsig' => 'http://www.w3.org/2000/09/xmldsig#'
407
- ).content
408
-
409
- actual_cert = @params.fetch(:cert).to_s
410
- actual_cert = actual_cert.split('-----BEGIN CERTIFICATE-----')[1]
411
- actual_cert = actual_cert.split('-----END CERTIFICATE-----')[0]
412
- actual_cert.gsub!(/\s+/, "")
413
-
414
- assert_equal added_cert, actual_cert
415
- end
416
-
417
- def test_should_validate_against_schema
418
- Dir.chdir(@schemas_path) do
419
- xsd = Nokogiri::XML::Schema(IO.read('application_request.xsd'))
420
- assert xsd.valid?(@doc_file)
421
- end
422
- end
423
- end
@@ -1,99 +0,0 @@
1
- require File.expand_path('../../test_helper.rb', __FILE__)
2
-
3
- class CertApplicationRequestTest < MiniTest::Test
4
- def setup
5
- @schemapath = File.expand_path('../../../lib/sepa/xml_schemas',__FILE__)
6
- @templatepath = File.expand_path('../../../lib/sepa/xml_templates/application_request',__FILE__)
7
- @keyspath = File.expand_path('../nordea_test_keys', __FILE__)
8
-
9
- csrplain = "-----BEGIN CERTIFICATE REQUEST-----
10
- MIIBczCB3QIBADA0MRIwEAYDVQQDEwlEZXZsYWIgT3kxETAPBgNVBAUTCDExMTEx
11
- MTExMQswCQYDVQQGEwJGSTCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAo9wU
12
- c2Ys5hSso4nEanbc+RIhL71aS6GBGiWAegXjhlyb6dpwigrZBFPw4u6UZV/Vq7Y7
13
- Ku3uBq5rfZwk+lA+c/B634Eu0zWdI+EYfQxKVRrBrmhiGplKEtglHXbNmmMOn07e
14
- LPUaB0Ipx/6h/UczJGBINdtcuIbYVu0r7ZfyWbUCAwEAAaAAMA0GCSqGSIb3DQEB
15
- BQUAA4GBAIhh2o8mN4Byn+w1jdbhq6lxEXYqdqdh1F6GCajt2lQMUBgYP23I5cS/
16
- Z+SYNhu8vbj52cGQPAwEDN6mm5yLpcXu40wYzgWyfStLXV9d/b4hMy9qLMW00Dzb
17
- jo2ekdSDdw8qxKyxj1piv8oYzMd4fCjCpL+WDZtq7mdLErVZ92gH
18
- -----END CERTIFICATE REQUEST-----"
19
-
20
- # The params hash is populated with the data that is needed for gem to function
21
- @params = {
22
- bank: :nordea,
23
- command: :get_certificate,
24
- customer_id: '11111111',
25
- environment: 'TEST',
26
- csr_plain: csrplain,
27
- pin: '1234567890',
28
- # Selected service (For testing: service, For real: ISSUER)
29
- service: 'service'
30
- }
31
-
32
- @ar_cert = Sepa::SoapBuilder.new(@params).get_ar_as_base64
33
- @xml = Nokogiri::XML(Base64.decode64(@ar_cert))
34
- end
35
-
36
- def test_that_xml_template_is_unmodified
37
- sha1 = OpenSSL::Digest::SHA1.new
38
-
39
- get_certificate_template = File.read("#{@templatepath}/get_certificate.xml")
40
-
41
- digest = Base64.encode64(sha1.digest(get_certificate_template)).strip
42
-
43
- assert_equal digest, "mpoY4dd4XW5HskkoRxqtVEM+Tts="
44
- end
45
-
46
- def test_schemas_are_unmodified
47
- sha1 = OpenSSL::Digest::SHA1.new
48
-
49
- cert_schema = File.read(
50
- "#{@schemapath}/cert_application_request.xsd")
51
-
52
- cert_digest = sha1.digest(cert_schema)
53
-
54
- assert_equal Base64.encode64(cert_digest).strip,"sFwy9Tj+cERTdcmaGhm8WpmJBH4="
55
- end
56
-
57
- def test_should_initialize_with_only_get_certificate_params
58
- assert Sepa::ApplicationRequest.new(@params)
59
- end
60
-
61
- def test_should_get_argument_errors_unless_command_is_get_certificate
62
- assert_raises(ArgumentError) do
63
- @params[:command] = :wrong_command
64
- ar = Sepa::ApplicationRequest.new(@params)
65
- xml = ar.get_as_base64
66
- end
67
- end
68
-
69
- def test_should_have_customer_id_set
70
- assert_equal @xml.at_css("CustomerId").content, @params[:customer_id]
71
- end
72
-
73
- def test_should_have_timestamp_set_properly
74
- timestamp = Time.strptime(@xml.at_css("Timestamp").content,
75
- '%Y-%m-%dT%H:%M:%S%z')
76
-
77
- assert timestamp <= Time.now && timestamp > (Time.now - 60),
78
- "Timestamp was not set correctly"
79
- end
80
-
81
- def test_should_have_command_set_when_get_certificate
82
- assert_equal @xml.at_css("Command").content, "GetCertificate"
83
- end
84
-
85
- def test_should_have_environment_set
86
- assert_equal @xml.at_css("Environment").content, @params[:environment]
87
- end
88
-
89
- def test_should_have_service_set
90
- assert_equal @xml.at_css("Service").content, @params[:service]
91
- end
92
-
93
- def test_should_validate_against_schema
94
- Dir.chdir(@schemapath) do
95
- xsd = Nokogiri::XML::Schema(IO.read('cert_application_request.xsd'))
96
- assert xsd.valid?(@xml)
97
- end
98
- end
99
- end
@@ -1,112 +0,0 @@
1
- require File.expand_path('../../test_helper.rb', __FILE__)
2
-
3
- class NordeaCertRequestSoapBuilderTest < MiniTest::Test
4
- def setup
5
- @schemapath = File.expand_path('../../../lib/sepa/xml_schemas',__FILE__)
6
- @templatepath = File.expand_path('../../../lib/sepa/xml_templates/soap',__FILE__)
7
- @keyspath = File.expand_path('../nordea_test_keys', __FILE__)
8
-
9
- csrplain = "-----BEGIN CERTIFICATE REQUEST-----
10
- MIIBczCB3QIBADA0MRIwEAYDVQQDEwlEZXZsYWIgT3kxETAPBgNVBAUTCDExMTEx
11
- MTExMQswCQYDVQQGEwJGSTCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAo9wU
12
- c2Ys5hSso4nEanbc+RIhL71aS6GBGiWAegXjhlyb6dpwigrZBFPw4u6UZV/Vq7Y7
13
- Ku3uBq5rfZwk+lA+c/B634Eu0zWdI+EYfQxKVRrBrmhiGplKEtglHXbNmmMOn07e
14
- LPUaB0Ipx/6h/UczJGBINdtcuIbYVu0r7ZfyWbUCAwEAAaAAMA0GCSqGSIb3DQEB
15
- BQUAA4GBAIhh2o8mN4Byn+w1jdbhq6lxEXYqdqdh1F6GCajt2lQMUBgYP23I5cS/
16
- Z+SYNhu8vbj52cGQPAwEDN6mm5yLpcXu40wYzgWyfStLXV9d/b4hMy9qLMW00Dzb
17
- jo2ekdSDdw8qxKyxj1piv8oYzMd4fCjCpL+WDZtq7mdLErVZ92gH
18
- -----END CERTIFICATE REQUEST-----"
19
-
20
- # The params hash is populated with the data that is needed for gem to function
21
- @params = {
22
- bank: :nordea,
23
- command: :get_certificate,
24
- pin: '1234567890',
25
- customer_id: '11111111',
26
- environment: 'TEST',
27
- csr_plain: csrplain,
28
- # Selected service (For testing: service, For real: ISSUER)
29
- service: 'service'
30
- }
31
-
32
- @certrequest = Sepa::SoapBuilder.new(@params)
33
-
34
- @xml = Nokogiri::XML(@certrequest.to_xml)
35
- end
36
-
37
- def test_should_fail_if_bank_doesnt_support_command
38
- @params[:command] = :create_certificate
39
-
40
- assert_raises(ArgumentError) { Sepa::SoapBuilder.new(@params) }
41
- end
42
-
43
- def test_that_get_certificate_soap_template_is_unmodified
44
- sha1 = OpenSSL::Digest::SHA1.new
45
- template = File.read("#{@templatepath}/get_certificate.xml")
46
- digest = Base64.encode64(sha1.digest(template)).strip
47
-
48
- assert_equal digest, "iYJcoQAlXZj5Pp9vLlSROXxY3+k="
49
- end
50
-
51
- def test_should_initialize_with_proper_params
52
- assert Sepa::SoapBuilder.new(@params)
53
- end
54
-
55
- def test_should_get_error_if_command_missing
56
- @params.delete(:command)
57
-
58
- assert_raises(ArgumentError) do
59
- Sepa::SoapBuilder.new(@params)
60
- end
61
- end
62
-
63
- def test_should_get_error_if_customer_id_missing
64
- @params.delete(:customer_id)
65
-
66
- assert_raises(ArgumentError) do
67
- Sepa::SoapBuilder.new(@params)
68
- end
69
- end
70
-
71
- def test_should_load_correct_template_with_get_certificate
72
- @params[:command] = :get_certificate
73
- xml = Nokogiri::XML(Sepa::SoapBuilder.new(@params).to_xml)
74
-
75
- assert xml.xpath('//cer:getCertificatein', 'cer' => 'http://bxd.fi/CertificateService').first
76
- end
77
-
78
- def test_should_raise_error_if_command_not_correct
79
- @params[:command] = :wrong_command
80
- assert_raises(ArgumentError) do
81
- soap = Sepa::SoapBuilder.new(@params).to_xml
82
- end
83
- end
84
-
85
- def test_timestamp_is_set_correctly
86
- timestamp_node = @xml.xpath(
87
- "//cer:Timestamp", 'cer' => 'http://bxd.fi/CertificateService'
88
- ).first
89
-
90
- timestamp = Time.strptime(timestamp_node.content, '%Y-%m-%dT%H:%M:%S%z')
91
-
92
- assert timestamp <= Time.now && timestamp > (Time.now - 60)
93
- end
94
-
95
- def test_application_request_should_be_inserted_properly
96
- ar_node = @xml.xpath(
97
- "//cer:ApplicationRequest", 'cer' => 'http://bxd.fi/CertificateService'
98
- ).first
99
-
100
- ar_doc = Nokogiri::XML(Base64.decode64(ar_node.content))
101
-
102
- assert ar_doc.respond_to?(:canonicalize)
103
- assert_equal ar_doc.at_css("CustomerId").content, @params[:customer_id]
104
- end
105
-
106
- def test_should_validate_against_schema
107
- Dir.chdir(@schemapath) do
108
- xsd = Nokogiri::XML::Schema(IO.read('soap.xsd'))
109
- assert xsd.valid?(@xml)
110
- end
111
- end
112
- end