#!/usr/bin/env expect
############################################################################
# Purpose: Test of Slurm functionality
#          Test of slurmrestd basic functionality.
############################################################################
# Copyright (C) 2020 SchedMD LLC
# Written by Nathan Rini <nate@schedmd.gov>
#
# 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

if {![file exists $slurmrestd]} {
	skip "slurmrestd not installed"
}

# Avoid fatal on slurmrestd because it should not be run as SlurmUser
set env(SLURMRESTD_SECURITY) disable_user_check

run_command -subtest        "$slurmrestd -h"
run_command -subtest        "$slurmrestd -h"
run_command -subtest -xfail "$slurmrestd --invalid"
run_command -subtest        "$slurmrestd -a list"
run_command -subtest -xfail "$slurmrestd -a invalid_plugin"
run_command -subtest        "$slurmrestd -s list"
run_command -subtest -xfail "$slurmrestd -s invalid_plugin"
run_command -subtest        -stdin "GET /openapi HTTP/1.1\r\nConnection: Close\r\n\r\n" "$slurmrestd -a rest_auth/local"
run_command -subtest -xfail -stdin "GET /openapi HTTP/1.1\r\nConnection: Close\r\n\r\n" "$slurmrestd -a rest_auth/invalid"
# Subtests related to Bug 10388:
run_command -subtest -xfail -stdin "INVALID" "$slurmrestd"
run_command -subtest -xfail -stdin "INVALID\r\n\r\n" "$slurmrestd"
run_command -subtest -xfail -stdin "INVALID\r\nINVALID\r\n\r\n" "$slurmrestd"
run_command -subtest -xfail -stdin "GET /openapi HTTP/1.1\r\nINVALID\r\n\r\n" "$slurmrestd"
