Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref(mediators): Make validator into a dataclass #79116

Merged
merged 7 commits into from
Oct 16, 2024

Conversation

Christinarlong
Copy link
Contributor

@Christinarlong Christinarlong commented Oct 15, 2024

Turns the token_exchange Validator into dataclass and update refs/usages to reflect that

issue ref (#73857 )

@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Oct 15, 2024
src/sentry/mediators/token_exchange/refresher.py Outdated Show resolved Hide resolved
src/sentry/web/frontend/oauth_token.py Show resolved Hide resolved
install=self.install, client_id=self.client_id, user=self.user
)
def test_validates_generic_token_exchange_requirements(self):
assert self.refresher._validate()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

is this too sus ? Since we're testing/calling a private function ? Lowkey, this is the easiest way to write this test with current design.

Copy link

codecov bot commented Oct 15, 2024

Codecov Report

Attention: Patch coverage is 97.22222% with 1 line in your changes missing coverage. Please review.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/sentry/sentry_apps/token_exchange/validator.py 94.11% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##           master   #79116    +/-   ##
========================================
  Coverage   78.30%   78.30%            
========================================
  Files        7135     7134     -1     
  Lines      314258   314434   +176     
  Branches    51331    51350    +19     
========================================
+ Hits       246064   246220   +156     
- Misses      61758    61772    +14     
- Partials     6436     6442     +6     

Comment on lines 40 to 41
self.record_analytics()
return token
Copy link
Member

Choose a reason for hiding this comment

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

These lines could be outside the transaction block 🤷

from sentry.models.apiapplication import ApiApplication
from sentry.sentry_apps.models.sentry_app import SentryApp
from sentry.sentry_apps.services.app import RpcSentryAppInstallation
from sentry.users.models.user import User


class Validator(Mediator):
@dataclass
class Validator:
Copy link
Member

Choose a reason for hiding this comment

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

Interesting that this is just validation logic 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, I did some more reading and this class is p. simple so it doesn't really matter which way we go about it.

install=self.install, client_id=self.client_id, user=self.user
)
def test_validate_generic_token_exchange_requirements(self):
assert self.grant_exchanger._validate()
Copy link
Member

Choose a reason for hiding this comment

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

Having tests call 'protected methods' can make tests brittle as code changes over time. The mock solution also had this weakness though. It looks like we have integration tests for the validation flow below though, and we could just delete these tests without losing any coverage.

@Christinarlong Christinarlong marked this pull request as ready for review October 16, 2024 20:07
@Christinarlong Christinarlong requested review from a team as code owners October 16, 2024 20:07
@Christinarlong Christinarlong merged commit e2df3f1 into master Oct 16, 2024
51 checks passed
@Christinarlong Christinarlong deleted the christinarlong/ref-mediators-validator branch October 16, 2024 20:08
@Christinarlong Christinarlong added the Trigger: Revert add to a merged PR to revert it (skips CI) label Oct 16, 2024
@getsentry-bot
Copy link
Contributor

PR reverted: 30dd412

getsentry-bot added a commit that referenced this pull request Oct 16, 2024
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 Trigger: Revert add to a merged PR to revert it (skips CI)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants