Skip to content

Commit

Permalink
Added missing tests
Browse files Browse the repository at this point in the history
Signed-off-by: t-burch <[email protected]>
  • Loading branch information
t-burch committed Nov 8, 2023
1 parent 3564dbc commit 9bfc951
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 11 deletions.
28 changes: 17 additions & 11 deletions core/src/test/java/com/predic8/membrane/core/UnitTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,26 @@
import com.predic8.membrane.core.config.ProxyTest;
import com.predic8.membrane.core.config.ReadRulesConfigurationTest;
import com.predic8.membrane.core.config.ReadRulesWithInterceptorsConfigurationTest;
import com.predic8.membrane.core.exchangestore.*;
import com.predic8.membrane.core.exchangestore.AbortExchangeTest;
import com.predic8.membrane.core.exchangestore.AbstractExchangeStoreTest;
import com.predic8.membrane.core.exchangestore.LimitedMemoryExchangeStoreTest;
import com.predic8.membrane.core.graphql.GraphQLProtectionInterceptorTest;
import com.predic8.membrane.core.http.*;
import com.predic8.membrane.core.http.cookie.*;
import com.predic8.membrane.core.http.cookie.MessageBytesTest;
import com.predic8.membrane.core.interceptor.*;
import com.predic8.membrane.core.interceptor.acl.AccessControlParserTest;
import com.predic8.membrane.core.interceptor.acl.HostnameTest;
import com.predic8.membrane.core.interceptor.acl.ParseTypeTest;
import com.predic8.membrane.core.interceptor.acl.matchers.Cidr.IpRangeTest;
import com.predic8.membrane.core.interceptor.balancer.*;
import com.predic8.membrane.core.interceptor.beautifier.BeautifierInterceptorTest;
import com.predic8.membrane.core.interceptor.cbr.XPathCBRInterceptorTest;
import com.predic8.membrane.core.interceptor.formvalidation.FormValidationInterceptorTest;
import com.predic8.membrane.core.interceptor.groovy.GroovyInterceptorTest;
import com.predic8.membrane.core.interceptor.javascript.*;
import com.predic8.membrane.core.interceptor.json.*;
import com.predic8.membrane.core.interceptor.misc.*;
import com.predic8.membrane.core.interceptor.javascript.JavascriptInterceptor;
import com.predic8.membrane.core.interceptor.json.JsonPointerExtractorInterceptorTest;
import com.predic8.membrane.core.interceptor.json.JsonProtectionInterceptorTest;
import com.predic8.membrane.core.interceptor.misc.ReturnInterceptorTest;
import com.predic8.membrane.core.interceptor.oauth2.OAuth2UnitTests;
import com.predic8.membrane.core.interceptor.ratelimit.RateLimitInterceptorTest;
import com.predic8.membrane.core.interceptor.rest.HTTP2XMLInterceptorTest;
Expand All @@ -42,7 +46,7 @@
import com.predic8.membrane.core.interceptor.schemavalidation.SOAPMessageValidatorInterceptorTest;
import com.predic8.membrane.core.interceptor.schemavalidation.SOAPUtilTest;
import com.predic8.membrane.core.interceptor.schemavalidation.ValidatorInterceptorTest;
import com.predic8.membrane.core.interceptor.security.*;
import com.predic8.membrane.core.interceptor.security.PaddingHeaderInterceptorTest;
import com.predic8.membrane.core.interceptor.soap.SoapOperationExtractorTest;
import com.predic8.membrane.core.interceptor.templating.TemplateInterceptorTest;
import com.predic8.membrane.core.interceptor.xml.Json2XmlInterceptorTest;
Expand All @@ -52,20 +56,20 @@
import com.predic8.membrane.core.interceptor.xmlcontentfilter.SimpleXPathParserTest;
import com.predic8.membrane.core.interceptor.xmlcontentfilter.XMLContentFilterTest;
import com.predic8.membrane.core.interceptor.xmlcontentfilter.XMLElementFinderTest;
import com.predic8.membrane.core.interceptor.xmlprotection.*;
import com.predic8.membrane.core.interceptor.xmlprotection.XMLProtectorTest;
import com.predic8.membrane.core.interceptor.xslt.XSLTInterceptorTest;
import com.predic8.membrane.core.kubernetes.client.KubernetesClientTest;
import com.predic8.membrane.core.lang.spel.*;
import com.predic8.membrane.core.lang.spel.ExchangeEvaluationContextTest;
import com.predic8.membrane.core.magic.MagicTest;
import com.predic8.membrane.core.multipart.ReassembleTest;
import com.predic8.membrane.core.resolver.SingleResolverTest;
import com.predic8.membrane.core.rules.ProxyRuleTest;
import com.predic8.membrane.core.rules.ServiceProxyKeyTest;
import com.predic8.membrane.core.transport.ExchangeTest;
import com.predic8.membrane.core.transport.http.HostColonPortTest;
import com.predic8.membrane.core.transport.http2.Http2ClientServerTest;
import com.predic8.membrane.core.transport.http.HttpKeepAliveTest;
import com.predic8.membrane.core.transport.http.ServiceInvocationTest;
import com.predic8.membrane.core.transport.http2.Http2ClientServerTest;
import com.predic8.membrane.core.transport.ssl.SSLContextTest;
import com.predic8.membrane.core.transport.ssl.SessionResumptionTest;
import com.predic8.membrane.core.transport.ssl.acme.AcmeRenewTest;
Expand All @@ -74,7 +78,9 @@
import com.predic8.membrane.core.ws.relocator.RelocatorTest;
import com.predic8.membrane.core.ws.relocator.RelocatorWADLTest;
import com.predic8.membrane.interceptor.MultipleLoadBalancersTest;
import org.junit.platform.suite.api.*;
import org.junit.platform.suite.api.SelectClasses;
import org.junit.platform.suite.api.SelectPackages;
import org.junit.platform.suite.api.Suite;

@Suite
@SelectClasses({HeaderTest.class, BodyTest.class, ByteUtilTest.class,
Expand All @@ -84,7 +90,7 @@
ResponseBuilderTest.class,

MagicTest.class, WSDLInterceptorTest.class,
AccessControlParserTest.class, HostnameTest.class, ParseTypeTest.class,
AccessControlParserTest.class, HostnameTest.class, ParseTypeTest.class, IpRangeTest.class,
DispatchingInterceptorTest.class,
HostColonPortTest.class,
HTTP2XMLInterceptorTest.class, ReadRulesConfigurationTest.class,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.predic8.membrane.core.interceptor.acl.matchers.Cidr;

import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;

public class IpRangeTest {

@Test
void getMask() {
assertEquals(0xFFFFFF00, IpRange.getMask(24)); // for 255.255.255.0
assertEquals(0xFFFF0000, IpRange.getMask(16)); // for 255.255.0.0
assertEquals(0xFF000000, IpRange.getMask(8)); // for 255.0.0.0
assertEquals(0x80000000, IpRange.getMask(1)); // for 128.0.0.0
assertEquals(~0, IpRange.getMask(32)); // for 255.255.255.255
assertEquals(0, IpRange.getMask(0)); // for 0.0.0.0
}

@Test
void getIntegerValue() {
assertEquals(0x7F000001, IpRange.getIntegerValue(new byte[] {127, 0, 0, 1}));
assertEquals(0xC0A80001, IpRange.getIntegerValue(new byte[] {(byte) 192, (byte) 168, 0, 1}));
assertEquals(0x00000000, IpRange.getIntegerValue(new byte[] {0, 0, 0, 0}));
assertEquals(0xFFFFFFFF, IpRange.getIntegerValue(new byte[] {(byte) 255, (byte) 255, (byte) 255, (byte) 255}));
assertEquals(0x00007F00, IpRange.getIntegerValue(new byte[] {0, 0, 127, 0}));
}
}

0 comments on commit 9bfc951

Please sign in to comment.