added user/pass auth test
This commit is contained in:
parent
f713f1df7e
commit
e52e29444f
@ -21,6 +21,14 @@ DATA_HOST_KEY = {
|
||||
"id": 1,
|
||||
}
|
||||
|
||||
DATA_HOST_KEY_WITH_TOKEN = {
|
||||
"jsonrpc": "2.0",
|
||||
"method": "history.push",
|
||||
"params": {"host": HOST, "key": KEY, "value": VALUE},
|
||||
"id": 1,
|
||||
"auth": "3fe6ed01a69ebd79907a120bcd04e494"
|
||||
}
|
||||
|
||||
DATA_ITEMID = {
|
||||
"jsonrpc": "2.0",
|
||||
"method": "history.push",
|
||||
@ -200,6 +208,43 @@ def test_ping_monitor_config_host_and_key_with_api_key_auth_data_successful():
|
||||
).and_return(flexmock(ok=True)).once()
|
||||
flexmock(module.logger).should_receive('warning').never()
|
||||
|
||||
module.ping_monitor(
|
||||
hook_config,
|
||||
{},
|
||||
'config.yaml',
|
||||
borgmatic.hooks.monitor.State.FAIL,
|
||||
monitoring_log_level=1,
|
||||
dry_run=False,
|
||||
)
|
||||
|
||||
def test_ping_monitor_config_host_and_key_with_username_password_auth_data_successful():
|
||||
# This test should simulate a successful POST to a Zabbix server. This test uses USERNAME/PASSWORD
|
||||
# to authenticate and HOST/KEY to know which item to populate in Zabbix.
|
||||
hook_config = {
|
||||
'server': SERVER,
|
||||
'host': HOST,
|
||||
'key': KEY,
|
||||
'username': USERNAME,
|
||||
'password': PASSWORD
|
||||
}
|
||||
|
||||
auth_response = flexmock(ok=True)
|
||||
auth_response.should_receive('json').and_return({"jsonrpc":"2.0","result":"3fe6ed01a69ebd79907a120bcd04e494","id":1})
|
||||
|
||||
flexmock(module.requests).should_receive('post').with_args(
|
||||
f'{SERVER}',
|
||||
headers=AUTH_HEADERS_USERNAME_PASSWORD,
|
||||
json=DATA_USER_LOGIN,
|
||||
).and_return(auth_response).once()
|
||||
|
||||
flexmock(module.logger).should_receive('warning').never()
|
||||
|
||||
flexmock(module.requests).should_receive('post').with_args(
|
||||
f'{SERVER}',
|
||||
headers=AUTH_HEADERS_USERNAME_PASSWORD,
|
||||
json=DATA_HOST_KEY_WITH_TOKEN,
|
||||
).and_return(flexmock(ok=True)).once()
|
||||
|
||||
module.ping_monitor(
|
||||
hook_config,
|
||||
{},
|
||||
|
Loading…
x
Reference in New Issue
Block a user