Skip to content

Handle invalid UUIDs in found_by parameter within prepare_common_search_params() #633

@stefopl

Description

@stefopl

There are a lot of errors of this type appearing:

--- Stack trace ---
#0 /okapi/services/caches/search/SearchAssistant.php(430): okapi\core\OkapiErrorHandler::handle()
#1 [internal function]: okapi\services\caches\search\SearchAssistant->okapi\services\caches\search\{closure}()
#2 /okapi/services/caches/search/SearchAssistant.php(430): array_map()
#3 /okapi/services/caches/search/nearest/WebService.php(55): okapi\services\caches\search\SearchAssistant->prepare_common_search_params()
#4 [internal function]: okapi\services\caches\search\nearest\WebService::call()
#5 /okapi/core/OkapiServiceRunner.php(142): call_user_func()
#6 /okapi/services/caches/shortcuts/search_and_retrieve/WebService.php(66): okapi\core\OkapiServiceRunner::call()
#7 [internal function]: okapi\services\caches\shortcuts\search_and_retrieve\WebService::call()
#8 /okapi/core/OkapiServiceRunner.php(142): call_user_func()
#9 /okapi/views/method_call/View.php(19): okapi\core\OkapiServiceRunner::call()
#10 [internal function]: okapi\views\method_call\View::call()
#11 /okapi/OkapiScriptEntryPointController.php(50): call_user_func_array()
#12 /okapi/index.php(49): okapi\OkapiScriptEntryPointController::dispatch_request()
#13 {main}

--- OKAPI method called ---
/okapi/services/caches/shortcuts/search_and_retrieve?search_method=services/caches/search/nearest&search_params={"limit":"200","offset":"0","center":"39.380853|-77.364065","radius":"200","found_by":"unknown-user"}&retr_method=services/caches/geocaches&retr_params={"fields": "code|name|location|type|status|difficulty|terrain|size|size2|date_hidden|trackables_count|owner|founds|notfounds|rating|rating_votes|recommendations|region|country2|attr_acodes|attrnames"}&wrap=true&langpref=en&consumer_key=[REDACTED]

I suspect that all of them are coming from c:geo.

https://github.com/cgeo/cgeo/blob/405083903b8da9e88f3a00ba329ff10285b82eeb/main/src/main/java/cgeo/geocaching/connector/oc/OkapiClient.java#L445
https://github.com/cgeo/cgeo/blob/405083903b8da9e88f3a00ba329ff10285b82eeb/main/src/main/java/cgeo/geocaching/connector/oc/OkapiClient.java#L494

When getUserUUID() returns null, c:geo makes a request to /okapi/services/caches/shortcuts/search_and_retrieve with the found_by parameter set to unknown-user, which is not a valid UUID and causes an error.

I suggest implementing proper handling for cases where the UUID is invalid.

Below is a table showing the expected behavior in various cases and the current behavior:
(To simplify the examples, I used /okapi/services/caches/search/all instead of /okapi/services/caches/shortcuts/search_and_retrieve)

Description Query Expected Status Expected Type Current Status Current Type
Query causing the problem /okapi/services/caches/shortcuts/search_and_retrieve?search_method=services/caches/search/nearest&search_params={"limit":"200","offset":"0","center":"25.380853|18.364065","radius":"200","found_by":"unknown-user"}&retr_method=services/caches/geocaches&retr_params={"fields": "code |name |location |type |status |difficulty |terrain |size |size2 |date_hidden |trackables_count |owner |founds |notfounds |rating |rating_votes |recommendations |region |country2 |attr_acodes |attrnames"}&wrap=true&langpref=en&consumer_key=[REDACTED] 400 json 500 txt
Valid UUID /okapi/services/caches/search/all?found_by=BAA8F3CF-DD81-8254-E5EC-AD407B51EA4E&consumer_key=[REDACTED] 200 json 200 json
Invalid UUID /okapi/services/caches/search/all?found_by=dummy&consumer_key=[REDACTED] 400 json 500 txt
Valid UUIDs /okapi/services/caches/search/all?found_by=BAA8F3CF-DD81-8254-E5EC-AD407B51EA4E|7DEE1844-C97F-74C8-605C-972150B1BBA4&consumer_key=[REDACTED] 200 json 200 json
Two valid UUIDs and two invalid UUIDs /okapi/services/caches/search/all?found_by=BAA8F3CF-DD81-8254-E5EC-AD407B51EA4E|7DEE1844-C97F-74C8-605C-972150B1BBA4|dummy|dummy2&consumer_key=[REDACTED] 400 json 500 txt
/okapi/services/caches/search/all?found_by&consumer_key=[REDACTED] 200 json 200 json
/okapi/services/caches/search/all?consumer_key=[REDACTED] 200 json 200 json

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions