http oracle invalid location#1554
Conversation
| /** | ||
| * Checks the invalid-location oracle: | ||
| * | ||
| * POST|PUT /X -> 2xx with Location header L |
There was a problem hiding this comment.
not just for POST/PUT, but any verb where response has a location header
| * Sequence checked: the last two main actions of the individual. | ||
| * - second-to-last (creator) is POST or PUT, has a 2xx status, and its result has a | ||
| * non-blank Location header. | ||
| * - last is a GET bound to the creator's saved Location via [RestCallAction.usePreviousLocationId]. |
There was a problem hiding this comment.
that part of the code is deemed to refactoring... as naming of some methods has evolved since their original implementation :( eg, that one also includes linking without Location header
| val follow = actions[actions.size - 1] | ||
|
|
||
| // creator must be a potential resource-creating verb (POST/PUT) | ||
| if (!creator.isPotentialActionForCreation()) return false |
There was a problem hiding this comment.
any verb is fine, although i guess 99% of time it would be a POST :)
|
|
||
| // follow-up must be a GET, and it must actually be chained to the creator's Location | ||
| if (follow.verb != HttpVerb.GET) return false | ||
| val expectedLocId = try { creator.creationLocationId() } catch (e: Exception) { return false } |
There was a problem hiding this comment.
add a TODO stating this will need to be refactored once we fix that function.
at a certain point i need to start a major refactoring of the action bindings... and i can then update the code here by checking the TODOs
| ?: return false | ||
|
|
||
| // creator must have succeeded and returned a Location header | ||
| if (!StatusGroup.G_2xx.isInGroup(resCreator.getStatusCode())) return false |
There was a problem hiding this comment.
why succeed? if it fails, and still it returns a location header, we want to check the location header being correct :)
|
|
||
|
|
||
| /** | ||
| * HTTP_INVALID_LOCATION oracle: a POST/PUT that returns 2xx with a Location header |
There was a problem hiding this comment.
any verb, not just POST/PUT
|
|
||
| for (verb in creatorVerbs) { | ||
|
|
||
| val creatorOps = RestIndividualSelectorUtils.getAllActionDefinitions(actionDefinitions, verb) |
There was a problem hiding this comment.
we should rather search in the archive, for each endpoint, the tests for which in response there is a Location header, eg, HttpWsCallResult.getLocation()
|
|
||
| // GET endpoint to follow up on: same path (e.g. PUT /x/{id} -> GET /x/{id}) | ||
| // or the closest descendant (e.g. POST /x -> GET /x/{id}) | ||
| val getDef = actionDefinitions.find { it.verb == HttpVerb.GET && it.path == creatorOp.path } |
There was a problem hiding this comment.
the GET to do should be based on the actual Location header. if the location header is faulty, with mistakes in it, then it would not match any endpoint in the schema. those are the actual cases in which we want to verify this oracle. we might need to create a special action (or special configuration) to handle this kind of custom GET request
| val creator = ind.seeMainExecutableActions().last() | ||
|
|
||
| // Build the follow-up GET and force Location chaining. | ||
| val getAction = getDef.copy() as RestCallAction |
There was a problem hiding this comment.
the GET should be as based in the Location header, which might use a relative URL or not, and/or have query parameters. most likely we need new action subtype to handle this. might also most likely impact how we output test cases
| // actually stored, so a follow-up GET on it will return 404 | ||
|
|
||
| val status = if (isNew) 201 else 200 | ||
| return ResponseEntity.status(status) |
There was a problem hiding this comment.
also add test case for when the relative path is invalid, eg, /somePathThatDoesNotExist, and also full URL, eg, http://localhost:$port/api/resources/${id+1000}
No description provided.