Skip to content

Commit

Permalink
service: scan unique user id (#38)
Browse files Browse the repository at this point in the history
Github Issue: #38
  • Loading branch information
y10k committed Sep 13, 2020
1 parent 7a85928 commit c946f87
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
17 changes: 17 additions & 0 deletions lib/rims/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,23 @@ def make_key_value_store_path(mailbox_data_structure_version, unique_user_id)
make_key_value_store_base_dir(mailbox_data_structure_version) + bucket_dir_name + store_dir_name
end

def scan_unique_user_id(mailbox_data_structure_version)
return enum_for(:scan_unique_user_id, mailbox_data_structure_version) unless block_given?
key_value_store_base_dir = make_key_value_store_base_dir(mailbox_data_structure_version)
key_value_store_base_dir.glob('[0-9a-z][0-9a-z]') do |bucket_dir|
if (bucket_dir.directory?) then
bucket_dir.glob('[0-9a-z]*') do |store_dir|
if (store_dir.directory?) then
unique_user_id = bucket_dir.basename.to_s + store_dir.basename.to_s
yield(unique_user_id)
end
end
end
end

nil
end

def make_authentication
if (@config.dig('authentication')&.is_a? Hash) then
auth_conf = @config.dig('authentication')
Expand Down
15 changes: 15 additions & 0 deletions test/test_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1229,6 +1229,21 @@ def test_make_key_value_store_path_short_unique_user_id_error(data)
assert_equal('too short unique user ID.', error.message)
end

data('empty' => [],
'single_user' => %w[ 1122222222 ],
'some_users' => %w[
1122222222
1133333333
4455555555
])
def test_scan_unique_user_id(data)
expected_unique_user_id_list = data
for unique_user_id in expected_unique_user_id_list
FileUtils.mkdir_p(@c.make_key_value_store_path('mailbox', unique_user_id).to_s)
end
assert_equal(expected_unique_user_id_list.sort, @c.scan_unique_user_id('mailbox').to_a.sort)
end

authentication_users = {
presence: [
{ 'user' => 'alice', 'pass' => 'open sesame' },
Expand Down

0 comments on commit c946f87

Please sign in to comment.