Skip to content

fix(bitbucket): treat empty whoami identity as fatal at Connect - #53

Merged
lao merged 1 commit into
mainfrom
fix/bitbucket-empty-self-guard
Aug 6, 2026
Merged

fix(bitbucket): treat empty whoami identity as fatal at Connect#53
lao merged 1 commit into
mainfrom
fix/bitbucket-empty-self-guard

Conversation

@lao

@lao lao commented Aug 6, 2026

Copy link
Copy Markdown
Owner

Addresses the finding in #52.

Problem

On Cloud API-token mode, the bot's self-identity is resolved via GET /2.0/user at Connect. The code treated only a non-nil error as fatal — a successful whoami returning an empty uuid was stored verbatim, leaving a.self == "".

isSelf is self != "" && id == self, so an empty self never matches: the bot's own comments are never dropped, opening a reply loop. The GitLab sibling makes an unresolved self fatal by design; this path let an empty-but-error-free result slip through.

Fix

Treat an empty resolved identity the same as a resolve failure (deps.Done + close the listener) so a bot that cannot recognize itself never starts serving. Data Center is unaffected — it requires Config.Self at New, so the resolve block never runs.

internal/bitbucket/server.go — 3-line guard. New test TestConnectWhoamiEmptyIdentityFatal covers the empty-identity path.

Verification

make all clean (fmt + vet + lint + test-race, incl. _examples).

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Bitbucket connections now fail fast when no self-identity is provided during startup.
    • Prevents connections from starting in an invalid configuration state.

On Cloud API-token mode, self-identity is resolved via GET /2.0/user. A
successful response carrying an empty uuid was stored verbatim, leaving
a.self == "". isSelf then never matches, silently disabling the reply-loop
guard so the bot's own comments are dispatched. Treat an empty resolved
identity like a resolve failure (deps.Done + close listener), matching the
GitLab sibling's fatal-on-unresolved-self posture.
@botbooter-test

botbooter-test Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

✅ No issues found. 32d38e29

  • Fetch changed files
  • Build repository context
  • Generate review
  • Post findings

@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Bitbucket connection startup now treats an empty successful self-identity lookup as a fatal configuration error. A test verifies that Done reports ErrMissingConfig.

Changes

Bitbucket identity validation

Layer / File(s) Summary
Reject empty self-identity
internal/bitbucket/server.go, internal/bitbucket/server_test.go
Startup wraps an empty self-identity result with ErrMissingConfig. The test verifies that Done reports the error within the timeout.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the Bitbucket fix for treating an empty whoami identity as fatal during Connect.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/bitbucket-empty-self-guard

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@botbooter-test botbooter-test Bot 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.

Verdict: approve · Grade: 9/10

📝 Summary of changes

This is a small, well-targeted fix in internal/bitbucket/server.go. On Cloud API-token mode the bot's self-identity is resolved via GET /2.0/user; previously only a non-nil error was treated as fatal, so a successful whoami returning a blank uuid would leave a.self == "", silently disabling the isSelf reply-loop guard. The change treats an empty-but-error-free identity as a fatal resolve failure (surfaced via deps.Done, listener closed), mirroring the GitLab sibling's non-zero selfID requirement. A focused test TestConnectWhoamiEmptyIdentityFatal exercises the new path and asserts the error surfaces via Done as ErrMissingConfig.

The logic is correct: only the Cloud path (cfg.Self == "") reaches the guard, Data Center requires Config.Self at New, and fmt/ErrMissingConfig are already used in this package. The reasoning in the PR description matches the code, and there is no attempt to steer the review. Clean change.

✅ No issues found.


Reviewed by prbooter. Comment /recheck to re-run, /security-review for a security audit, /auto-fix to have me attempt the fixes, or /clean to remove my comments.

@coderabbitai coderabbitai 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.

🧹 Nitpick comments (1)
internal/bitbucket/server_test.go (1)

397-404: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Cover listener shutdown and clean up the asynchronous connection.

The test verifies Done and ErrMissingConfig, but it does not verify that the listener is closed and no webhook is served after the fatal result. Use a cancelable context, clean it up after the test, and assert that the bound address does not accept a request after Done. This also prevents the Connect context watcher from remaining blocked on context.Background().

This covers the listener-closure requirement in the PR objective.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/bitbucket/server_test.go` around lines 397 - 404, Update the
asynchronous connection test around Connect to use a cancelable context, defer
its cleanup, and pass it instead of context.Background() so the context watcher
cannot remain blocked. After receiving ErrMissingConfig from done, verify the
listener’s bound address no longer accepts webhook requests, while preserving
the timeout assertion for Done.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@internal/bitbucket/server_test.go`:
- Around line 397-404: Update the asynchronous connection test around Connect to
use a cancelable context, defer its cleanup, and pass it instead of
context.Background() so the context watcher cannot remain blocked. After
receiving ErrMissingConfig from done, verify the listener’s bound address no
longer accepts webhook requests, while preserving the timeout assertion for
Done.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 42d72000-8e8e-498d-8f16-892d2847ad1c

📥 Commits

Reviewing files that changed from the base of the PR and between ed36a4a and 32d38e2.

📒 Files selected for processing (2)
  • internal/bitbucket/server.go
  • internal/bitbucket/server_test.go

@lao
lao merged commit 160ffa2 into main Aug 6, 2026
0 of 2 checks passed
@lao
lao deleted the fix/bitbucket-empty-self-guard branch August 6, 2026 18:15
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.

1 participant