This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/9.0.x by this push:
new 3c790aa14e Tests and fixes for Precondition requests for resources
that don't exist
3c790aa14e is described below
commit 3c790aa14e2e66bdb91d5aa3b3efe8cea4428118
Author: Mark Thomas <[email protected]>
AuthorDate: Fri Dec 13 15:44:11 2024 +0000
Tests and fixes for Precondition requests for resources that don't exist
Code clean-up - reformatting
---
.../apache/catalina/servlets/DefaultServlet.java | 41 ++++----
...efaultServletRfc9110Section13Parameterized.java | 109 ++++++++++++++++-----
2 files changed, 102 insertions(+), 48 deletions(-)
diff --git a/java/org/apache/catalina/servlets/DefaultServlet.java
b/java/org/apache/catalina/servlets/DefaultServlet.java
index a34d583ae9..032bbed83f 100644
--- a/java/org/apache/catalina/servlets/DefaultServlet.java
+++ b/java/org/apache/catalina/servlets/DefaultServlet.java
@@ -827,6 +827,10 @@ public class DefaultServlet extends HttpServlet {
if (isError) {
response.sendError(((Integer)
request.getAttribute(RequestDispatcher.ERROR_STATUS_CODE)).intValue());
} else {
+ // Need to check If headers before we return a 404
+ if (!checkIfHeaders(request, response, resource)) {
+ return;
+ }
response.sendError(HttpServletResponse.SC_NOT_FOUND,
sm.getString("defaultServlet.missingResource",
requestUri));
}
@@ -2359,36 +2363,27 @@ public class DefaultServlet extends HttpServlet {
// representation for the target resource.
if (resourceETag != null) {
conditionSatisfied = false;
- } else {
- conditionSatisfied = true;
}
break;
}
} else {
- if (resourceETag == null) {
- // None of the entity tag matches.
- conditionSatisfied = true;
- break;
- } else {
- // RFC 7232 requires weak comparison for If-None-Match
headers
- Boolean matched = EntityTag.compareEntityTag(new
StringReader(headerValue), true, resourceETag);
- if (matched == null) {
- if (debug > 10) {
- log("DefaultServlet.checkIfNoneMatch: Invalid
header value [" + headerValue + "]");
- }
- response.sendError(HttpServletResponse.SC_BAD_REQUEST);
- return false;
- }
- if (matched.booleanValue()) {
- // RFC9110: If the field value is a list of entity
tags, the condition is false if one of the
- // listed tags
- // matches the entity tag of the selected
representation.
- conditionSatisfied = false;
- break;
+ // RFC 7232 requires weak comparison for If-None-Match headers
+ Boolean matched = EntityTag.compareEntityTag(new
StringReader(headerValue), true, resourceETag);
+ if (matched == null) {
+ if (debug > 10) {
+ log("DefaultServlet.checkIfNoneMatch: Invalid header
value [" + headerValue + "]");
}
+ response.sendError(HttpServletResponse.SC_BAD_REQUEST);
+ return false;
+ }
+ if (matched.booleanValue()) {
+ // RFC9110: If the field value is a list of entity tags,
the condition is false if one of the
+ // listed tags
+ // matches the entity tag of the selected representation.
+ conditionSatisfied = false;
+ break;
}
}
-
}
if (headerValues.hasMoreElements()) {
headerCount++;
diff --git
a/test/org/apache/catalina/servlets/TestDefaultServletRfc9110Section13Parameterized.java
b/test/org/apache/catalina/servlets/TestDefaultServletRfc9110Section13Parameterized.java
index 4b79e5ec7b..9138bd5b97 100644
---
a/test/org/apache/catalina/servlets/TestDefaultServletRfc9110Section13Parameterized.java
+++
b/test/org/apache/catalina/servlets/TestDefaultServletRfc9110Section13Parameterized.java
@@ -151,6 +151,65 @@ public class
TestDefaultServletRfc9110Section13Parameterized extends TomcatBaseT
null, Boolean.FALSE, SC_200 });
}
+ for (Task task : Arrays.asList(Task.HEAD_404_HTML,
Task.GET_404_HTML, Task.POST_404_HTML)) {
+ // 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,
EtagPrecondition.ALL, dateCondition, null,
+ null, null, null, Boolean.FALSE, SC_412 });
+ parameterSets.add(new Object[] { useStrongEtag, task,
EtagPrecondition.IN, dateCondition, null,
+ null, null, null, Boolean.FALSE, SC_412 });
+ parameterSets.add(new Object[] { useStrongEtag, task,
EtagPrecondition.NOT_IN, dateCondition, null,
+ null, null, null, Boolean.FALSE, SC_412 });
+ parameterSets.add(new Object[] { useStrongEtag, task,
EtagPrecondition.INVALID, dateCondition, null,
+ null, null, null, Boolean.FALSE, SC_400 });
+ parameterSets.add(new Object[] { useStrongEtag, task,
EtagPrecondition.INVALID_ALL_PLUS_OTHER,
+ dateCondition, null, null, null, null,
Boolean.FALSE, SC_400 });
+ }
+
+ // RFC 9110, Section 13.2.2, Step 2, HEAD: If-Unmodified-Since
only
+ parameterSets.add(new Object[] { useStrongEtag, task, null,
DatePrecondition.EQ, null, null, null, null,
+ Boolean.FALSE, SC_404 });
+ parameterSets.add(new Object[] { useStrongEtag, task, null,
DatePrecondition.LT, null, null, null, null,
+ Boolean.FALSE, SC_404 });
+ parameterSets.add(new Object[] { useStrongEtag, task, null,
DatePrecondition.GT, null, null, null, null,
+ Boolean.FALSE, SC_404 });
+ parameterSets.add(new Object[] { useStrongEtag, task, null,
DatePrecondition.MULTI_IN, null, null, null,
+ null, Boolean.FALSE, SC_404 });
+ parameterSets.add(new Object[] { useStrongEtag, task, null,
DatePrecondition.MULTI_IN_REV, null, null,
+ null, null, Boolean.FALSE, SC_404 });
+ parameterSets.add(new Object[] { useStrongEtag, task, null,
DatePrecondition.INVALID, null, null, null,
+ null, Boolean.FALSE, SC_404 });
+
+ // RFC 9110, Section 13.2.2, Step 3, HEAD: If-None-Match with
and without If-Modified-Since
+ for (DatePrecondition dateCondition :
DatePrecondition.values()) {
+ parameterSets.add(new Object[] { useStrongEtag, task,
null, null, EtagPrecondition.ALL,
+ dateCondition, null, null, Boolean.FALSE, SC_404
});
+ parameterSets.add(new Object[] { useStrongEtag, task,
null, null, EtagPrecondition.IN,
+ dateCondition, null, null, Boolean.FALSE, SC_404
});
+ parameterSets.add(new Object[] { useStrongEtag, task,
null, null, EtagPrecondition.NOT_IN,
+ dateCondition, null, null, Boolean.FALSE, SC_404
});
+ parameterSets.add(new Object[] { useStrongEtag, task,
null, null, EtagPrecondition.INVALID,
+ dateCondition, null, null, Boolean.FALSE, SC_400
});
+ parameterSets.add(
+ new Object[] { useStrongEtag, task, null, null,
EtagPrecondition.INVALID_ALL_PLUS_OTHER,
+ dateCondition, null, null, Boolean.FALSE,
SC_400 });
+ }
+
+ // RFC 9110, Section 13.2.2, Step 4, HEAD: If-Modified-Since
only
+ parameterSets.add(new Object[] { useStrongEtag, task, null,
null, null, DatePrecondition.EQ, null, null,
+ Boolean.FALSE, SC_404 });
+ parameterSets.add(new Object[] { useStrongEtag, task, null,
null, null, DatePrecondition.LT, null, null,
+ Boolean.FALSE, SC_404 });
+ parameterSets.add(new Object[] { useStrongEtag, task, null,
null, null, DatePrecondition.GT, null, null,
+ Boolean.FALSE, SC_404 });
+ parameterSets.add(new Object[] { useStrongEtag, task, null,
null, null, DatePrecondition.MULTI_IN, null,
+ null, Boolean.FALSE, SC_404 });
+ parameterSets.add(new Object[] { useStrongEtag, task, null,
null, null, DatePrecondition.MULTI_IN_REV,
+ null, null, Boolean.FALSE, SC_404 });
+ parameterSets.add(new Object[] { useStrongEtag, task, null,
null, null, DatePrecondition.INVALID, null,
+ null, Boolean.FALSE, SC_404 });
+ }
+
// RFC 9110, Section 13.2.2, Step 5, GET: If-Range only
// entity-tag
parameterSets.add(new Object[] { useStrongEtag,
Task.GET_INDEX_HTML, null, null, null, null,
@@ -261,31 +320,31 @@ public class
TestDefaultServletRfc9110Section13Parameterized extends TomcatBaseT
// DELETE TESTS
parameterSets.add(new Object[] { useStrongEtag,
Task.DELETE_EXIST_TXT, null, null, null, null, null, null,
Boolean.FALSE, SC_204 });
- parameterSets.add(new Object[] { useStrongEtag,
Task.DELETE_EXIST_TXT, EtagPrecondition.ALL, null, null, null, null, null,
- Boolean.FALSE, SC_204 });
- parameterSets.add(new Object[] { useStrongEtag,
Task.DELETE_EXIST_TXT, EtagPrecondition.EXACTLY, null, null, null, null, null,
- Boolean.FALSE, useStrongEtag.booleanValue() ? SC_204 :
SC_412 });
- parameterSets.add(new Object[] { useStrongEtag,
Task.DELETE_EXIST_TXT, EtagPrecondition.IN, null, null, null, null, null,
- Boolean.FALSE, useStrongEtag.booleanValue() ? SC_204 :
SC_412 });
- parameterSets.add(new Object[] { useStrongEtag,
Task.DELETE_EXIST_TXT, EtagPrecondition.NOT_IN, null, null, null, null, null,
- Boolean.FALSE, SC_412 });
- parameterSets.add(new Object[] { useStrongEtag,
Task.DELETE_EXIST_TXT, EtagPrecondition.INVALID, null, null, null, null, null,
- Boolean.FALSE, SC_400 });
- parameterSets.add(new Object[] { useStrongEtag,
Task.DELETE_EXIST_TXT, EtagPrecondition.INVALID_ALL_PLUS_OTHER, null, null,
null, null, null,
- Boolean.FALSE, SC_400 });
-
- parameterSets.add(new Object[] { useStrongEtag,
Task.DELETE_NOT_EXIST_TXT, null, null, null, null, null, null,
- Boolean.FALSE, SC_404 });
- parameterSets.add(new Object[] { useStrongEtag,
Task.DELETE_NOT_EXIST_TXT, EtagPrecondition.ALL, null, null, null, null, null,
- Boolean.FALSE, SC_412 });
- parameterSets.add(new Object[] { useStrongEtag,
Task.DELETE_NOT_EXIST_TXT, EtagPrecondition.IN, null, null, null, null, null,
- Boolean.FALSE, SC_412 });
- parameterSets.add(new Object[] { useStrongEtag,
Task.DELETE_NOT_EXIST_TXT, EtagPrecondition.NOT_IN, null, null, null, null,
null,
- Boolean.FALSE, SC_412 });
- parameterSets.add(new Object[] { useStrongEtag,
Task.DELETE_NOT_EXIST_TXT, EtagPrecondition.INVALID, null, null, null, null,
null,
- Boolean.FALSE, SC_400 });
- parameterSets.add(new Object[] { useStrongEtag,
Task.DELETE_NOT_EXIST_TXT, EtagPrecondition.INVALID_ALL_PLUS_OTHER, null, null,
null, null, null,
- Boolean.FALSE, SC_400 });
+ parameterSets.add(new Object[] { useStrongEtag,
Task.DELETE_EXIST_TXT, EtagPrecondition.ALL, null, null,
+ null, null, null, Boolean.FALSE, SC_204 });
+ parameterSets.add(new Object[] { useStrongEtag,
Task.DELETE_EXIST_TXT, EtagPrecondition.EXACTLY, null, null,
+ null, null, null, Boolean.FALSE,
useStrongEtag.booleanValue() ? SC_204 : SC_412 });
+ parameterSets.add(new Object[] { useStrongEtag,
Task.DELETE_EXIST_TXT, EtagPrecondition.IN, null, null,
+ null, null, null, Boolean.FALSE,
useStrongEtag.booleanValue() ? SC_204 : SC_412 });
+ parameterSets.add(new Object[] { useStrongEtag,
Task.DELETE_EXIST_TXT, EtagPrecondition.NOT_IN, null, null,
+ null, null, null, Boolean.FALSE, SC_412 });
+ parameterSets.add(new Object[] { useStrongEtag,
Task.DELETE_EXIST_TXT, EtagPrecondition.INVALID, null, null,
+ null, null, null, Boolean.FALSE, SC_400 });
+ parameterSets.add(new Object[] { useStrongEtag,
Task.DELETE_EXIST_TXT,
+ EtagPrecondition.INVALID_ALL_PLUS_OTHER, null, null, null,
null, null, Boolean.FALSE, SC_400 });
+
+ parameterSets.add(new Object[] { useStrongEtag,
Task.DELETE_NOT_EXIST_TXT, null, null, null, null, null,
+ null, Boolean.FALSE, SC_404 });
+ parameterSets.add(new Object[] { useStrongEtag,
Task.DELETE_NOT_EXIST_TXT, EtagPrecondition.ALL, null, null,
+ null, null, null, Boolean.FALSE, SC_412 });
+ parameterSets.add(new Object[] { useStrongEtag,
Task.DELETE_NOT_EXIST_TXT, EtagPrecondition.IN, null, null,
+ null, null, null, Boolean.FALSE, SC_412 });
+ parameterSets.add(new Object[] { useStrongEtag,
Task.DELETE_NOT_EXIST_TXT, EtagPrecondition.NOT_IN, null,
+ null, null, null, null, Boolean.FALSE, SC_412 });
+ parameterSets.add(new Object[] { useStrongEtag,
Task.DELETE_NOT_EXIST_TXT, EtagPrecondition.INVALID, null,
+ null, null, null, null, Boolean.FALSE, SC_400 });
+ parameterSets.add(new Object[] { useStrongEtag,
Task.DELETE_NOT_EXIST_TXT,
+ EtagPrecondition.INVALID_ALL_PLUS_OTHER, null, null, null,
null, null, Boolean.FALSE, SC_400 });
}
return parameterSets;
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]