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 valid_groups = %w(docker admin fuse).select { |g| Etc.getgrnam(g) rescue false }
14 # binstub_new_user/useradd will exit non-zero because its args
15 # won't match any line in this empty file:
16 File.open(@tmpdir+'/succeed', 'w') do |f| end
17 invoke_sync binstubs: ['new_user']
18 spied = File.read(@tmpdir+'/spy')
19 assert_match %r{useradd -m -c active -s /bin/bash active}, spied
20 assert_match %r{useradd -m -c adminroot -s /bin/bash adminroot}, spied
23 def test_useradd_success
24 # binstub_new_user/useradd will succeed.
25 File.open(@tmpdir+'/succeed', 'w') do |f|
26 f.puts 'useradd -m -c active -s /bin/bash -G active'
27 f.puts 'useradd -m -c adminroot -s /bin/bash adminroot'
29 $stderr.puts "*** Expect crash after getpwnam() fails:"
30 invoke_sync binstubs: ['new_user']
32 spied = File.read(@tmpdir+'/spy')
33 # Expect a crash after adding one user, because Dir.mkdir({home}) fails.
34 assert_match %r{^useradd -m -c [^\n]+\n$}s, spied