Skip to content

#366: Add pname format and length validation to lock/unlock/name_exists?/recent#376

Merged
yegor256 merged 3 commits into
zerocracy:masterfrom
VasilevNStas:366
Jun 29, 2026
Merged

#366: Add pname format and length validation to lock/unlock/name_exists?/recent#376
yegor256 merged 3 commits into
zerocracy:masterfrom
VasilevNStas:366

Conversation

@VasilevNStas

Copy link
Copy Markdown
Contributor

Problem

BazaRb::Fake#checkname validates pname format (\A[a-z0-9-]+\z) and length (≤32), but four BazaRb methods only checked nil and empty:

  • lock(pname, owner) — pname goes into /lock/<pname>
  • unlock(pname, owner) — pname goes into /unlock/<pname>
  • name_exists?(pname) — pname goes into /exists/<pname>
  • recent(name) — name goes into /recent/<name>.txt

All four risk URL injection and Fake/Real divergence.

Solution

Added format and length guards to each method after the existing nil/empty checks, matching Fake#checkname:

raise(RuntimeError, "The name #{pname.inspect} is not valid") unless pname.match?(/\A[a-z0-9-]+\z/)
raise(RuntimeError, "The name #{pname.inspect} is too long") if pname.length > 32

Tests added (5 new edge tests)

  • test_lock_raises_when_pname_is_invalid
  • test_lock_raises_when_pname_is_too_long
  • test_unlock_raises_when_pname_is_invalid
  • test_name_exists_raises_when_pname_is_invalid
  • test_recent_raises_when_pname_is_invalid

Verification

  • bundle exec rubocop — 0 offenses
  • All 50 edge tests pass (5 new)
  • All 26 unit/Pact/fake tests pass

Closes #366.

@VasilevNStas

Copy link
Copy Markdown
Contributor Author

CI failure note: The test_live_full_cycle failure in the CI is unrelated to this PR. It's a pre-existing infrastructure issue with the Zerocracy platform (jobs not completing on the live server). See issue #354 for details and discussion.

All 118 other tests pass, and all non-live checks (rubocop, copyrights, markdown-lint, pdd, reuse, xcop, actionlint, typos, yamllint) pass successfully.

@GHX5T-SOL GHX5T-SOL left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed current head 706842c2966cb825c093f0064c791a823d197e5e; this looks correct to me.

The change adds the same /\A[a-z0-9-]+\z/ and length <= 32 guards before each touched method appends the name into the URL. The new test/test_baza_edge.rb cases use fake_baza, which is actually a real BazaRb pointed at example.org, so they exercise the production client path.

I also checked the missing overlong variants with a local no-network WebMock probe: invalid and overlong values for lock, unlock, name_exists?, and recent all raised before any HTTP request, while valid valid-name reached the expected stubbed lock, unlock, exists, and recent paths.

Local validation passed: bundle check; syntax checks for lib/baza-rb.rb and test/test_baza_edge.rb; git diff --check upstream/master...HEAD; focused new edge tests; full coverage-disabled test/test_baza_edge.rb, test/test_baza.rb, and test/test_fake.rb; bundle exec rubocop; bundle exec rake picks; and bundle exec rake yard.

Hosted readback: all non-rake checks pass. Ubuntu rake passes the new validation tests and the existing touched client tests, then fails only TestBazaLive#test_live_full_cycle with a Zerocracy live job not finishing; macOS rake was canceled. I did not run full local bundle exec rake because it includes live Zerocracy API tests.

@0crat

0crat commented Jun 10, 2026

Copy link
Copy Markdown

@GHX5T-SOL Thanks for the review! You've earned +10 points for this contribution: +18 as a base reward for authoring the code review, then -8 deducted due to absolutely no comments being posted during the review process. Your running score is +1404; don't forget to check your Zerocracy account too.

@VasilevNStas

Copy link
Copy Markdown
Contributor Author

@yegor256 this PR is blocked by the test_live_full_cycle flaky test (#354). You mentioned in #393 (comment) that you'd fix the platform first.

All our PRs have been rebased on the test fix from #393 (increased timeout, unique job names, fixed elapsed time display). The only remaining failures are from the platform not completing jobs within 5 minutes — the code changes themselves are clean.

A review and platform fix would unblock all of these. Thanks!

@VasilevNStas

Copy link
Copy Markdown
Contributor Author

@yegor256 fixed it, please review

@yegor256
yegor256 merged commit 4773659 into zerocracy:master Jun 29, 2026
10 checks passed
@0crat

0crat commented Jul 10, 2026

Copy link
Copy Markdown

@VasilevNStas Thanks for the contribution! You've earned +24 points. Please, keep them coming. Your running score is +2148; don't forget to check your Zerocracy account too).

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.

BazaRb#lock/#unlock/#name_exists?/#recent lack pname format and length validation

4 participants