Skip to content

Conversation

martincostello
Copy link
Collaborator

Fix incorrect ETag for compressed files by resetting the compressed stream to the beginning before computing the SHA256 hash.

See #3486 (comment).

Fix incorrect ETag for compressed files by resetting the compressed stream to the beginning before computing the SHA256 hash.

See #3486.
@martincostello martincostello added this to the v9.0.4 milestone Jul 8, 2025
@Copilot Copilot AI review requested due to automatic review settings July 8, 2025 15:46
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR ensures the compressed stream is reset before computing the hash so that ETag values for compressed files are correct.

  • Reset the compressed stream position in EmbeddedResourceProvider before hashing.
  • Introduce a shared constant for the empty-string hash in tests and replace hard-coded literals.
  • Add assertions to verify the empty-string hash does not appear in the ETag tag.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
test/Swashbuckle.AspNetCore.IntegrationTests/SwaggerUIIntegrationTests.cs Added EmptyStringSha256Hash constant, replaced literals, and added Assert.DoesNotContain checks on ETag.
test/Swashbuckle.AspNetCore.IntegrationTests/ReDocIntegrationTests.cs Mirrored the same constant and assertions changes for ReDoc tests.
src/Shared/EmbeddedResourceProvider.cs Inserted compressed.Seek(0, SeekOrigin.Begin) before hashing.
Comments suppressed due to low confidence (2)

test/Swashbuckle.AspNetCore.IntegrationTests/SwaggerUIIntegrationTests.cs:10

  • The constant name suggests SHA256 but the code uses SHA1; consider renaming it to EmptyStringSha1Hash for accuracy.
    private const string EmptyStringSha256Hash = "2jmj7l5rSw0yVb/vlWAYkK/YBwk=";

test/Swashbuckle.AspNetCore.IntegrationTests/ReDocIntegrationTests.cs:13

  • The constant name suggests SHA256 but the code uses SHA1; consider renaming it to EmptyStringSha1Hash for accuracy.
    private const string EmptyStringSha256Hash = "2jmj7l5rSw0yVb/vlWAYkK/YBwk=";

@martincostello martincostello enabled auto-merge (rebase) July 8, 2025 15:49
Copy link

codecov bot commented Jul 8, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.91%. Comparing base (4903084) to head (e52cc59).
Report is 1 commits behind head on master.

✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #3490   +/-   ##
=======================================
  Coverage   93.91%   93.91%           
=======================================
  Files         110      110           
  Lines        3810     3811    +1     
  Branches      723      723           
=======================================
+ Hits         3578     3579    +1     
  Misses        232      232           
Flag Coverage Δ
Linux 93.91% <100.00%> (+<0.01%) ⬆️
Windows 93.91% <100.00%> (+<0.01%) ⬆️
macOS 93.91% <100.00%> (+<0.01%) ⬆️

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:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@martincostello martincostello merged commit 525a8a3 into master Jul 8, 2025
12 checks passed
@martincostello martincostello deleted the fix-etag branch July 8, 2025 15:51
This was referenced Aug 27, 2025
This was referenced Sep 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant