From ab8c8a800edcbd4acf4fbfb35a039b78168990ff Mon Sep 17 00:00:00 2001 From: Mark Thomas Date: Thu, 12 Dec 2024 11:30:48 +0000 Subject: [PATCH] Expand testing of If-Match and If-Unmodified-Since combinations --- ...tServletRfc9110Section13Parameterized.java | 48 ++++++++++++++----- 1 file changed, 35 insertions(+), 13 deletions(-) diff --git a/test/org/apache/catalina/servlets/TestDefaultServletRfc9110Section13Parameterized.java b/test/org/apache/catalina/servlets/TestDefaultServletRfc9110Section13Parameterized.java index e3948e5ab925..c653cdbb1db4 100644 --- a/test/org/apache/catalina/servlets/TestDefaultServletRfc9110Section13Parameterized.java +++ b/test/org/apache/catalina/servlets/TestDefaultServletRfc9110Section13Parameterized.java @@ -70,19 +70,24 @@ public class TestDefaultServletRfc9110Section13Parameterized extends TomcatBaseT public static Collection parameters() { List parameterSets = new ArrayList<>(); for (Boolean useStrongEtag : booleans) { - // RFC 9110, Section 13.2.2, Step 1, HEAD - parameterSets.add(new Object[] { useStrongEtag, Task.HEAD_INDEX_HTML, EtagPrecondition.ALL, null, null, null, - null, Boolean.FALSE, SC_200 }); - parameterSets.add(new Object[] { useStrongEtag, Task.HEAD_INDEX_HTML, EtagPrecondition.EXACTLY, null, null, null, - null, Boolean.FALSE, useStrongEtag.booleanValue() ? SC_200 : SC_412}); - parameterSets.add(new Object[] { useStrongEtag, Task.HEAD_INDEX_HTML, EtagPrecondition.IN, null, null, null, - null, Boolean.FALSE, useStrongEtag.booleanValue() ? SC_200 : SC_412 }); - parameterSets.add(new Object[] { useStrongEtag, Task.HEAD_INDEX_HTML, EtagPrecondition.NOT_IN, null, null, null, - null, Boolean.FALSE, SC_412 }); - parameterSets.add(new Object[] { useStrongEtag, Task.HEAD_INDEX_HTML, EtagPrecondition.INVALID_ALL_PLUS_OTHER, - null, null, null, null, Boolean.FALSE, SC_400 }); + // RFC 9110, Section 13.2.2, Step 1, HEAD: If-Match with and without If-Unmodified-Since + for (DatePrecondition dateCondition : DatePrecondition.values()) { + parameterSets.add(new Object[] { useStrongEtag, Task.HEAD_INDEX_HTML, EtagPrecondition.ALL, + dateCondition, null, null, null, Boolean.FALSE, SC_200 }); + parameterSets.add( + new Object[] { useStrongEtag, Task.HEAD_INDEX_HTML, EtagPrecondition.EXACTLY, dateCondition, + null, null, null, Boolean.FALSE, useStrongEtag.booleanValue() ? SC_200 : SC_412 }); + parameterSets + .add(new Object[] { useStrongEtag, Task.HEAD_INDEX_HTML, EtagPrecondition.IN, dateCondition, + null, null, null, Boolean.FALSE, useStrongEtag.booleanValue() ? SC_200 : SC_412 }); + parameterSets.add(new Object[] { useStrongEtag, Task.HEAD_INDEX_HTML, EtagPrecondition.NOT_IN, + dateCondition, null, null, null, Boolean.FALSE, SC_412 }); + parameterSets.add( + new Object[] { useStrongEtag, Task.HEAD_INDEX_HTML, EtagPrecondition.INVALID_ALL_PLUS_OTHER, + dateCondition, null, null, null, Boolean.FALSE, SC_400 }); + } - // RFC 9110, Section 13.2.2, Step 2, HEAD + // RFC 9110, Section 13.2.2, Step 2, HEAD: If-Unmodified-Since only parameterSets.add(new Object[] { useStrongEtag, Task.HEAD_INDEX_HTML, null, DatePrecondition.EQ, null, null, null, Boolean.FALSE, SC_200 }); parameterSets.add(new Object[] { useStrongEtag, Task.HEAD_INDEX_HTML, null, DatePrecondition.LT, null, null, @@ -91,6 +96,15 @@ public static Collection parameters() { null, Boolean.FALSE, SC_200 }); parameterSets.add(new Object[] { useStrongEtag, Task.HEAD_INDEX_HTML, null, DatePrecondition.MULTI_IN, null, null, null, Boolean.FALSE, SC_200 }); + + // Ensure If-Unmodified-Since takes precedence over If-Modified-Since + // If-Unmodified-Since only + parameterSets.add(new Object[] { useStrongEtag, Task.HEAD_INDEX_HTML, null, DatePrecondition.LT, null, null, + null, Boolean.FALSE, SC_412 }); + // If-Modified-Since only + parameterSets.add(new Object[] { useStrongEtag, Task.HEAD_INDEX_HTML, null, null, null, DatePrecondition.GT, + null, Boolean.FALSE, SC_304 }); + // Both parameterSets.add(new Object[] { useStrongEtag, Task.HEAD_INDEX_HTML, null, DatePrecondition.LT, null, DatePrecondition.GT, null, Boolean.FALSE, SC_412 }); } @@ -100,6 +114,7 @@ public static Collection parameters() { private static Integer SC_200 = Integer.valueOf(200); + private static Integer SC_304 = Integer.valueOf(304); private static Integer SC_400 = Integer.valueOf(400); private static Integer SC_412 = Integer.valueOf(412); @@ -174,7 +189,11 @@ private enum DatePrecondition { /** * not a valid HTTP-date */ - INVALID; + INVALID, + /** + * None. + */ + NONE; } @@ -244,6 +263,9 @@ protected void genDatePrecondition(long lastModifiedTimestamp, DatePrecondition case INVALID: headerValues.add("2024.12.09 GMT"); break; + case NONE: + // NO-OP + break; } if (!headerValues.isEmpty()) { requestHeaders.put(headerName, headerValues);