mirror of
https://github.com/ntop/ntopng.git
synced 2026-04-29 23:49:33 +00:00
Adjusts endpoint tests
This commit is contained in:
parent
71870f5158
commit
5d798db8fc
5 changed files with 37 additions and 37 deletions
|
|
@ -12,7 +12,7 @@ local alerts_api = require("alerts_api")
|
|||
local format_utils = require("format_utils")
|
||||
|
||||
local plugins_utils = require "plugins_utils"
|
||||
local notification_endpoints = require("notification_endpoints")
|
||||
local notification_configs = require("notification_configs")
|
||||
local notification_recipients = require("notification_recipients")
|
||||
|
||||
sendHTTPContentTypeHeader('text/html')
|
||||
|
|
@ -31,66 +31,66 @@ local res
|
|||
-- TEST ENDPOINT CONFIGS --
|
||||
---------------------------
|
||||
|
||||
res = notification_endpoints.reset_configs()
|
||||
res = notification_configs.reset_configs()
|
||||
assert(res["status"] == "OK")
|
||||
|
||||
res = notification_endpoints.delete_config("nonexisting_config_name")
|
||||
res = notification_configs.delete_config("nonexisting_config_name")
|
||||
assert(res["status"] == "failed" and res["error"]["type"] == "endpoint_config_not_existing")
|
||||
|
||||
res = notification_endpoints.add_config("nonexisting", nil, nil)
|
||||
res = notification_configs.add_config("nonexisting", nil, nil)
|
||||
assert(res["status"] == "failed" and res["error"]["type"] == "endpoint_not_existing")
|
||||
|
||||
res = notification_endpoints.add_config("email", nil, nil)
|
||||
res = notification_configs.add_config("email", nil, nil)
|
||||
assert(res["status"] == "failed" and res["error"]["type"] == "invalid_endpoint_conf_name")
|
||||
|
||||
res = notification_endpoints.add_config("email", "ntop_email", nil)
|
||||
res = notification_configs.add_config("email", "ntop_email", nil)
|
||||
|
||||
assert(res["status"] == "failed" and res["error"]["type"] == "invalid_conf_params")
|
||||
|
||||
-- see email.lua for mandatory conf_params
|
||||
local conf_params = {
|
||||
smtp_server_name = "mail.ntop.org"
|
||||
smtp_server = "mail.ntop.org"
|
||||
}
|
||||
|
||||
res = notification_endpoints.add_config("email", "ntop_email", conf_params)
|
||||
res = notification_configs.add_config("email", "ntop_email", conf_params)
|
||||
assert(res["status"] == "failed" and res["error"]["type"] == "missing_mandatory_param")
|
||||
|
||||
conf_params = {
|
||||
smtp_server_name = "mail.ntop.org",
|
||||
sender = "tester@ntop.org"
|
||||
smtp_server = "mail.ntop.org",
|
||||
email_sender = "tester@ntop.org"
|
||||
}
|
||||
res = notification_endpoints.add_config("email", "ntop_email", conf_params)
|
||||
res = notification_configs.add_config("email", "ntop_email", conf_params)
|
||||
assert(res["status"] == "OK")
|
||||
|
||||
-- Duplicate addition
|
||||
res = notification_endpoints.add_config("email", "ntop_email", conf_params)
|
||||
res = notification_configs.add_config("email", "ntop_email", conf_params)
|
||||
assert(res["status"] == "failed" and res["error"]["type"] == "endpoint_config_already_existing")
|
||||
|
||||
-- Delete the endpoint
|
||||
res = notification_endpoints.delete_config("ntop_email")
|
||||
res = notification_configs.delete_config("ntop_email")
|
||||
assert(res["status"] == "OK")
|
||||
|
||||
-- Add also some optional params
|
||||
conf_params = {
|
||||
smtp_server_name = "mail.ntop.org",
|
||||
sender = "tester@ntop.org",
|
||||
username = "ntopuser",
|
||||
password = "ntoppassword"
|
||||
smtp_server = "mail.ntop.org",
|
||||
email_sender = "tester@ntop.org",
|
||||
smpt_username = "ntopuser",
|
||||
smtp_password = "ntoppassword"
|
||||
}
|
||||
|
||||
res = notification_endpoints.add_config("email", "ntop_email", conf_params)
|
||||
res = notification_configs.add_config("email", "ntop_email", conf_params)
|
||||
assert(res["status"] == "OK")
|
||||
|
||||
res = notification_endpoints.delete_config("ntop_email")
|
||||
res = notification_configs.delete_config("ntop_email")
|
||||
assert(res["status"] == "OK")
|
||||
|
||||
-- Add some garbage and make sure it is not written
|
||||
conf_params["garbage"] = "trash"
|
||||
|
||||
res = notification_endpoints.add_config("email", "ntop_email", conf_params)
|
||||
res = notification_configs.add_config("email", "ntop_email", conf_params)
|
||||
assert(res["status"] == "OK")
|
||||
|
||||
res = notification_endpoints.get_endpoint_config("ntop_email")
|
||||
res = notification_configs.get_endpoint_config("ntop_email")
|
||||
assert(res["status"] == "OK")
|
||||
assert(res["endpoint_key"] == "email")
|
||||
assert(res["endpoint_conf_name"] == "ntop_email")
|
||||
|
|
@ -103,30 +103,30 @@ for k, v in pairs(res["endpoint_conf"]) do
|
|||
end
|
||||
|
||||
-- Edit the config
|
||||
conf_params["smtp_server_name"] = "mail2.ntop.org"
|
||||
res = notification_endpoints.edit_config("ntop_email", conf_params)
|
||||
conf_params["smtp_server"] = "mail2.ntop.org"
|
||||
res = notification_configs.edit_config("ntop_email", conf_params)
|
||||
assert(res["status"] == "OK")
|
||||
|
||||
res = notification_endpoints.get_endpoint_config("ntop_email")
|
||||
res = notification_configs.get_endpoint_config("ntop_email")
|
||||
assert(res["status"] == "OK")
|
||||
assert(res["endpoint_key"] == "email")
|
||||
assert(res["endpoint_conf_name"] == "ntop_email")
|
||||
assert(res["endpoint_conf"])
|
||||
assert(res["endpoint_conf"]["smtp_server_name"] == "mail2.ntop.org")
|
||||
assert(res["endpoint_conf"]["smtp_server"] == "mail2.ntop.org")
|
||||
|
||||
-- Add another endpoint
|
||||
conf_params = {
|
||||
smtp_server_name = "mail.google.com",
|
||||
sender = "tester@google.com",
|
||||
username = "googleuser",
|
||||
password = "googlepassword"
|
||||
smtp_server = "mail.google.com",
|
||||
email_sender = "tester@google.com",
|
||||
smpt_username = "googleuser",
|
||||
smtp_password = "googlepassword"
|
||||
}
|
||||
|
||||
res = notification_endpoints.add_config("email", "google_email", conf_params)
|
||||
res = notification_configs.add_config("email", "google_email", conf_params)
|
||||
assert(res["status"] == "OK")
|
||||
|
||||
-- Get all configs
|
||||
res = notification_endpoints.get_configs()
|
||||
res = notification_configs.get_configs()
|
||||
assert(#res == 2)
|
||||
|
||||
------------------------------
|
||||
|
|
@ -147,7 +147,7 @@ res = notification_recipients.add_recipient("ntop_email", "sysadmins", {})
|
|||
assert(res["status"] == "failed" and res["error"]["type"] == "missing_mandatory_param")
|
||||
|
||||
local recipient_params = {
|
||||
to = "ci@ntop.org"
|
||||
email_recipient = "ci@ntop.org"
|
||||
}
|
||||
|
||||
res = notification_recipients.add_recipient("ntop_email", "sysadmins", recipient_params)
|
||||
|
|
@ -172,25 +172,25 @@ assert(res["status"] == "OK")
|
|||
res = notification_recipients.get_recipient("sysadmins")
|
||||
assert(res["status"] == "OK")
|
||||
assert(res["recipient_params"])
|
||||
assert(res["recipient_params"]["to"] == "ci@ntop.org")
|
||||
assert(res["recipient_params"]["email_recipient"] == "ci@ntop.org")
|
||||
assert(not res["recipient_params"]["garbage"])
|
||||
|
||||
-- Test edit
|
||||
recipient_params["to"] = "ci2@ntop.org"
|
||||
recipient_params["email_recipient"] = "ci2@ntop.org"
|
||||
res = notification_recipients.edit_recipient("sysadmins", recipient_params)
|
||||
assert(res["status"] == "OK")
|
||||
|
||||
res = notification_recipients.get_recipient("sysadmins")
|
||||
assert(res["status"] == "OK")
|
||||
assert(res["recipient_params"])
|
||||
assert(res["recipient_params"]["to"] == "ci2@ntop.org")
|
||||
assert(res["recipient_params"]["email_recipient"] == "ci2@ntop.org")
|
||||
|
||||
-- Add another couple of recipients
|
||||
recipient_params["to"] = "devops2@ntop.org"
|
||||
recipient_params["email_recipient"] = "devops2@ntop.org"
|
||||
res = notification_recipients.add_recipient("ntop_email", "devops", recipient_params)
|
||||
assert(res["status"] == "OK")
|
||||
|
||||
recipient_params["to"] = "sres@gmail.com"
|
||||
recipient_params["email_recipient"] = "sres@gmail.com"
|
||||
res = notification_recipients.add_recipient("google_email", "sres", recipient_params)
|
||||
assert(res["status"] == "OK")
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue