Skip to content

Commit

Permalink
Expand testing of If-Match and If-Unmodified-Since combinations
Browse files Browse the repository at this point in the history
  • Loading branch information
markt-asf committed Dec 12, 2024
1 parent e585746 commit ab8c8a8
Showing 1 changed file with 35 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,24 @@ public class TestDefaultServletRfc9110Section13Parameterized extends TomcatBaseT
public static Collection<Object[]> parameters() {
List<Object[]> 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,
Expand All @@ -91,6 +96,15 @@ public static Collection<Object[]> 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 });
}
Expand All @@ -100,6 +114,7 @@ public static Collection<Object[]> 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);

Expand Down Expand Up @@ -174,7 +189,11 @@ private enum DatePrecondition {
/**
* not a valid HTTP-date
*/
INVALID;
INVALID,
/**
* None.
*/
NONE;
}


Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit ab8c8a8

Please sign in to comment.