sepafm 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,7 +5,7 @@ class NordeaCertApplicationRequestTest < ActiveSupport::TestCase
5
5
 
6
6
  def setup
7
7
  @get_cert_params = nordea_cert_params
8
- ar_cert = Sepa::SoapBuilder.new(@get_cert_params).ar
8
+ ar_cert = Sepa::SoapBuilder.new(@get_cert_params).application_request
9
9
  @xml = Nokogiri::XML(ar_cert.to_xml)
10
10
  end
11
11
 
@@ -13,7 +13,7 @@ class NordeaCertApplicationRequestTest < ActiveSupport::TestCase
13
13
  sha1 = OpenSSL::Digest::SHA1.new
14
14
  cert_schema = File.read("#{SCHEMA_PATH}/cert_application_request.xsd")
15
15
  cert_digest = sha1.digest(cert_schema)
16
- assert_equal Base64.encode64(cert_digest).strip, "sFwy9Tj+cERTdcmaGhm8WpmJBH4="
16
+ assert_equal encode(cert_digest).strip, "sFwy9Tj+cERTdcmaGhm8WpmJBH4="
17
17
  end
18
18
 
19
19
  def test_should_initialize_with_only_get_certificate_params
@@ -49,7 +49,7 @@ class NordeaCertRequestSoapBuilderTest < ActiveSupport::TestCase
49
49
  "//cer:ApplicationRequest", 'cer' => 'http://bxd.fi/CertificateService'
50
50
  ).first
51
51
 
52
- ar_doc = Nokogiri::XML(Base64.decode64(ar_node.content))
52
+ ar_doc = Nokogiri::XML(decode(ar_node.content))
53
53
 
54
54
  assert ar_doc.respond_to?(:canonicalize)
55
55
  assert_equal ar_doc.at_css("CustomerId").content, @nordea_generic_params[:customer_id]
@@ -124,7 +124,7 @@ class NordeaGenericSoapBuilderTest < ActiveSupport::TestCase
124
124
  "//bxd:ApplicationRequest", 'bxd' => 'http://model.bxd.fi'
125
125
  ).first
126
126
 
127
- ar_doc = Nokogiri::XML(Base64.decode64(ar_node.content))
127
+ ar_doc = Nokogiri::XML(decode(ar_node.content))
128
128
 
129
129
  assert ar_doc.respond_to?(:canonicalize)
130
130
  assert_equal ar_doc.at_css("CustomerId").content, @nordea_generic_params[:customer_id]
@@ -163,7 +163,7 @@ class NordeaGenericSoapBuilderTest < ActiveSupport::TestCase
163
163
  with_comments = false
164
164
  )
165
165
 
166
- actual_digest = Base64.encode64(sha1.digest(body_node)).strip
166
+ actual_digest = encode(sha1.digest(body_node)).strip
167
167
 
168
168
  assert_equal actual_digest, added_digest
169
169
  end
@@ -211,7 +211,7 @@ class NordeaGenericSoapBuilderTest < ActiveSupport::TestCase
211
211
  with_comments = false
212
212
  )
213
213
 
214
- actual_digest = Base64.encode64(sha1.digest(timestamp_node)).strip
214
+ actual_digest = encode(sha1.digest(timestamp_node)).strip
215
215
 
216
216
  assert_equal actual_digest, added_digest
217
217
  end
@@ -233,7 +233,7 @@ class NordeaGenericSoapBuilderTest < ActiveSupport::TestCase
233
233
  with_comments = false
234
234
  )
235
235
 
236
- actual_signature = Base64.encode64(
236
+ actual_signature = encode(
237
237
  private_key.sign(sha1, signed_info_node)
238
238
  ).gsub(/\s+/, "")
239
239
 
@@ -4,43 +4,59 @@ class NordeaResponseTest < ActiveSupport::TestCase
4
4
  include Sepa::Utilities
5
5
 
6
6
  def setup
7
- keys_path = File.expand_path('../keys', __FILE__)
8
- @root_cert = OpenSSL::X509::Certificate.new File.read("#{keys_path}/root_cert.cer")
9
- @not_root_cert = OpenSSL::X509::Certificate.new File.read("#{keys_path}/nordea.crt")
10
-
11
- dfl = Nokogiri::XML(File.read("#{NORDEA_TEST_RESPONSE_PATH}/dfl.xml"))
12
- @dfl = Sepa::Response.new(dfl, command: :download_file_list)
13
-
14
- uf = Nokogiri::XML(File.read("#{NORDEA_TEST_RESPONSE_PATH}/uf.xml"))
15
- @uf = Sepa::Response.new(uf, command: :upload_file)
16
-
17
- df_tito = Nokogiri::XML(File.read("#{NORDEA_TEST_RESPONSE_PATH}/df_tito.xml"))
18
- @df_tito = Sepa::Response.new(df_tito, command: :download_file)
19
-
20
- df_ktl = Nokogiri::XML(File.read("#{NORDEA_TEST_RESPONSE_PATH}/df_ktl.xml"))
21
- @df_ktl = Sepa::Response.new(df_ktl, command: :download_file)
22
-
23
- gui = Nokogiri::XML(File.read("#{NORDEA_TEST_RESPONSE_PATH}/gui.xml"))
24
- @gui = Sepa::Response.new(gui, command: :get_user_info)
25
-
26
- gc = Nokogiri::XML(File.read("#{NORDEA_TEST_RESPONSE_PATH}/gc.xml"))
27
- @gc = Sepa::NordeaResponse.new(gc, command: :get_certificate)
7
+ options = {
8
+ response: File.read("#{NORDEA_TEST_RESPONSE_PATH}/dfl.xml"),
9
+ command: :download_file_list
10
+ }
11
+ @dfl = Sepa::NordeaResponse.new options
12
+
13
+ options = {
14
+ response: File.read("#{NORDEA_TEST_RESPONSE_PATH}/uf.xml"),
15
+ command: :upload_file
16
+ }
17
+ @uf = Sepa::NordeaResponse.new options
18
+
19
+ options = {
20
+ response: File.read("#{NORDEA_TEST_RESPONSE_PATH}/df_tito.xml"),
21
+ command: :download_file
22
+ }
23
+ @df_tito = Sepa::NordeaResponse.new options
24
+
25
+ options = {
26
+ response: File.read("#{NORDEA_TEST_RESPONSE_PATH}/df_ktl.xml"),
27
+ command: :download_file
28
+ }
29
+ @df_ktl = Sepa::NordeaResponse.new options
30
+
31
+ options = {
32
+ response: File.read("#{NORDEA_TEST_RESPONSE_PATH}/gui.xml"),
33
+ command: :get_user_info
34
+ }
35
+ @gui = Sepa::NordeaResponse.new options
36
+
37
+ options = {
38
+ response: File.read("#{NORDEA_TEST_RESPONSE_PATH}/gc.xml"),
39
+ command: :get_certificate
40
+ }
41
+ @gc = Sepa::NordeaResponse.new options
28
42
  end
29
43
 
30
44
  def test_should_be_valid
31
- assert @dfl.valid?
32
- assert @uf.valid?
33
- assert @df_tito.valid?
34
- assert @gui.valid?
45
+ assert @dfl.valid?, @dfl.errors.messages
46
+ assert @uf.valid?, @uf.errors.messages
47
+ assert @df_tito.valid?, @df_tito.errors.messages
48
+ assert @df_ktl.valid?, @df_ktl.errors.messages
49
+ assert @gui.valid?, @gui.errors.messages
50
+ assert @gc.valid?, @gc.errors.messages
35
51
  end
36
52
 
37
53
  def test_should_fail_with_improper_params
38
- a = Sepa::Response.new("Jees", command: 'not')
54
+ a = Sepa::Response.new({ response: "Jees", command: 'not'})
39
55
  refute a.valid?
40
56
  end
41
57
 
42
58
  def test_should_complain_if_ar_not_valid_against_schema
43
- a = Sepa::Response.new(Nokogiri::XML("<ar>text</ar>"), command: 'notvalid')
59
+ a = Sepa::Response.new({ response: "<ar>text</ar>", command: 'notvalid' })
44
60
  refute a.valid?
45
61
  end
46
62
 
@@ -52,21 +68,26 @@ class NordeaResponseTest < ActiveSupport::TestCase
52
68
  end
53
69
 
54
70
  def test_cert_check_should_work
55
- assert @dfl.cert_is_trusted(@root_cert)
71
+ keys_path = File.expand_path('../keys', __FILE__)
72
+ root_cert = OpenSSL::X509::Certificate.new File.read("#{keys_path}/root_cert.cer")
73
+ not_root_cert = OpenSSL::X509::Certificate.new File.read("#{keys_path}/nordea.crt")
74
+
75
+ assert @dfl.cert_is_trusted(root_cert)
56
76
  assert_raises(SecurityError) do
57
- @dfl.cert_is_trusted(@not_root_cert)
77
+ @dfl.cert_is_trusted(not_root_cert)
58
78
  end
59
79
  end
60
80
 
61
81
  def test_signature_check_should_work
62
82
  assert @dfl.signature_is_valid?
63
- @dfl.soap.at_css(
64
- 'xmlns|SignatureValue',
65
- 'xmlns' => 'http://www.w3.org/2000/09/xmldsig#'
66
- ).content = "kissa"
83
+ @dfl.doc.at('xmlns|SignatureValue', 'xmlns' => DSIG).content = "kissa"
67
84
  refute @dfl.signature_is_valid?
68
85
  end
69
86
 
87
+ test 'to_s works' do
88
+ assert_equal File.read("#{NORDEA_TEST_RESPONSE_PATH}/dfl.xml"), @dfl.to_s
89
+ end
90
+
70
91
  ##
71
92
  # Tests for download file command
72
93
 
@@ -110,7 +131,8 @@ class NordeaResponseTest < ActiveSupport::TestCase
110
131
 
111
132
  test 'certificate can be extracted from get certificate response' do
112
133
  assert_nothing_raised do
113
- OpenSSL::X509::Certificate.new Base64.decode64(@gc.content)
134
+ OpenSSL::X509::Certificate.new decode(@gc.own_signing_cert)
114
135
  end
115
136
  end
137
+
116
138
  end
@@ -8,24 +8,10 @@ class ClientTest < ActiveSupport::TestCase
8
8
  # Get params hashes from fixtures for different banks and for different request types
9
9
  @nordea_generic_params = nordea_generic_params
10
10
  @nordea_cert_params = nordea_cert_params
11
-
12
11
  @danske_cert_params = danske_cert_params
13
12
 
14
13
  # Namespaces
15
14
  @cor = 'http://bxd.fi/CorporateFileService'
16
-
17
- # Create an observer to fake sending requests to bank
18
- observer = Class.new {
19
- def notify(operation_name, builder, globals, locals)
20
- @operation_name = operation_name
21
- @builder = builder
22
- @globals = globals
23
- @locals = locals
24
- HTTPI::Response.new(200, { "Reponse is actually" => "the request, w0000t" }, locals[:xml])
25
- end
26
- }.new
27
-
28
- Savon.observers << observer
29
15
  end
30
16
 
31
17
  test "should initialize class" do
@@ -172,75 +158,75 @@ class ClientTest < ActiveSupport::TestCase
172
158
 
173
159
  # # The response from savon will be the request to check that a proper request
174
160
  # # was made in the following four tests
175
- def test_should_send_proper_request_with_get_user_info
161
+ test "should_send_proper_request_with_get_user_info" do
176
162
  @nordea_generic_params[:command] = :get_user_info
177
163
  client = Sepa::Client.new(@nordea_generic_params)
178
164
  response = client.send_request
179
165
 
180
- assert response.soap.at_css('cor|getUserInfoin', cor: @cor)
166
+ assert response.doc.at_css('cor|getUserInfoin', cor: @cor)
181
167
 
182
168
  Dir.chdir(SCHEMA_PATH) do
183
169
  xsd = Nokogiri::XML::Schema(IO.read('soap.xsd'))
184
- assert xsd.valid?(response.soap)
170
+ assert xsd.valid?(response.doc)
185
171
  end
186
172
  end
187
173
 
188
- def test_should_send_proper_request_with_download_file_list
174
+ test "should_send_proper_request_with_download_file_list" do
189
175
  @nordea_generic_params[:command] = :download_file_list
190
176
  client = Sepa::Client.new(@nordea_generic_params)
191
177
  response = client.send_request
192
178
 
193
- assert response.soap.at_css('cor|downloadFileListin', cor: @cor)
179
+ assert response.doc.at_css('cor|downloadFileListin', cor: @cor)
194
180
 
195
181
  Dir.chdir(SCHEMA_PATH) do
196
182
  xsd = Nokogiri::XML::Schema(IO.read('soap.xsd'))
197
- assert xsd.valid?(response.soap)
183
+ assert xsd.valid?(response.doc)
198
184
  end
199
185
  end
200
186
 
201
- def test_should_send_proper_request_with_download_file
187
+ test "should_send_proper_request_with_download_file" do
202
188
  @nordea_generic_params[:command] = :download_file
203
189
  client = Sepa::Client.new(@nordea_generic_params)
204
190
  response = client.send_request
205
191
 
206
- assert response.soap.at_css('cor|downloadFilein', cor: @cor)
192
+ assert response.doc.at_css('cor|downloadFilein', cor: @cor)
207
193
 
208
194
  Dir.chdir(SCHEMA_PATH) do
209
195
  xsd = Nokogiri::XML::Schema(IO.read('soap.xsd'))
210
- assert xsd.valid?(response.soap)
196
+ assert xsd.valid?(response.doc)
211
197
  end
212
198
  end
213
199
 
214
- def test_should_send_proper_request_with_upload_file
200
+ test "should_send_proper_request_with_upload_file" do
215
201
  @nordea_generic_params[:command] = :upload_file
216
202
  client = Sepa::Client.new(@nordea_generic_params)
217
203
  response = client.send_request
218
204
 
219
- assert response.soap.at_css('cor|uploadFilein', cor: @cor)
205
+ assert response.doc.at_css('cor|uploadFilein', cor: @cor)
220
206
 
221
207
  Dir.chdir(SCHEMA_PATH) do
222
208
  xsd = Nokogiri::XML::Schema(IO.read('soap.xsd'))
223
- assert xsd.valid?(response.soap)
209
+ assert xsd.valid?(response.doc)
224
210
  end
225
211
  end
226
212
 
227
- def test_should_initialize_with_proper_cert_params
213
+ test "should_initialize_with_proper_cert_params" do
228
214
  assert Sepa::Client.new(@nordea_cert_params)
229
215
  end
230
216
 
231
- def test_should_send_proper_request_with_get_certificate
217
+ test "should_send_proper_request_with_get_certificate" do
232
218
  client = Sepa::Client.new(@nordea_cert_params)
233
219
  response = client.send_request
234
220
 
235
- assert response.soap.at_css('cer|getCertificatein')
221
+ assert response.doc.at_css('cer|getCertificatein')
236
222
 
237
223
  Dir.chdir(SCHEMA_PATH) do
238
224
  xsd = Nokogiri::XML::Schema(IO.read('soap.xsd'))
239
- assert xsd.valid?(response.soap)
225
+ assert xsd.valid?(response.doc)
240
226
  end
241
227
  end
242
228
 
243
- def test_should_check_signing_cert_request_with_create_certificate
229
+ test "should_check_signing_cert_request_with_create_certificate" do
244
230
  @danske_cert_params[:command] = :create_certificate
245
231
  @danske_cert_params.delete(:signing_cert_pkcs10)
246
232
 
@@ -249,7 +235,7 @@ class ClientTest < ActiveSupport::TestCase
249
235
  assert_includes sepa.errors.messages.to_s, SIGNING_CERT_REQUEST_ERROR_MESSAGE
250
236
  end
251
237
 
252
- def test_should_check_encryption_cert_request_with_create_certificate
238
+ test "should_check_encryption_cert_request_with_create_certificate" do
253
239
  @danske_cert_params[:command] = :create_certificate
254
240
  @danske_cert_params.delete(:encryption_cert_pkcs10)
255
241
 
@@ -258,7 +244,7 @@ class ClientTest < ActiveSupport::TestCase
258
244
  assert_includes sepa.errors.messages.to_s, ENCRYPTION_CERT_REQUEST_ERROR_MESSAGE
259
245
  end
260
246
 
261
- def test_should_check_pin_with_create_certificate
247
+ test "should_check_pin_with_create_certificate" do
262
248
  @danske_cert_params[:command] = :create_certificate
263
249
  @danske_cert_params.delete(:pin)
264
250
 
@@ -267,7 +253,7 @@ class ClientTest < ActiveSupport::TestCase
267
253
  assert_includes sepa.errors.messages.to_s, PIN_ERROR_MESSAGE
268
254
  end
269
255
 
270
- def test_should_check_encryption_cert_with_create_certificate
256
+ test "should_check_encryption_cert_with_create_certificate" do
271
257
  @danske_cert_params[:command] = :create_certificate
272
258
  @danske_cert_params.delete(:enc_cert)
273
259
 
@@ -276,4 +262,27 @@ class ClientTest < ActiveSupport::TestCase
276
262
  assert_includes sepa.errors.messages.to_s, ENCRYPTION_CERT_ERROR_MESSAGE
277
263
  end
278
264
 
265
+ test "response should be invalid on savon exception" do
266
+ # Create an observer to fake sending requests to bank
267
+ observer = Class.new {
268
+ def notify(operation_name, builder, globals, locals)
269
+ @operation_name = operation_name
270
+ @builder = builder
271
+ @globals = globals
272
+ @locals = locals
273
+ HTTPI::Response.new(500, {}, 'THE ERROR!')
274
+ end
275
+ }.new
276
+
277
+ Savon.observers << observer
278
+
279
+ client = Sepa::Client.new @nordea_generic_params
280
+ response = client.send_request
281
+
282
+ refute response.valid?, response.errors.messages
283
+ assert_includes response.errors.messages.to_s, "HTTP error (500): THE ERROR!"
284
+
285
+ Savon.observers.pop
286
+ end
287
+
279
288
  end
@@ -50,7 +50,7 @@ Sn4Uz7Zjk3UrBIbMYEv0u2mcCypwsb0nGE5/gzDPjGE9cxWW+rXARIs+sNQVClnh
50
50
  target_id: '11111111A1',
51
51
  language: 'FI',
52
52
  file_type: 'TITO',
53
- content: Base64.encode64("haisuli"),
53
+ content: encode("haisuli"),
54
54
  file_reference: "11111111A12006030329501800000014"
55
55
  }
56
56
  end
@@ -4,7 +4,7 @@ class TestSepa < ActiveSupport::TestCase
4
4
 
5
5
  def test_version_must_be_defined
6
6
  refute_nil Sepa::VERSION
7
- assert_equal "0.1.0", Sepa::VERSION
7
+ assert_equal "0.1.1", Sepa::VERSION
8
8
  end
9
9
 
10
10
  end
@@ -20,6 +20,8 @@ end
20
20
  require 'sepafm'
21
21
  require 'sepa/fixtures'
22
22
 
23
+ include Sepa::Utilities
24
+
23
25
  # Test responses
24
26
  NORDEA_TEST_RESPONSE_PATH = "#{ROOT_PATH}/test/sepa/banks/nordea/responses"
25
27
  DANSKE_TEST_RESPONSE_PATH = "#{ROOT_PATH}/test/sepa/banks/danske/responses/"
@@ -32,3 +34,16 @@ DANSKE_BANK_ROOT_CERT = File.read "#{DANSKE_TEST_KEYS_PATH}bank_root_cert.pem"
32
34
  DANSKE_OWN_ENCRYPTION_CERT = File.read "#{DANSKE_TEST_KEYS_PATH}own_enc_cert.pem"
33
35
 
34
36
  I18n.enforce_available_locales = true
37
+
38
+ # Create an observer to fake sending requests to bank
39
+ observer = Class.new {
40
+ def notify(operation_name, builder, globals, locals)
41
+ @operation_name = operation_name
42
+ @builder = builder
43
+ @globals = globals
44
+ @locals = locals
45
+ HTTPI::Response.new(200, { "Reponse is actually" => "the request, w0000t" }, locals[:xml])
46
+ end
47
+ }.new
48
+
49
+ Savon.observers << observer
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sepafm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joni Kanerva
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-06-19 00:00:00.000000000 Z
13
+ date: 2014-06-26 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: savon
@@ -136,7 +136,6 @@ files:
136
136
  - ".travis.yml"
137
137
  - Gemfile
138
138
  - LICENSE
139
- - README.md
140
139
  - Rakefile
141
140
  - lib/sepa/application_request.rb
142
141
  - lib/sepa/application_response.rb
@@ -185,6 +184,7 @@ files:
185
184
  - lib/sepa/xml_templates/soap/header.xml
186
185
  - lib/sepa/xml_templates/soap/upload_file.xml
187
186
  - lib/sepafm.rb
187
+ - readme.md
188
188
  - sepafm.gemspec
189
189
  - test/sepa/banks/danske/danske_cert_response_test.rb
190
190
  - test/sepa/banks/danske/danske_cert_soap_builder_test.rb