Skip to content

fix: reject service URLs with spaces - #357

Merged
uniqueg merged 3 commits into
devfrom
fix/service-url-spaces
Nov 4, 2026
Merged

uniqueg merged 3 commits into
devfrom
fix/service-url-spaces

Conversation

@uniqueg

@uniqueg uniqueg commented Nov 4, 2026 •

Copy link
Copy Markdown
Member

Summary

A service url with leading or trailing spaces now returns 400 Bad Request on POST and PUT /services and on PUT verifications, instead of being stored as written. Rejecting matches how the registry handles links, and what the ExternalServiceRegister schema already says. The strip branches in normalize_url() and check_url_scheme() are gone. The API docs, the upgrade steps and the rc2 release notes are updated.

Closes #356

Verification

Run locally on the branch:

  • Failing tests first: the new cases failed before the fix and pass after it
  • pytest without the chart tests: 1752 passed, 11 skipped (tests/test_chart.py and TestChartOverlay excluded)
  • coverage report: 100%, measured on the first commit, in a run where the chart tests failed and 2 outdated test cases were later corrected
  • ruff check, ruff format --check, mypy: pass
  • mkdocs build --strict: passes

Not run locally:

  • Chart tests: helm dependency build deployment failed here with a mise error, so they failed for lack of the library chart; left to CI
  • semgrep: it could not write its settings in the sandbox; left to the push hook and CI
  • Docker Compose smoke test and image scan: left to CI

Declined review findings

  • "A stored service with spaces in its URL makes the app refuse to start": service_key() has no startup caller, and rc2 needs a fresh database, so no such data exists. For the same reason, warn_url_schemes blaming the scheme of such a stored URL needs no change.

Open questions

None.

🤖 Generated with Claude Code

Summary by Sourcery

Reject service URLs containing surrounding whitespace and document the resulting API behavior.

Bug Fixes:

  • Reject service URLs with leading or trailing spaces during service registration and verification instead of storing them unchanged.

Enhancements:

  • Align service URL validation with link handling and the existing schema by treating all whitespace as invalid.

Documentation:

  • Update API documentation, upgrade guidance, and release notes to describe the stricter service URL validation.

Tests:

  • Add coverage for whitespace rejection on service creation, updates, normalization, and verification.

uniqueg and others added 3 commits November 4, 2026 14:57
Service URLs with leading or trailing spaces were stored as written, as
only the checks stripped them. With FOCA 0.21's response validation, one
such value would fail whole lists. Reject them with 400, like links.

Closes #356

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Also rewrap a paragraph of the API docs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@uniqueg uniqueg added this to the v1.0.0-rc2 milestone Nov 4, 2026
@sourcery-ai

sourcery-ai Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Service URL validation no longer strips leading or trailing spaces: the existing URL validators now reject them, preventing invalid values from being stored during registration or verification. Documentation and release guidance describe the behavior change, with regression tests covering POST/PUT registration and PUT verification.

Sequence diagram for rejecting whitespace in service URLs

sequenceDiagram
    actor Client
    participant API
    participant Validator
    participant Registry

    Client->>API: POST or PUT /services
    API->>Validator: normalize_url(url)
    Validator-->>API: InvalidService for surrounding whitespace
    API-->>Client: 400 Bad Request
    Note over API,Registry: Invalid URL is not stored

    Client->>API: PUT verification
    API->>Validator: check_url_scheme(url, schemes)
    Validator-->>API: InvalidService for surrounding whitespace
    API-->>Client: 400 Bad Request
Loading

Flow diagram for service URL validation behavior

flowchart LR
    Input[Service URL] --> Normalize["normalize_url(url)"]
    Input --> Scheme["check_url_scheme(url, schemes)"]
    Normalize --> Reject[400 Bad Request]
    Scheme --> Reject
    Reject --> NotStored[URL is not stored]
Loading

File-Level Changes

Change Details Files
Stop trimming service URLs before validation so surrounding whitespace is rejected consistently.
  • Remove .strip(" ") from URL normalization and scheme checks.
  • Preserve invalid-URL handling through the existing InvalidService/400 response path.
cloud_registry/ga4gh/registry/service.py
Document the new validation behavior and migration impact.
  • Update API guidance to classify all whitespace, including surrounding whitespace, as invalid.
  • Add upgrade instructions and rc2 release-note coverage for registration and verification behavior.
docs/api.md
docs/upgrading.md
docs/releases/1.0.0rc2.md
Add regression coverage for rejecting surrounding whitespace without persisting invalid services.
  • Cover spaced URLs for both POST and PUT service registration.
  • Cover spaced URLs in PUT service verification and assert a 400 response with no verification stored.
  • Update normalization and existing registration cases to treat surrounding whitespace as invalid.
tests/ga4gh/registry/test_service.py
tests/ga4gh/registry/test_verification.py

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@codecov

codecov Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (d3e4fd7) to head (82b11fe).
⚠️ Report is 1 commits behind head on dev.

Additional details and impacted files
@@            Coverage Diff            @@
##               dev      #357   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           23        23           
  Lines         2579      2579           
=========================================
  Hits          2579      2579           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@uniqueg
uniqueg marked this pull request as ready for review November 4, 2026 14:21

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've reviewed your changes and they look great!

Linked issues

#356 Service URLs with surrounding spaces are stored · 2 of 3 met · 1 to check by hand

# Requirement Status Notes
1 POST and PUT /services and PUT verifications with leading or trailing spaces return 400 ✅ Met The service URL checks no longer strip spaces; registration rejects the URL with InvalidService (a BadRequest), and verification rejects it through service_key(). Tests cover both registration modes and verification.
2 Remove the tolerance from code and docs, and mention the change in the rc2 release notes ✅ Met The strip calls are removed, the API docs describe rejecting whitespace around URLs, and the rc2 release notes mention the change.
3 Coverage stays at 100% 👀 Check by hand (runtime) Run the coverage report on the final branch to confirm it remains at 100%; the description says the reported measurement was taken before later test corrections.

Sourcery assessment

Approved.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

@uniqueg
uniqueg merged commit 9ba72e9 into dev Nov 4, 2026
44 checks passed
@uniqueg
uniqueg deleted the fix/service-url-spaces branch November 4, 2026 14:38
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.

Service URLs with surrounding spaces are stored

1 participant