Skip to content

http oracle invalid location#1554

Open
omursahin wants to merge 3 commits into
masterfrom
http-invalid-location
Open

http oracle invalid location#1554
omursahin wants to merge 3 commits into
masterfrom
http-invalid-location

Conversation

@omursahin
Copy link
Copy Markdown
Collaborator

No description provided.

@omursahin omursahin requested a review from arcuri82 May 21, 2026 17:02
/**
* Checks the invalid-location oracle:
*
* POST|PUT /X -> 2xx with Location header L
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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].
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 }
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any verb, not just POST/PUT


for (verb in creatorVerbs) {

val creatorOps = RestIndividualSelectorUtils.getAllActionDefinitions(actionDefinitions, verb)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 }
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants