[], 'expected_error' => 'Invalid parameter "/": cannot be empty.' ], // Check action id validation. [ 'drule' => [''], 'expected_error' => 'Invalid parameter "/1": a number is expected.' ], [ 'drule' => ['abc'], 'expected_error' => 'Invalid parameter "/1": a number is expected.' ], [ 'drule' => ['1.1'], 'expected_error' => 'Invalid parameter "/1": a number is expected.' ], [ 'drule' => ['123456'], 'expected_error' => 'No permissions to referred object or it does not exist!' ], [ 'drule' => ['10', '10'], 'expected_error' => 'Invalid parameter "/2": value (10) already exists.' ], [ 'drule' => ['10', 'abcd'], 'expected_error' => 'Invalid parameter "/2": a number is expected.' ], [ 'drule' => ['15'], 'expected_error' => 'Discovery rule "API discovery rule used in action" is used in "API action for Discovery check" action.' ], [ 'drule' => ['16'], 'expected_error' => 'Discovery rule "API discovery rule used in action 2" is used in "API action for Discovery rule" action.' ], // Successfully delete action. // Discovery rule without proxy [ 'drule' => ['10'], 'expected_error' => null ], // Discovery rule with proxy [ 'drule' => ['11'], 'expected_error' => null ], // Delete two Discovery rules [ 'drule' => ['12','13'], 'expected_error' => null ] ]; } /** * @dataProvider getDRuleDeleteData */ public function testDRule_Delete($drule, $expected_error) { $result = $this->call('drule.delete', $drule, $expected_error); if ($expected_error === null) { foreach ($result['result']['druleids'] as $id) { $this->assertEquals(0, CDBHelper::getCount('SELECT NULL FROM drules WHERE druleid='.zbx_dbstr($id))); } } } public static function getDRuleUserPermissionsData() { return [ [ 'login' => ['user' => 'guest', 'password' => ''], 'drule' => ['14'], 'expected_error' => 'No permissions to call "drule.delete".' ], [ 'login' => ['user' => 'action-user', 'password' => 'zabbix'], 'drule' => ['14'], 'expected_error' => 'No permissions to call "drule.delete".' ], [ 'login' => ['user' => 'action-admin', 'password' => 'zabbix'], 'drule' => ['1'], 'expected_error' => 'No permissions to referred object or it does not exist!' ], [ 'login' => ['user' => 'action-admin', 'password' => 'zabbix'], 'drule' => ['14'], 'expected_error' => null ] ]; } /** * @onBefore removeGuestFromDisabledGroup * @onAfter addGuestToDisabledGroup * * @dataProvider getDRuleUserPermissionsData */ public function testDRule_Permissions($login, $drule, $expected_error) { $sql = 'SELECT * FROM drules ORDER BY druleid'; $old_drule=CDBHelper::getHash($sql); $this->authorize($login['user'], $login['password']); $result = $this->call('drule.delete', $drule, $expected_error); if ($expected_error === null) { foreach ($result['result']['druleids'] as $id) { $this->assertEquals(0, CDBHelper::getCount('SELECT * FROM drules WHERE druleid='.zbx_dbstr($id))); } } else { $this->assertEquals($old_drule, CDBHelper::getHash($sql)); } } /** * Guest user needs to be out of "Disabled" group to have access to frontend. */ public static function removeGuestFromDisabledGroup() { DBexecute('DELETE FROM users_groups WHERE userid=2 AND usrgrpid=9'); } public function addGuestToDisabledGroup() { DBexecute('INSERT INTO users_groups (id, usrgrpid, userid) VALUES (150, 9, 2)'); } }