File: test14.9

package info (click to toggle)
slurm-wlm 22.05.8-4%2Bdeb12u3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 48,492 kB
  • sloc: ansic: 475,246; exp: 69,020; sh: 8,862; javascript: 6,528; python: 6,444; makefile: 4,185; perl: 4,069; pascal: 131
file content (104 lines) | stat: -rwxr-xr-x 4,364 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/env expect
############################################################################
# Purpose: Test of Slurm functionality
#          Verify that an sbcast credential is properly validated.
############################################################################
# Copyright (C) 2012 SchedMD LLC.
# Written by Morris Jette <jette@schedmd.com>
#
# This file is part of Slurm, a resource management program.
# For details, see <https://slurm.schedmd.com/>.
# Please also read the included file: DISCLAIMER.
#
# Slurm is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 2 of the License, or (at your option)
# any later version.
#
# Slurm is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along
# with Slurm; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA.
############################################################################
source ./globals

set bcast_file  "/tmp/${test_name}_sbcast"
set job_id      0

if {[get_config_param "FrontendName"] ne "MISSING"} {
	skip "This test is incompatible with front-end systems"
}
if {![check_run_as_user $testsuite_user]} {
	skip "This test needs testsuite_user configured in globals.local"
}

proc cleanup {} {
	global job_id sacctmgr testsuite_user test_name

	cancel_job $job_id
	run_command -none "$sacctmgr -vi delete user name=$testsuite_user"
	run_command -none "$sacctmgr -vi delete account name=$test_name"
}

if { [get_config_param -dbd "AllowNoDefAcct"] eq "Yes" } {
	set def_acct " defaultaccount=$test_name"
} else {
	set def_acct ""
}

# Setup the test user
run_command -fail "$sacctmgr -vi add account name=$test_name"
run_command -fail "$sacctmgr -vi add user name=$testsuite_user account=$test_name$def_acct"
run_command -fail "$sacctmgr -vi update user $testsuite_user set adminlevel=None"

#
# Test that testsuite_user can sbcast to own jobs
#
log_info "Test that a user can sbcast to its own jobs"

# Spawn an salloc job and obtain the job id
set salloc_output [run_command_output -fail -user $testsuite_user "$salloc -v -N1 -t2 --no-shell"]
if {![regexp {Granted job allocation (\d+)} $salloc_output - job_id]} {
	fail "Allocation not granted ($output)"
}

# Clear out the broadcast file
run_command -fail -user $testsuite_user "$srun --jobid $job_id $bin_rm -f $bcast_file"

# Attempt to broadcast the file
set sbcast_output [run_command_output -user $testsuite_user -subtest "$sbcast --jobid $job_id $sbcast $bcast_file"]
subtest {![regexp -line {error:.*Invalid user id} $sbcast_output]} "sbcast should NOT generate an error"

# Verify the file was broadcasted
set ls_output [run_command_output -user $testsuite_user -subtest "$srun --jobid $job_id ls $bcast_file"]
subtest [regexp $bcast_file $ls_output] "The file should have been broadcasted"

# Clear out the broadcast file
run_command -fail -user $testsuite_user "$srun --jobid $job_id $bin_rm -f $bcast_file"
run_command -fail -user $testsuite_user "$scancel $job_id"

#
# Test that testsuite_user cannot sbcast to jobs from other users
#
log_info "Test that unauthorized users cannot sbcast to a job"

# Spawn an salloc job and obtain the job id
set salloc_output [run_command_output -fail "$salloc -v -N1 -t2 --no-shell"]
if {![regexp {Granted job allocation (\d+)} $salloc_output - job_id]} {
    fail "Allocation not granted ($output)"
}

# Clear out the broadcast file
run_command -fail "$srun --jobid $job_id $bin_rm -f $bcast_file"

# Attempt to broadcast the file as a different (and unauthorized) user
set sbcast_output [run_command_output -user $testsuite_user -subtest -xfail "$sbcast --jobid $job_id $sbcast $bcast_file"]
subtest [regexp -line {error:.*Invalid user id} $sbcast_output] "sbcast should generate an error"

# Verify the file was not broadcast
set ls_output [run_command_output -subtest -xfail "$srun --jobid $job_id ls $bcast_file"]
subtest [regexp -line {ls.* (?:No such file|does not exist|not found)} $ls_output] "The file should not have been broadcast"