Source
// Check Telnet type change and new parameters. "username", "password" and "port" can remain for SSH, and other fields should be properly written to DB.
<?php
/*
** Zabbix
** Copyright (C) 2001-2025 Zabbix SIA
**
** This program 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.
**
** This program 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 this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
require_once dirname(__FILE__).'/../include/CAPITest.php';
/**
* @backup scripts
*/
class testScripts extends CAPITest {
public static function script_create_data_invalid() {
return [
// Check script type.
'Test missing type' => [
'script' => [
'name' => 'API create script',
'command' => 'reboot server'
],
'expected_error' => 'Invalid parameter "/1": the parameter "type" is missing.'
],
'Test invalid type (empty)' => [
'script' => [
'name' => 'API create script',
'type' => '',
'command' => 'reboot server'
],
'expected_error' => 'Invalid parameter "/1/type": an integer is expected.'
],
'Test invalid type (string)' => [
'script' => [
'name' => 'API create script',
'type' => 'abc',
'command' => 'reboot server'
],
'expected_error' => 'Invalid parameter "/1/type": an integer is expected.'
],
'Test invalid type' => [
'script' => [
'name' => 'API create script',
'type' => 999999,
'command' => 'reboot server'
],
'expected_error' => 'Invalid parameter "/1/type": value must be one of '.
implode(', ', [ZBX_SCRIPT_TYPE_CUSTOM_SCRIPT, ZBX_SCRIPT_TYPE_IPMI, ZBX_SCRIPT_TYPE_SSH,
ZBX_SCRIPT_TYPE_TELNET, ZBX_SCRIPT_TYPE_WEBHOOK
]).'.'
],
// Check script command.
'Test missing command' => [
'script' => [
'name' => 'API create script',
'type' => ZBX_SCRIPT_TYPE_CUSTOM_SCRIPT
],
'expected_error' => 'Invalid parameter "/1": the parameter "command" is missing.'
],
'Test empty command' => [
'script' => [
'name' => 'API create script',
'type' => ZBX_SCRIPT_TYPE_CUSTOM_SCRIPT,
'command' => ''
],
'expected_error' => 'Invalid parameter "/1/command": cannot be empty.'
],
// Check script name.
'Test missing name' => [
'script' => [
'type' => ZBX_SCRIPT_TYPE_CUSTOM_SCRIPT,
'command' => 'reboot server'
],
'expected_error' => 'Invalid parameter "/1": the parameter "name" is missing.'
],
'Test empty name' => [
'script' => [