Skip to content

Commit

Permalink
dcache-bulk,dcache-frontend: distinguish "Not Found" from "Invalid" r…
Browse files Browse the repository at this point in the history
…equest

Motivation:

See #7165
REST API (Frontend): non-existent request returns 400 instead of 404

Modification:

Check existence of the request before permissions.

Result:

Correct error code is returned.

Target: master
Request: 9.0
Request: 8.2
Closes: #7165
Patch: https://rb.dcache.org/r/13984/
Requires-notes: yes
Acked-by: Tigran
  • Loading branch information
alrossi committed May 17, 2023
1 parent 5a90236 commit ff7a67a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
Expand Up @@ -209,6 +209,10 @@ public Reply messageArrived(BulkRequestStatusMessage message) {
try {
Subject subject = message.getSubject();
String uuid = message.getRequestUuid();
/*
* First check to see if the request corresponds to a stored one.
*/
requestStore.getKey(uuid);
checkRestrictions(message.getRestriction(), uuid);
matchActivity(message.getActivity(), uuid);
BulkRequestInfo status = requestStore.getRequestInfo(subject, uuid,
Expand Down Expand Up @@ -236,6 +240,10 @@ public Reply messageArrived(BulkRequestCancelMessage message) {
try {
Subject subject = message.getSubject();
String uuid = message.getRequestUuid();
/*
* First check to see if the request corresponds to a stored one.
*/
requestStore.getKey(uuid);
checkRestrictions(message.getRestriction(), uuid);
matchActivity(message.getActivity(), uuid);
List<String> targetPaths = message.getTargetPaths();
Expand Down Expand Up @@ -267,6 +275,10 @@ public Reply messageArrived(BulkRequestClearMessage message) {
try {
String uuid = message.getRequestUuid();
Subject subject = message.getSubject();
/*
* First check to see if the request corresponds to a stored one.
*/
requestStore.getKey(uuid);
checkRestrictions(message.getRestriction(), uuid);
matchActivity(message.getActivity(), uuid);
submissionHandler.clearRequest(subject, uuid, message.isCancelIfRunning());
Expand Down
Expand Up @@ -816,8 +816,7 @@ private BulkRequestTargetInfo toRequestTargetInfo(BulkRequestTarget target, FsP
private BulkRequest valid(String uid) throws BulkStorageException {
BulkRequest stored = get(uid);
if (stored == null) {
String error = "request id " + uid + " is no longer valid!";
throw new BulkRequestNotFoundException(error);
throw new BulkRequestNotFoundException("request " + uid + " not found");
}
return stored;
}
Expand Down
Expand Up @@ -374,6 +374,7 @@ public Response update(@ApiParam("The unique id of the request.")
@ApiResponse(code = 400, message = "Bad request"),
@ApiResponse(code = 401, message = "Unauthorized"),
@ApiResponse(code = 403, message = "Forbidden"),
@ApiResponse(code = 404, message = "Not Found"),
@ApiResponse(code = 500, message = "Internal Server Error")
})
@Path("/{id}")
Expand Down
Expand Up @@ -197,6 +197,7 @@ public StageRequestInfo getStageInfo(@ApiParam("The unique id of the request.")
@ApiResponse(code = 400, message = "Bad request"),
@ApiResponse(code = 401, message = "Unauthorized"),
@ApiResponse(code = 403, message = "Forbidden"),
@ApiResponse(code = 404, message = "Not Found"),
@ApiResponse(code = 429, message = "Too many requests"),
@ApiResponse(code = 500, message = "Internal Server Error")
})
Expand Down Expand Up @@ -322,6 +323,7 @@ public Response submit(
@ApiResponse(code = 400, message = "Bad request"),
@ApiResponse(code = 401, message = "Unauthorized"),
@ApiResponse(code = 403, message = "Forbidden"),
@ApiResponse(code = 404, message = "Not Found"),
@ApiResponse(code = 500, message = "Internal Server Error")
})
@Path("/{id}")
Expand Down

0 comments on commit ff7a67a

Please sign in to comment.