feat(exports): export datagram handler types and align tests with updated nftables and route security APIs
This commit is contained in:
@@ -1,7 +1,13 @@
|
||||
import { IpUtils } from '../../../ts/core/utils/ip-utils.js';
|
||||
import { IpMatcher } from '../../../ts/core/routing/matchers/ip.js';
|
||||
|
||||
const isGlobIPMatch = (ip: string, patterns: string[]): boolean =>
|
||||
patterns.some((pattern) => IpMatcher.match(pattern, ip));
|
||||
|
||||
const isIPAuthorized = (ip: string, allowedIPs: string[], blockedIPs: string[]): boolean =>
|
||||
IpMatcher.isAuthorized(ip, allowedIPs, blockedIPs);
|
||||
|
||||
// Test the overlap case
|
||||
const result = IpUtils.isIPAuthorized('127.0.0.1', ['127.0.0.1'], ['127.0.0.1']);
|
||||
const result = isIPAuthorized('127.0.0.1', ['127.0.0.1'], ['127.0.0.1']);
|
||||
console.log('Result of IP that is both allowed and blocked:', result);
|
||||
|
||||
// Trace through the code logic
|
||||
@@ -13,10 +19,10 @@ console.log('Step 1 check:', (!ip || (allowedIPs.length === 0 && blockedIPs.leng
|
||||
|
||||
// Check if IP is blocked - blocked IPs take precedence
|
||||
console.log('blockedIPs length > 0:', blockedIPs.length > 0);
|
||||
console.log('isGlobIPMatch result:', IpUtils.isGlobIPMatch(ip, blockedIPs));
|
||||
console.log('Step 2 check (is blocked):', (blockedIPs.length > 0 && IpUtils.isGlobIPMatch(ip, blockedIPs)));
|
||||
console.log('isGlobIPMatch result:', isGlobIPMatch(ip, blockedIPs));
|
||||
console.log('Step 2 check (is blocked):', (blockedIPs.length > 0 && isGlobIPMatch(ip, blockedIPs)));
|
||||
|
||||
// Check if IP is allowed
|
||||
console.log('allowedIPs length === 0:', allowedIPs.length === 0);
|
||||
console.log('isGlobIPMatch for allowed:', IpUtils.isGlobIPMatch(ip, allowedIPs));
|
||||
console.log('Step 3 (is allowed):', allowedIPs.length === 0 || IpUtils.isGlobIPMatch(ip, allowedIPs));
|
||||
console.log('isGlobIPMatch for allowed:', isGlobIPMatch(ip, allowedIPs));
|
||||
console.log('Step 3 (is allowed):', allowedIPs.length === 0 || isGlobIPMatch(ip, allowedIPs));
|
||||
|
||||
Reference in New Issue
Block a user