Source
$this->assertEquals((HOST_ENCRYPTION_PSK|HOST_ENCRYPTION_NONE), CDBHelper::getValue('SELECT autoreg_tls_accept FROM config'));
<?php
/*
** 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 Affero General Public License as published by the Free Software Foundation, version 3.
**
** 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 Affero General Public License for more details.
**
** You should have received a copy of the GNU Affero General Public License along with this program.
** If not, see <https://www.gnu.org/licenses/>.
**/
require_once dirname(__FILE__) . '/../../include/CWebTest.php';
/**
* @backup config
*/
class testFormAdministrationGeneralAutoregistration extends CWebTest {
/**
* Check the default state of page elements, when first time open Autoregistration.
*/
public function testFormAdministrationGeneralAutoregistration_checkDefaultState() {
// Navigate to autoregistration page from dashboard page.
$this->page->login()->open('zabbix.php?action=gui.edit');
$this->query('id:page-title-general')->asPopupButton()->one()->select('Autoregistration');
// Check elements default state.
$form = $this->query('id:autoreg-form')->asForm()->one();
$this->assertEquals(['No encryption'], $form->getField('Encryption level')->getValue());
$this->assertFalse($form->query('id:tls_psk_identity')->one()->isDisplayed());
$this->assertFalse($form->query('id:tls_psk')->one()->isDisplayed());
}
/**
* Check PSK field values, when PSK encryption is set and unset.
*/
public function testFormAdministrationGeneralAutoregistration_PskValues() {
$data = [
'Encryption level' => ['PSK'],
'PSK identity' => 'PSK004',
'PSK' => '07df83bf21bf0be663090bb8d4128558ab9b95fba66a6dbf834f8b91ae5e08ae'
];
$this->page->login()->open('zabbix.php?action=autoreg.edit');
$form = $this->query('id:autoreg-form')->asForm()->one();
$form->fill($data);
// Check entered PSK values.
$this->assertEquals($data['PSK identity'], $form->getField('PSK identity')->getValue());
$this->assertEquals($data['PSK'], $form->getField('PSK')->getValue());
// Uncheck PSK. PSK fields are hidden.
$form->getField('Encryption level')->set('PSK', false);
$this->assertFalse($form->query('id:tls_psk_identity')->one()->isDisplayed());
$this->assertFalse($form->query('id:tls_psk')->one()->isDisplayed());
// Set PSK again, and check that PSK values remain the same.
$form->getField('Encryption level')->set('PSK', true);
$this->assertEquals($data['PSK identity'], $form->getField('PSK identity')->getValue());
$this->assertEquals($data['PSK'], $form->getField('PSK')->getValue());
}
/**
* The order of the test cases is important. Test cases depend on each other.
*/
public static function getAuditReportData() {
return [
// Add PSK encryption.
[
[
'fields' => [
'Encryption level' => ['PSK'],
'PSK identity' => 'PSK005',
'PSK' => '07df83bf21bf0be663090bb8d4128558ab9b95fba66a6dbf834f8b91ae5e08ae'
],
'audit' => [
'User' => 'Admin',
'Resource' => 'Autoregistration',
'Action' => 'Update',
'ID' => 1,
'Details' => [
'Details',
'autoregistration.tls_accept: 1 => 2',
'autoregistration.tls_psk: ****** => ******'
]
],
'detail_button' => [