1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
5 require 'minitest/autorun'
9 class TestAddUser < Minitest::Test
12 def test_useradd_error
13 # binstub_new_user/useradd will exit non-zero because its args
14 # won't match any line in this empty file:
15 File.open(@tmpdir+'/succeed', 'w') do |f| end
16 invoke_sync binstubs: ['new_user']
17 spied = File.read(@tmpdir+'/spy')
18 assert_match %r{useradd -m -c active -s /bin/bash -G fuse active}, spied
19 # BUG(TC): This assertion succeeds only if docker and fuse groups
20 # exist on the host, but is insensitive to the admin group (groups
21 # are quietly ignored by login-sync if they don't exist on the
23 assert_match %r{useradd -m -c adminroot -s /bin/bash -G docker(,admin)?,fuse adminroot}, spied
26 def test_useradd_success
27 # binstub_new_user/useradd will succeed.
28 File.open(@tmpdir+'/succeed', 'w') do |f|
29 f.puts 'useradd -m -c active -s /bin/bash -G fuse active'
30 # Accept either form; see note about groups in test_useradd_error.
31 f.puts 'useradd -m -c adminroot -s /bin/bash -G docker,fuse adminroot'
32 f.puts 'useradd -m -c adminroot -s /bin/bash -G docker,admin,fuse adminroot'
34 $stderr.puts "*** Expect crash after getpwnam() fails:"
35 invoke_sync binstubs: ['new_user']
37 spied = File.read(@tmpdir+'/spy')
38 # Expect a crash after adding one user, because Dir.mkdir({home}) fails.
39 assert_match %r{^useradd -m -c [^\n]+\n$}s, spied