iso8583 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,68 @@
1
+ require 'lib/iso8583'
2
+ require 'test/unit'
3
+
4
+ class BitmapTests < Test::Unit::TestCase
5
+ def test_create_empty
6
+ b = Bitmap.new
7
+ assert_equal(b.to_s.size, 64, "proper length: 64")
8
+ b.set(112)
9
+ assert_equal(b.to_s.size, 128, "proper length: 128")
10
+ assert_equal(b.to_s, "10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000")
11
+ b.unset(112)
12
+ 5.step(20,2){|i| b.set(i)}
13
+ assert(b.to_s.size==64, "proper length: 64")
14
+ assert_equal(b.to_s, "0000101010101010101000000000000000000000000000000000000000000000")
15
+ assert b[5]
16
+ assert b[7]
17
+ assert b[11]
18
+ assert !b[12]
19
+ assert !b[199]
20
+
21
+ assert_raises(ISO8583Exception) {b.set 1000 }
22
+ assert_raises(ISO8583Exception) { b.set 1 }
23
+ assert_raises(ISO8583Exception) { b.set -1 }
24
+
25
+
26
+
27
+ end
28
+
29
+ def test_out_of_bounds_errors
30
+ b = Bitmap.new
31
+ assert_raises(ISO8583Exception) {b.set 1000 }
32
+ assert_raises(ISO8583Exception) { b.set 1 }
33
+ assert_raises(ISO8583Exception) { b.set -1 }
34
+ end
35
+
36
+ def test_parse_bmp
37
+ # 0000000001001001001001001001001001001001001001001001001001000000
38
+ # generated by: 10.step(60,3) {|i| mp.set(i)}
39
+
40
+ tst = "\x00\x49\x24\x92\x49\x24\x92\x40"
41
+ b = Bitmap.new tst
42
+ 10.step(60,3) {|i|
43
+ assert(b[i], "bit #{i} is not set.")
44
+ assert(!b[i+i], "bit #{i+i} is set.")
45
+ }
46
+
47
+ #10000000000000000001000000100000010000001000000100000010000001000000100000010000001000000100000010000001000000100000010000001000
48
+ # generated by: 20.step(128,7) {|i| mp.set(i)}
49
+ tst = "\x80\x00\x10\x20\x40\x81\x02\x04\x08\x10\x20\x40\x81\x02\x04\x08"
50
+ b = Bitmap.new tst
51
+ 20.step(128,7) {|i|
52
+ assert(b[i], "bit #{i} is not set. (128 bit map)")
53
+ assert(!b[i+i], "bit #{i+i} is set. (128 bit map)")
54
+ }
55
+ end
56
+
57
+ def test_parse_rest
58
+ tst = "\x00\x49\x24\x92\x49\x24\x92\x40\x31\x32\x33\x34"
59
+ b, rest = Bitmap.parse tst
60
+ 10.step(60,3) {|i|
61
+ assert(b[i], "bit #{i} is not set.")
62
+ assert(!b[i+i], "bit #{i+i} is set.")
63
+ }
64
+ assert_equal("1234", rest)
65
+ end
66
+
67
+ end
68
+
@@ -0,0 +1,124 @@
1
+ require 'lib/iso8583'
2
+ require 'lib/berlin'
3
+ require 'test/unit'
4
+
5
+ class MessageTest < Test::Unit::TestCase
6
+ def test_create_empty
7
+ mes = BerlinMessage.new
8
+ mes.mti = 1100
9
+ pan = 474747474747
10
+ mes.pan = pan
11
+ assert_equal pan, mes.pan
12
+ assert_equal pan, mes[2]
13
+ assert_equal pan, mes["Primary Account Number (PAN)"]
14
+ assert_equal "1100@\000\000\000\000\000\000\00012474747474747", mes.to_b
15
+
16
+ mes = BerlinMessage.new
17
+ mes.mti = "Authorization Request Response Issuer Gateway"
18
+ pan = 474747474747
19
+ mes[2] = pan
20
+ assert_equal pan, mes.pan
21
+ assert_equal pan, mes[2]
22
+ assert_equal pan, mes["Primary Account Number (PAN)"]
23
+ assert_equal "1110@\000\000\000\000\000\000\00012474747474747", mes.to_b
24
+
25
+ mes = BerlinMessage.new
26
+ mes.mti = 1420
27
+ pan = 474747474747
28
+ mes["Primary Account Number (PAN)"] = pan
29
+ assert_equal pan, mes.pan
30
+ assert_equal pan, mes[2]
31
+ assert_equal pan, mes["Primary Account Number (PAN)"]
32
+ assert_equal "1420@\000\000\000\000\000\000\00012474747474747", mes.to_b
33
+ end
34
+
35
+ def test_parse
36
+ pan = 474747474747
37
+
38
+ assert_raises(ISO8583Exception) {
39
+ mes = BerlinMessage.parse "@\000\000\000\000\000\000\00012474747474747"
40
+ }
41
+ mes = BerlinMessage.parse "1430@\000\000\000\000\000\000\00012474747474747"
42
+ assert_equal pan, mes.pan
43
+ assert_equal 1430, mes.mti
44
+ end
45
+
46
+ def test_to_s
47
+ mes = BerlinMessage.new
48
+ mes.mti = "Network Management Request Response Issuer Gateway or Acquirer Gateway"
49
+ mes[2] = 12341234
50
+ mes[3] = 1111
51
+ mes[4] = 100
52
+ mes[6] = 101
53
+ mes[7] = "0808120000"
54
+ mes[10] = 100
55
+ mes[11] = 0
56
+ mes[12] = "740808120000"
57
+ mes[14] = "1010"
58
+ mes[22] = "POSDATACODE"
59
+ mes[23] = 0
60
+ mes[24] = 1
61
+ mes[25] = 90
62
+ mes[26] = 4444
63
+ mes[30] = 150
64
+ mes[32] = 321321
65
+ mes[35] = ";123123123=123?5"
66
+ mes[37] = "123 123"
67
+ mes[38] = "90"
68
+ mes[39] = 90
69
+ mes[41] = "TermLoc!"
70
+ mes[42] = "ID Code!"
71
+ mes[43] = "Card Acceptor Name Location"
72
+ mes[49] = "840"
73
+ mes[51] = 978
74
+ mes[52] = '\x00\x01\x02\x03'
75
+ mes[53] = '\x07\x06\x05\x04'
76
+ mes[54] = "No additional amount"
77
+ mes[55] = '\x07\x06\x05\x04'
78
+ mes[56] = 88888888888
79
+ mes[59] = "I'm you're private data, data for money..."
80
+ mes[64] = "\xF0\xF0\xF0\xF0"
81
+
82
+ expected = <<-END
83
+ MTI:1814 (Network Management Request Response Issuer Gateway or Acquirer Gateway)
84
+
85
+ 002 Primary Account Number (PAN) : 12341234
86
+ 003 Processing Code : 1111
87
+ 004 Amount (Transaction) : 100
88
+ 006 Amount, Cardholder Billing : 101
89
+ 007 Date and Time, Transmission : 0808120000
90
+ 010 Conversion Rate, Cardholder Billing : 100
91
+ 011 System Trace Audit Number (STAN) : 0
92
+ 012 Date and Time, Local Transaction : 740808120000
93
+ 014 Date, Expiration : 1010
94
+ 022 POS Data Code : POSDATACODE
95
+ 023 Card Sequence Number : 0
96
+ 024 Function Code : 1
97
+ 025 Message Reason Code : 90
98
+ 026 Card Acceptor Business Code : 4444
99
+ 030 Amounts, Original : 150
100
+ 032 Acquiring Institution Identification Code : 321321
101
+ 035 Track 2 Data : ;123123123=123?5
102
+ 037 Retrieval Reference Number : 123 123
103
+ 038 Approval Code : 90
104
+ 039 Action Code : 90
105
+ 041 Card Acceptor Terminal Identification : TermLoc!
106
+ 042 Card Acceptor Identification Code : ID Code!
107
+ 043 Card Acceptor Name/Location : Card Acceptor Name Location
108
+ 049 Currency Code, Transaction : 840
109
+ 051 Currency Code, Cardholder Billing : 978
110
+ 052 Personal Identification Number (PIN) Data : \\x00\\x01\\x02\\x03
111
+ 053 Security Related Control Information : \\x07\\x06\\x05\\x04
112
+ 054 Amounts, Additional : No additional amount
113
+ 055 Integrated Circuit Card (ICC) System Related Data : \\x07\\x06\\x05\\x04
114
+ 056 Original Data Elements : 88888888888
115
+ 059 Additional Data - Private : I'm you're private data, data for money...
116
+ 064 Message Authentication Code (MAC) Field : \360\360\360\360
117
+ END
118
+ assert_equal expected, mes.to_s
119
+ end
120
+
121
+
122
+
123
+ end
124
+
@@ -0,0 +1,90 @@
1
+ require 'test/unit'
2
+ require 'lib/iso8583'
3
+
4
+ class FieldTest < Test::Unit::TestCase
5
+
6
+
7
+
8
+ def test_MMDDhhmmssCodec
9
+ dt = MMDDhhmmssCodec.decode "1212121212"
10
+ assert_equal DateTime, dt.class
11
+ assert_equal 12, dt.month
12
+ assert_equal 12, dt.day
13
+ assert_equal 12, dt.hour
14
+ assert_equal 12, dt.min
15
+ assert_equal 12, dt.sec
16
+
17
+
18
+ assert_raise(ISO8583Exception) {
19
+ dt = MMDDhhmmssCodec.decode "1312121212"
20
+ }
21
+
22
+ assert_raise(ISO8583Exception) {
23
+ dt = MMDDhhmmssCodec.encode "1312121212"
24
+ }
25
+
26
+ assert_equal "1212121212", MMDDhhmmssCodec.encode("1212121212")
27
+ end
28
+
29
+ def test_YYMMDDhhmmssCodec
30
+ dt = YYMMDDhhmmssCodec.decode "081212121212"
31
+ assert_equal DateTime, dt.class
32
+ assert_equal 2008, dt.year
33
+ assert_equal 12, dt.month
34
+ assert_equal 12, dt.day
35
+ assert_equal 12, dt.hour
36
+ assert_equal 12, dt.min
37
+ assert_equal 12, dt.sec
38
+
39
+
40
+ assert_raise(ISO8583Exception) {
41
+ dt = YYMMDDhhmmssCodec.decode "091312121212"
42
+ }
43
+
44
+ assert_raise(ISO8583Exception) {
45
+ dt = YYMMDDhhmmssCodec.encode "091312121212"
46
+ }
47
+
48
+ assert_equal "091212121212", YYMMDDhhmmssCodec.encode("091212121212")
49
+
50
+ end
51
+ def test_YYMMCodec
52
+ dt = YYMMCodec.decode "0812"
53
+ assert_equal DateTime, dt.class
54
+ assert_equal 2008, dt.year
55
+ assert_equal 12, dt.month
56
+
57
+
58
+ assert_raise(ISO8583Exception) {
59
+ dt = YYMMCodec.decode "0913"
60
+ }
61
+
62
+ assert_raise(ISO8583Exception) {
63
+ dt = YYMMCodec.encode "0913"
64
+ }
65
+
66
+ assert_equal "0912", YYMMCodec.encode("0912")
67
+
68
+ end
69
+
70
+ def test_AN_Codec
71
+ assert_raise(ISO8583Exception) {
72
+ dt = AN_Codec.encode "!!!"
73
+ }
74
+ assert_equal "bla", AN_Codec.encode("bla")
75
+ assert_equal "bla", AN_Codec.decode("bla")
76
+ end
77
+
78
+ def test_Track2_Codec
79
+ assert_raise(ISO8583Exception) {
80
+ dt = Track2.encode "!!!"
81
+ }
82
+ assert_raise(ISO8583Exception) {
83
+ dt = Track2.encode ";12312312=123?5"
84
+ }
85
+ assert_equal ";123123123=123?5", Track2.encode(";123123123=123?5")
86
+ assert_equal ";123123123=123?5", Track2.decode(";123123123=123?5")
87
+ end
88
+
89
+
90
+ end
@@ -0,0 +1,164 @@
1
+ require 'test/unit'
2
+ require 'lib/iso8583'
3
+
4
+ class FieldTest < Test::Unit::TestCase
5
+
6
+
7
+
8
+ def test_LLL
9
+ value, rest = LLL.parse "123456"
10
+ assert_equal 123, value
11
+ assert_equal "456", rest
12
+
13
+ assert_raise(ISO8583ParseException) {
14
+ l,rest = LLL.parse "12"
15
+ }
16
+
17
+ enc = LLL.encode 123
18
+ assert_equal "\x31\x32\x33", enc
19
+
20
+ enc = LLL.encode "123"
21
+ assert_equal "\x31\x32\x33", enc
22
+
23
+ enc = LLL.encode 12
24
+ assert_equal "\x30\x31\x32", enc
25
+
26
+ #enc = LLL.encode "012"
27
+ #assert_equal "\x30\x31\x32", enc
28
+
29
+
30
+ assert_raise(ISO8583Exception) {
31
+ enc = LLL.encode 1234
32
+ }
33
+
34
+ assert_raise(ISO8583Exception) {
35
+ enc = LLL.encode "1234"
36
+ }
37
+
38
+
39
+
40
+ end
41
+
42
+ def test_LLVAR_N
43
+ value, rest = LLVAR_N.parse "021234"
44
+ assert_equal 12, value
45
+ assert_equal "34", rest
46
+
47
+ value, rest = LLLVAR_N.parse "0041234"
48
+ assert_equal 1234, value
49
+ assert_equal "", rest
50
+ assert_raise(ISO8583ParseException) {
51
+ l,rest = LLLVAR_N.parse "12"
52
+ }
53
+ assert_raise(ISO8583ParseException) {
54
+ l,rest = LLVAR_N.parse "12123"
55
+ }
56
+
57
+ enc = LLVAR_N.encode 1234
58
+ assert_equal "041234", enc
59
+
60
+ enc = LLVAR_N.encode 123412341234
61
+ assert_equal "12123412341234", enc
62
+
63
+ assert_raise(ISO8583Exception) {
64
+ enc = LLVAR_N.encode "1234ABCD"
65
+ }
66
+
67
+ enc = LLLVAR_N.encode "123412341234"
68
+ assert_equal "012123412341234", enc
69
+
70
+ assert_raise(ISO8583Exception) {
71
+ enc = LLLVAR_N.encode "1234ABCD"
72
+ }
73
+
74
+ end
75
+ def test_LLVAR_Z
76
+ value, rest = LLVAR_Z.parse "16;123123123=123?5"+"021234"
77
+ assert_equal ";123123123=123?5", value
78
+ assert_equal "021234", rest
79
+
80
+ value, rest = LLVAR_Z.parse "16;123123123=123?5"
81
+ assert_equal ";123123123=123?5", value
82
+ assert_equal "", rest
83
+ assert_raise(ISO8583ParseException) {
84
+ l,rest = LLVAR_Z.parse "12"
85
+ }
86
+ assert_raise(ISO8583ParseException) {
87
+ l,rest = LLVAR_Z.parse "17;123123123=123?5"
88
+ }
89
+
90
+ enc = LLVAR_Z.encode ";123123123=123?5"
91
+ assert_equal "16;123123123=123?5", enc
92
+
93
+
94
+ assert_raise(ISO8583Exception) {
95
+ enc = LLVAR_Z.encode "1234ABCD"
96
+ }
97
+
98
+
99
+
100
+
101
+ end
102
+
103
+ def test_AN
104
+ fld = AN.dup
105
+ fld.length = 3
106
+ value, rest = fld.parse "1234"
107
+ assert_equal "123", value
108
+ assert_equal "4", rest
109
+
110
+ assert_raise(ISO8583ParseException) {
111
+ fld.parse "12"
112
+ }
113
+
114
+ assert_raise(ISO8583Exception) {
115
+ fld.encode "888810"
116
+ }
117
+ end
118
+
119
+ def test_ANP
120
+ fld = ANP.dup
121
+ fld.length = 3
122
+ value, rest = fld.parse "1234"
123
+ assert_equal "123", value
124
+ assert_equal "4", rest
125
+
126
+ assert_raise(ISO8583ParseException) {
127
+ fld.parse "12"
128
+ }
129
+
130
+ assert_equal "10 ", fld.encode("10")
131
+ end
132
+
133
+ def test_ANS
134
+ fld = ANS.dup
135
+ fld.length = 3
136
+ value, rest = fld.parse "1234"
137
+ assert_equal "123", value
138
+ assert_equal "4", rest
139
+
140
+ assert_raise(ISO8583ParseException) {
141
+ fld.parse "12"
142
+ }
143
+
144
+ assert_equal "10 ", fld.encode("10")
145
+ assert_equal ["1!", "a"], fld.parse("1! a")
146
+ end
147
+ def test_B
148
+ fld = B.dup
149
+ fld.length = 3
150
+ value, rest = fld.parse "\000234"
151
+ assert_equal "\00023", value
152
+ assert_equal "4", rest
153
+
154
+ assert_raise(ISO8583ParseException) {
155
+ fld.parse "12"
156
+ }
157
+
158
+ assert_equal "10\000", fld.encode("10")
159
+ assert_equal ["1! ", "a"], fld.parse("1! a")
160
+ assert_equal ["1!", ""], fld.parse("1!\000")
161
+ end
162
+
163
+
164
+ end
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: iso8583
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Tim Becker
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-08-15 00:00:00 +02:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Ruby implementation of ISO 8583 financial messaging
17
+ email: tim.becker@kuriositaet.de
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - lib/berlin.rb
26
+ - lib/bitmap.rb
27
+ - lib/codec.rb
28
+ - lib/exception.rb
29
+ - lib/field.rb
30
+ - lib/fields.rb
31
+ - lib/iso8583.rb
32
+ - lib/message.rb
33
+ - AUTHORS
34
+ - CHANGELOG
35
+ - LICENSE
36
+ - Rakefile
37
+ - README
38
+ - TODO
39
+ - test/BitmapTests.rb
40
+ - test/message_test.rb
41
+ - test/test_codec.rb
42
+ - test/test_fields.rb
43
+ has_rdoc: true
44
+ homepage: http://iso8583.rubyforge.org/
45
+ post_install_message:
46
+ rdoc_options: []
47
+
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: "0"
55
+ version:
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: "0"
61
+ version:
62
+ requirements:
63
+ - none
64
+ rubyforge_project: iso8583
65
+ rubygems_version: 1.3.1
66
+ signing_key:
67
+ specification_version: 2
68
+ summary: "iso8583: Ruby implementation of ISO 8583 financial messaging"
69
+ test_files: []
70
+