Skip to content

Commit

Permalink
remove DefaultCookieDecoder (#10659)
Browse files Browse the repository at this point in the history
#10435 remove DefaultCookieDecoder from services because its broken for parsing request cookies
  • Loading branch information
n0tl3ss authored Mar 28, 2024
1 parent 5063469 commit 8ea2045
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 9 deletions.
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

0 comments on commit 8ea2045

Please sign in to comment.