ServerCookieEncoderTest Class — netty Architecture
Architecture documentation for the ServerCookieEncoderTest class in ServerCookieEncoderTest.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD 8f5d85cb_9261_ef89_d9fb_1265f8ca3574["ServerCookieEncoderTest"] 49ffe1f5_0163_530e_23aa_f9b231dc96e2["ServerCookieEncoderTest.java"] 8f5d85cb_9261_ef89_d9fb_1265f8ca3574 -->|defined in| 49ffe1f5_0163_530e_23aa_f9b231dc96e2 2eef5372_fa00_c5e1_002f_8e06849438b1["testEncodingSingleCookieV0()"] 8f5d85cb_9261_ef89_d9fb_1265f8ca3574 -->|method| 2eef5372_fa00_c5e1_002f_8e06849438b1 17d27176_3014_dd29_1298_34cb8bf6c25f["testEncodingWithNoCookies()"] 8f5d85cb_9261_ef89_d9fb_1265f8ca3574 -->|method| 17d27176_3014_dd29_1298_34cb8bf6c25f 0d452ae9_7544_5c57_719c_f9c1d985af9e["testEncodingMultipleCookiesStrict()"] 8f5d85cb_9261_ef89_d9fb_1265f8ca3574 -->|method| 0d452ae9_7544_5c57_719c_f9c1d985af9e 5ee80b38_ce79_84d7_426d_6533edc99d4d["illegalCharInCookieNameMakesStrictEncoderThrowsException()"] 8f5d85cb_9261_ef89_d9fb_1265f8ca3574 -->|method| 5ee80b38_ce79_84d7_426d_6533edc99d4d cbcfbd19_8009_dc58_3d1d_405c810af727["illegalCharInCookieValueMakesStrictEncoderThrowsException()"] 8f5d85cb_9261_ef89_d9fb_1265f8ca3574 -->|method| cbcfbd19_8009_dc58_3d1d_405c810af727 1b258d45_d224_b3b5_0b8e_bbc03e01b34a["illegalCharInWrappedValueAppearsInException()"] 8f5d85cb_9261_ef89_d9fb_1265f8ca3574 -->|method| 1b258d45_d224_b3b5_0b8e_bbc03e01b34a bc0ea344_0e78_692e_1b68_65849ecc43b7["testEncodingMultipleCookiesLax()"] 8f5d85cb_9261_ef89_d9fb_1265f8ca3574 -->|method| bc0ea344_0e78_692e_1b68_65849ecc43b7
Relationship Graph
Source Code
codec-http/src/test/java/io/netty/handler/codec/http/cookie/ServerCookieEncoderTest.java lines 38–160
public class ServerCookieEncoderTest {
@Test
public void testEncodingSingleCookieV0() throws ParseException {
int maxAge = 50;
String result = "myCookie=myValue; Max-Age=50; Expires=(.+?); Path=/apathsomewhere;" +
" Domain=.adomainsomewhere; Secure; SameSite=Lax; Partitioned";
DefaultCookie cookie = new DefaultCookie("myCookie", "myValue");
cookie.setDomain(".adomainsomewhere");
cookie.setMaxAge(maxAge);
cookie.setPath("/apathsomewhere");
cookie.setSecure(true);
cookie.setSameSite(SameSite.Lax);
cookie.setPartitioned(true);
String encodedCookie = ServerCookieEncoder.STRICT.encode(cookie);
Matcher matcher = Pattern.compile(result).matcher(encodedCookie);
assertTrue(matcher.find());
Date expiresDate = DateFormatter.parseHttpDate(matcher.group(1));
long diff = (expiresDate.getTime() - System.currentTimeMillis()) / 1000;
// 2 secs should be fine
assertTrue(Math.abs(diff - maxAge) <= 2);
}
@Test
public void testEncodingWithNoCookies() {
String encodedCookie1 = ClientCookieEncoder.STRICT.encode();
List<String> encodedCookie2 = ServerCookieEncoder.STRICT.encode();
assertNull(encodedCookie1);
assertNotNull(encodedCookie2);
assertTrue(encodedCookie2.isEmpty());
}
@Test
public void testEncodingMultipleCookiesStrict() {
List<String> result = new ArrayList<String>();
result.add("cookie2=value2");
result.add("cookie1=value3");
Cookie cookie1 = new DefaultCookie("cookie1", "value1");
Cookie cookie2 = new DefaultCookie("cookie2", "value2");
Cookie cookie3 = new DefaultCookie("cookie1", "value3");
List<String> encodedCookies = ServerCookieEncoder.STRICT.encode(cookie1, cookie2, cookie3);
assertEquals(result, encodedCookies);
}
@Test
public void illegalCharInCookieNameMakesStrictEncoderThrowsException() {
Set<Character> illegalChars = new HashSet<Character>();
// CTLs
for (int i = 0x00; i <= 0x1F; i++) {
illegalChars.add((char) i);
}
illegalChars.add((char) 0x7F);
// separators
for (char c : new char[] { '(', ')', '<', '>', '@', ',', ';', ':', '\\', '"', '/', '[', ']',
'?', '=', '{', '}', ' ', '\t' }) {
illegalChars.add(c);
}
int exceptions = 0;
for (char c : illegalChars) {
try {
ServerCookieEncoder.STRICT.encode(new DefaultCookie("foo" + c + "bar", "value"));
} catch (IllegalArgumentException e) {
exceptions++;
}
}
assertEquals(illegalChars.size(), exceptions);
}
@Test
public void illegalCharInCookieValueMakesStrictEncoderThrowsException() {
Set<Character> illegalChars = new HashSet<Character>();
// CTLs
for (int i = 0x00; i <= 0x1F; i++) {
illegalChars.add((char) i);
Source
Frequently Asked Questions
What is the ServerCookieEncoderTest class?
ServerCookieEncoderTest is a class in the netty codebase, defined in codec-http/src/test/java/io/netty/handler/codec/http/cookie/ServerCookieEncoderTest.java.
Where is ServerCookieEncoderTest defined?
ServerCookieEncoderTest is defined in codec-http/src/test/java/io/netty/handler/codec/http/cookie/ServerCookieEncoderTest.java at line 38.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free