Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove DefaultCookieDecoder #10659

Merged
merged 8 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package io.micronaut.http.netty.cookies

import io.micronaut.http.cookie.ClientCookieEncoder
import io.micronaut.http.cookie.Cookie

import spock.lang.Specification

class NettyLaxClientCookieEncoderSpec extends Specification {
Expand All @@ -17,4 +16,9 @@ class NettyLaxClientCookieEncoderSpec extends Specification {
then:
"SID=31d4d96e407aad42" == cookieEncoder.encode(cookie)
}

void "ClientCookieEncoder is NettyLaxClientCookieDecoder"() {
expect:
ClientCookieEncoder.INSTANCE instanceof NettyLaxClientCookieEncoder
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package io.micronaut.http.netty.cookies

import io.micronaut.core.order.OrderUtil
import io.micronaut.http.cookie.DefaultServerCookieDecoder
import io.micronaut.http.cookie.ServerCookieDecoder
import spock.lang.Specification

class NettyLaxServerCookieDecoderSpec extends Specification {

void "ServerCookieDecoder is NettyLaxServerCookieDecoder"() {
expect:
ServerCookieDecoder.INSTANCE instanceof NettyLaxServerCookieDecoder
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,19 @@ class NettyServerCookieEncoderSpec extends Specification {

when:
long maxAge = 2592000
cookie = Cookie.of("id", "a3fWa").maxAge(maxAge)
String result = cookieEncoder.encode(cookie).get(0)
String expected = "id=a3fWa; Max-Age=2592000; " + Cookie.ATTRIBUTE_EXPIRES + "=" + expires(maxAge)
String expected2 = "id=a3fWa; Max-Age=2592000; " + Cookie.ATTRIBUTE_EXPIRES + "=" + expires(maxAge + 1) // To prevent flakiness
cookie = Cookie.of("id", "a3fWa").maxAge(maxAge);
String result = cookieEncoder.encode(cookie).get(0);
String expected3 = "id=a3fWa; Max-Age=2592000; " + Cookie.ATTRIBUTE_EXPIRES + "=" + expires(maxAge - 1) // To prevent flakiness

then:
expected == result || expected2 == result
expected == result || expected2 == result || expected3 == result
}

void "ServerCookieEncoder is NettyServerCookieEncoder"() {
expect:
ServerCookieEncoder.INSTANCE instanceof NettyServerCookieEncoder
}

private static String expires(Long maxAgeSeconds) {
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;

class DefaultClientCookieEncoderTest {
@Test
void clientCookieEncoderIsDefaultClientCookieEncoder() {
assertInstanceOf(DefaultClientCookieEncoder.class, ClientCookieEncoder.INSTANCE);
}

@Test
void clientCookieEncoding() {
ClientCookieEncoder cookieEncoder = new DefaultClientCookieEncoder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
import static org.junit.jupiter.api.Assertions.*;

class DefaultServerCookieDecoderTest {
@Test
void serverCookieDecoderIsDefaultServerCookieDecoder() {
assertInstanceOf(DefaultServerCookieDecoder.class, ServerCookieDecoder.INSTANCE);
}

@Test
void testCookieDecoding() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.*;

class DefaultServerCookieEncoderTest {

Expand All @@ -32,6 +31,11 @@ void encodeCookie() {
assertTrue(expected.equals(result) || expected2.equals(result));
}

@Test
void serverCookieEncoderIsDefaultServerCookieEncoder() {
assertInstanceOf(DefaultServerCookieEncoder.class, ServerCookieEncoder.INSTANCE);
}

private static String expires(Long maxAgeSeconds) {
ZoneId gmtZone = ZoneId.of("GMT");
LocalDateTime localDateTime = LocalDateTime.now(gmtZone).plusSeconds(maxAgeSeconds);
Expand Down
Loading