Skip to content

test(integrations): Add permission, IDOR, and edge case tests for bulk code mappings#109786

Merged
romtsn merged 5 commits intomasterfrom
rz/feat/bulk-code-mappings-edge-cases
Mar 17, 2026
Merged

test(integrations): Add permission, IDOR, and edge case tests for bulk code mappings#109786
romtsn merged 5 commits intomasterfrom
rz/feat/bulk-code-mappings-edge-cases

Conversation

@romtsn
Copy link
Copy Markdown
Member

@romtsn romtsn commented Mar 3, 2026

Summary

  • Add tests for org:ci token authentication (sentry-cli CI use case)
  • Add IDOR prevention tests (cross-org project and repo access)
  • Add permission tests (project access check, org member access)
  • Add edge case tests (duplicate stackRoots in request, multiple repos with same name)

Depends on #109785
Closes getsentry/sentry-android-gradle-plugin#1075

Test plan

  • 7 additional tests (27 total), all passing
  • Pre-commit passes

Copy link
Copy Markdown
Contributor

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

@romtsn romtsn force-pushed the rz/feat/bulk-code-mappings-edge-cases branch from bba4e7d to fb4125f Compare March 3, 2026 23:14
@romtsn romtsn force-pushed the rz/feat/bulk-code-mappings-endpoint branch from 388490d to f859e09 Compare March 3, 2026 23:22
@romtsn romtsn requested review from a team as code owners March 3, 2026 23:22
@romtsn romtsn force-pushed the rz/feat/bulk-code-mappings-edge-cases branch from fb4125f to 7c50a5e Compare March 3, 2026 23:22
@romtsn romtsn force-pushed the rz/feat/bulk-code-mappings-edge-cases branch from 7c50a5e to 7a39daa Compare March 5, 2026 20:38
@romtsn romtsn force-pushed the rz/feat/bulk-code-mappings-edge-cases branch from 7a39daa to 63d0d0c Compare March 5, 2026 20:52
@romtsn romtsn force-pushed the rz/feat/bulk-code-mappings-edge-cases branch from 63d0d0c to 84754bc Compare March 5, 2026 20:59
@romtsn romtsn force-pushed the rz/feat/bulk-code-mappings-edge-cases branch from 84754bc to 7a5a034 Compare March 5, 2026 21:15
@romtsn romtsn force-pushed the rz/feat/bulk-code-mappings-edge-cases branch from 7a5a034 to 1627b8f Compare March 5, 2026 22:39
@romtsn romtsn force-pushed the rz/feat/bulk-code-mappings-endpoint branch from 8a88ceb to e78bac9 Compare March 6, 2026 12:20
@romtsn romtsn requested a review from a team as a code owner March 6, 2026 12:20
@romtsn romtsn force-pushed the rz/feat/bulk-code-mappings-edge-cases branch from 1627b8f to 2802318 Compare March 6, 2026 12:20
@romtsn romtsn force-pushed the rz/feat/bulk-code-mappings-edge-cases branch from 2802318 to 2def8c1 Compare March 6, 2026 14:15
instance = mock_prc.call_args[0][0]
assert instance._skip_post_save is False

def test_skip_post_save_does_not_leak_to_fetched_instances(self) -> None:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you please explain what does this test actually test? I'm not following it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Added a docstring explaining the test: the endpoint sets _skip_post_save on in-memory instances to batch side-effects, and this test verifies that freshly fetched instances from the DB don't carry the suppressed flag.

— Claude Code

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

To ensure the transient skip_post_save flag does not leak. added a docstring in 5401221

@romtsn romtsn force-pushed the rz/feat/bulk-code-mappings-endpoint branch 3 times, most recently from d64c9f8 to a042869 Compare March 17, 2026 12:45
Base automatically changed from rz/feat/bulk-code-mappings-endpoint to master March 17, 2026 14:58
romtsn added 4 commits March 17, 2026 16:57
- Switch Repository.objects.create to self.create_repo() factory
- Assert automatically_generated=False in happy path test
Suppress the per-save post_save signal during the mapping loop to avoid
300 redundant cache clears and celery task dispatches. Side effects
(update_code_owners_schema + clear commit context cache) now fire once
after the entire batch completes.

Adds dispatch_uid to the RepositoryProjectPathConfig post_save signal
connection to enable clean disconnect/reconnect.
…k code mappings

Add tests for org:ci token auth, project access checks, cross-org IDOR
prevention, duplicate stackRoot handling, and multiple repos with the
same name.
The setUp login_as establishes a session that takes precedence over the
Bearer token, so the test was passing via session auth, not the org:ci
token. Adding logout ensures only token auth is exercised.
@romtsn romtsn force-pushed the rz/feat/bulk-code-mappings-edge-cases branch from 990bed3 to 3b10358 Compare March 17, 2026 16:00
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Mar 17, 2026
@romtsn romtsn merged commit 944f2e3 into master Mar 17, 2026
59 checks passed
@romtsn romtsn deleted the rz/feat/bulk-code-mappings-edge-cases branch March 17, 2026 17:13
romtsn added a commit to getsentry/sentry-cli that referenced this pull request Mar 20, 2026
_#skip-changelog_

Add the `sentry-cli code-mappings upload` subcommand group and the
`upload`
subcommand with file parsing and validation.

This is the first in a stack of 4 PRs to support bulk uploading code
mappings
from a JSON file — useful for Java/Android multi-module projects that
need
dozens of mappings.

This PR adds:
- Command scaffold following the `repos`/`deploys` pattern
- JSON file reading and validation (empty arrays, empty
stackRoot/sourceRoot)
- CLI args: positional `PATH`, `--repo`, `--default-branch`
- Help and no-subcommand trycmd integration tests

Stack: **#3207** → #3208#3209#3210

Backend PRs: getsentry/sentry#109783, getsentry/sentry#109785,
getsentry/sentry#109786

Closes getsentry/sentry-android-gradle-plugin#1076
Closes getsentry/sentry-android-gradle-plugin#1077

---------

Co-authored-by: Claude Opus 4.6 <[email protected]>
romtsn added a commit to getsentry/sentry-cli that referenced this pull request Mar 24, 2026
…3208)

*#skip-changelog*

When `--repo` or `--default-branch` are not provided, infer them from
the<br>local git repository. Uses the configured VCS remote
(SENTRY_VCS_REMOTE / ini)<br>first, then falls back to best-effort
remote detection (upstream > origin > first).

Also extracts `find_best_remote()` as a shared utility in
`src/utils/vcs.rs`,<br>replacing the inline logic that was duplicated in
`git_repo_base_repo_name_preserve_case`.

Stack: #3207 →
[#3208](<#3208>) →
[#3209](<#3209>) →
[#3210](<#3210>)

Backend PRs:
[getsentry/sentry#109783](<getsentry/sentry#109783>),
[getsentry/sentry#109785](<getsentry/sentry#109785>),
[getsentry/sentry#109786](<getsentry/sentry#109786>)

Closes
[GRADLE-79](https://linear.app/getsentry/issue/GRADLE-79/add-git-inference-for-repo-name-and-default-branch)

---------

Co-authored-by: Claude Opus 4.6 <[email protected]>
romtsn added a commit to getsentry/sentry-cli that referenced this pull request Mar 24, 2026
…#3209)

_#skip-changelog_

Connect the `code-mappings upload` command to the bulk code mappings API
endpoint (`POST /api/0/organizations/{org}/code-mappings/bulk/`).

Adds:
- `bulk_upload_code_mappings()` method on `AuthenticatedApi`
- Request/response data types in `src/api/data_types/code_mappings.rs`
- Summary table and error reporting in the command output
- Happy-path integration test with mock endpoint

Stack: #3207#3208 → **#3209** → #3210

Backend PRs: getsentry/sentry#109783, getsentry/sentry#109785,
getsentry/sentry#109786

Closes getsentry/sentry-android-gradle-plugin#1079

---------

Co-authored-by: Claude Opus 4.6 <[email protected]>
romtsn added a commit to getsentry/sentry-cli that referenced this pull request Mar 24, 2026
_#skip-changelog_

Split large mapping files into batches of 300 (the backend limit) per
request.
Each batch is sent sequentially with progress reporting, and results are
merged
into a single summary.

Also changes the output table to only show error rows — for large
uploads
(hundreds of mappings), printing every row would flood the terminal.
Successful
mappings are reflected in the summary counts instead.

Stack: #3207#3208#3209 → **#3210**

Backend PRs: getsentry/sentry#109783, getsentry/sentry#109785,
getsentry/sentry#109786

---------

Co-authored-by: Claude Opus 4.6 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add tests for bulk code mappings endpoint

3 participants