rims 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -20,7 +20,9 @@ module RIMS::Test
20
20
 
21
21
  @auth = RIMS::Authentication.new(time_source: make_pseudo_time_source(src_time),
22
22
  random_string_source: make_pseudo_random_string_source(random_seed))
23
- @auth.entry(@username, @password)
23
+ @pw = RIMS::Password::PlainSource.new
24
+ @pw.entry(@username, @password)
25
+ @auth.add_plug_in(@pw)
24
26
  end
25
27
 
26
28
  def test_unique_user_id
@@ -0,0 +1,36 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require 'rims'
4
+ require 'test/unit'
5
+
6
+ module RIMS::Test
7
+ class CmdTest < Test::Unit::TestCase
8
+ data('string' => [ :foo, 'foo' ],
9
+ 'hash' => [ { foo: 'bar' }, { 'foo' => 'bar' } ],
10
+ 'hash_hash' => [ { foo: { bar: 'baz' } }, { 'foo' => { 'bar' => 'baz' } }, ],
11
+ 'array_hash' => [ [ { foo: 'bar' } ], [ { 'foo' => 'bar' } ] ])
12
+ def test_symbolize_string_key(data)
13
+ expected, conversion_target = data
14
+ saved_conversion_target = Marshal.restore(Marshal.dump(conversion_target))
15
+ assert_equal(expected, RIMS::Cmd::Config.symbolize_string_key(conversion_target))
16
+ assert_equal(saved_conversion_target, conversion_target)
17
+ end
18
+
19
+ data('symbol' => :foo,
20
+ 'integer' => 1,
21
+ 'array' => [ :foo, 1 ],
22
+ 'hash' => { foo: 'bar' },
23
+ 'hash_hash' => { foo: { bar: 'baz' } },
24
+ 'array_hash' => [ { foo: 'bar' } ])
25
+ def test_symbolize_string_key_not_converted(data)
26
+ saved_data = Marshal.restore(Marshal.dump(data))
27
+ assert_equal(saved_data, RIMS::Cmd::Config.symbolize_string_key(data))
28
+ assert_equal(saved_data, data)
29
+ end
30
+ end
31
+ end
32
+
33
+ # Local Variables:
34
+ # mode: Ruby
35
+ # indent-tabs-mode: nil
36
+ # End:
@@ -1,92 +1,36 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
- require 'logger'
4
- require 'pp' if $DEBUG
5
3
  require 'rims'
6
4
  require 'test/unit'
7
5
 
8
6
  module RIMS::Test
9
7
  class TestError < Test::Unit::TestCase
10
- class FooError < StandardError
11
- end
12
-
13
- class BarError < StandardError
14
- end
15
-
16
- def setup
17
- @logger = Logger.new(STDOUT)
18
- @logger.level = ($DEBUG) ? Logger::DEBUG : Logger::FATAL
19
- @flow_list = []
20
- end
21
-
22
- def teardown
23
- pp @flow_list if $DEBUG
24
- end
25
-
26
- def test_suppress_2nd_error_at_resource_closing_no_error
27
- begin
28
- @flow_list << :main
29
- ensure
30
- RIMS::Error.suppress_2nd_error_at_resource_closing{ @flow_list << :close }
31
- end
32
- assert_equal([ :main, :close ], @flow_list)
33
-
34
- begin
35
- @flow_list << :main
36
- ensure
37
- RIMS::Error.suppress_2nd_error_at_resource_closing(logger: @logger) { @flow_list << :close }
38
- end
39
- assert_equal([ :main, :close, :main, :close ], @flow_list)
40
- end
41
-
42
- def test_suppress_2nd_error_at_resource_closing_raise_1st_error
43
- assert_raise(FooError) {
44
- begin
45
- raise FooError
46
- @flow_list << :main
47
- ensure
48
- RIMS::Error.suppress_2nd_error_at_resource_closing{ @flow_list << :close }
49
- end
50
- }
51
- assert_equal([ :close ], @flow_list)
52
-
53
- assert_raise(FooError) {
54
- begin
55
- raise FooError
56
- @flow_list << :main
57
- ensure
58
- RIMS::Error.suppress_2nd_error_at_resource_closing(logger: @logger) { @flow_list << :close }
59
- end
60
- }
61
- assert_equal([ :close, :close ], @flow_list)
62
- end
63
-
64
- def test_suppress_2nd_error_at_resource_closing_suppress_2nd_error
65
- assert_raise(FooError) {
66
- begin
67
- raise FooError
68
- @flow_list << :main
69
- ensure
70
- RIMS::Error.suppress_2nd_error_at_resource_closing{
71
- raise BarError
72
- @flow_list << :close
73
- }
74
- end
75
- }
76
- assert_equal([], @flow_list)
77
-
78
- assert_raise(FooError) {
8
+ def test_trace_error_chain
9
+ exception = assert_raise(RuntimeError) {
79
10
  begin
80
- raise FooError
81
- @flow_list << :main
11
+ begin
12
+ begin
13
+ raise 'error level 0'
14
+ ensure
15
+ raise 'error level 1'
16
+ end
17
+ ensure
18
+ raise 'error level 2'
19
+ end
82
20
  ensure
83
- RIMS::Error.suppress_2nd_error_at_resource_closing(logger: @logger) {
84
- raise BarError
85
- @flow_list << :close
86
- }
21
+ raise 'error level 3'
87
22
  end
88
23
  }
89
- assert_equal([], @flow_list)
24
+ assert_equal('error level 3', exception.message)
25
+
26
+ errors = RIMS::Error.trace_error_chain(exception).to_a
27
+ assert_equal(4, errors.length)
28
+ assert_equal([ RuntimeError ] * 4, errors.map(&:class))
29
+ assert_equal([ 'error level 3',
30
+ 'error level 2',
31
+ 'error level 1',
32
+ 'error level 0'
33
+ ], errors.map(&:message))
90
34
  end
91
35
  end
92
36
  end
@@ -20,7 +20,9 @@ module RIMS::Test
20
20
 
21
21
  @auth = RIMS::Authentication.new(time_source: make_pseudo_time_source(src_time),
22
22
  random_string_source: make_pseudo_random_string_source(random_seed))
23
- @auth.entry(@username, @password)
23
+ @pw = RIMS::Password::PlainSource.new
24
+ @pw.entry(@username, @password)
25
+ @auth.add_plug_in(@pw)
24
26
 
25
27
  @input = StringIO.new('', 'r')
26
28
  @output = StringIO.new('', 'w')
@@ -4,6 +4,7 @@ require 'logger'
4
4
  require 'net/imap'
5
5
  require 'pp' if $DEBUG
6
6
  require 'rims'
7
+ require 'riser'
7
8
  require 'stringio'
8
9
  require 'test/unit'
9
10
  require 'time'
@@ -134,8 +135,10 @@ module RIMS::Test
134
135
 
135
136
  @auth = RIMS::Authentication.new(time_source: make_pseudo_time_source(src_time),
136
137
  random_string_source: make_pseudo_random_string_source(random_seed))
137
- @auth.entry('foo', 'open_sesame')
138
- @auth.entry('#postman', 'password_of_mail_delivery_user')
138
+ @pw = RIMS::Password::PlainSource.new
139
+ @pw.entry('foo', 'open_sesame')
140
+ @pw.entry('#postman', 'password_of_mail_delivery_user')
141
+ @auth.add_plug_in(@pw)
139
142
 
140
143
  @logger = Logger.new(STDOUT)
141
144
  @logger.level = ($DEBUG) ? Logger::DEBUG : Logger::FATAL
@@ -239,7 +242,7 @@ module RIMS::Test
239
242
  input = StringIO.new(client_command_list_text, 'r')
240
243
  output = StringIO.new('', 'w')
241
244
 
242
- RIMS::Protocol::Decoder.repl(@decoder, input, RIMS::BufferedWriter.new(output), @logger)
245
+ RIMS::Protocol::Decoder.repl(@decoder, input, Riser::WriteBufferStream.new(output), @logger)
243
246
  response_lines = output.string.each_line
244
247
 
245
248
  assert_imap_response(response_lines) {|assert|
@@ -0,0 +1,1120 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require 'fileutils'
4
+ require 'logger'
5
+ require 'pathname'
6
+ require 'rims'
7
+ require 'socket'
8
+ require 'test/unit'
9
+ require 'yaml'
10
+
11
+ module RIMS::Test
12
+ class ServiceConfigurationClassMethodTest < Test::Unit::TestCase
13
+ data('symbol' => [ 'foo', :foo ],
14
+ 'array' => [ %w[ foo ], [ :foo ] ],
15
+ 'hash' => [ { 'foo' => 'bar' }, { foo: :bar } ],
16
+ 'hash_array' => [ { 'foo' => %w[ bar ] }, { foo: [ :bar ] } ],
17
+ 'array_hash' => [ [ { 'foo' => 'bar' } ], [ { foo: :bar } ] ])
18
+ def test_stringify_symbol(data)
19
+ expected, conversion_target = data
20
+ saved_conversion_target = Marshal.restore(Marshal.dump(conversion_target))
21
+ assert_equal(expected, RIMS::Service::Configuration.stringify_symbol(conversion_target))
22
+ assert_equal(saved_conversion_target, conversion_target)
23
+ end
24
+
25
+ data('string' => 'foo',
26
+ 'integer' => 1,
27
+ 'array' => [ 'foo', 1 ],
28
+ 'hash' => { 'foo' => 'bar' },
29
+ 'hash_array' => { 'foo' => [ 'bar', 1 ] },
30
+ 'array_hash' => [ { 'foo' => 'bar' }, 1 ])
31
+ def test_stringify_symbol_not_converted(data)
32
+ saved_data = Marshal.restore(Marshal.dump(data))
33
+ assert_equal(saved_data, RIMS::Service::Configuration.stringify_symbol(data))
34
+ assert_equal(saved_data, data)
35
+ end
36
+
37
+ data('value' => [ 'bar', 'foo', 'bar' ],
38
+ 'array' => [ [ 1, 2, 3 ], [ 1 ], [ 2, 3 ] ],
39
+ 'array_replace' => [ 'foo', %w[ foo ], 'foo' ],
40
+ 'hash_merge' => [ { 'foo' => 'a', 'bar' => 'b' }, { 'foo' => 'a' }, { 'bar' => 'b' } ],
41
+ 'hash_replace' => [ { 'foo' => 'b' }, { 'foo' => 'a' }, { 'foo' => 'b' } ],
42
+ 'hash_array' => [ { 'foo' => [ 1, 2, 3 ] }, { 'foo' => [ 1 ] }, { 'foo' => [ 2, 3 ] } ],
43
+ 'hash_array_replace' => [ { 'foo' => 'bar' }, { 'foo' => %w[ bar ] }, { 'foo' => 'bar' } ])
44
+ def test_update(data)
45
+ expected, dest, other = data
46
+ assert_equal(expected, RIMS::Service::Configuration.update(dest, other))
47
+ end
48
+
49
+ data('array' => [ [ 1, 2, 3 ], [ 1 ], [ 2, 3 ] ],
50
+ 'hash_merge' => [ { 'foo' => 'a', 'bar' => 'b' }, { 'foo' => 'a' }, { 'bar' => 'b' } ],
51
+ 'hash_replace' => [ { 'foo' => 'b' }, { 'foo' => 'a' }, { 'foo' => 'b' } ],
52
+ 'hash_array' => [ { 'foo' => [ 1, 2, 3 ] }, { 'foo' => [ 1 ] }, { 'foo' => [ 2, 3 ] } ],
53
+ 'hash_array_replace' => [ { 'foo' => 'bar' }, { 'foo' => %w[ bar ] }, { 'foo' => 'bar' } ])
54
+ def test_update_destructive(data)
55
+ expected, dest, other = data
56
+ RIMS::Service::Configuration.update(dest, other)
57
+ assert_equal(expected, dest)
58
+ end
59
+
60
+ def test_update_not_hash_error
61
+ error = assert_raise(ArgumentError) { RIMS::Service::Configuration.update({}, 'foo') }
62
+ assert_equal('hash can only be updated with hash.', error.message)
63
+ end
64
+
65
+ def test_get_configuration_hash
66
+ assert_equal({ 'foo' => 'bar' },
67
+ RIMS::Service::Configuration.get_configuration({ 'configuration' => { 'foo' => 'bar' } },
68
+ Pathname('/path/to/nothing')))
69
+ end
70
+
71
+ def test_get_configuration_file_relpath
72
+ config_dir = 'config_dir'
73
+ config_file = 'config.yml'
74
+ FileUtils.mkdir_p(config_dir)
75
+ begin
76
+ IO.write(File.join(config_dir, config_file), { 'foo' => 'bar' }.to_yaml)
77
+ assert_equal({ 'foo' => 'bar' },
78
+ RIMS::Service::Configuration.get_configuration({ 'configuration_file' => config_file },
79
+ Pathname(config_dir)))
80
+ ensure
81
+ FileUtils.rm_rf(config_dir)
82
+ end
83
+ end
84
+
85
+ def test_get_configuration_file_abspath
86
+ config_file = 'config.yml'
87
+ begin
88
+ IO.write(config_file, { 'foo' => 'bar' }.to_yaml)
89
+ assert_equal({ 'foo' => 'bar' },
90
+ RIMS::Service::Configuration.get_configuration({ 'configuration_file' => File.expand_path(config_file) },
91
+ Pathname('/path/to/nothing')))
92
+ ensure
93
+ FileUtils.rm_f(config_file)
94
+ end
95
+ end
96
+
97
+ def test_get_configuration_file_no_config
98
+ assert_equal({}, RIMS::Service::Configuration.get_configuration({}, Pathname('/path/to/nothing')))
99
+ end
100
+
101
+ def test_get_configuration_file_conflict_error
102
+ error = assert_raise(KeyError) {
103
+ RIMS::Service::Configuration.get_configuration({ 'configuration' => { 'foo' => 'bar' },
104
+ 'configuration_file' => 'config.yml' },
105
+ Pathname('/path/to/nothing'))
106
+ }
107
+ assert_equal('configuration conflict: configuration, configuraion_file', error.message)
108
+ end
109
+
110
+ def test_get_configuration_file_no_base_dir_error
111
+ error = assert_raise(ArgumentError) {
112
+ RIMS::Service::Configuration.get_configuration({ 'configuration_file' => 'config.yml' })
113
+ }
114
+ assert_equal('need for base_dir.', error.message)
115
+ end
116
+ end
117
+
118
+ class ServiceConfigurationLoadTest < Test::Unit::TestCase
119
+ def setup
120
+ @c = RIMS::Service::Configuration.new
121
+ @config_dir = 'config_dir'
122
+ end
123
+
124
+ def teardown
125
+ FileUtils.rm_rf(@config_dir)
126
+ end
127
+
128
+ data('rel_path' => 'foo/bar',
129
+ 'abs_path' => '/foo/bar')
130
+ def test_base_dir(path)
131
+ @c.load(base_dir: path)
132
+ assert_equal(Pathname(path), @c.base_dir)
133
+ end
134
+
135
+ data('rel_path' => 'foo/bar',
136
+ 'abs_path' => '/foo/bar')
137
+ def test_load_path(path)
138
+ @c.load({}, path)
139
+ assert_equal(Pathname(path), @c.base_dir)
140
+ end
141
+
142
+ data('rel_path' => [ '/path/foo/bar', 'foo/bar', '/path' ],
143
+ 'abs_path' => [ '/foo/bar', '/foo/bar', '/path' ])
144
+ def test_base_dir_with_load_path(data)
145
+ expected_path, base_dir, load_path = data
146
+ @c.load({ base_dir: base_dir }, load_path)
147
+ assert_equal(Pathname(expected_path), @c.base_dir)
148
+ end
149
+
150
+ def test_base_dir_not_defined_error
151
+ error = assert_raise(KeyError) { @c.base_dir }
152
+ assert_equal('not defined base_dir.', error.message)
153
+ end
154
+
155
+ def test_load_yaml_load_path
156
+ FileUtils.mkdir_p(@config_dir)
157
+ config_path = File.join(@config_dir, 'config.yml')
158
+ IO.write(config_path, {}.to_yaml)
159
+
160
+ @c.load_yaml(config_path)
161
+ assert_equal(Pathname(@config_dir), @c.base_dir)
162
+ end
163
+
164
+ data('rel_path' => [ %q{"#{@config_dir}/foo/bar"}, 'foo/bar' ],
165
+ 'abs_path' => [ %q{'/foo/bar'}, '/foo/bar' ])
166
+ def test_load_yaml_base_dir(data)
167
+ expected_path, base_dir = data
168
+
169
+ FileUtils.mkdir_p(@config_dir)
170
+ config_path = File.join(@config_dir, 'config.yml')
171
+ IO.write(config_path, { 'base_dir' => base_dir }.to_yaml)
172
+
173
+ @c.load_yaml(config_path)
174
+ assert_equal(Pathname(eval(expected_path)), @c.base_dir)
175
+ end
176
+
177
+ def test_default_config
178
+ assert_raise(NoMethodError) { RIMS::Service::DEFAULT_CONFIG.load({}) }
179
+ assert_raise(NoMethodError) { RIMS::Service::DEFAULT_CONFIG.load_yaml('config.yml') }
180
+ assert_equal([], RIMS::Service::DEFAULT_CONFIG.get_required_features)
181
+ assert_raise(KeyError) { RIMS::Service::DEFAULT_CONFIG.base_dir }
182
+ assert_equal([ 'rims.log', { level: 'info', progname: 'rims'} ], RIMS::Service::DEFAULT_CONFIG.make_file_logger_params)
183
+ assert_equal([ STDOUT, { level: 'info', progname: 'rims' } ], RIMS::Service::DEFAULT_CONFIG.make_stdout_logger_params)
184
+ assert_equal([ 'protocol.log', { level: 'unknown', progname: 'rims' } ], RIMS::Service::DEFAULT_CONFIG.make_protocol_logger_params)
185
+ assert_equal(true, RIMS::Service::DEFAULT_CONFIG.daemonize?)
186
+ assert_equal('rims', RIMS::Service::DEFAULT_CONFIG.daemon_name)
187
+ assert_equal(false, RIMS::Service::DEFAULT_CONFIG.daemon_debug?)
188
+ assert_equal('rims.pid', RIMS::Service::DEFAULT_CONFIG.status_file)
189
+ assert_equal(3, RIMS::Service::DEFAULT_CONFIG.server_polling_interval_seconds)
190
+ assert_equal(0, RIMS::Service::DEFAULT_CONFIG.server_restart_overlap_seconds)
191
+ assert_nil(RIMS::Service::DEFAULT_CONFIG.server_privileged_user)
192
+ assert_nil(RIMS::Service::DEFAULT_CONFIG.server_privileged_group)
193
+ assert_equal('0.0.0.0:1430', RIMS::Service::DEFAULT_CONFIG.listen_address)
194
+ assert_equal(0.1, RIMS::Service::DEFAULT_CONFIG.accept_polling_timeout_seconds)
195
+ assert_equal(0, RIMS::Service::DEFAULT_CONFIG.process_num)
196
+ assert_equal(20, RIMS::Service::DEFAULT_CONFIG.process_queue_size)
197
+ assert_equal(0.1, RIMS::Service::DEFAULT_CONFIG.process_queue_polling_timeout_seconds)
198
+ assert_equal(0.1, RIMS::Service::DEFAULT_CONFIG.process_send_io_polling_timeout_seconds)
199
+ assert_equal(20, RIMS::Service::DEFAULT_CONFIG.thread_num)
200
+ assert_equal(20, RIMS::Service::DEFAULT_CONFIG.thread_queue_size)
201
+ assert_equal(0.1, RIMS::Service::DEFAULT_CONFIG.thread_queue_polling_timeout_seconds)
202
+ assert_equal(1024 * 16, RIMS::Service::DEFAULT_CONFIG.send_buffer_limit_size)
203
+ assert_nil(RIMS::Service::DEFAULT_CONFIG.ssl_context)
204
+ assert_equal(30, RIMS::Service::DEFAULT_CONFIG.read_lock_timeout_seconds)
205
+ assert_equal(30, RIMS::Service::DEFAULT_CONFIG.write_lock_timeout_seconds)
206
+ assert_equal(1, RIMS::Service::DEFAULT_CONFIG.cleanup_write_lock_timeout_seconds)
207
+ assert_equal({ origin_type: RIMS::GDBM_KeyValueStore,
208
+ origin_config: {},
209
+ middleware_list: [ RIMS::Checksum_KeyValueStore ]
210
+ },
211
+ RIMS::Service::DEFAULT_CONFIG.make_meta_key_value_store_params.to_h)
212
+ assert_equal({ origin_type: RIMS::GDBM_KeyValueStore,
213
+ origin_config: {},
214
+ middleware_list: [ RIMS::Checksum_KeyValueStore ]
215
+ },
216
+ RIMS::Service::DEFAULT_CONFIG.make_text_key_value_store_params.to_h)
217
+ assert_raise(KeyError) { RIMS::Service::DEFAULT_CONFIG.make_key_value_store_path('path', 'abcd') }
218
+ assert_equal(Socket.gethostname, RIMS::Service::DEFAULT_CONFIG.make_authentication.hostname)
219
+ assert_equal('#postman', RIMS::Service::DEFAULT_CONFIG.mail_delivery_user)
220
+ end
221
+ end
222
+
223
+ class ServiceConfigurationTest < Test::Unit::TestCase
224
+ BASE_DIR = 'config_dir'
225
+
226
+ def setup
227
+ @c = RIMS::Service::Configuration.new
228
+ @base_dir = BASE_DIR
229
+ @c.load(base_dir: @base_dir)
230
+ @logger = Logger.new(STDOUT)
231
+ @logger.level = ($DEBUG) ? Logger::DEBUG : Logger::UNKNOWN
232
+ end
233
+
234
+ def teardown
235
+ FileUtils.rm_rf(@base_dir)
236
+ end
237
+
238
+ def test_require_features
239
+ assert(! defined? Prime)
240
+ assert(! ($LOADED_FEATURES.any? %r"prime"))
241
+
242
+ fork{
243
+ @c.load(required_features: %w[ prime ])
244
+ assert_equal(%w[ prime ], @c.get_required_features)
245
+ @c.require_features
246
+ assert(defined? Prime)
247
+ assert($LOADED_FEATURES.any? %r"prime")
248
+ }
249
+
250
+ Process.wait
251
+ assert_equal(0, $?.exitstatus)
252
+ end
253
+
254
+ def test_require_features_no_features
255
+ assert_equal([], @c.get_required_features)
256
+ saved_loaded_features = $LOADED_FEATURES.dup
257
+ @c.require_features
258
+ assert_equal(saved_loaded_features, $LOADED_FEATURES)
259
+ end
260
+
261
+ data('default' => [ [], {} ],
262
+ 'config' => [ %w[ rims/qdbm rims/passwd/ldap ],
263
+ { required_features: %w[ rims/qdbm rims/passwd/ldap ] } ],
264
+ 'compat' => [ %w[ rims/qdbm rims/passwd/ldap ],
265
+ { load_libraries: %w[ rims/qdbm rims/passwd/ldap ] } ],
266
+ 'priority' => [ %w[ rims/qdbm ],
267
+ { required_features: %w[ rims/qdbm ],
268
+ load_libraries: %w[ rims/passwd/ldap ]
269
+ }
270
+ ])
271
+ def test_get_required_features(data)
272
+ expected_features, config = data
273
+ @c.load(config)
274
+ assert_equal(expected_features, @c.get_required_features)
275
+ end
276
+
277
+ default_rims_log = File.join(BASE_DIR, 'rims.log')
278
+ data('default' => [ [ default_rims_log,{ level: 'info', progname: 'rims' } ], {} ],
279
+ 'rel_path' => [ [ File.join(BASE_DIR, 'server.log'), { level: 'info', progname: 'rims' } ],
280
+ { logging: { file: { path: 'server.log' } } } ],
281
+ 'abs_path' => [ [ '/var/log/rims.log', { level: 'info', progname: 'rims' } ],
282
+ { logging: { file: { path: '/var/log/rims.log' } } } ],
283
+ 'compat_path' => [ [ File.join(BASE_DIR, 'server.log'), { level: 'info', progname: 'rims' } ],
284
+ { log_file: 'server.log' } ],
285
+ 'shift_age' => [ [ default_rims_log, 10, { level: 'info', progname: 'rims' } ],
286
+ { logging: { file: { shift_age: 10 } } } ],
287
+ 'compat_shift_age' => [ [ default_rims_log, 10, { level: 'info', progname: 'rims' } ],
288
+ { log_shift_age: 10 } ],
289
+ 'shift_daily' => [ [ default_rims_log, 'daily', { level: 'info', progname: 'rims' } ],
290
+ { logging: { file: { shift_age: 'daily' } } } ],
291
+ 'shift_weekly' => [ [ default_rims_log, 'weekly', { level: 'info', progname: 'rims' } ],
292
+ { logging: { file: { shift_age: 'weekly' } } } ],
293
+ 'shift_monthly' => [ [ default_rims_log, 'monthly', { level: 'info', progname: 'rims' } ],
294
+ { logging: { file: { shift_age: 'monthly' } } } ],
295
+ 'shift_size' => [ [ default_rims_log, 0, 16777216, { level: 'info', progname: 'rims' } ],
296
+ { logging: { file: { shift_size: 16777216 } } } ],
297
+ 'compat_shift_size' => [ [ default_rims_log, 0, 16777216, { level: 'info', progname: 'rims' } ],
298
+ { log_shift_size: 16777216 } ],
299
+ 'level' => [ [ default_rims_log, { level: 'debug', progname: 'rims' } ],
300
+ { logging: { file: { level: 'debug' } } } ],
301
+ 'compat_level' => [ [ default_rims_log, { level: 'debug', progname: 'rims' } ],
302
+ { log_level: 'debug' } ],
303
+ 'datetime_format' => [ [ default_rims_log, { level: 'info', progname: 'rims', datetime_format: '%Y%m%d%H%M%S' } ],
304
+ { logging: { file: { datetime_format: '%Y%m%d%H%M%S' } } } ],
305
+ 'shift_period_suffix' => [ [ default_rims_log, { level: 'info', progname: 'rims', shift_period_suffix: '%Y-%m-%d' } ],
306
+ { logging: { file: { shift_period_suffix: '%Y-%m-%d' } } } ],
307
+ 'all' => [ [ '/var/log/rims.log',
308
+ 10,
309
+ 16777216,
310
+ { level: 'debug',
311
+ progname: 'rims',
312
+ datetime_format: '%Y%m%d%H%M%S',
313
+ shift_period_suffix: '%Y-%m-%d'
314
+ }
315
+ ],
316
+ { logging: {
317
+ file: {
318
+ path: '/var/log/rims.log',
319
+ shift_age: 10,
320
+ shift_size: 16777216,
321
+ level: 'debug',
322
+ datetime_format: '%Y%m%d%H%M%S',
323
+ shift_period_suffix: '%Y-%m-%d'
324
+ }
325
+ }
326
+ }
327
+ ],
328
+ 'priority' => [ [ '/var/log/rims.log',
329
+ 10,
330
+ 16777216,
331
+ { level: 'debug',
332
+ progname: 'rims',
333
+ }
334
+ ],
335
+ { logging: {
336
+ file: {
337
+ path: '/var/log/rims.log',
338
+ shift_age: 10,
339
+ shift_size: 16777216,
340
+ level: 'debug'
341
+ }
342
+ },
343
+ log_file: '/var/log/server.log',
344
+ log_shift_age: 7,
345
+ log_shift_size: 1048576,
346
+ log_level: 'info'
347
+ }
348
+ ])
349
+ def test_make_file_logger_params(data)
350
+ expected_logger_params, config = data
351
+ @c.load(config)
352
+ assert_equal(expected_logger_params, @c.make_file_logger_params)
353
+ end
354
+
355
+ data('default' => [ [ STDOUT, { level: 'info', progname: 'rims' } ], {} ],
356
+ 'level' => [ [ STDOUT, { level: 'debug', progname: 'rims' } ],
357
+ { logging: { stdout: { level: 'debug' } } } ],
358
+ 'compat_level' => [ [ STDOUT, { level: 'debug', progname: 'rims' } ],
359
+ { log_stdout: 'debug' } ],
360
+ 'datetime_format' => [ [ STDOUT, { level: 'info', progname: 'rims', datetime_format: '%Y%m%d%H%M%S' } ],
361
+ { logging: { stdout: { datetime_format: '%Y%m%d%H%M%S' } } } ],
362
+ 'all' => [ [ STDOUT, { level: 'debug', progname: 'rims', datetime_format: '%Y%m%d%H%M%S' } ],
363
+ { logging: {
364
+ stdout: {
365
+ level: 'debug',
366
+ datetime_format: '%Y%m%d%H%M%S'
367
+ }
368
+ }
369
+ }
370
+ ],
371
+ 'priority' => [ [ STDOUT, { level: 'debug', progname: 'rims' } ],
372
+ { logging: { stdout: { level: 'debug' } },
373
+ log_stdout: 'info'
374
+ }
375
+ ])
376
+ def test_make_stdout_logger_params(data)
377
+ expected_logger_params, config = data
378
+ @c.load(config)
379
+ assert_equal(expected_logger_params, @c.make_stdout_logger_params)
380
+ end
381
+
382
+ default_protocol_log = File.join(BASE_DIR, 'protocol.log')
383
+ data('default' => [ [ default_protocol_log, { level: 'unknown', progname: 'rims' } ], {} ],
384
+ 'rel_path' => [ [ File.join(BASE_DIR, 'imap.log'), { level: 'unknown', progname: 'rims' } ],
385
+ { logging: { protocol: { path: 'imap.log' } } } ],
386
+ 'abs_path' => [ [ '/var/log/imap.log', { level: 'unknown', progname: 'rims' } ],
387
+ { logging: { protocol: { path: '/var/log/imap.log' } } } ],
388
+ 'shift_age' => [ [ default_protocol_log, 10, { level: 'unknown', progname: 'rims' } ],
389
+ { logging: { protocol: { shift_age: 10 } } } ],
390
+ 'shift_daily' => [ [ default_protocol_log, 'daily', { level: 'unknown', progname: 'rims' } ],
391
+ { logging: { protocol: { shift_age: 'daily' } } } ],
392
+ 'shift_weekly' => [ [ default_protocol_log, 'weekly', { level: 'unknown', progname: 'rims' } ],
393
+ { logging: { protocol: { shift_age: 'weekly' } } } ],
394
+ 'shift_monthly' => [ [ default_protocol_log, 'monthly', { level: 'unknown', progname: 'rims' } ],
395
+ { logging: { protocol: { shift_age: 'monthly' } } } ],
396
+ 'shift_size' => [ [ default_protocol_log, 0, 16777216, { level: 'unknown', progname: 'rims' } ],
397
+ { logging: { protocol: { shift_size: 16777216 } } } ],
398
+ 'level' => [ [ default_protocol_log, { level: 'info', progname: 'rims' } ],
399
+ { logging: { protocol: { level: 'info' } } } ],
400
+ 'datetime_format' => [ [ default_protocol_log, { level: 'unknown', progname: 'rims', datetime_format: '%Y%m%d%H%M%S' } ],
401
+ { logging: { protocol: { datetime_format: '%Y%m%d%H%M%S' } } } ],
402
+ 'shift_period_suffix' => [ [ default_protocol_log, { level: 'unknown', progname: 'rims', shift_period_suffix: '%Y-%m-%d' } ],
403
+ { logging: { protocol: { shift_period_suffix: '%Y-%m-%d' } } } ],
404
+ 'all' => [ [ '/var/log/imap.log',
405
+ 10,
406
+ 16777216,
407
+ { level: 'info',
408
+ progname: 'rims',
409
+ datetime_format: '%Y%m%d%H%M%S',
410
+ shift_period_suffix: '%Y-%m-%d'
411
+ }
412
+ ],
413
+ { logging: {
414
+ protocol: {
415
+ path: '/var/log/imap.log',
416
+ shift_age: 10,
417
+ shift_size: 16777216,
418
+ level: 'info',
419
+ datetime_format: '%Y%m%d%H%M%S',
420
+ shift_period_suffix: '%Y-%m-%d'
421
+ }
422
+ }
423
+ }
424
+ ])
425
+ def test_make_protocol_logger_params(data)
426
+ expected_logger_params, config = data
427
+ @c.load(config)
428
+ assert_equal(expected_logger_params, @c.make_protocol_logger_params)
429
+ end
430
+
431
+ data('default' => [ true, {} ],
432
+ 'daemonize' => [ true, { daemon: { daemonize: true } } ],
433
+ 'not_daemonize' => [ false, { daemon: { daemonize: false } } ])
434
+ def test_daemonize?(data)
435
+ expected_value, config = data
436
+ @c.load(config)
437
+ assert_equal(expected_value, @c.daemonize?)
438
+ end
439
+
440
+ data('default' => [ false, {} ],
441
+ 'debug' => [ true, { daemon: { debug: true } } ],
442
+ 'not_debug' => [ false, { daemon: { debug: false } } ])
443
+ def test_daemon_debug?(data)
444
+ expected_value, config = data
445
+ @c.load(config)
446
+ assert_equal(expected_value, @c.daemon_debug?)
447
+ end
448
+
449
+ data('default' => [ File.join(BASE_DIR, 'rims.pid'), {} ],
450
+ 'rel_path' => [ File.join(BASE_DIR, 'status'), { daemon: { status_file: 'status' } } ],
451
+ 'abs_path' => [ '/var/run/rims.pid', { daemon: { status_file: '/var/run/rims.pid' } } ])
452
+ def test_status_file(data)
453
+ expected_value, config = data
454
+ @c.load(config)
455
+ assert_equal(expected_value, @c.status_file)
456
+ end
457
+
458
+ data('default' => [ 3, {} ],
459
+ 'config' => [ 1, { daemon: { server_polling_interval_seconds: 1 } } ])
460
+ def test_server_polling_interval_seconds(data)
461
+ expected_value, config = data
462
+ @c.load(config)
463
+ assert_equal(expected_value, @c.server_polling_interval_seconds)
464
+ end
465
+
466
+ data('default' => [ nil, {} ],
467
+ 'name' => [ 'imap', { daemon: { server_privileged_user: 'imap' } } ],
468
+ 'uid' => [ 1000, { daemon: { server_privileged_user: 1000 } } ],
469
+ 'compat' => [ 'imap', { process_privilege_user: 'imap' } ],
470
+ 'priority' => [ 'imap',
471
+ { daemon: { server_privileged_user: 'imap' },
472
+ process_privilege_user: 'nobody'
473
+ }
474
+ ])
475
+ def test_server_privileged_user(data)
476
+ expected_value, config = data
477
+ @c.load(config)
478
+ assert_equal(expected_value, @c.server_privileged_user)
479
+ end
480
+
481
+ data('default' => [ nil, {} ],
482
+ 'name' => [ 'imap', { daemon: { server_privileged_group: 'imap' } } ],
483
+ 'gid' => [ 1000, { daemon: { server_privileged_group: 1000 } } ],
484
+ 'compat' => [ 'imap', { process_privilege_group: 'imap' } ],
485
+ 'priority' => [ 'imap',
486
+ { daemon: { server_privileged_group: 'imap' },
487
+ process_privilege_group: 'nogroup'
488
+ }
489
+ ])
490
+ def test_server_privileged_group(data)
491
+ expected_value, config = data
492
+ @c.load(config)
493
+ assert_equal(expected_value, @c.server_privileged_group)
494
+ end
495
+
496
+ data('default' => [ '0.0.0.0:1430', {} ],
497
+ 'string' => [ 'imap.example.com:143',
498
+ { server: { listen_address: 'imap.example.com:143' } } ],
499
+ 'uri' => [ 'tcp://imap.example.com:143',
500
+ { server: { listen_address: 'tcp://imap.example.com:143' } } ],
501
+ 'hash' => [ { 'type' => 'tcp',
502
+ 'host' => 'imap.example.com',
503
+ 'port' => 143,
504
+ 'backlog' => 64
505
+ },
506
+ { server: {
507
+ listen_address: {
508
+ 'type' => 'tcp',
509
+ 'host' => 'imap.example.com',
510
+ 'port' => 143,
511
+ 'backlog' => 64
512
+ }
513
+ }
514
+ }
515
+ ],
516
+ 'compat_imap_host' => [ { 'type' => 'tcp',
517
+ 'host' => 'imap.example.com',
518
+ 'port' => 1430
519
+ },
520
+ { imap_host: 'imap.example.com',
521
+ ip_addr: 'imap2.example.com'
522
+ }
523
+ ],
524
+ 'compat_ip_addr' => [ { 'type' => 'tcp',
525
+ 'host' => 'imap.example.com',
526
+ 'port' => 1430
527
+ },
528
+ { ip_addr: 'imap.example.com' }
529
+ ],
530
+ 'compat_imap_port' => [ { 'type' => 'tcp',
531
+ 'host' => '0.0.0.0',
532
+ 'port' => 143
533
+ },
534
+ { imap_port: 143,
535
+ ip_port: 5000
536
+ }
537
+ ],
538
+ 'compat_ip_port' => [ { 'type' => 'tcp',
539
+ 'host' => '0.0.0.0',
540
+ 'port' => 143
541
+ },
542
+ { ip_port: 143 }
543
+ ],
544
+ 'priority' => [ 'imap.example.com:143',
545
+ { server: {
546
+ listen_address: 'imap.example.com:143'
547
+ },
548
+ imap_host: 'imap2.example.com',
549
+ imap_port: 5000,
550
+ ip_addr: 'imap3.example.com',
551
+ ip_port: 6000
552
+ }
553
+ ])
554
+ def test_listen_address(data)
555
+ expected_value, config = data
556
+ @c.load(config)
557
+ assert_equal(expected_value, @c.listen_address)
558
+ end
559
+
560
+ data('default' => [ 0.1, {} ],
561
+ 'config' => [ 1, { server: { accept_polling_timeout_seconds: 1 } }])
562
+ def test_accept_polling_timeout_seconds(data)
563
+ expected_value, config = data
564
+ @c.load(config)
565
+ assert_equal(expected_value, @c.accept_polling_timeout_seconds)
566
+ end
567
+
568
+ data('default' => [ 20, {} ],
569
+ 'config' => [ 30, { server: { thread_num: 30 } } ])
570
+ def test_thread_num(data)
571
+ expected_value, config = data
572
+ @c.load(config)
573
+ assert_equal(expected_value, @c.thread_num)
574
+ end
575
+
576
+ data('default' => [ 20, {} ],
577
+ 'config' => [ 30, { server: { thread_queue_size: 30 } }])
578
+ def test_thread_queue_size(data)
579
+ expected_value, config = data
580
+ @c.load(config)
581
+ assert_equal(expected_value, @c.thread_queue_size)
582
+ end
583
+
584
+ data('default' => [ 0.1, {} ],
585
+ 'config' => [ 1, { server: { thread_queue_polling_timeout_seconds: 1 } } ])
586
+ def test_thread_queue_polling_timeout_seconds(data)
587
+ expected_value, config = data
588
+ @c.load(config)
589
+ assert_equal(expected_value, @c.thread_queue_polling_timeout_seconds)
590
+ end
591
+
592
+ tls_dir = Pathname(__FILE__).dirname / "tls"
593
+ TLS_SERVER_PKEY = tls_dir / 'server.priv_key'
594
+ TLS_SERVER_CERT = tls_dir / 'server_localhost.cert'
595
+
596
+ unless ([ TLS_SERVER_PKEY, TLS_SERVER_CERT ].all?(&:file?)) then
597
+ warn("warning: do `rake test_cert:make' to create TLS private key file and TLS certificate file for test.")
598
+ end
599
+
600
+ def test_ssl_context
601
+ FileUtils.mkdir_p(@base_dir)
602
+ FileUtils.cp(TLS_SERVER_PKEY.to_path, @base_dir)
603
+ FileUtils.cp(TLS_SERVER_CERT.to_path, @base_dir)
604
+
605
+ @c.load(openssl: {
606
+ ssl_context: <<-EOF
607
+ _.key = PKey.read((base_dir / #{TLS_SERVER_PKEY.basename.to_path.dump}).read)
608
+ _.cert = X509::Certificate.new((base_dir / #{TLS_SERVER_CERT.basename.to_path.dump}).read)
609
+ EOF
610
+ })
611
+
612
+ ssl_context = @c.ssl_context
613
+ assert_instance_of(OpenSSL::SSL::SSLContext, ssl_context)
614
+ assert_equal(OpenSSL::PKey::RSA.new(TLS_SERVER_PKEY.read).params, ssl_context.key.params)
615
+ assert_equal(OpenSSL::X509::Certificate.new(TLS_SERVER_CERT.read), ssl_context.cert)
616
+ end
617
+
618
+ def test_ssl_context_use_ssl
619
+ @c.load(openssl: {
620
+ use_ssl: true
621
+ })
622
+
623
+ ssl_context = @c.ssl_context
624
+ assert_instance_of(OpenSSL::SSL::SSLContext, ssl_context)
625
+ assert_nil(ssl_context.key)
626
+ assert_nil(ssl_context.cert)
627
+ end
628
+
629
+ data('default' => {},
630
+ 'no_ssl_context' => { openssl: {} },
631
+ 'not_use_ssl' => { openssl: {
632
+ use_ssl: false,
633
+ ssl_context: <<-EOF
634
+ _.key = PKey.read((base_dir / #{TLS_SERVER_PKEY.basename.to_path.dump}).read)
635
+ _.cert = X509::Certificate.new((base_dir / #{TLS_SERVER_CERT.basename.to_path.dump}).read)
636
+ EOF
637
+ }
638
+ })
639
+ def test_ssl_context_not_use_ssl(config)
640
+ @c.load(config)
641
+ assert_nil(@c.ssl_context)
642
+ end
643
+
644
+ data('default' => [ 1024 * 16, {} ],
645
+ 'config' => [ 1024 * 64, { server: { send_buffer_limit_size: 1024 * 64 } } ],
646
+ 'compat' => [ 1024 * 64, { send_buffer_limit: 1024 * 64 } ],
647
+ 'priority' => [ 1024 * 64,
648
+ { server: { send_buffer_limit_size: 1024 * 64 },
649
+ send_buffer_limit: 1024 * 32
650
+ }
651
+ ])
652
+ def test_send_buffer_limit_size(data)
653
+ expected_value, config = data
654
+ @c.load(config)
655
+ assert_equal(expected_value, @c.send_buffer_limit_size)
656
+ end
657
+
658
+ data('default' => [ 30, {} ],
659
+ 'config' => [ 15, { lock: { read_lock_timeout_seconds: 15 } } ],
660
+ 'compat' => [ 15, { read_lock_timeout_seconds: 15 } ],
661
+ 'priority' => [ 15,
662
+ { lock: { read_lock_timeout_seconds: 15 },
663
+ read_lock_timeout_seconds: 20
664
+ }
665
+ ])
666
+ def test_read_lock_timeout_seconds(data)
667
+ expected_value, config = data
668
+ @c.load(config)
669
+ assert_equal(expected_value, @c.read_lock_timeout_seconds)
670
+ end
671
+
672
+ data('default' => [ 30, {} ],
673
+ 'config' => [ 15, { lock: { write_lock_timeout_seconds: 15 } } ],
674
+ 'compat' => [ 15, { write_lock_timeout_seconds: 15 } ],
675
+ 'priority' => [ 15,
676
+ { lock: { write_lock_timeout_seconds: 15 },
677
+ write_lock_timeout_seconds: 20,
678
+ }
679
+ ])
680
+ def test_write_lock_timeout_seconds(data)
681
+ expected_value, config = data
682
+ @c.load(config)
683
+ assert_equal(expected_value, @c.write_lock_timeout_seconds)
684
+ end
685
+
686
+ data('default' => [ 1, {} ],
687
+ 'config' => [ 3, { lock: { cleanup_write_lock_timeout_seconds: 3 } } ],
688
+ 'compat' => [ 3, { cleanup_write_lock_timeout_seconds: 3 } ],
689
+ 'priority' => [ 3,
690
+ { lock: { cleanup_write_lock_timeout_seconds: 3 },
691
+ cleanup_write_lock_timeout_seconds: 5
692
+ }
693
+ ])
694
+ def test_cleanup_write_lock_timeout_seconds(data)
695
+ expected_value, config = data
696
+ @c.load(config)
697
+ assert_equal(expected_value, @c.cleanup_write_lock_timeout_seconds)
698
+ end
699
+
700
+ data('default' => [ { origin_type: RIMS::GDBM_KeyValueStore,
701
+ origin_config: {},
702
+ middleware_list: [ RIMS::Checksum_KeyValueStore ]
703
+ },
704
+ {}
705
+ ],
706
+ 'origin_type' => [ { origin_type: RIMS::GDBM_KeyValueStore,
707
+ origin_config: {},
708
+ middleware_list: [ RIMS::Checksum_KeyValueStore ]
709
+ },
710
+ { storage: { meta_key_value_store: { type: 'gdbm' } } }
711
+ ],
712
+ 'compat_origin_type' => [ { origin_type: RIMS::GDBM_KeyValueStore,
713
+ origin_config: {},
714
+ middleware_list: [ RIMS::Checksum_KeyValueStore ]
715
+ },
716
+ { meta_key_value_store: { plug_in: 'gdbm' } }
717
+ ],
718
+ 'compat_origin_type2' => [ { origin_type: RIMS::GDBM_KeyValueStore,
719
+ origin_config: {},
720
+ middleware_list: [ RIMS::Checksum_KeyValueStore ]
721
+ },
722
+ { key_value_store_type: 'gdbm' }
723
+ ],
724
+ 'compat_origin_type_priority' => [ { origin_type: RIMS::GDBM_KeyValueStore,
725
+ origin_config: {},
726
+ middleware_list: [ RIMS::Checksum_KeyValueStore ]
727
+ },
728
+ { meta_key_value_store: { plug_in: 'gdbm' },
729
+ key_value_store_type: 'qdbm'
730
+ }
731
+ ],
732
+ 'origin_config' => [ { origin_type: RIMS::GDBM_KeyValueStore,
733
+ origin_config: { 'foo' => 'bar' },
734
+ middleware_list: [ RIMS::Checksum_KeyValueStore ]
735
+ },
736
+ { storage: { meta_key_value_store: { configuration: { 'foo' => 'bar' } } } }
737
+ ],
738
+ 'compat_origin_config' => [ { origin_type: RIMS::GDBM_KeyValueStore,
739
+ origin_config: { 'foo' => 'bar' },
740
+ middleware_list: [ RIMS::Checksum_KeyValueStore ]
741
+ },
742
+ { meta_key_value_store: { configuration: { 'foo' => 'bar' } } }
743
+ ],
744
+ 'use_checksum' => [ { origin_type: RIMS::GDBM_KeyValueStore,
745
+ origin_config: {},
746
+ middleware_list: [ RIMS::Checksum_KeyValueStore ]
747
+ },
748
+ { storage: { meta_key_value_store: { use_checksum: true } } }
749
+ ],
750
+ 'use_checksum_no' => [ { origin_type: RIMS::GDBM_KeyValueStore,
751
+ origin_config: {},
752
+ middleware_list: []
753
+ },
754
+ { storage: { meta_key_value_store: { use_checksum: false } } }
755
+ ],
756
+ 'compat_use_checksum' => [ { origin_type: RIMS::GDBM_KeyValueStore,
757
+ origin_config: {},
758
+ middleware_list: []
759
+ },
760
+ { meta_key_value_store: { use_checksum: false } }
761
+ ],
762
+ 'compat_use_checksum2' => [ { origin_type: RIMS::GDBM_KeyValueStore,
763
+ origin_config: {},
764
+ middleware_list: []
765
+ },
766
+ { use_key_value_store_checksum: false }
767
+ ],
768
+ 'compat_use_checksum_priority' => [ { origin_type: RIMS::GDBM_KeyValueStore,
769
+ origin_config: {},
770
+ middleware_list: []
771
+ },
772
+ { meta_key_value_store: { use_checksum: false },
773
+ use_key_value_store_checksum: true
774
+ }
775
+ ],
776
+ 'all' => [ { origin_type: RIMS::GDBM_KeyValueStore,
777
+ origin_config: { 'foo' => 'bar' },
778
+ middleware_list: [ RIMS::Checksum_KeyValueStore ]
779
+ },
780
+ { storage: {
781
+ meta_key_value_store: {
782
+ type: 'gdbm',
783
+ configuration: { 'foo' => 'bar' },
784
+ use_checksum: true
785
+ }
786
+ }
787
+ }
788
+ ],
789
+ 'priority' => [ { origin_type: RIMS::GDBM_KeyValueStore,
790
+ origin_config: { 'foo' => 'bar' },
791
+ middleware_list: []
792
+ },
793
+ { storage: {
794
+ meta_key_value_store: {
795
+ type: 'gdbm',
796
+ configuration: { 'foo' => 'bar' },
797
+ use_checksum: false
798
+ }
799
+ },
800
+ meta_key_value_store: {
801
+ plug_in: 'qdbm',
802
+ configuration: { 'foo' => 'baz' },
803
+ use_checksum: true
804
+ },
805
+ key_value_store_type: 'qdbm',
806
+ use_key_value_store_checksum: true
807
+ }
808
+ ])
809
+ def test_make_meta_key_value_store_params(data)
810
+ expected_params, config = data
811
+ @c.load(config)
812
+ assert_equal(expected_params, @c.make_meta_key_value_store_params.to_h)
813
+ end
814
+
815
+ data('default' => [ { origin_type: RIMS::GDBM_KeyValueStore,
816
+ origin_config: {},
817
+ middleware_list: [ RIMS::Checksum_KeyValueStore ]
818
+ },
819
+ {}
820
+ ],
821
+ 'origin_type' => [ { origin_type: RIMS::GDBM_KeyValueStore,
822
+ origin_config: {},
823
+ middleware_list: [ RIMS::Checksum_KeyValueStore ]
824
+ },
825
+ { storage: { text_key_value_store: { type: 'gdbm' } } }
826
+ ],
827
+ 'compat_origin_type' => [ { origin_type: RIMS::GDBM_KeyValueStore,
828
+ origin_config: {},
829
+ middleware_list: [ RIMS::Checksum_KeyValueStore ]
830
+ },
831
+ { text_key_value_store: { plug_in: 'gdbm' } }
832
+ ],
833
+ 'compat_origin_type2' => [ { origin_type: RIMS::GDBM_KeyValueStore,
834
+ origin_config: {},
835
+ middleware_list: [ RIMS::Checksum_KeyValueStore ]
836
+ },
837
+ { key_value_store_type: 'gdbm' }
838
+ ],
839
+ 'compat_origin_type_priority' => [ { origin_type: RIMS::GDBM_KeyValueStore,
840
+ origin_config: {},
841
+ middleware_list: [ RIMS::Checksum_KeyValueStore ]
842
+ },
843
+ { text_key_value_store: { plug_in: 'gdbm' },
844
+ key_value_store_type: 'qdbm'
845
+ }
846
+ ],
847
+ 'origin_config' => [ { origin_type: RIMS::GDBM_KeyValueStore,
848
+ origin_config: { 'foo' => 'bar' },
849
+ middleware_list: [ RIMS::Checksum_KeyValueStore ]
850
+ },
851
+ { storage: { text_key_value_store: { configuration: { 'foo' => 'bar' } } } }
852
+ ],
853
+ 'compat_origin_config' => [ { origin_type: RIMS::GDBM_KeyValueStore,
854
+ origin_config: { 'foo' => 'bar' },
855
+ middleware_list: [ RIMS::Checksum_KeyValueStore ]
856
+ },
857
+ { text_key_value_store: { configuration: { 'foo' => 'bar' } } }
858
+ ],
859
+ 'use_checksum' => [ { origin_type: RIMS::GDBM_KeyValueStore,
860
+ origin_config: {},
861
+ middleware_list: [ RIMS::Checksum_KeyValueStore ]
862
+ },
863
+ { storage: { text_key_value_store: { use_checksum: true } } }
864
+ ],
865
+ 'use_checksum_no' => [ { origin_type: RIMS::GDBM_KeyValueStore,
866
+ origin_config: {},
867
+ middleware_list: []
868
+ },
869
+ { storage: { text_key_value_store: { use_checksum: false } } }
870
+ ],
871
+ 'compat_use_checksum' => [ { origin_type: RIMS::GDBM_KeyValueStore,
872
+ origin_config: {},
873
+ middleware_list: []
874
+ },
875
+ { text_key_value_store: { use_checksum: false } }
876
+ ],
877
+ 'compat_use_checksum2' => [ { origin_type: RIMS::GDBM_KeyValueStore,
878
+ origin_config: {},
879
+ middleware_list: []
880
+ },
881
+ { use_key_value_store_checksum: false }
882
+ ],
883
+ 'compat_use_checksum_priority' => [ { origin_type: RIMS::GDBM_KeyValueStore,
884
+ origin_config: {},
885
+ middleware_list: []
886
+ },
887
+ { text_key_value_store: { use_checksum: false },
888
+ use_key_value_store_checksum: true
889
+ }
890
+ ],
891
+ 'all' => [ { origin_type: RIMS::GDBM_KeyValueStore,
892
+ origin_config: { 'foo' => 'bar' },
893
+ middleware_list: [ RIMS::Checksum_KeyValueStore ]
894
+ },
895
+ { storage: {
896
+ text_key_value_store: {
897
+ type: 'gdbm',
898
+ configuration: { 'foo' => 'bar' },
899
+ use_checksum: true
900
+ }
901
+ }
902
+ }
903
+ ],
904
+ 'priority' => [ { origin_type: RIMS::GDBM_KeyValueStore,
905
+ origin_config: { 'foo' => 'bar' },
906
+ middleware_list: []
907
+ },
908
+ { storage: {
909
+ text_key_value_store: {
910
+ type: 'gdbm',
911
+ configuration: { 'foo' => 'bar' },
912
+ use_checksum: false
913
+ }
914
+ },
915
+ text_key_value_store: {
916
+ plug_in: 'qdbm',
917
+ configuration: { 'foo' => 'baz' },
918
+ use_checksum: true
919
+ },
920
+ key_value_store_type: 'qdbm',
921
+ use_key_value_store_checksum: true
922
+ }
923
+ ])
924
+ def test_make_text_key_value_store_params(data)
925
+ expected_params, config = data
926
+ @c.load(config)
927
+ assert_equal(expected_params, @c.make_text_key_value_store_params.to_h)
928
+ end
929
+
930
+ def test_make_key_value_store_path
931
+ assert_equal(Pathname(File.join(@base_dir, 'mailbox', '11', '22222222')),
932
+ @c.make_key_value_store_path('mailbox', '1122222222'))
933
+ end
934
+
935
+ def test_make_key_value_store_path_short_mailbox_data_structure_version_error
936
+ error = assert_raise(ArgumentError) { @c.make_key_value_store_path('', '1122222222') }
937
+ assert_equal('too short mailbox data structure version.', error.message)
938
+ end
939
+
940
+ data('too_short' => '1',
941
+ 'boundary' => '12')
942
+ def test_make_key_value_store_path_short_unique_user_id_error(data)
943
+ unique_user_id = data
944
+ error = assert_raise(ArgumentError) { @c.make_key_value_store_path('mailbox', unique_user_id) }
945
+ assert_equal('too short unique user ID.', error.message)
946
+ end
947
+
948
+ authentication_users = {
949
+ presence: [
950
+ { 'user' => 'alice', 'pass' => 'open sesame' },
951
+ { 'user' => 'bob', 'pass' => 'Z1ON0101' }
952
+ ],
953
+ absence: [
954
+ { 'user' => 'no_user', 'pass' => 'nothing' }
955
+ ]
956
+ }
957
+
958
+ data('users', authentication_users)
959
+ def test_make_authentication_default(data)
960
+ auth = @c.make_authentication
961
+ assert_equal(Socket.gethostname, auth.hostname)
962
+
963
+ auth.start_plug_in(@logger)
964
+ for pw in data[:presence]
965
+ assert_equal(false, (auth.user? pw['user']), "user: #{pw['user']}")
966
+ assert(! auth.authenticate_login(pw['user'], pw['pass']), "user: #{pw['user']}")
967
+ end
968
+ for pw in data[:absence]
969
+ assert_equal(false, (auth.user? pw['user']), "user: #{pw['user']}")
970
+ assert(! auth.authenticate_login(pw['user'], pw['pass']), "user: #{pw['user']}")
971
+ end
972
+ auth.stop_plug_in(@logger)
973
+ end
974
+
975
+ data('config' => { authentication: { hostname: 'imap.example.com' } },
976
+ 'compat' => { hostname: 'imap.example.com' },
977
+ 'priority' => { authentication: { hostname: 'imap.example.com' },
978
+ hostname: 'imap2.example.com'
979
+ })
980
+ def test_make_authentication_hostname(config)
981
+ @c.load(config)
982
+ auth = @c.make_authentication
983
+ assert_equal('imap.example.com', auth.hostname)
984
+ end
985
+
986
+ data('single' => [ authentication_users,
987
+ { authentication: {
988
+ password_sources: [
989
+ { type: 'plain',
990
+ configuration: authentication_users[:presence]
991
+ }
992
+ ]
993
+ }
994
+ }
995
+ ],
996
+ 'multiple' => [ authentication_users,
997
+ { authentication: {
998
+ password_sources: authentication_users[:presence].map{|pw|
999
+ { type: 'plain',
1000
+ configuration: [ pw ]
1001
+ }
1002
+ }
1003
+ }
1004
+ }
1005
+ ],
1006
+ 'compat_username' => [ { presence: [ authentication_users[:presence][0] ],
1007
+ absence: authentication_users[:absence]
1008
+ },
1009
+ { username: authentication_users[:presence][0]['user'],
1010
+ password: authentication_users[:presence][0]['pass'],
1011
+ }
1012
+ ],
1013
+ 'compat_user_list' => [ authentication_users,
1014
+ { user_list: authentication_users[:presence] }
1015
+ ],
1016
+ 'compat_authentication' => [ authentication_users,
1017
+ { authentication: [
1018
+ { plug_in: 'plain',
1019
+ configuration: authentication_users[:presence]
1020
+ }
1021
+ ]
1022
+ }
1023
+ ],
1024
+ 'compat_priored_user_list' => [ authentication_users,
1025
+ { username: authentication_users[:presence][0]['user'],
1026
+ password: 'random',
1027
+ user_list: authentication_users[:presence],
1028
+ authentication: [
1029
+ { plug_in: 'plain',
1030
+ configuration: authentication_users[:presence].map{|pw|
1031
+ { user: pw['user'],
1032
+ pass: 'random'
1033
+ }
1034
+ }
1035
+ }
1036
+ ]
1037
+ }
1038
+ ],
1039
+ 'compat_priored_username' => [ { presence: [ authentication_users[:presence][0] ],
1040
+ absence: authentication_users[:absence]
1041
+ },
1042
+ { username: authentication_users[:presence][0]['user'],
1043
+ password: authentication_users[:presence][0]['pass'],
1044
+ authentication: [
1045
+ { plug_in: 'plain',
1046
+ configuration: [
1047
+ { user: authentication_users[:presence][0]['user'],
1048
+ pass: 'random'
1049
+ }
1050
+ ]
1051
+ }
1052
+ ]
1053
+ }
1054
+ ],
1055
+ 'priority' => [ authentication_users,
1056
+ { authentication: {
1057
+ password_sources: [
1058
+ { type: 'plain',
1059
+ configuration: authentication_users[:presence]
1060
+ }
1061
+ ]
1062
+ },
1063
+ username: authentication_users[:presence][0]['user'],
1064
+ password: 'random',
1065
+ user_list: authentication_users[:presence].map{|pw|
1066
+ { user: pw['user'],
1067
+ pass: 'random'
1068
+ }
1069
+ }
1070
+ }
1071
+ ])
1072
+ def test_make_authentication_password_sources(data)
1073
+ users, config = data
1074
+ @c.load(config)
1075
+ auth = @c.make_authentication
1076
+
1077
+ auth.start_plug_in(@logger)
1078
+ for pw in users[:presence]
1079
+ assert_equal(true, (auth.user? pw['user']), "user: #{pw['user']}")
1080
+ assert(auth.authenticate_login(pw['user'], pw['pass']), "user: #{pw['user']}")
1081
+ assert(! auth.authenticate_login(pw['user'], pw['pass'].succ), "user: #{pw['user']}")
1082
+ end
1083
+ for pw in users[:absence]
1084
+ assert_equal(false, (auth.user? pw['user']), "user: #{pw['user']}")
1085
+ assert(! auth.authenticate_login(pw['user'], pw['pass']), "user: #{pw['user']}")
1086
+ end
1087
+ auth.stop_plug_in(@logger)
1088
+ end
1089
+
1090
+ data('users', authentication_users)
1091
+ def test_make_authentication_no_type_error(data)
1092
+ @c.load(authentication: {
1093
+ password_sources: [
1094
+ { configuration: data[:presence] }
1095
+ ]
1096
+ })
1097
+ error = assert_raise(KeyError) { @c.make_authentication }
1098
+ assert_equal('not found a password source type.', error.message)
1099
+ end
1100
+
1101
+ data('default' => [ '#postman', {} ],
1102
+ 'config' => [ 'alice', { authorization: { mail_delivery_user: 'alice' } } ],
1103
+ 'compat' => [ 'alice', { mail_delivery_user: 'alice' } ],
1104
+ 'priority' => [ 'alice',
1105
+ { authorization: { mail_delivery_user: 'alice' },
1106
+ mail_delivery_user: 'bob'
1107
+ }
1108
+ ])
1109
+ def test_mail_delivery_user(data)
1110
+ expected_user, config = data
1111
+ @c.load(config)
1112
+ assert_equal(expected_user, @c.mail_delivery_user)
1113
+ end
1114
+ end
1115
+ end
1116
+
1117
+ # Local Variables:
1118
+ # mode: Ruby
1119
+ # indent-tabs-mode: nil
1120
+ # End: