ydim 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +6 -0
- data/LICENSE.txt +339 -0
- data/Manifest.txt +43 -0
- data/README.txt +21 -0
- data/Rakefile +28 -0
- data/bin/ydim-edit +55 -0
- data/bin/ydim-inject +33 -0
- data/bin/ydimd +55 -0
- data/install.rb +1098 -0
- data/lib/ydim/autoinvoicer.rb +41 -0
- data/lib/ydim/client.rb +29 -0
- data/lib/ydim/config.rb +32 -0
- data/lib/ydim/currency_converter.rb +28 -0
- data/lib/ydim/currency_updater.rb +39 -0
- data/lib/ydim/debitor.rb +86 -0
- data/lib/ydim/factory.rb +58 -0
- data/lib/ydim/invoice.rb +146 -0
- data/lib/ydim/item.rb +36 -0
- data/lib/ydim/mail.rb +95 -0
- data/lib/ydim/odba.rb +39 -0
- data/lib/ydim/root_session.rb +143 -0
- data/lib/ydim/root_user.rb +14 -0
- data/lib/ydim/server.rb +165 -0
- data/lib/ydim/smtp_tls.rb +58 -0
- data/lib/ydim/util.rb +16 -0
- data/test/data/search.html +58 -0
- data/test/stub/odba.rb +21 -0
- data/test/suite.rb +10 -0
- data/test/test_autoinvoicer.rb +51 -0
- data/test/test_currency_converter.rb +37 -0
- data/test/test_currency_updater.rb +45 -0
- data/test/test_debitor.rb +96 -0
- data/test/test_factory.rb +99 -0
- data/test/test_invoice.rb +131 -0
- data/test/test_item.rb +41 -0
- data/test/test_mail.rb +94 -0
- data/test/test_root_session.rb +347 -0
- data/test/test_root_user.rb +20 -0
- data/test/test_server.rb +142 -0
- metadata +137 -0
@@ -0,0 +1,347 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# TestRootSession -- ydim -- 10.01.2006 -- hwyss@ywesee.com
|
3
|
+
|
4
|
+
|
5
|
+
$: << File.expand_path('../lib', File.dirname(__FILE__))
|
6
|
+
|
7
|
+
require 'test/unit'
|
8
|
+
require 'test/stub/odba'
|
9
|
+
require 'ydim/root_session'
|
10
|
+
require 'flexmock'
|
11
|
+
|
12
|
+
module YDIM
|
13
|
+
class TestRootSession < Test::Unit::TestCase
|
14
|
+
include FlexMock::TestCase
|
15
|
+
def setup
|
16
|
+
@user = FlexMock.new
|
17
|
+
@session = RootSession.new(@user)
|
18
|
+
@serv = FlexMock.new
|
19
|
+
@session.serv = @serv
|
20
|
+
end
|
21
|
+
def assert_logged(*levels, &block)
|
22
|
+
@mock_logger = flexmock("logger")
|
23
|
+
levels.uniq.each { |level|
|
24
|
+
@mock_logger.should_receive(level).times(levels.select { |l|
|
25
|
+
l == level}.size).and_return { |usr, blc|
|
26
|
+
assert_equal('user', usr)
|
27
|
+
blc.call
|
28
|
+
}
|
29
|
+
}
|
30
|
+
@user.should_receive(:unique_id).and_return { 'user' }
|
31
|
+
@serv.should_receive(:logger).and_return { @mock_logger }
|
32
|
+
block.call
|
33
|
+
end
|
34
|
+
def test_add_items
|
35
|
+
config = FlexMock.new('config')
|
36
|
+
config.should_receive(:vat_rate).and_return { 7.6 }
|
37
|
+
invoice = FlexMock.new('invoice')
|
38
|
+
invoice.should_receive(:suppress_vat).and_return { false }
|
39
|
+
@serv.should_receive(:config).and_return { config }
|
40
|
+
flexstub(Invoice).should_receive(:find_by_unique_id)\
|
41
|
+
.with('123').and_return(invoice)
|
42
|
+
items = [
|
43
|
+
{ :quantity => 1, :unit => 'St�ck', :text => 'Item 1', :price => 10.00,
|
44
|
+
:vat_rate => 7.6, :data => {}, :time => Time.now, :expiry_time => nil},
|
45
|
+
{ :quantity => 2, :unit => 'St�ck', :text => 'Item 2', :price => 20.00,
|
46
|
+
:vat_rate => 7.6, :data => {}, :time => Time.now, :expiry_time => nil},
|
47
|
+
{ :quantity => 3, :unit => 'St�ck', :text => 'Item 3', :price => 30.00,
|
48
|
+
:vat_rate => 7.6, :data => {}, :time => Time.now, :expiry_time => nil},
|
49
|
+
{ :quantity => 4, :unit => 'St�ck', :text => 'Item 4', :price => 40.00,
|
50
|
+
:vat_rate => 7.6, :data => {}, :time => Time.now, :expiry_time => nil},
|
51
|
+
]
|
52
|
+
added_items = []
|
53
|
+
invoice.should_receive(:add_item).and_return { |item|
|
54
|
+
assert_instance_of(Item, item)
|
55
|
+
added_items.push(item)
|
56
|
+
}
|
57
|
+
invoice.should_receive(:items).and_return { added_items }
|
58
|
+
invoice.should_receive(:odba_store, 1).and_return {}
|
59
|
+
retval = nil
|
60
|
+
assert_logged(:debug, :debug) {
|
61
|
+
retval = @session.add_items(123, items)
|
62
|
+
}
|
63
|
+
assert_equal(added_items, retval)
|
64
|
+
end
|
65
|
+
def test_autoinvoice
|
66
|
+
inv = flexmock('autoinvoice')
|
67
|
+
flexstub(AutoInvoice).should_receive(:find_by_unique_id)\
|
68
|
+
.with("123").times(1).and_return(inv)
|
69
|
+
retval = nil
|
70
|
+
assert_logged(:debug) {
|
71
|
+
retval = @session.autoinvoice(123)
|
72
|
+
}
|
73
|
+
assert_equal(inv, retval)
|
74
|
+
end
|
75
|
+
def test_autoinvoice__invalid_id
|
76
|
+
inv = flexmock('autoinvoice')
|
77
|
+
flexstub(AutoInvoice).should_receive(:find_by_unique_id)\
|
78
|
+
.times(1)
|
79
|
+
retval = nil
|
80
|
+
assert_logged(:debug, :error) {
|
81
|
+
assert_raises(IndexError) {
|
82
|
+
@session.autoinvoice(123)
|
83
|
+
}
|
84
|
+
}
|
85
|
+
end
|
86
|
+
def test_collect_garbage
|
87
|
+
inv1 = flexmock('Invoice1')
|
88
|
+
inv1.should_receive(:deleted).and_return(true)
|
89
|
+
inv1.should_receive(:info).and_return('info1')
|
90
|
+
inv1.should_receive(:odba_delete).times(1)\
|
91
|
+
.and_return { assert(true) }
|
92
|
+
inv1.should_receive(:debitor_id).and_return(2)
|
93
|
+
inv2 = flexmock('Invoice2')
|
94
|
+
inv2.should_receive(:deleted).and_return(false)
|
95
|
+
inv2.should_receive(:debitor_id).and_return(3)
|
96
|
+
flexstub(Invoice).should_receive(:odba_extent)\
|
97
|
+
.and_return { |blk| [inv1, inv2].each(&blk) }
|
98
|
+
res = nil
|
99
|
+
assert_logged(:info) {
|
100
|
+
res = @session.collect_garbage
|
101
|
+
}
|
102
|
+
assert_equal(['info1'], res)
|
103
|
+
end
|
104
|
+
def test_collect_garbage__debitor
|
105
|
+
inv1 = flexmock('Invoice1')
|
106
|
+
inv1.should_receive(:deleted).and_return(true)
|
107
|
+
inv1.should_receive(:info).and_return('info1')
|
108
|
+
inv1.should_receive(:odba_delete).times(1)\
|
109
|
+
.and_return { assert(true) }
|
110
|
+
inv1.should_receive(:debitor_id).and_return(2)
|
111
|
+
inv2 = flexmock('Invoice2')
|
112
|
+
inv2.should_receive(:deleted).and_return(true)
|
113
|
+
inv2.should_receive(:debitor_id).and_return(3)
|
114
|
+
flexstub(Invoice).should_receive(:odba_extent)\
|
115
|
+
.and_return { |blk| [inv1, inv2].each(&blk) }
|
116
|
+
res = nil
|
117
|
+
assert_logged(:info) {
|
118
|
+
res = @session.collect_garbage(2)
|
119
|
+
}
|
120
|
+
assert_equal(['info1'], res)
|
121
|
+
end
|
122
|
+
def test_create_autoinvoice
|
123
|
+
factory = FlexMock.new
|
124
|
+
flexstub(Debitor).should_receive(:find_by_unique_id).with("1")
|
125
|
+
@serv.should_receive(:factory).and_return { factory }
|
126
|
+
assert_logged(:debug, :debug, :debug, :debug, :error) {
|
127
|
+
assert_raises(IndexError) { @session.create_autoinvoice(1) }
|
128
|
+
}
|
129
|
+
debitor = flexmock('Debitor')
|
130
|
+
flexstub(Debitor).should_receive(:find_by_unique_id).with("2")\
|
131
|
+
.and_return(debitor)
|
132
|
+
factory.should_receive(:create_autoinvoice).and_return { |deb|
|
133
|
+
assert_equal(debitor, deb)
|
134
|
+
'invoice created by Factory'
|
135
|
+
}
|
136
|
+
invoice = nil
|
137
|
+
assert_nothing_raised { invoice = @session.create_autoinvoice(2) }
|
138
|
+
assert_equal('invoice created by Factory', invoice)
|
139
|
+
end
|
140
|
+
def test_create_debitor
|
141
|
+
id_server = FlexMock.new
|
142
|
+
@serv.should_receive(:id_server).and_return { id_server }
|
143
|
+
id_server.should_receive(:next_id).and_return { |key|
|
144
|
+
assert_equal(:debitor, key)
|
145
|
+
23
|
146
|
+
}
|
147
|
+
debitor = nil
|
148
|
+
deb = flexmock('Debitor')
|
149
|
+
flexstub(Debitor).should_receive(:new).and_return(deb)
|
150
|
+
deb.should_receive(:odba_store).times(1).and_return {
|
151
|
+
assert(true)
|
152
|
+
deb
|
153
|
+
}
|
154
|
+
assert_logged(:info) {
|
155
|
+
debitor = @session.create_debitor
|
156
|
+
}
|
157
|
+
assert_equal(deb, debitor)
|
158
|
+
end
|
159
|
+
def test_create_invoice
|
160
|
+
factory = FlexMock.new
|
161
|
+
flexstub(Debitor).should_receive(:find_by_unique_id).with("1")
|
162
|
+
@serv.should_receive(:factory).and_return { factory }
|
163
|
+
assert_logged(:debug, :debug, :debug, :debug, :error) {
|
164
|
+
assert_raises(IndexError) { @session.create_invoice(1) }
|
165
|
+
}
|
166
|
+
debitor = flexmock('Debitor')
|
167
|
+
flexstub(Debitor).should_receive(:find_by_unique_id).with("2")\
|
168
|
+
.and_return(debitor)
|
169
|
+
factory.should_receive(:create_invoice).and_return { |deb|
|
170
|
+
assert_equal(debitor, deb)
|
171
|
+
'invoice created by Factory'
|
172
|
+
}
|
173
|
+
invoice = nil
|
174
|
+
assert_nothing_raised { invoice = @session.create_invoice(2) }
|
175
|
+
assert_equal('invoice created by Factory', invoice)
|
176
|
+
end
|
177
|
+
def test_currency_converter
|
178
|
+
conv = flexmock('converter')
|
179
|
+
conv.should_receive(:drb_dup).and_return {
|
180
|
+
assert(true)
|
181
|
+
'duplicate'
|
182
|
+
}
|
183
|
+
@serv.should_receive(:currency_converter).and_return(conv)
|
184
|
+
res = nil
|
185
|
+
assert_logged(:debug) { res = @session.currency_converter }
|
186
|
+
assert_equal('duplicate', res)
|
187
|
+
end
|
188
|
+
def test_debitor
|
189
|
+
flexstub(Debitor).should_receive(:find_by_unique_id).with("1")
|
190
|
+
assert_logged(:debug, :error) {
|
191
|
+
assert_raises(IndexError) { @session.debitor(1) }
|
192
|
+
}
|
193
|
+
debitor = flexmock('Debitor')
|
194
|
+
flexstub(Debitor).should_receive(:find_by_unique_id).with("2")\
|
195
|
+
.and_return(debitor)
|
196
|
+
assert_logged(:debug) {
|
197
|
+
assert_equal(debitor, @session.debitor(2))
|
198
|
+
}
|
199
|
+
end
|
200
|
+
def test_debitors
|
201
|
+
flexstub(Debitor).should_receive(:odba_extent).and_return(['deb1'])
|
202
|
+
res = nil
|
203
|
+
assert_logged(:debug) { res = @session.debitors }
|
204
|
+
assert_equal(['deb1'], res)
|
205
|
+
end
|
206
|
+
def test_delete_autoinvoice
|
207
|
+
inv = flexmock('autoinvoice')
|
208
|
+
inv.should_receive(:odba_delete).times(1)
|
209
|
+
flexstub(AutoInvoice).should_receive(:find_by_unique_id)\
|
210
|
+
.with("17").times(1).and_return(inv)
|
211
|
+
assert_logged(:debug, :debug) {
|
212
|
+
@session.delete_autoinvoice(17)
|
213
|
+
}
|
214
|
+
end
|
215
|
+
def test_delete_item
|
216
|
+
invoice = FlexMock.new
|
217
|
+
item1 = FlexMock.new
|
218
|
+
item1.should_receive(:index).and_return { 0 }
|
219
|
+
item2 = FlexMock.new
|
220
|
+
item2.should_receive(:index).and_return { 1 }
|
221
|
+
item3 = FlexMock.new
|
222
|
+
item3.should_receive(:index).and_return { 2 }
|
223
|
+
items = [item1, item2, item3]
|
224
|
+
flexstub(Invoice).should_receive(:find_by_unique_id)\
|
225
|
+
.with('3').and_return(invoice)
|
226
|
+
invoice.should_receive(:items).and_return { items }
|
227
|
+
invoice.should_receive(:odba_store, 1).and_return {}
|
228
|
+
retval = nil
|
229
|
+
assert_logged(:debug, :debug) {
|
230
|
+
retval = @session.delete_item(3, 1)
|
231
|
+
}
|
232
|
+
assert_equal([item1,item3], retval)
|
233
|
+
end
|
234
|
+
def test_generate_invoice
|
235
|
+
factory = flexmock('factory')
|
236
|
+
@serv.should_receive(:factory).and_return(factory)
|
237
|
+
generated = flexmock('invoice')
|
238
|
+
inv = flexmock('autoinvoice')
|
239
|
+
factory.should_receive(:generate_invoice)\
|
240
|
+
.with(inv).times(1).and_return {
|
241
|
+
assert(true)
|
242
|
+
generated
|
243
|
+
}
|
244
|
+
flexstub(AutoInvoice).should_receive(:find_by_unique_id)\
|
245
|
+
.with("17").times(1).and_return(inv)
|
246
|
+
res = nil
|
247
|
+
assert_logged(:info, :debug) {
|
248
|
+
res = @session.generate_invoice(17)
|
249
|
+
}
|
250
|
+
assert_equal(generated, res)
|
251
|
+
end
|
252
|
+
def test_invoice__error
|
253
|
+
inv = flexmock('invoice')
|
254
|
+
flexstub(Invoice).should_receive(:find_by_unique_id)\
|
255
|
+
.and_return(inv)
|
256
|
+
res = nil
|
257
|
+
assert_logged(:debug) {
|
258
|
+
res = @session.invoice(17)
|
259
|
+
}
|
260
|
+
assert_equal(inv, res)
|
261
|
+
end
|
262
|
+
def test_invoice__error
|
263
|
+
flexstub(Invoice).should_receive(:find_by_unique_id)
|
264
|
+
assert_logged(:debug, :error) {
|
265
|
+
assert_raises(IndexError) {
|
266
|
+
@session.invoice(17)
|
267
|
+
}
|
268
|
+
}
|
269
|
+
end
|
270
|
+
def test_invoice_infos
|
271
|
+
inv1 = flexmock('invoice1')
|
272
|
+
inv1.should_receive(:status).and_return('selectable')
|
273
|
+
inv1.should_receive(:info).and_return('info1')
|
274
|
+
inv2 = flexmock('invoice2')
|
275
|
+
inv2.should_receive(:status).and_return('not selectable')
|
276
|
+
flexstub(Invoice).should_receive(:search_by_status)\
|
277
|
+
.with('selectable').and_return([inv1])
|
278
|
+
res = nil
|
279
|
+
assert_logged(:debug) {
|
280
|
+
res = @session.invoice_infos('selectable')
|
281
|
+
}
|
282
|
+
assert_equal(['info1'], res)
|
283
|
+
end
|
284
|
+
def test_search_debitors
|
285
|
+
debitors = flexstub(Debitor)
|
286
|
+
debitor = FlexMock.new
|
287
|
+
debitors.should_receive(:search_by_exact_email).and_return { |email|
|
288
|
+
res = []
|
289
|
+
res.push(debitor) if(email == 'test@ywesee.com')
|
290
|
+
res
|
291
|
+
}
|
292
|
+
debitors.should_receive(:search_by_exact_name).and_return { |name|
|
293
|
+
res = []
|
294
|
+
res.push(debitor) if(name == 'ywesee GmbH')
|
295
|
+
res
|
296
|
+
}
|
297
|
+
assert_logged(:debug) {
|
298
|
+
assert_equal([], @session.search_debitors('Unknown Name'))
|
299
|
+
}
|
300
|
+
assert_logged(:debug) {
|
301
|
+
assert_equal([], @session.search_debitors('unknown@ywesee.com'))
|
302
|
+
}
|
303
|
+
assert_logged(:debug) {
|
304
|
+
assert_equal([debitor], @session.search_debitors('ywesee GmbH'))
|
305
|
+
}
|
306
|
+
assert_logged(:debug) {
|
307
|
+
assert_equal([debitor], @session.search_debitors('test@ywesee.com'))
|
308
|
+
}
|
309
|
+
end
|
310
|
+
def test_send_invoice
|
311
|
+
inv = flexmock('invoice')
|
312
|
+
flexstub(Invoice).should_receive(:find_by_unique_id)\
|
313
|
+
.with('17').and_return(inv)
|
314
|
+
@serv.should_receive(:config).and_return('cnf')
|
315
|
+
flexstub(Mail).should_receive(:send_invoice).with('cnf', inv)
|
316
|
+
assert_logged(:info, :debug) {
|
317
|
+
@session.send_invoice(17)
|
318
|
+
}
|
319
|
+
end
|
320
|
+
def test_update_item__invoice
|
321
|
+
item = flexmock('item')
|
322
|
+
inv = flexmock('invoice')
|
323
|
+
inv.should_receive(:item).with(4).and_return(item)
|
324
|
+
inv.should_receive(:odba_store).times(1)\
|
325
|
+
.and_return { assert(true) }
|
326
|
+
flexstub(Invoice).should_receive(:find_by_unique_id)\
|
327
|
+
.with('12').and_return(inv)
|
328
|
+
item.should_receive(:update).with({:foo => 'bar'})
|
329
|
+
assert_logged(:debug, :debug) {
|
330
|
+
@session.update_item(12, 4, {:foo => 'bar'})
|
331
|
+
}
|
332
|
+
end
|
333
|
+
def test_update_item__autoinvoice
|
334
|
+
item = flexmock('item')
|
335
|
+
inv = flexmock('invoice')
|
336
|
+
inv.should_receive(:item).with(4).and_return(item)
|
337
|
+
inv.should_receive(:odba_store).times(1)\
|
338
|
+
.and_return { assert(true) }
|
339
|
+
flexstub(AutoInvoice).should_receive(:find_by_unique_id)\
|
340
|
+
.with('12').and_return(inv)
|
341
|
+
item.should_receive(:update).with({:foo => 'bar'})
|
342
|
+
assert_logged(:debug, :debug) {
|
343
|
+
@session.update_item(12, 4, {:foo => 'bar'}, :autoinvoice)
|
344
|
+
}
|
345
|
+
end
|
346
|
+
end
|
347
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# TestRootUser -- ydim -- 10.01.2006 -- hwyss@ywesee.com
|
3
|
+
|
4
|
+
$: << File.expand_path('../lib', File.dirname(__FILE__))
|
5
|
+
|
6
|
+
require 'test/unit'
|
7
|
+
require 'ydim/root_user'
|
8
|
+
|
9
|
+
module YDIM
|
10
|
+
class TestRootUser < Test::Unit::TestCase
|
11
|
+
def setup
|
12
|
+
@user = RootUser.new(:root)
|
13
|
+
end
|
14
|
+
def test_session
|
15
|
+
session = @user.new_session
|
16
|
+
assert_instance_of(RootSession, session)
|
17
|
+
assert_equal('root', session.whoami)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/test/test_server.rb
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# TestServer -- ydim -- 10.01.2006 -- hwyss@ywesee.com
|
3
|
+
|
4
|
+
|
5
|
+
$: << File.expand_path('../lib', File.dirname(__FILE__))
|
6
|
+
|
7
|
+
require 'test/unit'
|
8
|
+
require 'test/stub/odba'
|
9
|
+
require 'flexmock'
|
10
|
+
require 'ydim/server'
|
11
|
+
|
12
|
+
module YDIM
|
13
|
+
class TestServer < Test::Unit::TestCase
|
14
|
+
def setup
|
15
|
+
@config = FlexMock.new
|
16
|
+
@config.should_receive(:autoinvoice_hour).and_return { nil }
|
17
|
+
@config.should_receive(:currency_update_hour).and_return { nil }
|
18
|
+
@logger = FlexMock.new('logger')
|
19
|
+
@logger.should_ignore_missing
|
20
|
+
@server = Server.new(@config, @logger)
|
21
|
+
@needle = @server.instance_variable_get('@serv')
|
22
|
+
@datadir = File.expand_path('tmp', File.dirname(__FILE__))
|
23
|
+
end
|
24
|
+
def test_config
|
25
|
+
assert_equal(@config, @needle.config)
|
26
|
+
end
|
27
|
+
def test_root_user__file_relative
|
28
|
+
FileUtils.mkdir_p(@datadir)
|
29
|
+
@config.should_receive(:root_name).and_return { 'Root' }
|
30
|
+
@config.should_receive(:root_email).and_return { 'test@ywesee.com' }
|
31
|
+
@config.should_receive(:root_key).and_return { "root_dsa.pub" }
|
32
|
+
@config.should_receive(:conf_dir).and_return { @datadir }
|
33
|
+
filepath = File.join(@datadir, "root_dsa.pub")
|
34
|
+
key = OpenSSL::PKey::DSA.new(8)
|
35
|
+
File.open(filepath, 'w') { |fh|
|
36
|
+
fh.puts(key.public_key.to_s)
|
37
|
+
}
|
38
|
+
auth_server = nil
|
39
|
+
assert_nothing_raised {
|
40
|
+
auth_server = @needle.auth_server
|
41
|
+
}
|
42
|
+
assert_instance_of(RRBA::Server, auth_server)
|
43
|
+
root = auth_server.instance_variable_get('@root')
|
44
|
+
assert_equal('Root', root.name)
|
45
|
+
assert_equal('test@ywesee.com', root.email)
|
46
|
+
assert(root.public_key.sysverify('test', key.syssign('test')))
|
47
|
+
ensure
|
48
|
+
FileUtils.rm_r(@datadir) if File.exist?(@datadir)
|
49
|
+
end
|
50
|
+
def test_root_user__file_absolute
|
51
|
+
FileUtils.mkdir_p(@datadir)
|
52
|
+
@config.should_receive(:root_name).and_return { 'Root' }
|
53
|
+
@config.should_receive(:root_email).and_return { 'test@ywesee.com' }
|
54
|
+
@config.should_receive(:root_key).and_return {
|
55
|
+
File.join(@datadir, "absolute_dsa.pub")
|
56
|
+
}
|
57
|
+
@config.should_receive(:conf_dir).and_return { @datadir }
|
58
|
+
filepath = File.join(@datadir, "absolute_dsa.pub")
|
59
|
+
key = OpenSSL::PKey::DSA.new(8)
|
60
|
+
File.open(filepath, 'w') { |fh|
|
61
|
+
fh.puts(key.public_key.to_s)
|
62
|
+
}
|
63
|
+
auth_server = nil
|
64
|
+
assert_nothing_raised {
|
65
|
+
auth_server = @needle.auth_server
|
66
|
+
}
|
67
|
+
assert_instance_of(RRBA::Server, auth_server)
|
68
|
+
root = auth_server.instance_variable_get('@root')
|
69
|
+
assert_equal('Root', root.name)
|
70
|
+
assert_equal('test@ywesee.com', root.email)
|
71
|
+
assert(root.public_key.sysverify('test', key.syssign('test')))
|
72
|
+
ensure
|
73
|
+
FileUtils.rm_r(@datadir) if File.exist?(@datadir)
|
74
|
+
end
|
75
|
+
def test_root_user__dump
|
76
|
+
key = OpenSSL::PKey::DSA.new(8)
|
77
|
+
@config.should_receive(:root_name).and_return { 'Root' }
|
78
|
+
@config.should_receive(:root_email).and_return { 'test@ywesee.com' }
|
79
|
+
@config.should_receive(:root_key).and_return {
|
80
|
+
key.public_key.to_s
|
81
|
+
}
|
82
|
+
@config.should_receive(:conf_dir).and_return { @datadir }
|
83
|
+
auth_server = nil
|
84
|
+
assert_nothing_raised {
|
85
|
+
auth_server = @needle.auth_server
|
86
|
+
}
|
87
|
+
assert_instance_of(RRBA::Server, auth_server)
|
88
|
+
root = auth_server.instance_variable_get('@root')
|
89
|
+
assert_equal('Root', root.name)
|
90
|
+
assert_equal('test@ywesee.com', root.email)
|
91
|
+
assert(root.public_key.sysverify('test', key.syssign('test')))
|
92
|
+
end
|
93
|
+
def test_login_ok
|
94
|
+
debug_messages = ''
|
95
|
+
info_messages = ''
|
96
|
+
error_messages = ''
|
97
|
+
@logger.should_receive(:debug).and_return { |msg, block|
|
98
|
+
debug_messages << msg << "\n" }
|
99
|
+
@logger.should_receive(:info).and_return { |msg, block|
|
100
|
+
info_messages << msg << "\n" }
|
101
|
+
@logger.should_receive(:error).and_return { |msg, block|
|
102
|
+
error_messages << msg << "\n" }
|
103
|
+
@logger.should_receive(:error).and_return { |msg, block| flunk(msg) }
|
104
|
+
key = OpenSSL::PKey::DSA.new(8)
|
105
|
+
@config.should_receive(:root_name).and_return { 'Root' }
|
106
|
+
@config.should_receive(:root_email).and_return { 'test@ywesee.com' }
|
107
|
+
@config.should_receive(:root_key).and_return {
|
108
|
+
key.public_key.to_s
|
109
|
+
}
|
110
|
+
@config.should_receive(:conf_dir).and_return { @datadir }
|
111
|
+
client = FlexMock.new
|
112
|
+
client.should_receive(:__drburi).and_return { 'druby://localhost:0' }
|
113
|
+
session = @server.login(client, :root) { |challenge|
|
114
|
+
key.syssign(challenge)
|
115
|
+
}
|
116
|
+
assert_instance_of(RootSession, session)
|
117
|
+
end
|
118
|
+
def test_login_fail
|
119
|
+
debug_messages = ''
|
120
|
+
info_messages = ''
|
121
|
+
error_messages = ''
|
122
|
+
@logger.should_receive(:debug).and_return { |msg, block|
|
123
|
+
debug_messages << msg << "\n" }
|
124
|
+
@logger.should_receive(:info).and_return { |msg, block|
|
125
|
+
info_messages << msg << "\n" }
|
126
|
+
@logger.should_receive(:error).and_return { |msg, block|
|
127
|
+
error_messages << msg << "\n" }
|
128
|
+
key = OpenSSL::PKey::DSA.new(8)
|
129
|
+
@config.should_receive(:root_name).and_return { 'Root' }
|
130
|
+
@config.should_receive(:root_email).and_return { 'test@ywesee.com' }
|
131
|
+
@config.should_receive(:root_key).and_return {
|
132
|
+
key.public_key.to_s
|
133
|
+
}
|
134
|
+
@config.should_receive(:conf_dir).and_return { @datadir }
|
135
|
+
client = FlexMock.new
|
136
|
+
client.should_receive(:__drburi).and_return { 'druby://localhost:0' }
|
137
|
+
assert_raises(OpenSSL::PKey::DSAError) {
|
138
|
+
@server.login(client, :root) { |challenge| challenge }
|
139
|
+
}
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
metadata
ADDED
@@ -0,0 +1,137 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ydim
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
- 0
|
10
|
+
version: 1.0.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Masaomi Hatakeyama, Zeno R.R. Davatz
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-12-20 00:00:00 +01:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: hoe
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 47
|
30
|
+
segments:
|
31
|
+
- 2
|
32
|
+
- 8
|
33
|
+
- 0
|
34
|
+
version: 2.8.0
|
35
|
+
type: :development
|
36
|
+
version_requirements: *id001
|
37
|
+
description: ywesee distributed invoice manager, Ruby
|
38
|
+
email:
|
39
|
+
- mhatakeyama@ywesee.com, zdavatz@ywesee.com
|
40
|
+
executables:
|
41
|
+
- ydim-edit
|
42
|
+
- ydim-inject
|
43
|
+
- ydimd
|
44
|
+
extensions: []
|
45
|
+
|
46
|
+
extra_rdoc_files:
|
47
|
+
- History.txt
|
48
|
+
- Manifest.txt
|
49
|
+
- README.txt
|
50
|
+
- LICENSE.txt
|
51
|
+
files:
|
52
|
+
- History.txt
|
53
|
+
- Manifest.txt
|
54
|
+
- README.txt
|
55
|
+
- Rakefile
|
56
|
+
- LICENSE.txt
|
57
|
+
- bin/ydim-edit
|
58
|
+
- bin/ydim-inject
|
59
|
+
- bin/ydimd
|
60
|
+
- install.rb
|
61
|
+
- lib/ydim/autoinvoicer.rb
|
62
|
+
- lib/ydim/client.rb
|
63
|
+
- lib/ydim/config.rb
|
64
|
+
- lib/ydim/currency_converter.rb
|
65
|
+
- lib/ydim/currency_updater.rb
|
66
|
+
- lib/ydim/debitor.rb
|
67
|
+
- lib/ydim/factory.rb
|
68
|
+
- lib/ydim/invoice.rb
|
69
|
+
- lib/ydim/item.rb
|
70
|
+
- lib/ydim/mail.rb
|
71
|
+
- lib/ydim/odba.rb
|
72
|
+
- lib/ydim/root_session.rb
|
73
|
+
- lib/ydim/root_user.rb
|
74
|
+
- lib/ydim/server.rb
|
75
|
+
- lib/ydim/smtp_tls.rb
|
76
|
+
- lib/ydim/util.rb
|
77
|
+
- test/data/search.html
|
78
|
+
- test/stub/odba.rb
|
79
|
+
- test/suite.rb
|
80
|
+
- test/test_autoinvoicer.rb
|
81
|
+
- test/test_currency_converter.rb
|
82
|
+
- test/test_currency_updater.rb
|
83
|
+
- test/test_debitor.rb
|
84
|
+
- test/test_factory.rb
|
85
|
+
- test/test_invoice.rb
|
86
|
+
- test/test_item.rb
|
87
|
+
- test/test_mail.rb
|
88
|
+
- test/test_root_session.rb
|
89
|
+
- test/test_root_user.rb
|
90
|
+
- test/test_server.rb
|
91
|
+
has_rdoc: true
|
92
|
+
homepage: http://scm.ywesee.com/?p=ydim/.git;a=summary
|
93
|
+
licenses: []
|
94
|
+
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options:
|
97
|
+
- --main
|
98
|
+
- README.txt
|
99
|
+
require_paths:
|
100
|
+
- lib
|
101
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
102
|
+
none: false
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
hash: 3
|
107
|
+
segments:
|
108
|
+
- 0
|
109
|
+
version: "0"
|
110
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
|
+
none: false
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
hash: 3
|
116
|
+
segments:
|
117
|
+
- 0
|
118
|
+
version: "0"
|
119
|
+
requirements: []
|
120
|
+
|
121
|
+
rubyforge_project: ydim
|
122
|
+
rubygems_version: 1.3.7
|
123
|
+
signing_key:
|
124
|
+
specification_version: 3
|
125
|
+
summary: ywesee distributed invoice manager, Ruby
|
126
|
+
test_files:
|
127
|
+
- test/test_autoinvoicer.rb
|
128
|
+
- test/test_currency_converter.rb
|
129
|
+
- test/test_currency_updater.rb
|
130
|
+
- test/test_debitor.rb
|
131
|
+
- test/test_factory.rb
|
132
|
+
- test/test_invoice.rb
|
133
|
+
- test/test_item.rb
|
134
|
+
- test/test_mail.rb
|
135
|
+
- test/test_root_session.rb
|
136
|
+
- test/test_root_user.rb
|
137
|
+
- test/test_server.rb
|