Skip to content

[AvatarController] Restrict UploadAvatar to current user #3839

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 5 commits into from
Jun 5, 2025

Conversation

imnasnainaec
Copy link
Collaborator

@imnasnainaec imnasnainaec commented Jun 3, 2025

Also expand controller testing.


This change is Reviewable

@imnasnainaec imnasnainaec self-assigned this Jun 3, 2025
@imnasnainaec imnasnainaec added backend test maintenance Issue that makes it difficult to maintain the software or to upgrade installations post-release. labels Jun 3, 2025
Copy link

codecov bot commented Jun 3, 2025

Codecov Report

Attention: Patch coverage is 71.42857% with 2 lines in your changes missing coverage. Please review.

Project coverage is 73.19%. Comparing base (919afe0) to head (4ca1440).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
Backend/Controllers/AvatarController.cs 83.33% 1 Missing ⚠️
src/components/UserSettings/ClickableAvatar.tsx 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3839      +/-   ##
==========================================
+ Coverage   73.02%   73.19%   +0.16%     
==========================================
  Files         286      286              
  Lines       10758    10758              
  Branches     1340     1340              
==========================================
+ Hits         7856     7874      +18     
+ Misses       2502     2487      -15     
+ Partials      400      397       -3     
Flag Coverage Δ
backend 82.53% <83.33%> (+0.38%) ⬆️
frontend 65.87% <0.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link

@myieye myieye left a comment

Choose a reason for hiding this comment

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

Looks good to me 🙂

{
if (!_permissionService.IsUserIdAuthorized(HttpContext, userId))
if (!_permissionService.IsCurrentUserAuthorized(HttpContext))
Copy link

Choose a reason for hiding this comment

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

It's intriguing to me that this isn't already handled via the [Authorize] attribute on the controller.
But that's outside the scope of this PR.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It may be superfluous. I'll look into that, thank you.

[HttpGet("download", Name = "DownloadAvatar")]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(FileContentResult))]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public async Task<IActionResult> DownloadAvatar(string userId)
{
// SECURITY: Omitting authentication so the frontend can use the API endpoint directly as a URL.
Copy link

Choose a reason for hiding this comment

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

This comment feels somewhat superfluous with the method now explicitly being marked with [AllowAnonymous]

public void TestUploadAudioFileEmptyFile()
{
using var stream = File.OpenRead(_filePath);
// Use 0 for the third argument
Copy link

Choose a reason for hiding this comment

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

This looks forgotten or incomplete

Copy link

github-actions bot commented Jun 5, 2025

⚠️ Commit Message Format Issues ⚠️
commit c4fef0c213:
1: T3 Title has trailing punctuation (.): "Update comments."

@imnasnainaec imnasnainaec merged commit d3fd57d into master Jun 5, 2025
18 of 21 checks passed
@imnasnainaec imnasnainaec deleted the avatar-controller branch June 5, 2025 13:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend maintenance Issue that makes it difficult to maintain the software or to upgrade installations post-release. test
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants