Skip to content

feat(browser-reports): Validate both browser report formats #93917

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

Merged
merged 2 commits into from
Jun 20, 2025

Conversation

armenzg
Copy link
Member

@armenzg armenzg commented Jun 19, 2025

This validates both the Working Draft and the Editor's Draft formats.

Fixes ID-730 - Accept current and upcoming data model.

@armenzg armenzg self-assigned this Jun 19, 2025
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Jun 19, 2025
Copy link

codecov bot commented Jun 19, 2025

Codecov Report

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

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...ry/issues/endpoints/browser_reporting_collector.py 97.05% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #93917      +/-   ##
==========================================
- Coverage   88.04%   86.86%   -1.18%     
==========================================
  Files       10340    10340              
  Lines      597231   597334     +103     
  Branches    23208    23208              
==========================================
- Hits       525805   518887    -6918     
- Misses      70921    77942    +7021     
  Partials      505      505              

]


@dataclass
class BrowserReport:
Copy link
Member Author

Choose a reason for hiding this comment

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

This would only do static typing but not runtime verification.

"coop", # Cross-Origin-Opener-Policy violations
"document-policy-violation", # Document Policy violations
"permissions-policy", # Permissions Policy violations
BROWSER_REPORT_TYPES = [
Copy link
Member Author

Choose a reason for hiding this comment

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

As far as I know. There may be more.

age = serializers.IntegerField(required=False)
timestamp = serializers.IntegerField(required=False, min_value=0)

def validate_timestamp(self, value: int) -> int:
Copy link
Member Author

Choose a reason for hiding this comment

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

These two methods validate that we're dealing with the format for one spec or the other.

owner = ApiOwner.ISSUES

# CSRF exemption and CORS support required for Browser Reporting API
@csrf_exempt
@allow_cors_options
def post(self, request: Request, *args: Any, **kwargs: Any) -> HttpResponse:
def post(self, request: Request, *args: Any, **kwargs: Any) -> Response:
Copy link
Member Author

Choose a reason for hiding this comment

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

It's preferred to use Response over Django's HttpResponse.

@armenzg armenzg marked this pull request as ready for review June 19, 2025 19:36
@armenzg armenzg requested review from a team as code owners June 19, 2025 19:36
@armenzg armenzg merged commit e6c0196 into master Jun 20, 2025
65 checks passed
@armenzg armenzg deleted the fix/support-both/browser_reporting/armenzg branch June 20, 2025 16:50
@github-actions github-actions bot locked and limited conversation to collaborators Jul 6, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Scope: Backend Automatically applied to PRs that change backend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants