Merge branch '19886-crunch-run-early-log-commit'
[arvados.git] / services / api / test / unit / application_test.rb
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: AGPL-3.0
4
5 require 'test_helper'
6
7 class ApplicationTest < ActiveSupport::TestCase
8   include CurrentApiClient
9
10   test "act_as_system_user" do
11     Thread.current[:user] = users(:active)
12     assert_equal users(:active), Thread.current[:user]
13     act_as_system_user do
14       assert_not_equal users(:active), Thread.current[:user]
15       assert_equal system_user, Thread.current[:user]
16     end
17     assert_equal users(:active), Thread.current[:user]
18   end
19
20   test "act_as_system_user is exception safe" do
21     Thread.current[:user] = users(:active)
22     assert_equal users(:active), Thread.current[:user]
23     caught = false
24     begin
25       act_as_system_user do
26         assert_not_equal users(:active), Thread.current[:user]
27         assert_equal system_user, Thread.current[:user]
28         raise "Fail"
29       end
30     rescue
31       caught = true
32     end
33     assert caught
34     assert_equal users(:active), Thread.current[:user]
35   end
36
37   test "config maps' keys are returned as symbols" do
38     assert Rails.configuration.Users.AutoSetupUsernameBlacklist.is_a? ActiveSupport::OrderedOptions
39     assert Rails.configuration.Users.AutoSetupUsernameBlacklist.keys.size > 0
40     Rails.configuration.Users.AutoSetupUsernameBlacklist.keys.each do |k|
41       assert k.is_a? Symbol
42     end
43   end
44 end