22 lines
1.1 KiB
Java
22 lines
1.1 KiB
Java
package com.moyi.controlplane.gateway;
|
|
import org.junit.jupiter.api.Test;
|
|
import static org.junit.jupiter.api.Assertions.*;
|
|
import java.util.List;
|
|
class EnterprisePoliciesTest {
|
|
@Test void ipv4AndIpv6CidrAreMatchedWithoutDns() {
|
|
assertTrue(EnterprisePolicies.matches("192.0.2.23","192.0.2.0/24"));
|
|
assertFalse(EnterprisePolicies.matches("192.0.3.23","192.0.2.0/24"));
|
|
assertTrue(EnterprisePolicies.matches("2001:db8::4","2001:db8::/32"));
|
|
assertFalse(EnterprisePolicies.matches("2001:db9::4","2001:db8::/32"));
|
|
assertFalse(EnterprisePolicies.matches("127.0.0.1","localhost"));
|
|
assertFalse(EnterprisePolicies.matches("127.0.0.1","127.0.0.1/33"));
|
|
assertThrows(RuntimeException.class,()->EnterprisePolicies.validateRanges(List.of("127.1")));
|
|
}
|
|
@Test void nullBudgetIsUnlimitedAndZeroBudgetBlocksSpending() {
|
|
assertNull(EnterprisePolicyController.budget(""));
|
|
assertEquals(0,EnterprisePolicyController.budget("0").signum());
|
|
assertThrows(RuntimeException.class,()->EnterprisePolicyController.budget("-1"));
|
|
assertThrows(RuntimeException.class,()->EnterprisePolicyController.integer("1.5",100));
|
|
}
|
|
}
|