18700: Merge branch 'main'
[arvados.git] / services / login-sync / test / test_add_user.rb
index c7d92b7efe5f72f805e55eba651bc70d87bf6a87..db909ac83fc63bb2bbbca5aac7ea5c943a0a1c05 100644 (file)
@@ -1,3 +1,7 @@
+# Copyright (C) The Arvados Authors. All rights reserved.
+#
+# SPDX-License-Identifier: AGPL-3.0
+
 require 'minitest/autorun'
 
 require 'stubs'
@@ -6,23 +10,23 @@ class TestAddUser < Minitest::Test
   include Stubs
 
   def test_useradd_error
+    valid_groups = %w(docker admin fuse).select { |g| Etc.getgrnam(g) rescue false }
     # binstub_new_user/useradd will exit non-zero because its args
     # won't match any line in this empty file:
     File.open(@tmpdir+'/succeed', 'w') do |f| end
     invoke_sync binstubs: ['new_user']
     spied = File.read(@tmpdir+'/spy')
-    assert_match %r{useradd -m -c active -s /bin/bash -G fuse active}, spied
-    assert_match %r{useradd -m -c adminroot -s /bin/bash -G docker,fuse adminroot}, spied
+    assert_match %r{useradd -m -c active -s /bin/bash active}, spied
+    assert_match %r{useradd -m -c adminroot -s /bin/bash adminroot}, spied
   end
 
   def test_useradd_success
-    # binstub_new_user/useradd will exit non-zero because its args
-    # won't match any line in this empty file:
+    # binstub_new_user/useradd will succeed.
     File.open(@tmpdir+'/succeed', 'w') do |f|
-      f.puts 'useradd -m -c active -s /bin/bash -G fuse active'
-      f.puts 'useradd -m -c adminroot -s /bin/bash -G docker,fuse adminroot'
+      f.puts 'useradd -m -c active -s /bin/bash -G active'
+      f.puts 'useradd -m -c adminroot -s /bin/bash adminroot'
     end
-    $stderr.puts "*** Expect crash in dir_s_mkdir:"
+    $stderr.puts "*** Expect crash after getpwnam() fails:"
     invoke_sync binstubs: ['new_user']
     assert !$?.success?
     spied = File.read(@tmpdir+'/spy')