-
Notifications
You must be signed in to change notification settings - Fork 28
Correctly merge signature and expire params in UploadParamsGenerator #184
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
base: main
Are you sure you want to change the base?
Conversation
WalkthroughThe changes modify the signature generation and upload parameter handling: Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10–15 minutes
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Warning Review ran into problems🔥 ProblemsErrors were encountered while retrieving linked issues. Errors (1)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Jira integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (3)
lib/uploadcare/param/upload/signature_generator.rb(1 hunks)lib/uploadcare/param/upload/upload_params_generator.rb(1 hunks)spec/uploadcare/param/upload/upload_params_generator_spec.rb(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
spec/uploadcare/param/upload/upload_params_generator_spec.rb (4)
lib/uploadcare/param/upload/signature_generator.rb (2)
call(9-21)call(12-20)lib/uploadcare/param/upload/upload_params_generator.rb (2)
call(9-39)call(12-19)lib/uploadcare/param/authentication_header.rb (2)
call(11-39)call(13-23)lib/uploadcare/param/user_agent.rb (2)
call(8-19)call(13-18)
lib/uploadcare/param/upload/signature_generator.rb (1)
lib/uploadcare/param/secure_auth_header.rb (1)
signature(26-31)
🔇 Additional comments (2)
lib/uploadcare/param/upload/upload_params_generator.rb (1)
15-18: LGTM! Merge pattern correctly fixes the signature nesting bug.The refactored merge pattern properly flattens the signature and expire keys into the params hash instead of nesting them under a 'signature' key. This aligns with the Uploadcare API requirements and maintains consistency with other string-keyed parameters.
lib/uploadcare/param/upload/signature_generator.rb (1)
17-18: LGTM! String keys ensure consistency with the params structure.Changing from symbol keys to string keys aligns with the other parameters in
UploadParamsGenerator(which uses'UPLOADCARE_PUB_KEY','UPLOADCARE_STORE', etc.) and enables proper merging into the params hash.
| it 'generates upload params with signature if sign_uploads is true' do | ||
| Uploadcare.config.sign_uploads = true | ||
| params = subject.call | ||
| expect(params['signature']).not_to be_nil | ||
| expect(params['expire']).not_to be_nil | ||
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Restore config state after test to prevent test pollution.
The test modifies the global Uploadcare.config.sign_uploads setting but doesn't restore it afterward, which could affect other tests running in the same suite.
Apply this diff to ensure the config is restored:
it 'generates upload params with signature if sign_uploads is true' do
+ original_value = Uploadcare.config.sign_uploads
Uploadcare.config.sign_uploads = true
params = subject.call
expect(params['signature']).not_to be_nil
expect(params['expire']).not_to be_nil
+ensure
+ Uploadcare.config.sign_uploads = original_value
end📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| it 'generates upload params with signature if sign_uploads is true' do | |
| Uploadcare.config.sign_uploads = true | |
| params = subject.call | |
| expect(params['signature']).not_to be_nil | |
| expect(params['expire']).not_to be_nil | |
| end | |
| it 'generates upload params with signature if sign_uploads is true' do | |
| begin | |
| original_value = Uploadcare.config.sign_uploads | |
| Uploadcare.config.sign_uploads = true | |
| params = subject.call | |
| expect(params['signature']).not_to be_nil | |
| expect(params['expire']).not_to be_nil | |
| ensure | |
| Uploadcare.config.sign_uploads = original_value | |
| end | |
| end |
🤖 Prompt for AI Agents
In spec/uploadcare/param/upload/upload_params_generator_spec.rb around lines 20
to 25, the test mutates the global Uploadcare.config.sign_uploads without
restoring it; wrap the change so the original value is saved before setting
sign_uploads = true and restored after the example (use an ensure block inside
the example or an RSpec around/after hook) so other tests are not polluted —
save original = Uploadcare.config.sign_uploads, set
Uploadcare.config.sign_uploads = true, run the subject.call expectations, then
ensure Uploadcare.config.sign_uploads = original.
Fix: Correctly merge signature and expire params in UploadParamsGenerator
Problem
When
sign_uploadsis enabled,UploadParamsGeneratorincorrectly assigned the entire signature hash to the'signature'key instead of merging bothsignatureandexpireinto the params hash.Before (buggy code):
This resulted in:
Instead of:
Solution
Changed the code to merge the signature hash returned by
SignatureGenerator.call:After (fixed code):
This ensures both
signatureandexpireare merged into the params hash whensign_uploadsis enabled.Additional Fix
Also updated
SignatureGeneratorto return string keys ('signature'and'expire') instead of symbol keys to match the rest of the params hash.Testing
upload_params_generator_spec.rbto verify bothsignatureandexpireare present whensign_uploadsis enabledChecklist
Summary by CodeRabbit
Bug Fixes
Tests
✏️ Tip: You can customize this high-level summary in your review settings.