Add mg_check_ip_acl()

This commit is contained in:
Sergey Lyubka committed 2021-08-25 07:59:31 +01:00
1 parent 1c456fc2df
commit fc9c454518
6 files changed
+110 -15

No files matched your search

+14
View File
@@ -1461,8 +1461,22 @@ static void test_udp(void) {
ASSERT(mgr.conns == NULL);
}
static void test_check_ip_acl(void) {
uint32_t ip = 0x01020304;
ASSERT(mg_check_ip_acl(mg_str(NULL), ip) == 1);
ASSERT(mg_check_ip_acl(mg_str(""), ip) == 1);
ASSERT(mg_check_ip_acl(mg_str("invalid"), ip) == -1);
ASSERT(mg_check_ip_acl(mg_str("+hi"), ip) == -2);
ASSERT(mg_check_ip_acl(mg_str("+//"), ip) == -2);
ASSERT(mg_check_ip_acl(mg_str("-0.0.0.0/0"), ip) == 0);
ASSERT(mg_check_ip_acl(mg_str("-0.0.0.0/0,+1.0.0.0/8"), ip) == 1);
ASSERT(mg_check_ip_acl(mg_str("-0.0.0.0/0,+1.2.3.4"), ip) == 1);
ASSERT(mg_check_ip_acl(mg_str("-0.0.0.0/0,+1.0.0.0/16"), ip) == 0);
}
int main(void) {
mg_log_set("3");
test_check_ip_acl();
test_udp();
test_pipe();
test_packed();