1 require 'minitest/autorun'
5 class TestAddUser < Minitest::Test
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
19 assert_match %r{useradd -m -c adminroot -s /bin/bash -G docker(,admin)?,fuse adminroot}, spied
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'
30 $stderr.puts "*** Expect crash in dir_s_mkdir:"
31 invoke_sync binstubs: ['new_user']
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