-
Notifications
You must be signed in to change notification settings - Fork 535
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: NPE on misformatted Date or Expires header (#2592)
* fix: NPE on misformatted Date or Expires header * fix: null check in date difference * test: cache control max age with valid and invalid headers * test: does not need to extend WebClientTestBase
- Loading branch information
Showing
2 changed files
with
46 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
vertx-web-client/src/test/java/io/vertx/ext/web/client/impl/cache/CacheControlTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package io.vertx.ext.web.client.impl.cache; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
import java.time.Duration; | ||
|
||
import org.junit.Test; | ||
|
||
import io.vertx.core.MultiMap; | ||
|
||
public class CacheControlTest { | ||
@Test | ||
public void testMaxAge() { | ||
MultiMap headers = MultiMap.caseInsensitiveMultiMap(); | ||
headers.add("Date", "Tue, 09 Apr 2024 19:10:51 GMT"); | ||
headers.add("Expires", "Thu, 09 May 2024 19:10:51 GMT"); | ||
|
||
CacheControl cc = CacheControl.parse(headers); | ||
assertEquals(Duration.ofDays(30).getSeconds(), cc.getMaxAge()); | ||
} | ||
|
||
@Test | ||
public void testInvalidHeaders() { | ||
// invalid Date | ||
MultiMap headers = MultiMap.caseInsensitiveMultiMap(); | ||
headers.add("Date", "this header doesn't make sense"); | ||
headers.add("Expires", "Thu, 09 May 2024 19:10:51 GMT"); | ||
|
||
CacheControl cc = CacheControl.parse(headers); | ||
assertEquals(Long.MAX_VALUE, cc.getMaxAge()); | ||
|
||
// invalid Expires | ||
headers = MultiMap.caseInsensitiveMultiMap(); | ||
headers.add("Date", "Tue, 09 Apr 2024 19:10:51 GMT"); | ||
headers.add("Expires", "this header doesn't make sense"); | ||
|
||
cc = CacheControl.parse(headers); | ||
assertEquals(Long.MAX_VALUE, cc.getMaxAge()); | ||
} | ||
} |