Files
shadowsocks-libev/tests/test_acl_literal.c
Max Lv 53adaf380e Replace uthash and ss_list with the C++ containers
The C cache (now used only by the reference codecs) moves to
tests/reference and src/uthash.h is deleted. ACL rules and ss-manager's
servers are ListNodes on IntrusiveLists; destroying an element unlinks
it, so the free paths no longer have to remember to. core.h keeps only
ss_ip. test_rule is ported to C++ and also covers literal rules.
2026-10-15 00:34:31 +08:00

53 lines
1.8 KiB
C

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include "acl.h"
int verbose = 0;
int
main(int argc, char **argv)
{
(void)argc;
char path[4096];
assert(snprintf(path, sizeof(path), "%s.acl", argv[0]) < (int)sizeof(path));
FILE *file = fopen(path, "w");
assert(file != NULL);
fputs("[black_list]\nfull:Exact.example\nsuffix:blocked.example\n10.0.0.0/8\n"
"2001:db8::/32\n[white_list]\nsuffix:allowed.example\n"
"[outbound_block_list]\nfull:outbound.example\n", file);
fclose(file);
assert(init_acl(path) == 0);
assert(acl_match_host("EXACT.example") == 1);
assert(acl_match_host("sub.exact.example") == 0);
assert(acl_match_host("blocked.example") == 1);
assert(acl_match_host("a.blocked.example") == 1);
assert(acl_match_host("notblocked.example") == 0);
assert(acl_match_host("blocked.example.evil") == 0);
assert(acl_match_host("a.allowed.example") == -1);
assert(outbound_block_match_host("outbound.example") == 1);
assert(outbound_block_match_host("a.outbound.example") == 0);
assert(acl_match_host("10.42.1.2") == 1);
assert(acl_remove_ip("10.42.1.2") == 0);
assert(acl_match_host("10.42.1.2") == 0);
assert(acl_match_host("10.42.1.3") == 1);
assert(acl_add_ip("10.42.1.2") == 0);
assert(acl_match_host("10.42.1.2") == 1);
assert(acl_remove_ip("2001:db8::42") == 0);
assert(acl_match_host("2001:db8::42") == 0);
assert(acl_match_host("2001:db8::43") == 1);
free_acl();
#if !SS_ENABLE_REGEX
file = fopen(path, "w");
assert(file != NULL);
fputs("[black_list]\n10.0.0.0/8\n^old\\.regex$\n", file);
fclose(file);
assert(init_acl(path) == -1);
assert(acl_match_host("10.1.1.1") == 0);
#endif
remove(path);
return 0;
}