8784: Fix test for latest firefox.
[arvados.git] / services / login-sync / test / test_add_user.rb
1 require 'minitest/autorun'
2
3 require 'stubs'
4
5 class TestAddUser < Minitest::Test
6   include Stubs
7
8   def test_useradd_error
9     # binstub_new_user/useradd will exit non-zero because its args
10     # won't match any line in this empty file:
11     File.open(@tmpdir+'/succeed', 'w') do |f| end
12     invoke_sync binstubs: ['new_user']
13     spied = File.read(@tmpdir+'/spy')
14     assert_match %r{useradd -m -c active -s /bin/bash -G fuse active}, spied
15     # BUG(TC): This assertion succeeds only if docker and fuse groups
16     # exist on the host, but is insensitive to the admin group (groups
17     # are quietly ignored by login-sync if they don't exist on the
18     # current host).
19     assert_match %r{useradd -m -c adminroot -s /bin/bash -G docker(,admin)?,fuse adminroot}, spied
20   end
21
22   def test_useradd_success
23     # binstub_new_user/useradd will succeed.
24     File.open(@tmpdir+'/succeed', 'w') do |f|
25       f.puts 'useradd -m -c active -s /bin/bash -G fuse active'
26       # Accept either form; see note about groups in test_useradd_error.
27       f.puts 'useradd -m -c adminroot -s /bin/bash -G docker,fuse adminroot'
28       f.puts 'useradd -m -c adminroot -s /bin/bash -G docker,admin,fuse adminroot'
29     end
30     $stderr.puts "*** Expect crash after getpwnam() fails:"
31     invoke_sync binstubs: ['new_user']
32     assert !$?.success?
33     spied = File.read(@tmpdir+'/spy')
34     # Expect a crash after adding one user, because Dir.mkdir({home}) fails.
35     assert_match %r{^useradd -m -c [^\n]+\n$}s, spied
36   end
37 end