sepafm 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/sepa/attribute_checks.rb +13 -4
- data/lib/sepa/banks/danske/danske_response.rb +4 -12
- data/lib/sepa/response.rb +19 -2
- data/lib/sepa/version.rb +1 -1
- data/test/sepa/banks/danske/danske_cert_response_test.rb +14 -6
- data/test/sepa/banks/nordea/nordea_response_test.rb +3 -19
- data/test/sepa/client_test.rb +1 -1
- data/test/sepa/sepa_test.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e3a2be4081eef183a47eae2d15775937b0afdeb7
|
4
|
+
data.tar.gz: 84c058d1e86826ddc435abb1aaa66ff4c73d4a7a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c4c73d8aa2da66edc8d915bd0690230e40c944e91acc5fc4de51134830ba5dc3e797d42d6b73a155632d1330c92b1d08cf7594589aa7aebad1b0c332cbdc6ff5
|
7
|
+
data.tar.gz: 4388e0c0357a779f637b731ff726f6cc81585c71bf88bddadeb160d37f7ea535d7e3f742c7f080cad204aa33b135ec7547ce75d31bcb26766e04723a68ea7dbc
|
@@ -71,15 +71,24 @@ module Sepa
|
|
71
71
|
end
|
72
72
|
|
73
73
|
def check_presence_and_length(attribute, length, error_message)
|
74
|
-
|
75
|
-
|
76
|
-
|
74
|
+
check = true
|
75
|
+
check &&= send(attribute)
|
76
|
+
check &&= send(attribute).respond_to? :size
|
77
|
+
check &&= send(attribute).size < length
|
78
|
+
check &&= send(attribute).size > 0
|
79
|
+
|
80
|
+
errors.add(attribute, error_message) unless check
|
77
81
|
end
|
78
82
|
|
79
83
|
def check_content
|
80
84
|
return unless command == :upload_file
|
81
85
|
|
82
|
-
|
86
|
+
check = true
|
87
|
+
check &&= content
|
88
|
+
check &&= content.respond_to? :length
|
89
|
+
check &&= content.length > 0
|
90
|
+
|
91
|
+
errors.add(:content, CONTENT_ERROR_MESSAGE) unless check
|
83
92
|
end
|
84
93
|
|
85
94
|
def check_pin
|
@@ -45,7 +45,7 @@ module Sepa
|
|
45
45
|
end
|
46
46
|
|
47
47
|
def certificate
|
48
|
-
if
|
48
|
+
if [:get_bank_certificate, :create_certificate].include? @command
|
49
49
|
@certificate ||= begin
|
50
50
|
extract_cert(doc, 'X509Certificate', DSIG)
|
51
51
|
end
|
@@ -72,9 +72,9 @@ module Sepa
|
|
72
72
|
def find_node_by_uri(uri)
|
73
73
|
return super unless [:get_bank_certificate, :create_certificate].include? @command
|
74
74
|
|
75
|
-
|
76
|
-
|
77
|
-
|
75
|
+
doc_without_signature = doc.dup
|
76
|
+
doc_without_signature.at('xmlns|Signature', xmlns: DSIG).remove
|
77
|
+
doc_without_signature.at("[xml|id='#{uri}']")
|
78
78
|
end
|
79
79
|
|
80
80
|
def decrypt_application_response
|
@@ -129,13 +129,5 @@ module Sepa
|
|
129
129
|
nil
|
130
130
|
end
|
131
131
|
|
132
|
-
def verify_signature
|
133
|
-
super unless [:get_bank_certificate, :create_certificate].include? @command
|
134
|
-
end
|
135
|
-
|
136
|
-
def validate_hashes
|
137
|
-
super unless [:get_bank_certificate, :create_certificate].include? @command
|
138
|
-
end
|
139
|
-
|
140
132
|
end
|
141
133
|
end
|
data/lib/sepa/response.rb
CHANGED
@@ -8,7 +8,7 @@ module Sepa
|
|
8
8
|
|
9
9
|
validate :document_must_validate_against_schema
|
10
10
|
validate :client_errors
|
11
|
-
validate :
|
11
|
+
validate :validate_response_code
|
12
12
|
validate :validate_hashes
|
13
13
|
validate :verify_signature
|
14
14
|
validate :verify_certificate
|
@@ -29,6 +29,9 @@ module Sepa
|
|
29
29
|
# i.e. verbose: true
|
30
30
|
def hashes_match?(options = {})
|
31
31
|
digests = find_digest_values
|
32
|
+
|
33
|
+
return false if digests.empty?
|
34
|
+
|
32
35
|
nodes = find_nodes_to_verify(digests)
|
33
36
|
|
34
37
|
verified_digests = digests.select do |uri, digest|
|
@@ -176,7 +179,7 @@ module Sepa
|
|
176
179
|
doc.at("[xmlns|Id='#{uri}']", xmlns: OASIS_UTILITY)
|
177
180
|
end
|
178
181
|
|
179
|
-
def
|
182
|
+
def validate_response_code
|
180
183
|
return if @error
|
181
184
|
|
182
185
|
unless %w(00 24).include? response_code
|
@@ -185,22 +188,36 @@ module Sepa
|
|
185
188
|
end
|
186
189
|
|
187
190
|
def validate_hashes
|
191
|
+
return if @error
|
192
|
+
return unless response_code_is_ok?
|
188
193
|
unless hashes_match?
|
189
194
|
errors.add(:base, HASH_ERROR_MESSAGE)
|
190
195
|
end
|
191
196
|
end
|
192
197
|
|
193
198
|
def verify_signature
|
199
|
+
return if @error
|
200
|
+
return unless response_code_is_ok?
|
201
|
+
|
194
202
|
unless signature_is_valid?
|
195
203
|
errors.add(:base, SIGNATURE_ERROR_MESSAGE)
|
196
204
|
end
|
197
205
|
end
|
198
206
|
|
199
207
|
def verify_certificate
|
208
|
+
return if @error
|
209
|
+
return unless response_code_is_ok?
|
210
|
+
|
200
211
|
unless certificate_is_trusted?
|
201
212
|
errors.add(:base, 'The certificate in the response is not trusted')
|
202
213
|
end
|
203
214
|
end
|
204
215
|
|
216
|
+
def response_code_is_ok?
|
217
|
+
return true if %w(00 24).include? response_code
|
218
|
+
|
219
|
+
false
|
220
|
+
end
|
221
|
+
|
205
222
|
end
|
206
223
|
end
|
data/lib/sepa/version.rb
CHANGED
@@ -65,23 +65,31 @@ class DanskeCertResponseTest < ActiveSupport::TestCase
|
|
65
65
|
assert ca_certificate.respond_to? :sign
|
66
66
|
end
|
67
67
|
|
68
|
-
# TODO: Get test to pass
|
69
68
|
test 'hashes should match' do
|
70
|
-
|
71
|
-
|
69
|
+
assert @get_bank_cert_response.hashes_match?
|
72
70
|
assert @create_certificate_response.hashes_match?
|
73
71
|
end
|
74
72
|
|
75
|
-
|
76
|
-
|
77
|
-
|
73
|
+
test 'hashes shouldnt match if they are not found' do
|
74
|
+
refute @get_bank_certificate_not_ok_response.hashes_match?
|
75
|
+
end
|
78
76
|
|
77
|
+
test 'hashes shouldnt match when data is corrupted' do
|
79
78
|
assert_output /These digests failed to verify: {"#response"=>"2vCYl3h7ksRgk7IyV2axgpXxTWM="}/ do
|
80
79
|
@create_certificate_response.doc.at('xmlns|ReturnText', xmlns: DANSKE_PKI).content = 'kana'
|
81
80
|
refute @create_certificate_response.hashes_match?({ verbose: true })
|
82
81
|
end
|
83
82
|
end
|
84
83
|
|
84
|
+
test 'signatures in correct responses should verify' do
|
85
|
+
assert @get_bank_cert_response.signature_is_valid?
|
86
|
+
assert @create_certificate_response.signature_is_valid?
|
87
|
+
end
|
88
|
+
|
89
|
+
test 'signature should not verify if not found' do
|
90
|
+
refute @get_bank_certificate_not_ok_response.signature_is_valid?
|
91
|
+
end
|
92
|
+
|
85
93
|
test 'should not be valid when response code is not 00 in get bank certificate' do
|
86
94
|
refute @get_bank_certificate_not_ok_response.valid?
|
87
95
|
refute_empty @get_bank_certificate_not_ok_response.errors.messages
|
@@ -65,7 +65,7 @@ class NordeaResponseTest < ActiveSupport::TestCase
|
|
65
65
|
@body_altered = Sepa::NordeaResponse.new options
|
66
66
|
end
|
67
67
|
|
68
|
-
|
68
|
+
test 'valid responses should be valid' do
|
69
69
|
assert @dfl.valid?, @dfl.errors.messages
|
70
70
|
assert @uf.valid?, @uf.errors.messages
|
71
71
|
assert @df_tito.valid?, @df_tito.errors.messages
|
@@ -74,12 +74,12 @@ class NordeaResponseTest < ActiveSupport::TestCase
|
|
74
74
|
assert @gc.valid?, @gc.errors.messages
|
75
75
|
end
|
76
76
|
|
77
|
-
|
77
|
+
test 'should fail with improper params' do
|
78
78
|
a = Sepa::NordeaResponse.new({ response: "Jees", command: 'not'})
|
79
79
|
refute a.valid?
|
80
80
|
end
|
81
81
|
|
82
|
-
|
82
|
+
test 'should complain if application response is not valid against schema' do
|
83
83
|
a = Sepa::NordeaResponse.new({ response: "<ar>text</ar>", command: 'notvalid' })
|
84
84
|
refute a.valid?
|
85
85
|
end
|
@@ -121,7 +121,6 @@ class NordeaResponseTest < ActiveSupport::TestCase
|
|
121
121
|
|
122
122
|
# TODO: Implement test
|
123
123
|
test 'response should not be valid when wrong certificate is embedded in soap' do
|
124
|
-
|
125
124
|
end
|
126
125
|
|
127
126
|
test 'signature should verify with correct responses' do
|
@@ -144,9 +143,6 @@ class NordeaResponseTest < ActiveSupport::TestCase
|
|
144
143
|
assert_equal File.read("#{NORDEA_TEST_RESPONSE_PATH}/dfl.xml"), @dfl.to_s
|
145
144
|
end
|
146
145
|
|
147
|
-
##
|
148
|
-
# Tests for download file command
|
149
|
-
|
150
146
|
# tito: Electronic account statement
|
151
147
|
def test_content_can_be_extracted_when_file_type_is_tito
|
152
148
|
refute_nil @df_tito.content
|
@@ -157,9 +153,6 @@ class NordeaResponseTest < ActiveSupport::TestCase
|
|
157
153
|
refute_nil @df_ktl.content
|
158
154
|
end
|
159
155
|
|
160
|
-
##
|
161
|
-
# Tests for download file list command
|
162
|
-
|
163
156
|
test 'content can be extracted from download file list response' do
|
164
157
|
refute_nil @dfl.content
|
165
158
|
end
|
@@ -168,23 +161,14 @@ class NordeaResponseTest < ActiveSupport::TestCase
|
|
168
161
|
assert_equal 14, @dfl.file_references.length
|
169
162
|
end
|
170
163
|
|
171
|
-
##
|
172
|
-
# Tests for upload file list command
|
173
|
-
|
174
164
|
test 'upload file list command returns a response' do
|
175
165
|
refute_nil @uf.content
|
176
166
|
end
|
177
167
|
|
178
|
-
##
|
179
|
-
# Tests for get user info command
|
180
|
-
|
181
168
|
test 'content can be extracted from get user info response' do
|
182
169
|
refute_nil @gui.content
|
183
170
|
end
|
184
171
|
|
185
|
-
##
|
186
|
-
# Tests for get certificate command
|
187
|
-
|
188
172
|
test 'certificate can be extracted from get certificate response' do
|
189
173
|
assert_nothing_raised do
|
190
174
|
x509_certificate @gc.own_signing_certificate
|
data/test/sepa/client_test.rb
CHANGED
@@ -297,7 +297,7 @@ class ClientTest < ActiveSupport::TestCase
|
|
297
297
|
end
|
298
298
|
|
299
299
|
test "should_check_pin_with_create_certificate" do
|
300
|
-
invalid_pins = [nil, false, true]
|
300
|
+
invalid_pins = [nil, false, true, ""]
|
301
301
|
|
302
302
|
invalid_pins.each do |invalid_pin|
|
303
303
|
@danske_create_certificate_params[:command] = :create_certificate
|
data/test/sepa/sepa_test.rb
CHANGED