diff --git a/src/main/java/com/thetransactioncompany/cors/CORSConfigurationLoader.java b/src/main/java/com/thetransactioncompany/cors/CORSConfigurationLoader.java
index fbd2840..55d807c 100644
--- a/src/main/java/com/thetransactioncompany/cors/CORSConfigurationLoader.java
+++ b/src/main/java/com/thetransactioncompany/cors/CORSConfigurationLoader.java
@@ -6,10 +6,10 @@
import java.util.Enumeration;
import java.util.Properties;
-import javax.servlet.FilterConfig;
import com.thetransactioncompany.cors.environment.Environment;
import com.thetransactioncompany.cors.environment.SystemProperties;
+import jakarta.servlet.FilterConfig;
/**
diff --git a/src/main/java/com/thetransactioncompany/cors/CORSFilter.java b/src/main/java/com/thetransactioncompany/cors/CORSFilter.java
index 7038009..70fa6fb 100644
--- a/src/main/java/com/thetransactioncompany/cors/CORSFilter.java
+++ b/src/main/java/com/thetransactioncompany/cors/CORSFilter.java
@@ -1,18 +1,13 @@
package com.thetransactioncompany.cors;
+import jakarta.servlet.*;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
+
import java.io.IOException;
import java.io.PrintWriter;
-import javax.servlet.Filter;
-import javax.servlet.FilterChain;
-import javax.servlet.FilterConfig;
-import javax.servlet.ServletException;
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
/**
* Cross-Origin Resource Sharing (CORS) servlet filter.
diff --git a/src/main/java/com/thetransactioncompany/cors/CORSRequestHandler.java b/src/main/java/com/thetransactioncompany/cors/CORSRequestHandler.java
index dbc6cb6..8407541 100644
--- a/src/main/java/com/thetransactioncompany/cors/CORSRequestHandler.java
+++ b/src/main/java/com/thetransactioncompany/cors/CORSRequestHandler.java
@@ -1,9 +1,8 @@
package com.thetransactioncompany.cors;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
/**
* Handles incoming cross-origin (CORS) requests according to the configured
@@ -86,7 +85,7 @@ public CORSRequestHandler(final CORSConfiguration config) {
* is not supported by the CORS
* policy.
*/
- public void handleActualRequest(final HttpServletRequest request,
+ public void handleActualRequest(final HttpServletRequest request,
final HttpServletResponse response)
throws InvalidCORSRequestException,
CORSOriginDeniedException,
diff --git a/src/main/java/com/thetransactioncompany/cors/CORSRequestType.java b/src/main/java/com/thetransactioncompany/cors/CORSRequestType.java
index 2e6e69a..7323063 100644
--- a/src/main/java/com/thetransactioncompany/cors/CORSRequestType.java
+++ b/src/main/java/com/thetransactioncompany/cors/CORSRequestType.java
@@ -1,8 +1,7 @@
package com.thetransactioncompany.cors;
-import javax.servlet.http.HttpServletRequest;
-
+import jakarta.servlet.http.HttpServletRequest;
/**
* Enumeration of the CORS request types.
diff --git a/src/main/java/com/thetransactioncompany/cors/CORSResponseWrapper.java b/src/main/java/com/thetransactioncompany/cors/CORSResponseWrapper.java
index 5347792..e67da92 100644
--- a/src/main/java/com/thetransactioncompany/cors/CORSResponseWrapper.java
+++ b/src/main/java/com/thetransactioncompany/cors/CORSResponseWrapper.java
@@ -1,14 +1,15 @@
package com.thetransactioncompany.cors;
+import jakarta.servlet.http.HttpServletResponse;
+import jakarta.servlet.http.HttpServletResponseWrapper;
+
import java.util.*;
-import javax.servlet.http.HttpServletResponse;
-import javax.servlet.http.HttpServletResponseWrapper;
/**
* HTTP response wrapper that preserves the CORS response headers on
- * {@link javax.servlet.ServletResponse#reset()}. Some web applications and
+ * {@link jakarta.servlet.ServletResponse#reset()}. Some web applications and
* frameworks (e.g. RestEasy) reset the servlet response when a HTTP 4xx error
* is produced; this wrapper ensures previously set CORS headers survive such a
* reset.
diff --git a/src/main/java/com/thetransactioncompany/cors/Origin.java b/src/main/java/com/thetransactioncompany/cors/Origin.java
index 0f70825..84d37b0 100644
--- a/src/main/java/com/thetransactioncompany/cors/Origin.java
+++ b/src/main/java/com/thetransactioncompany/cors/Origin.java
@@ -46,13 +46,14 @@ public Origin(final String value) {
this.value = value;
}
-
-
+
+
/**
* Returns a validated instance of this origin.
- *
+ *
* @throws OriginException If the value doesn't represent a valid and
* supported origin string.
+ * @return a validated instance of this origin
*/
public ValidatedOrigin validate()
throws OriginException {
diff --git a/src/main/java/com/thetransactioncompany/cors/RequestTagger.java b/src/main/java/com/thetransactioncompany/cors/RequestTagger.java
index 467d0a0..11cd1a8 100644
--- a/src/main/java/com/thetransactioncompany/cors/RequestTagger.java
+++ b/src/main/java/com/thetransactioncompany/cors/RequestTagger.java
@@ -1,8 +1,7 @@
package com.thetransactioncompany.cors;
-import javax.servlet.http.HttpServletRequest;
-
+import jakarta.servlet.http.HttpServletRequest;
/**
* Request tagger. Tags HTTP servlet requests to provide CORS information to
diff --git a/src/main/java/com/thetransactioncompany/cors/ValidatedOrigin.java b/src/main/java/com/thetransactioncompany/cors/ValidatedOrigin.java
index 9a06e72..6748aa3 100644
--- a/src/main/java/com/thetransactioncompany/cors/ValidatedOrigin.java
+++ b/src/main/java/com/thetransactioncompany/cors/ValidatedOrigin.java
@@ -121,8 +121,8 @@ public int getPort() {
* Example:
*
*
- * http://example.com => example.com
- * http://example.com:8080 => example.com:8080
+ * http://example.com = example.com
+ * http://example.com:8080 = example.com:8080
*
*
* @return The suffix.
diff --git a/src/main/java/com/thetransactioncompany/cors/demo/HelloWorldServlet.java b/src/main/java/com/thetransactioncompany/cors/demo/HelloWorldServlet.java
index 497d160..b06a008 100644
--- a/src/main/java/com/thetransactioncompany/cors/demo/HelloWorldServlet.java
+++ b/src/main/java/com/thetransactioncompany/cors/demo/HelloWorldServlet.java
@@ -1,10 +1,12 @@
package com.thetransactioncompany.cors.demo;
-import java.io.*;
+import jakarta.servlet.ServletException;
+import jakarta.servlet.http.HttpServlet;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
-import javax.servlet.*;
-import javax.servlet.http.*;
+import java.io.*;
/**
diff --git a/src/test/java/com/thetransactioncompany/cors/CORSConfigurationLoaderTest.java b/src/test/java/com/thetransactioncompany/cors/CORSConfigurationLoaderTest.java
index 8952ecf..4c1cefc 100644
--- a/src/test/java/com/thetransactioncompany/cors/CORSConfigurationLoaderTest.java
+++ b/src/test/java/com/thetransactioncompany/cors/CORSConfigurationLoaderTest.java
@@ -2,7 +2,11 @@
import com.thetransactioncompany.cors.environment.MockEnvironment;
-import junit.framework.TestCase;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+
/**
@@ -11,9 +15,10 @@
* @author David Bellem
* @author Vladimir Dzhuvinov
*/
-public class CORSConfigurationLoaderTest extends TestCase {
-
+public class CORSConfigurationLoaderTest {
+
+ @Test
public void testEnvVarBasedConfig() {
CORSConfigurationLoader configLoader = new CORSConfigurationLoader(new MockFilterConfig());
@@ -55,7 +60,7 @@ public void testEnvVarBasedConfig() {
assertTrue(c.isSupportedHeader("Accept"));
assertFalse(c.isSupportedHeader("X-Forwarded-Proto"));
- assertTrue(c.exposedHeaders.size() == 0);
+ assertEquals(0, c.exposedHeaders.size());
assertTrue(c.supportsCredentials);
diff --git a/src/test/java/com/thetransactioncompany/cors/CORSConfigurationTest.java b/src/test/java/com/thetransactioncompany/cors/CORSConfigurationTest.java
index 38cf85e..6272484 100644
--- a/src/test/java/com/thetransactioncompany/cors/CORSConfigurationTest.java
+++ b/src/test/java/com/thetransactioncompany/cors/CORSConfigurationTest.java
@@ -1,9 +1,11 @@
package com.thetransactioncompany.cors;
+import org.junit.jupiter.api.Test;
+
import java.util.Properties;
-import junit.framework.TestCase;
+import static org.junit.jupiter.api.Assertions.*;
/**
@@ -11,67 +13,72 @@
*
* @author Vladimir Dzhuvinov
*/
-public class CORSConfigurationTest extends TestCase {
-
-
+public class CORSConfigurationTest {
+
+
+ @Test
public void testParseWordsSpace() {
-
+
String[] p1 = CORSConfiguration.parseWords("GET POST HEAD");
-
+
assertEquals(3, p1.length);
}
-
-
+
+ @Test
public void testParseWordsComma() {
-
+
String[] p1 = CORSConfiguration.parseWords("GET,POST,HEAD");
-
+
assertEquals(3, p1.length);
}
-
-
+
+
+ @Test
public void testParseWordsMixed1() {
-
+
String[] p1 = CORSConfiguration.parseWords("GET, POST, HEAD");
-
+
assertEquals(3, p1.length);
}
-
-
+
+
+ @Test
public void testParseWordsMixed2() {
-
+
String[] p1 = CORSConfiguration.parseWords("GET , POST , HEAD");
-
+
assertEquals(3, p1.length);
}
-
-
+
+
+ @Test
public void testParseWordsEmpty() {
-
+
String[] p1 = CORSConfiguration.parseWords("");
-
+
assertEquals(0, p1.length);
}
-
-
+
+
+ @Test
public void testDefaultConfig() {
-
+
Properties p = new Properties();
-
+
CORSConfiguration c = null;
-
+
try {
c = new CORSConfiguration(p);
-
+
} catch (CORSConfigurationException e) {
fail(e.getMessage());
}
-
+
assertTrue(c.allowGenericHttpRequests);
-
+
assertTrue(c.allowAnyOrigin);
assertTrue(c.isAllowedOrigin(new Origin("http://example.com")));
-
+
assertTrue(c.isSupportedMethod("GET"));
assertTrue(c.isSupportedMethod("POST"));
assertTrue(c.isSupportedMethod("HEAD"));
@@ -79,18 +86,18 @@ public void testDefaultConfig() {
assertFalse(c.isSupportedMethod("DELETE"));
assertFalse(c.isSupportedMethod("PUT"));
assertFalse(c.isSupportedMethod("TRACE"));
-
+
assertTrue(c.supportAnyHeader);
assertTrue(c.isSupportedHeader("X-Requested-By"));
-
+
assertEquals(-1, c.maxAge);
assertFalse(c.tagRequests);
}
-
-
+
+
public void testPublicConfig() {
-
+
Properties p = new Properties();
p.setProperty("cors.allowGenericHttpRequests", "true");
p.setProperty("cors.allowOrigin", "*");
@@ -98,21 +105,21 @@ public void testPublicConfig() {
p.setProperty("cors.supportedHeaders", "*");
p.setProperty("cors.supportsCredentials", "false");
p.setProperty("cors.tagRequests", "true");
-
+
CORSConfiguration c = null;
-
+
try {
c = new CORSConfiguration(p);
-
+
} catch (CORSConfigurationException e) {
fail(e.getMessage());
}
-
+
assertTrue(c.allowGenericHttpRequests);
-
- assertTrue(c.allowAnyOrigin);
+
+ assertTrue(c.allowAnyOrigin);
assertTrue(c.isAllowedOrigin(new Origin("http://example.com")));
-
+
assertTrue(c.isSupportedMethod("GET"));
assertTrue(c.isSupportedMethod("POST"));
assertTrue(c.isSupportedMethod("OPTIONS"));
@@ -125,10 +132,11 @@ public void testPublicConfig() {
assertTrue(c.tagRequests);
}
-
-
+
+
+ @Test
public void testRestrictedConfig() {
-
+
Properties p = new Properties();
p.setProperty("cors.allowGenericHttpRequests", "false");
p.setProperty("cors.allowOrigin", "http://example.com:8080");
@@ -136,18 +144,18 @@ public void testRestrictedConfig() {
p.setProperty("cors.supportedHeaders", "");
p.setProperty("cors.supportsCredentials", "false");
p.setProperty("cors.tagRequests", "false");
-
+
CORSConfiguration c = null;
-
+
try {
c = new CORSConfiguration(p);
-
+
} catch (CORSConfigurationException e) {
fail(e.getMessage());
}
-
+
assertFalse(c.allowGenericHttpRequests);
-
+
assertFalse(c.allowAnyOrigin);
assertTrue(c.isAllowedOrigin(new Origin("http://example.com:8080")));
assertFalse(c.isAllowedOrigin(new Origin("http://example.com:8008")));
@@ -159,120 +167,126 @@ public void testRestrictedConfig() {
assertFalse(c.tagRequests);
}
-
-
+
+
+ @Test
public void testCustomHeaders() {
-
+
String h1 = "X-Requested-By";
String h2 = "X-Web-Client";
String h3 = "X-Not-Included";
-
+
Properties p = new Properties();
p.setProperty("cors.supportedHeaders", h1 + " " + h2);
-
-
+
+
CORSConfiguration c = null;
-
+
try {
c = new CORSConfiguration(p);
-
+
} catch (CORSConfigurationException e) {
fail(e.getMessage());
}
-
+
assertTrue(c.isSupportedHeader(h1));
assertTrue(c.isSupportedHeader(h2));
assertFalse(c.isSupportedHeader(h3));
}
-
-
+
+
+ @Test
public void testExposedHeaders() {
-
+
String h1 = "X-Powered-By";
String h2 = "X-Web-Service";
String h3 = "X-Hidden";
-
+
Properties p = new Properties();
p.setProperty("cors.exposedHeaders", h1 + " " + h2);
-
-
+
+
CORSConfiguration c = null;
-
+
try {
c = new CORSConfiguration(p);
-
+
} catch (CORSConfigurationException e) {
fail(e.getMessage());
}
-
+
assertTrue(c.exposedHeaders.contains(h1));
assertTrue(c.exposedHeaders.contains(h2));
assertFalse(c.exposedHeaders.contains(h3));
}
-
-
+
+
+ @Test
public void testSupportsCredentialsTrue() {
-
+
Properties p = new Properties();
p.setProperty("cors.supportsCredentials", "true");
-
-
+
+
CORSConfiguration c = null;
-
+
try {
c = new CORSConfiguration(p);
-
+
} catch (CORSConfigurationException e) {
fail(e.getMessage());
}
-
+
assertTrue(c.supportsCredentials);
-
+
}
-
-
+
+
+ @Test
public void testSupportsCredentialsFalse() {
-
+
Properties p = new Properties();
p.setProperty("cors.supportsCredentials", "false");
-
-
+
+
CORSConfiguration c = null;
-
+
try {
c = new CORSConfiguration(p);
-
+
} catch (CORSConfigurationException e) {
fail(e.getMessage());
}
-
+
assertFalse(c.supportsCredentials);
-
+
}
-
-
+
+
+ @Test
public void testMaxAge() {
-
+
Properties p = new Properties();
p.setProperty("cors.maxAge", "100");
-
-
+
+
CORSConfiguration c = null;
-
+
try {
c = new CORSConfiguration(p);
-
+
} catch (CORSConfigurationException e) {
fail(e.getMessage());
}
-
+
assertEquals(100, c.maxAge);
-
+
}
-
-
+
+
+ @Test
public void testDenySubdomainOrigins(){
-
+
Origin origin = new Origin("http://example.com:8080");
Origin subdomainOrigin = new Origin("http://test.example.com:8080");
@@ -286,7 +300,7 @@ public void testDenySubdomainOrigins(){
c = new CORSConfiguration(p);
} catch (CORSConfigurationException e) {
-
+
fail(e.getMessage());
}
@@ -295,8 +309,9 @@ public void testDenySubdomainOrigins(){
assertTrue(c.isAllowedOrigin(origin));
assertFalse(c.isAllowedOrigin(subdomainOrigin));
}
-
+
+ @Test
public void testAllowSubdomainOrigin(){
Properties p = new Properties();
@@ -317,8 +332,8 @@ public void testAllowSubdomainOrigin(){
assertTrue(c.isAllowedSubdomainOrigin(origin));
assertTrue(c.isAllowedOrigin(origin));
-
-
+
+
origin = new Origin("http://myexample.com:8080");
assertFalse(c.isAllowedSubdomainOrigin(origin));
diff --git a/src/test/java/com/thetransactioncompany/cors/CORSRequestHandlerTest.java b/src/test/java/com/thetransactioncompany/cors/CORSRequestHandlerTest.java
index 726a1eb..2cc0deb 100644
--- a/src/test/java/com/thetransactioncompany/cors/CORSRequestHandlerTest.java
+++ b/src/test/java/com/thetransactioncompany/cors/CORSRequestHandlerTest.java
@@ -6,7 +6,9 @@
import java.util.Properties;
import java.util.Set;
-import junit.framework.TestCase;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.*;
/**
@@ -14,10 +16,11 @@
*
* @author Vladimir Dzhuvinov
*/
-public class CORSRequestHandlerTest extends TestCase {
+public class CORSRequestHandlerTest {
- public void testActualRequestWithDefaultConfiguration()
+ @Test
+ public void testActualRequestWithDefaultConfiguration()
throws Exception {
CORSConfiguration config = new CORSConfiguration(new Properties());
@@ -40,7 +43,8 @@ public void testActualRequestWithDefaultConfiguration()
}
- public void testActualRequestWithCredentialsNotAllowed()
+ @Test
+ public void testActualRequestWithCredentialsNotAllowed()
throws Exception {
Properties props = new Properties();
@@ -64,7 +68,8 @@ public void testActualRequestWithCredentialsNotAllowed()
}
- public void testActualRequestWithExposedHeaders()
+ @Test
+ public void testActualRequestWithExposedHeaders()
throws Exception {
Properties props = new Properties();
@@ -92,7 +97,8 @@ public void testActualRequestWithExposedHeaders()
}
- public void testActualRequestWithDeniedOrigin()
+ @Test
+ public void testActualRequestWithDeniedOrigin()
throws Exception {
Properties props = new Properties();
@@ -117,7 +123,8 @@ public void testActualRequestWithDeniedOrigin()
}
- public void testActualRequestWithUnsupportedMethod()
+ @Test
+ public void testActualRequestWithUnsupportedMethod()
throws Exception {
Properties props = new Properties();
@@ -143,7 +150,8 @@ public void testActualRequestWithUnsupportedMethod()
}
- public void testPreflightRequestWithDefaultConfiguration()
+ @Test
+ public void testPreflightRequestWithDefaultConfiguration()
throws Exception {
CORSConfiguration config = new CORSConfiguration(new Properties());
@@ -175,7 +183,8 @@ public void testPreflightRequestWithDefaultConfiguration()
}
- public void testPreflightRequestWithCredentialsNotAllowed()
+ @Test
+ public void testPreflightRequestWithCredentialsNotAllowed()
throws Exception {
Properties props = new Properties();
@@ -208,7 +217,8 @@ public void testPreflightRequestWithCredentialsNotAllowed()
}
- public void testPreflightRequestWithSupportAnyHeader()
+ @Test
+ public void testPreflightRequestWithSupportAnyHeader()
throws Exception {
Properties props = new Properties();
diff --git a/src/test/java/com/thetransactioncompany/cors/HeaderNameTest.java b/src/test/java/com/thetransactioncompany/cors/HeaderNameTest.java
index 2ce7388..8e8dab1 100644
--- a/src/test/java/com/thetransactioncompany/cors/HeaderNameTest.java
+++ b/src/test/java/com/thetransactioncompany/cors/HeaderNameTest.java
@@ -1,18 +1,21 @@
package com.thetransactioncompany.cors;
-import junit.framework.TestCase;
+import org.junit.jupiter.api.Test;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.fail;
/**
* Tests the header field name class.
*
* @author Vladimir Dzhuvinov
*/
-public class HeaderNameTest extends TestCase {
+public class HeaderNameTest {
- public void testConstants() {
+ @Test
+ public void testConstants() {
assertEquals("Origin", HeaderName.ORIGIN);
assertEquals("Access-Control-Request-Method", HeaderName.ACCESS_CONTROL_REQUEST_METHOD);
@@ -29,37 +32,43 @@ public void testConstants() {
}
- public void testFormatCanonical1() {
+ @Test
+ public void testFormatCanonical1() {
assertEquals(HeaderName.formatCanonical("content-type"), "Content-Type");
}
- public void testFormatCanonical2() {
+ @Test
+ public void testFormatCanonical2() {
assertEquals(HeaderName.formatCanonical("CONTENT-TYPE"), "Content-Type");
}
- public void testFormatCanonical3() {
+ @Test
+ public void testFormatCanonical3() {
assertEquals(HeaderName.formatCanonical("X-type"), "X-Type");
}
- public void testFormatCanonical4() {
+ @Test
+ public void testFormatCanonical4() {
assertEquals(HeaderName.formatCanonical("Origin"), "Origin");
}
- public void testFormatCanonical5() {
+ @Test
+ public void testFormatCanonical5() {
assertEquals(HeaderName.formatCanonical("A"), "A");
}
- public void testFormatCanonical6() {
+ @Test
+ public void testFormatCanonical6() {
try {
assertEquals(HeaderName.formatCanonical(""), "");
@@ -71,92 +80,109 @@ public void testFormatCanonical6() {
}
- public void testTrim() {
+ @Test
+ public void testTrim() {
String expected = "Content-Type";
String n1 = HeaderName.formatCanonical("content-type\n");
String n2 = HeaderName.formatCanonical(" CONTEnt-Type ");
- assertEquals("All whitespace should be trimmed", expected, n1);
- assertEquals("All whitespace should be trimmed", expected, n2);
+ assertEquals(expected, n1, "All whitespace should be trimmed");
+ assertEquals(expected, n2, "All whitespace should be trimmed");
}
- public void testInvalid1() {
+ @Test
+ public void testInvalid1() {
assertInvalid("X-r@b");
}
- public void testInvalid2() {
+ @Test
+ public void testInvalid2() {
assertInvalid("1=X-r");
}
- public void testInvalid3() {
+ @Test
+ public void testInvalid3() {
assertInvalid("Aaa Bbb");
}
- public void testInvalid4() {
+ @Test
+ public void testInvalid4() {
assertInvalid("less");
}
- public void testInvalid6() {
+ @Test
+ public void testInvalid6() {
assertInvalid("X-Forwarded-By-{");
}
- public void testInvalid7() {
+ @Test
+ public void testInvalid7() {
assertInvalid("a}");
}
- public void testInvalid8() {
+ @Test
+ public void testInvalid8() {
assertInvalid("separator:");
}
- public void testInvalid9() {
+ @Test
+ public void testInvalid9() {
assertInvalid("asd\"f;");
}
- public void testInvalid10() {
+ @Test
+ public void testInvalid10() {
assertInvalid("rfc@w3c.org");
}
- public void testInvalid11() {
+ @Test
+ public void testInvalid11() {
assertInvalid("bracket[");
}
- public void testInvalid12() {
+ @Test
+ public void testInvalid12() {
assertInvalid("control\u0002header");
}
- public void testInvalid13() {
+ @Test
+ public void testInvalid13() {
assertInvalid("control\nembedded");
}
- public void testInvalid14() {
+ @Test
+ public void testInvalid14() {
assertInvalid("uni╚(•⌂•)╝");
}
- public void testInvalid15() {
+ @Test
+ public void testInvalid15() {
assertInvalid("uni\u3232_\u3232");
}
- public void testUnusualButValid() {
+ @Test
+ public void testUnusualButValid() {
HeaderName.formatCanonical("__2");
HeaderName.formatCanonical("$%.%");
HeaderName.formatCanonical("`~'*!^|");
diff --git a/src/test/java/com/thetransactioncompany/cors/HeaderUtilsTest.java b/src/test/java/com/thetransactioncompany/cors/HeaderUtilsTest.java
index 3c53a96..0b760c6 100644
--- a/src/test/java/com/thetransactioncompany/cors/HeaderUtilsTest.java
+++ b/src/test/java/com/thetransactioncompany/cors/HeaderUtilsTest.java
@@ -1,10 +1,12 @@
package com.thetransactioncompany.cors;
+import org.junit.jupiter.api.Test;
+
import java.util.LinkedHashSet;
import java.util.Set;
-import junit.framework.TestCase;
+import static org.junit.jupiter.api.Assertions.assertEquals;
/**
@@ -12,10 +14,11 @@
*
* @author Vladimir Dzhuvinov
*/
-public class HeaderUtilsTest extends TestCase {
+public class HeaderUtilsTest {
- public void testSerialize() {
+ @Test
+ public void testSerialize() {
Set values = new LinkedHashSet();
values.add("apples");
@@ -36,7 +39,8 @@ public void testSerialize() {
}
- public void testParseMultipleHeaderValues() {
+ @Test
+ public void testParseMultipleHeaderValues() {
String[] out = HeaderUtils.parseMultipleHeaderValues(null);
diff --git a/src/test/java/com/thetransactioncompany/cors/MockFilterConfig.java b/src/test/java/com/thetransactioncompany/cors/MockFilterConfig.java
index 7bea72a..6b268d2 100644
--- a/src/test/java/com/thetransactioncompany/cors/MockFilterConfig.java
+++ b/src/test/java/com/thetransactioncompany/cors/MockFilterConfig.java
@@ -1,10 +1,10 @@
package com.thetransactioncompany.cors;
-import java.util.Enumeration;
+import jakarta.servlet.FilterConfig;
+import jakarta.servlet.ServletContext;
-import javax.servlet.FilterConfig;
-import javax.servlet.ServletContext;
+import java.util.Enumeration;
/**
diff --git a/src/test/java/com/thetransactioncompany/cors/MockServletContext.java b/src/test/java/com/thetransactioncompany/cors/MockServletContext.java
index 19a8b72..0c389e3 100644
--- a/src/test/java/com/thetransactioncompany/cors/MockServletContext.java
+++ b/src/test/java/com/thetransactioncompany/cors/MockServletContext.java
@@ -1,6 +1,9 @@
package com.thetransactioncompany.cors;
+import jakarta.servlet.*;
+import jakarta.servlet.descriptor.JspConfigDescriptor;
+
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -11,8 +14,7 @@
import java.util.Map;
import java.util.Set;
-import javax.servlet.*;
-import javax.servlet.descriptor.JspConfigDescriptor;
+
/**
@@ -101,37 +103,12 @@ public RequestDispatcher getNamedDispatcher(String s) {
return null;
}
-
- @Override
- public Servlet getServlet(String s) throws ServletException {
- return null;
- }
-
-
- @Override
- public Enumeration getServlets() {
- return null;
- }
-
-
- @Override
- public Enumeration getServletNames() {
- return null;
- }
-
-
@Override
public void log(String s) {
}
- @Override
- public void log(Exception e, String s) {
-
- }
-
-
@Override
public void log(String s, Throwable throwable) {
@@ -215,6 +192,11 @@ public ServletRegistration.Dynamic addServlet(String s, Class extends Servlet>
return null;
}
+ @Override
+ public ServletRegistration.Dynamic addJspFile(String s, String s1) {
+ return null;
+ }
+
@Override
public T createServlet(Class tClass) throws ServletException {
@@ -334,4 +316,39 @@ public ClassLoader getClassLoader() {
public void declareRoles(String... strings) {
}
+
+ @Override
+ public String getVirtualServerName() {
+ return null;
+ }
+
+ @Override
+ public int getSessionTimeout() {
+ return 0;
+ }
+
+ @Override
+ public void setSessionTimeout(int i) {
+
+ }
+
+ @Override
+ public String getRequestCharacterEncoding() {
+ return null;
+ }
+
+ @Override
+ public void setRequestCharacterEncoding(String s) {
+
+ }
+
+ @Override
+ public String getResponseCharacterEncoding() {
+ return null;
+ }
+
+ @Override
+ public void setResponseCharacterEncoding(String s) {
+
+ }
}
diff --git a/src/test/java/com/thetransactioncompany/cors/MockServletRequest.java b/src/test/java/com/thetransactioncompany/cors/MockServletRequest.java
index 9ec42b6..b401f87 100644
--- a/src/test/java/com/thetransactioncompany/cors/MockServletRequest.java
+++ b/src/test/java/com/thetransactioncompany/cors/MockServletRequest.java
@@ -1,14 +1,14 @@
package com.thetransactioncompany.cors;
+import jakarta.servlet.*;
+import jakarta.servlet.http.*;
+
import java.io.BufferedReader;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.security.Principal;
import java.util.*;
-import javax.servlet.*;
-import javax.servlet.http.*;
-
/**
* Mock servlet request.
@@ -47,6 +47,11 @@ public Part getPart(String s) throws IOException, ServletException {
return null;
}
+ @Override
+ public T upgrade(Class aClass) throws IOException, ServletException {
+ return null;
+ }
+
@Override
public ServletContext getServletContext() {
@@ -89,6 +94,21 @@ public DispatcherType getDispatcherType() {
return null;
}
+ @Override
+ public String getRequestId() {
+ return null;
+ }
+
+ @Override
+ public String getProtocolRequestId() {
+ return null;
+ }
+
+ @Override
+ public ServletConnection getServletConnection() {
+ return null;
+ }
+
private String method = "GET";
@@ -214,22 +234,22 @@ public HttpSession getSession() {
}
@Override
- public boolean isRequestedSessionIdValid() {
- return false;
+ public String changeSessionId() {
+ return null;
}
@Override
- public boolean isRequestedSessionIdFromCookie() {
+ public boolean isRequestedSessionIdValid() {
return false;
}
@Override
- public boolean isRequestedSessionIdFromURL() {
+ public boolean isRequestedSessionIdFromCookie() {
return false;
}
@Override
- public boolean isRequestedSessionIdFromUrl() {
+ public boolean isRequestedSessionIdFromURL() {
return false;
}
@@ -257,6 +277,11 @@ public int getContentLength() {
return 0;
}
+ @Override
+ public long getContentLengthLong() {
+ return 0;
+ }
+
@Override
public String getContentType() {
return null;
@@ -350,11 +375,6 @@ public RequestDispatcher getRequestDispatcher(String s) {
return null;
}
- @Override
- public String getRealPath(String s) {
- return null;
- }
-
@Override
public int getRemotePort() {
return 0;
diff --git a/src/test/java/com/thetransactioncompany/cors/MockServletResponse.java b/src/test/java/com/thetransactioncompany/cors/MockServletResponse.java
index 50e3f00..b50229d 100644
--- a/src/test/java/com/thetransactioncompany/cors/MockServletResponse.java
+++ b/src/test/java/com/thetransactioncompany/cors/MockServletResponse.java
@@ -1,6 +1,10 @@
package com.thetransactioncompany.cors;
+import jakarta.servlet.ServletOutputStream;
+import jakarta.servlet.http.Cookie;
+import jakarta.servlet.http.HttpServletResponse;
+
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Collection;
@@ -8,10 +12,6 @@
import java.util.Locale;
import java.util.Map;
-import javax.servlet.ServletOutputStream;
-import javax.servlet.http.Cookie;
-import javax.servlet.http.HttpServletResponse;
-
/**
* Mock servlet response.
@@ -46,16 +46,6 @@ public String encodeRedirectURL(String s) {
return null;
}
- @Override
- public String encodeUrl(String s) {
- return null;
- }
-
- @Override
- public String encodeRedirectUrl(String s) {
- return null;
- }
-
@Override
public void sendError(int i, String s) throws IOException {
}
@@ -133,9 +123,7 @@ public int getStatus() {
public void setStatus(int i) {
}
- @Override
- public void setStatus(int i, String s) {
- }
+
@Override
public String getCharacterEncoding() {
@@ -165,6 +153,11 @@ public void setCharacterEncoding(String s) {
public void setContentLength(int i) {
}
+ @Override
+ public void setContentLengthLong(long l) {
+
+ }
+
@Override
public void setContentType(String s) {
}
diff --git a/src/test/java/com/thetransactioncompany/cors/OriginTest.java b/src/test/java/com/thetransactioncompany/cors/OriginTest.java
index 8363079..2681944 100644
--- a/src/test/java/com/thetransactioncompany/cors/OriginTest.java
+++ b/src/test/java/com/thetransactioncompany/cors/OriginTest.java
@@ -1,8 +1,9 @@
package com.thetransactioncompany.cors;
-import junit.framework.TestCase;
+import org.junit.jupiter.api.Test;
+import static org.junit.jupiter.api.Assertions.*;
/**
* Tests the base origin class.
@@ -11,85 +12,91 @@
* @author Jared Ottley
* @author Edraí Brosa
*/
-public class OriginTest extends TestCase {
-
-
- public void testOrigin() {
-
+public class OriginTest {
+
+
+ @Test
+ public void testOrigin() {
+
String uri = "http://example.com";
-
+
Origin o = new Origin(uri);
-
+
assertEquals(uri, o.toString());
assertEquals(uri.hashCode(), o.hashCode());
}
-
-
- public void testOriginEquality() {
-
+
+
+ @Test
+ public void testOriginEquality() {
+
String uri = "http://example.com";
-
+
Origin o1 = new Origin(uri);
Origin o2 = new Origin(uri);
-
+
assertTrue(o1.equals(o2));
}
-
-
- public void testOriginInequality() {
-
+
+
+ @Test
+ public void testOriginInequality() {
+
String uri1 = "http://example.com";
String uri2 = "HTTP://EXAMPLE.COM";
-
+
Origin o1 = new Origin(uri1);
Origin o2 = new Origin(uri2);
-
+
assertFalse(o1.equals(o2));
}
- public void testOriginInequalityNull() {
-
+ @Test
+ public void testOriginInequalityNull() {
+
assertFalse(new Origin("http://example.com").equals(null));
}
-
-
- public void testValidation() {
-
+
+
+ @Test
+ public void testValidation() {
+
String uri = "http://example.com";
-
+
ValidatedOrigin validatedOrigin = null;
-
+
try {
validatedOrigin = new Origin(uri).validate();
-
+
} catch (OriginException e) {
-
+
fail(e.getMessage());
}
-
+
assertNotNull(validatedOrigin);
-
+
assertEquals(uri, validatedOrigin.toString());
}
- public void testValidationAppScheme() {
-
+ @Test
+ public void testValidationAppScheme() {
+
String uri = "app://example.com";
-
+
ValidatedOrigin validatedOrigin = null;
-
+
try {
validatedOrigin = new Origin(uri).validate();
-
+
} catch (OriginException e) {
-
+
fail(e.getMessage());
}
-
+
assertNotNull(validatedOrigin);
-
+
assertEquals(uri, validatedOrigin.toString());
}
}
diff --git a/src/test/java/com/thetransactioncompany/cors/ValidatedOriginTest.java b/src/test/java/com/thetransactioncompany/cors/ValidatedOriginTest.java
index 3b7b0e6..5c5dcad 100644
--- a/src/test/java/com/thetransactioncompany/cors/ValidatedOriginTest.java
+++ b/src/test/java/com/thetransactioncompany/cors/ValidatedOriginTest.java
@@ -1,7 +1,10 @@
package com.thetransactioncompany.cors;
-import junit.framework.TestCase;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.fail;
/**
@@ -10,10 +13,11 @@
* @author Vladimir Dzhuvinov
* @author Jared Ottley
*/
-public class ValidatedOriginTest extends TestCase {
+public class ValidatedOriginTest {
- public void testHTTPOrigin() {
+ @Test
+ public void testHTTPOrigin() {
String uri = "http://example.com";
@@ -35,7 +39,8 @@ public void testHTTPOrigin() {
}
- public void testHTTPSOrigin() {
+ @Test
+ public void testHTTPSOrigin() {
String uri = "https://example.com";
@@ -79,7 +84,8 @@ public void testAPPOrigin() {
}
- public void testIPAddressHost() {
+ @Test
+ public void testIPAddressHost() {
String uri = "http://192.168.0.1:8080";