sepafm 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +35 -0
  3. data/.ruby-version +1 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE +8 -0
  6. data/README.md +236 -0
  7. data/Rakefile +10 -0
  8. data/lib/danske_get_bank_certificate_test.rb +15 -0
  9. data/lib/sepa/application_request.rb +182 -0
  10. data/lib/sepa/application_response.rb +123 -0
  11. data/lib/sepa/client.rb +79 -0
  12. data/lib/sepa/danske_testing/keys/danske_encryption.crt +24 -0
  13. data/lib/sepa/filedescriptor.rb +7 -0
  14. data/lib/sepa/filetypeservice.rb +6 -0
  15. data/lib/sepa/nordea_testing/keys/CSR.csr +0 -0
  16. data/lib/sepa/nordea_testing/keys/nordea.crt +27 -0
  17. data/lib/sepa/nordea_testing/keys/nordea.key +19 -0
  18. data/lib/sepa/nordea_testing/response/content_053.xml +998 -0
  19. data/lib/sepa/nordea_testing/response/content_054.xml +1 -0
  20. data/lib/sepa/nordea_testing/response/download_file_response.xml +14 -0
  21. data/lib/sepa/nordea_testing/response/download_filelist_response.xml +14 -0
  22. data/lib/sepa/nordea_testing/response/get_user_info_response.xml +14 -0
  23. data/lib/sepa/nordea_testing/response/upload_file_response.xml +14 -0
  24. data/lib/sepa/response.rb +177 -0
  25. data/lib/sepa/sender_verifier.rb +15 -0
  26. data/lib/sepa/signature.rb +7 -0
  27. data/lib/sepa/soap_builder.rb +395 -0
  28. data/lib/sepa/soap_danske.rb +47 -0
  29. data/lib/sepa/soap_nordea.rb +68 -0
  30. data/lib/sepa/userfiletype.rb +16 -0
  31. data/lib/sepa/version.rb +3 -0
  32. data/lib/sepa/wsdl/wsdl_danske.xml +234 -0
  33. data/lib/sepa/wsdl/wsdl_danske_cert.xml +280 -0
  34. data/lib/sepa/wsdl/wsdl_nordea.xml +234 -0
  35. data/lib/sepa/wsdl/wsdl_nordea_cert.xml +187 -0
  36. data/lib/sepa/xml_parser.rb +291 -0
  37. data/lib/sepa/xml_schemas/application_request.xsd +135 -0
  38. data/lib/sepa/xml_schemas/application_response.xsd +311 -0
  39. data/lib/sepa/xml_schemas/cert_application_request.xsd +107 -0
  40. data/lib/sepa/xml_schemas/danske_pki.xsd +334 -0
  41. data/lib/sepa/xml_schemas/oasis-200401-wss-wssecurity-secext-1.0.xsd +195 -0
  42. data/lib/sepa/xml_schemas/oasis-200401-wss-wssecurity-utility-1.0.xsd +108 -0
  43. data/lib/sepa/xml_schemas/soap.xsd +126 -0
  44. data/lib/sepa/xml_schemas/wsdl.xml +310 -0
  45. data/lib/sepa/xml_schemas/xml.xsd +287 -0
  46. data/lib/sepa/xml_schemas/xmldsig-core-schema.xsd +318 -0
  47. data/lib/sepa/xml_templates/application_request/create_certificate.xml +10 -0
  48. data/lib/sepa/xml_templates/application_request/danske_get_bank_certificate.xml +10 -0
  49. data/lib/sepa/xml_templates/application_request/download_file.xml +32 -0
  50. data/lib/sepa/xml_templates/application_request/download_file_list.xml +29 -0
  51. data/lib/sepa/xml_templates/application_request/get_certificate.xml +10 -0
  52. data/lib/sepa/xml_templates/application_request/get_user_info.xml +26 -0
  53. data/lib/sepa/xml_templates/application_request/upload_file.xml +29 -0
  54. data/lib/sepa/xml_templates/soap/create_certificate.xml +15 -0
  55. data/lib/sepa/xml_templates/soap/danske_get_bank_certificate.xml +14 -0
  56. data/lib/sepa/xml_templates/soap/download_file.xml +16 -0
  57. data/lib/sepa/xml_templates/soap/download_file_list.xml +16 -0
  58. data/lib/sepa/xml_templates/soap/get_certificate.xml +13 -0
  59. data/lib/sepa/xml_templates/soap/get_user_info.xml +16 -0
  60. data/lib/sepa/xml_templates/soap/header.xml +37 -0
  61. data/lib/sepa/xml_templates/soap/upload_file.xml +16 -0
  62. data/lib/sepa.rb +21 -0
  63. data/lib/sepa_client_testing_mika.rb +32 -0
  64. data/lib/sepa_client_testing_tiere.rb +80 -0
  65. data/sepa.gemspec +29 -0
  66. data/test/sepa/application_request_test.rb +423 -0
  67. data/test/sepa/application_response_test.rb +238 -0
  68. data/test/sepa/cert_application_request_test.rb +99 -0
  69. data/test/sepa/client_test.rb +425 -0
  70. data/test/sepa/danske_test_keys/danskeroot.pem +25 -0
  71. data/test/sepa/danske_test_keys/encryption_pkcs.csr +0 -0
  72. data/test/sepa/danske_test_keys/signing_key.pem +27 -0
  73. data/test/sepa/danske_test_keys/signing_pkcs.csr +0 -0
  74. data/test/sepa/nordea_cert_request_soap_builder_test.rb +112 -0
  75. data/test/sepa/nordea_generic_soap_builder_test.rb +427 -0
  76. data/test/sepa/nordea_test_keys/nordea.crt +27 -0
  77. data/test/sepa/nordea_test_keys/nordea.key +19 -0
  78. data/test/sepa/nordea_test_keys/root_cert.cer +0 -0
  79. data/test/sepa/nordea_test_keys/testcert.csr +0 -0
  80. data/test/sepa/response_test.rb +269 -0
  81. data/test/sepa/sepa_test.rb +20 -0
  82. data/test/sepa/test_files/invalid.wsdl +1 -0
  83. data/test/sepa/test_files/test_responses/df.xml +20 -0
  84. data/test/sepa/test_files/test_responses/dfl.xml +20 -0
  85. data/test/sepa/test_files/test_responses/gui.xml +20 -0
  86. data/test/sepa/test_files/test_responses/uf.xml +20 -0
  87. data/test/sepa/user_file_type_test.rb +21 -0
  88. data/test/sepa/xml_parser_test.rb +73 -0
  89. data/test/test_helper.rb +9 -0
  90. metadata +256 -0
@@ -0,0 +1,99 @@
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
@@ -0,0 +1,425 @@
1
+ require File.expand_path('../../test_helper.rb', __FILE__)
2
+
3
+ class ClientTest < MiniTest::Test
4
+ def setup
5
+ @schemas_path = File.expand_path('../../../lib/sepa/xml_schemas',__FILE__)
6
+
7
+ wsdl_path = File.expand_path('../../../lib/sepa/wsdl/wsdl_nordea.xml',
8
+ __FILE__)
9
+
10
+ keys_path = File.expand_path('../nordea_test_keys', __FILE__)
11
+
12
+ danske_keys_path = File.expand_path('../danske_test_keys', __FILE__)
13
+
14
+ private_key = OpenSSL::PKey::RSA.new File.read "#{keys_path}/nordea.key"
15
+ cert = OpenSSL::X509::Certificate.new File.read "#{keys_path}/nordea.crt"
16
+ certplain = "-----BEGIN CERTIFICATE-----
17
+ MIIDwTCCAqmgAwIBAgIEAX1JuTANBgkqhkiG9w0BAQUFADBkMQswCQYDVQQGEwJT
18
+ RTEeMBwGA1UEChMVTm9yZGVhIEJhbmsgQUIgKHB1YmwpMR8wHQYDVQQDExZOb3Jk
19
+ ZWEgQ29ycG9yYXRlIENBIDAxMRQwEgYDVQQFEws1MTY0MDYtMDEyMDAeFw0xMzA1
20
+ MDIxMjI2MzRaFw0xNTA1MDIxMjI2MzRaMEQxCzAJBgNVBAYTAkZJMSAwHgYDVQQD
21
+ DBdOb3JkZWEgRGVtbyBDZXJ0aWZpY2F0ZTETMBEGA1UEBRMKNTc4MDg2MDIzODCB
22
+ nzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAwtFEfAtbJuGzQwwRumZkvYh2BjGY
23
+ VsAMUeiKtOne3bZSeisfCq+TXqL1gI9LofyeAQ9I/sDm6tL80yrD5iaSUqVm6A73
24
+ 9MsmpW/iyZcVf7ms8xAN51ESUgN6akwZCU9pH62ngJDj2gUsktY0fpsoVsARdrvO
25
+ Fk0fTSUXKWd6LbcCAwEAAaOCAR0wggEZMAkGA1UdEwQCMAAwEQYDVR0OBAoECEBw
26
+ 2cj7+XMAMBMGA1UdIAQMMAowCAYGKoVwRwEDMBMGA1UdIwQMMAqACEALddbbzwun
27
+ MDcGCCsGAQUFBwEBBCswKTAnBggrBgEFBQcwAYYbaHR0cDovL29jc3Aubm9yZGVh
28
+ LnNlL0NDQTAxMA4GA1UdDwEB/wQEAwIFoDCBhQYDVR0fBH4wfDB6oHigdoZ0bGRh
29
+ cCUzQS8vbGRhcC5uYi5zZS9jbiUzRE5vcmRlYStDb3Jwb3JhdGUrQ0ErMDElMkNv
30
+ JTNETm9yZGVhK0JhbmsrQUIrJTI4cHVibCUyOSUyQ2MlM0RTRSUzRmNlcnRp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8W0Z1Hb1dSHrliUSVSrINbK5ZdEV15Rpu7VD
49
+ OePzIwJAPMslS+8alANyyR0iJUC65fDYX1jkZOPldDDNqIDJJxWf/hwd7WaTDpuc
50
+ mHmZDi3ZX2Y45oqUywSzYNtFoIuR1QJAZYUZuyqmSK77SdGB36K1DfSi9AFEQDC1
51
+ fwPAbTwTv6mFFPAiYxLiRZXxVPtW+QtjMXH4ymh2V4y/+GnCqbZyLwJBAJQSDAME
52
+ Sn4Uz7Zjk3UrBIbMYEv0u2mcCypwsb0nGE5/gzDPjGE9cxWW+rXARIs+sNQVClnh
53
+ 45nhdfYxOjgYff0=
54
+ -----END PRIVATE KEY-----"
55
+ csrplain = "-----BEGIN CERTIFICATE REQUEST-----
56
+ MIIBczCB3QIBADA0MRIwEAYDVQQDEwlEZXZsYWIgT3kxETAPBgNVBAUTCDExMTEx
57
+ MTExMQswCQYDVQQGEwJGSTCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAo9wU
58
+ c2Ys5hSso4nEanbc+RIhL71aS6GBGiWAegXjhlyb6dpwigrZBFPw4u6UZV/Vq7Y7
59
+ Ku3uBq5rfZwk+lA+c/B634Eu0zWdI+EYfQxKVRrBrmhiGplKEtglHXbNmmMOn07e
60
+ LPUaB0Ipx/6h/UczJGBINdtcuIbYVu0r7ZfyWbUCAwEAAaAAMA0GCSqGSIb3DQEB
61
+ BQUAA4GBAIhh2o8mN4Byn+w1jdbhq6lxEXYqdqdh1F6GCajt2lQMUBgYP23I5cS/
62
+ Z+SYNhu8vbj52cGQPAwEDN6mm5yLpcXu40wYzgWyfStLXV9d/b4hMy9qLMW00Dzb
63
+ jo2ekdSDdw8qxKyxj1piv8oYzMd4fCjCpL+WDZtq7mdLErVZ92gH
64
+ -----END CERTIFICATE REQUEST-----"
65
+ @params = {
66
+ bank: :nordea,
67
+ private_key_plain: pkeyplain,
68
+ cert_plain: certplain,
69
+ command: :get_user_info,
70
+ customer_id: '11111111',
71
+ environment: 'PRODUCTION',
72
+ status: 'NEW',
73
+ target_id: '11111111A1',
74
+ language: 'FI',
75
+ file_type: 'TITO',
76
+ content: Base64.encode64("Kurppa"),
77
+ file_reference: "11111111A12006030329501800000014"
78
+ }
79
+
80
+ @certparams = {
81
+ bank: :nordea,
82
+ command: :get_certificate,
83
+ customer_id: '11111111',
84
+ environment: 'TEST',
85
+ pin: '1234567890',
86
+ csr_plain: csrplain,
87
+ service: 'service'
88
+ }
89
+
90
+ encryptpkcsplain = "-----BEGIN CERTIFICATE REQUEST-----
91
+ MIICZjCCAU4CAQAwITESMBAGA1UEAxMJRGV2bGFiIE95MQswCQYDVQQGEwJGSTCC
92
+ ASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAKN2ceFGw+i4wAyg6WApu7/h
93
+ 5Rpl8tp+QRX1eLbmftYpf6bbzj+JwspWNST/s8p8enGBRrK+HkNT8ayj7ZSubJwx
94
+ g/bAn+ewxk64A984hiMqd0GMJgwFcWhGpHhwH9QiqA5CAQYXY0T1fs2UXf1mIJ1Z
95
+ 675yGRhU03ZyQgyIjhdTmXLznCluSLeIGypXPi7DCfHP5w0a6Dfpy31fowqi7n9A
96
+ gyoQ6JZuuXHAdEoQpNmxgpp9gBwxs9U+yBmDaBAvvB0DY3+0kMRFCn2oyCuQw5C4
97
+ mRo+0eOO+kA8Svd2bLXmcbe6js/5SgjvkHvvCgIqi9J6aPiJo0XCrLsB6BjQbpsC
98
+ AwEAAaAAMA0GCSqGSIb3DQEBBQUAA4IBAQAXepnKWQWTCiTKXhuT+e52n0/x5YHd
99
+ bLB8nelPpyMf0hiNeoUdzNTZoMM2OArtzvOhh5HWZ32GbjR/RDCy+kMfAGDm/tlB
100
+ /4uJNcDotMFF+MUsEAHVrAUpZh5n00mBeYDl7m098VnAEayxUxJHbQMYY1J1QdTl
101
+ M62i5c2v3sNJlDlT4GidRtoGW9KAID2oCdOL94krWpwLAZDP4wLwG7ACCbOx3rST
102
+ f9gDE6jFUn7ONuiiYvOBAqjwckDpyOH+vx3WkZH4cwdcp4KVeLnjJzlJZaw7yTIo
103
+ z8BKfQ26LmOO/S4CFe3Vzq6FRNKl3D4nvCu06WoMi5tAAEi57tk05B32
104
+ -----END CERTIFICATE REQUEST-----"
105
+ signingpkcsplain = "-----BEGIN CERTIFICATE REQUEST-----
106
+ MIICZjCCAU4CAQAwITESMBAGA1UEAxMJRGV2bGFiIE95MQswCQYDVQQGEwJGSTCC
107
+ ASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAK3yym5CztvmJCxbzhy6tOph
108
+ wzamimFKlJt88cG0VLzwAh0EiAhFz9Yj/39n1HywL+4xOLizIAup794MzLBDs3TH
109
+ OAZe7iZSrb5y4PMh5l9jwhXLPu7/tkqswcvMtstI5HZGqEqdw0kAT0BuKJBXdo+e
110
+ 8nOCVsiMPhrtk5ovLY54vWMzwfAQJeBkxbr1LH6Ib4k7IlsysKpQt7+VqQcTc/lL
111
+ IC+MnVfmKDA0qTXFKQsZC2hO353cu9ZfjdrnKpo5gutcPJRu+TBNS8HJNkI+3pNM
112
+ MTGPvweeY461tzgOpeSzL+FkmRFSWksOmPol1Q4DDZryYHaLDv7q6lELNDxEwQ8C
113
+ AwEAAaAAMA0GCSqGSIb3DQEBBQUAA4IBAQAIw3tbNWTsayBm4bUzugNKCFreayTo
114
+ 5npG3JUiA+n5jIdj3egqSXwxkXSJ5tdXcv0xqsFkV0wq3l5wEaeG7Jd7vLD6FX2y
115
+ MbtE49PHHcLwcY0U94qBj6qEleRwebGfyKwpMb2M90cAf3V/5IjZUJfvYyjOBQUT
116
+ H6Xhm3JG9g7AScHhFcM8r6PhmzcL1FubYBPTcUBuotDBYc4lbql7sbww/u8OyWvl
117
+ aIFd+oiwXGSYB7L8Fqg469jeIf0QtOZUtUEGOJWjM4JjTy+NnVmsj0jszMbuBZBW
118
+ 7wOrp+GMBUZ9/vaY/zr7nvJTfvKz7CJQOgADeh/0imZqhIYfVKIpJxR5
119
+ -----END CERTIFICATE REQU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Q4EFgQUP6wH
136
+ VNOmznu212c08M3oeYjeXW4wDgYDVR0PAQH/BAQDAgQwMA0GCSqGSIb3DQEBCwUA
137
+ A4IBAQAvJBfPug+ixGL/zWUnKMweV80atZXMjHJEn4mOE+iUkCNONLImMMt6MXJy
138
+ snJViL1gL5xMrka6A62PLLsVkl79kxDDbzXMPfGt5/mB9L7CMpyzaID0acDii3rs
139
+ ZwT3Wxpnate6wowN4zpmXgpCpTDGbxjuVRiOArsjQblerhfxnD/UAieZ1IWozIAN
140
+ s6SVms/TuOB+bODUr06ITxBkDJhizOJxjsXRIAtwZvvrH4qGjJz5qFcPb3nz4Txw
141
+ swU8X6yvbtqF+q4aAKPA6ZydnGZFQSoSzNJtcF28T1ItxEHN3+xyQqXpTgFviiuL
142
+ 277LaAl9YUFFnSgeh7GiFitWJPfD
143
+ -----END CERTIFICATE-----"
144
+ @danskecertparams = {
145
+ bank: :danske,
146
+ command: :create_certificate,
147
+ customer_id: 'ABC123',
148
+ environment: 'customertest',
149
+ key_generator_type: 'software',
150
+ encryption_cert_pkcs10_plain: encryptpkcsplain,
151
+ signing_cert_pkcs10_plain: signingpkcsplain,
152
+ cert_plain: danskebankencryptplain,
153
+ pin: '1234'
154
+ }
155
+
156
+ observer = Class.new {
157
+ def notify(operation_name, builder, globals, locals)
158
+ @operation_name = operation_name
159
+ @builder = builder
160
+ @globals = globals
161
+ @locals = locals
162
+
163
+ HTTPI::Response.new(200,
164
+ { "Reponse is actually" => "the request, w0000t" },
165
+ locals[:xml])
166
+ end
167
+ }.new
168
+
169
+ Savon.observers << observer
170
+ end
171
+
172
+ def test_should_get_error_if_key_gen_type_missing
173
+ @danskecertparams.delete(:key_generator_type)
174
+
175
+ assert_raises(ArgumentError) { Sepa::Client.new(@danskecertparams) }
176
+ end
177
+
178
+ def test_should_raise_error_with_wrong_bank
179
+ @params[:bank] = :royal_bank_of_skopje
180
+ assert_raises(ArgumentError) { Sepa::Client.new(@params) }
181
+ end
182
+
183
+ def test_should_raise_error_with_wrong_command_when_bank_doesnt_support_the_command
184
+ @certparams[:bank] = :danske
185
+ @certparams[:command] = :get_certificate
186
+ assert_raises(ArgumentError) { Sepa::Client.new(@certparams) }
187
+ end
188
+
189
+ def test_should_not_initialize_with_unsupported_danske_params
190
+ assert_raises(ArgumentError) { Sepa::Client.new(@danskecertparams) }
191
+ end
192
+
193
+ def test_should_initialize_with_proper_params
194
+ assert Sepa::Client.new(@params)
195
+ end
196
+
197
+ def test_should_give_proper_error_if_initialized_with_something_not_hash_like
198
+ not_hashes = ['Merihevonsenkenka', 1, :verhokangas]
199
+
200
+ not_hashes.each do |not_hash|
201
+ assert_raises(ArgumentError) { Sepa::Client.new(not_hash) }
202
+ end
203
+ end
204
+
205
+ def test_should_raise_error_if_private_key_plain_is_wrong
206
+ wrong_pks = ['Im not a key', :leppakerttu, nil]
207
+
208
+ wrong_pks.each do |wrong_pk|
209
+ @params[:private_key_plain] = wrong_pk
210
+ assert_raises(ArgumentError) { Sepa::Client.new(@params) }
211
+ end
212
+ end
213
+
214
+ def test_should_raise_error_if_cert_plain_file_is_wrong
215
+ wrong_certs = ['Im not a cert', 99, :leppakerttu, nil]
216
+
217
+ wrong_certs.each do |wrong_cert|
218
+ @params[:cert_plain] = wrong_cert
219
+ assert_raises(ArgumentError) { Sepa::Client.new(@params) }
220
+ end
221
+ end
222
+
223
+ def test_should_raise_error_if_command_wrong_or_missing
224
+ wrong_commands = ['string is not a command', 1337, :symbol_but_not_proper,
225
+ nil]
226
+
227
+ wrong_commands.each do |wrong_command|
228
+ @params[:command] = wrong_command
229
+
230
+ assert_raises(ArgumentError) { Sepa::Client.new(@params) }
231
+ end
232
+ end
233
+
234
+ def test_should_raise_error_if_customer_id_wrong_or_missing
235
+ wrong_ids = ["I'm a way too long a string and probably also not valid", nil]
236
+
237
+ wrong_ids.each do |wrong_id|
238
+ @params[:customer_id] = wrong_id
239
+
240
+ assert_raises(ArgumentError) { Sepa::Client.new(@params) }
241
+ end
242
+ end
243
+
244
+ def test_should_raise_error_if_environment_wrong_or_missing
245
+ wrong_envs = ["not proper", 5, :protuction, nil]
246
+
247
+ wrong_envs.each do |wrong_env|
248
+ @params[:environment] = wrong_env
249
+
250
+ assert_raises(ArgumentError) { Sepa::Client.new(@params) }
251
+ end
252
+ end
253
+
254
+ def test_should_raise_error_if_status_wrong
255
+ commands = [:download_file, :download_file_list]
256
+
257
+ commands.each do |command|
258
+ @params[:command] = command
259
+
260
+ wrong_statuses = ["ready", 'steady', 5, :nipsu]
261
+
262
+ wrong_statuses.each do |wrong_status|
263
+ @params[:status] = wrong_status
264
+
265
+ assert_raises(ArgumentError) { Sepa::Client.new(@params) }
266
+ end
267
+ end
268
+ end
269
+
270
+ def test_should_raise_error_if_target_id_wrong
271
+ commands = [:download_file, :download_file_list, :upload_file]
272
+
273
+ commands.each do |command|
274
+ @params[:command] = command
275
+
276
+ wrong_ids = ["ready"*81, nil]
277
+
278
+ wrong_ids.each do |wrong_id|
279
+ @params[:target_id] = wrong_id
280
+
281
+ assert_raises(ArgumentError) { Sepa::Client.new(@params) }
282
+ end
283
+ end
284
+ end
285
+
286
+ def test_should_raise_error_if_language_wrong
287
+ wrong_langs = ["Joo", 7, :protuction]
288
+
289
+ wrong_langs.each do |wrong_lang|
290
+ @params[:language] = wrong_lang
291
+
292
+ assert_raises(ArgumentError) { Sepa::Client.new(@params) }
293
+ end
294
+ end
295
+
296
+ def test_should_raise_error_if_file_type_wrong_or_missing
297
+ commands = [:download_file, :download_file_list, :upload_file]
298
+
299
+ commands.each do |command|
300
+ @params[:command] = command
301
+
302
+ wrong_types = ["kalle"*41, nil]
303
+
304
+ wrong_types.each do |wrong_type|
305
+ @params[:file_type] = wrong_type
306
+
307
+ assert_raises(ArgumentError) { Sepa::Client.new(@params) }
308
+ end
309
+ end
310
+ end
311
+
312
+ def test_should_raise_error_if_content_missing
313
+ @params[:command] = :upload_file
314
+ @params.delete(:content)
315
+
316
+ assert_raises(ArgumentError) { Sepa::Client.new(@params) }
317
+ end
318
+
319
+ # The response from savon will be the request to check that a proper request
320
+ # was made in the following four tests
321
+ def test_should_send_proper_request_with_get_user_info
322
+ client = Sepa::Client.new(@params)
323
+ response = client.send
324
+
325
+ assert_equal response.body.keys[0], :get_user_infoin
326
+
327
+ Dir.chdir(@schemas_path) do
328
+ xsd = Nokogiri::XML::Schema(IO.read('soap.xsd'))
329
+ assert xsd.valid?(Nokogiri::XML(response.to_xml))
330
+ end
331
+ end
332
+
333
+ def test_should_send_proper_request_with_download_file_list
334
+ @params[:command] = :download_file_list
335
+ client = Sepa::Client.new(@params)
336
+ response = client.send
337
+
338
+ assert_equal response.body.keys[0], :download_file_listin
339
+
340
+ Dir.chdir(@schemas_path) do
341
+ xsd = Nokogiri::XML::Schema(IO.read('soap.xsd'))
342
+ assert xsd.valid?(Nokogiri::XML(response.to_xml))
343
+ end
344
+ end
345
+
346
+ def test_should_send_proper_request_with_download_file
347
+ @params[:command] = :download_file
348
+ client = Sepa::Client.new(@params)
349
+ response = client.send
350
+
351
+ assert_equal response.body.keys[0], :download_filein
352
+
353
+ Dir.chdir(@schemas_path) do
354
+ xsd = Nokogiri::XML::Schema(IO.read('soap.xsd'))
355
+ assert xsd.valid?(Nokogiri::XML(response.to_xml))
356
+ end
357
+ end
358
+
359
+ def test_should_send_proper_request_with_upload_file
360
+ @params[:command] = :upload_file
361
+ client = Sepa::Client.new(@params)
362
+ response = client.send
363
+
364
+ assert_equal response.body.keys[0], :upload_filein
365
+
366
+ Dir.chdir(@schemas_path) do
367
+ xsd = Nokogiri::XML::Schema(IO.read('soap.xsd'))
368
+ assert xsd.valid?(Nokogiri::XML(response.to_xml))
369
+ end
370
+ end
371
+
372
+ def test_should_initialize_with_proper_cert_params
373
+ assert Sepa::Client.new(@certparams)
374
+ end
375
+
376
+ def test_should_send_proper_request_with_get_certificate
377
+ client = Sepa::Client.new(@certparams)
378
+ response = client.send
379
+
380
+ assert_equal response.body.keys[0], :get_certificatein
381
+
382
+ Dir.chdir(@schemas_path) do
383
+ xsd = Nokogiri::XML::Schema(IO.read('soap.xsd'))
384
+ assert xsd.valid?(Nokogiri::XML(response.to_xml))
385
+ end
386
+ end
387
+
388
+ def test_should_raise_error_if_cert_service_missing
389
+ @certparams[:command] = :get_certificate
390
+ @certparams.delete(:service)
391
+
392
+ assert_raises(ArgumentError) { Sepa::Client.new(@certparams) }
393
+ end
394
+
395
+ def test_should_raise_error_if_signing_pkcs_plain_and_path_missing_with_create_certificate
396
+ @danskecertparams[:command] = :create_certificate
397
+ @danskecertparams.delete(:signing_cert_pkcs10_plain)
398
+ @danskecertparams.delete(:signing_cert_pkcs10_path)
399
+
400
+ assert_raises(ArgumentError) { Sepa::Client.new(@danskecertparams) }
401
+ end
402
+
403
+ def test_should_raise_error_if_encryption_pkcs_plain_and_path_missing_with_create_certificate
404
+ @danskecertparams[:command] = :create_certificate
405
+ @danskecertparams.delete(:encryption_cert_pkcs10_plain)
406
+ @danskecertparams.delete(:encryption_cert_pkcs10_path)
407
+
408
+ assert_raises(ArgumentError) { Sepa::Client.new(@danskecertparams) }
409
+ end
410
+
411
+ def test_should_raise_error_if_pin_missing_with_create_certificate
412
+ @danskecertparams[:command] = :create_certificate
413
+ @danskecertparams.delete(:pin)
414
+
415
+ assert_raises(ArgumentError) { Sepa::Client.new(@danskecertparams) }
416
+ end
417
+
418
+ def test_should_raise_error_if_cert_plain_and_cert_path_missing_with_create_certificate
419
+ @danskecertparams[:command] = :create_certificate
420
+ @danskecertparams.delete(:cert_plain)
421
+ @danskecertparams.delete(:cert_path)
422
+
423
+ assert_raises(ArgumentError) { Sepa::Client.new(@danskecertparams) }
424
+ end
425
+ end
@@ -0,0 +1,25 @@
1
+ -----BEGIN CERTIFICATE-----
2
+ MIIEPzCCAyegAwIBAgIEQjoxcjANBgkqhkiG9w0BAQsFADCBmDEQMA4GA1UEAxMH
3
+ REJHUk9PVDELMAkGA1UEBhMCREsxEzARBgNVBAcTCkNvcGVuaGFnZW4xEDAOBgNV
4
+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27
+ -----END RSA PRIVATE KEY-----
@@ -0,0 +1,112 @@
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