-
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.
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.
Pull request overview
This PR fixes a bug in UploadParamsGenerator where the signature hash was being incorrectly assigned to a single 'signature' key instead of being merged into the params hash. The fix ensures that when sign_uploads is enabled, both 'signature' and 'expire' keys are properly included in the params hash.
Key changes:
- Modified
UploadParamsGeneratorto merge the signature hash instead of assigning it to a single key - Updated
SignatureGeneratorto return string keys instead of symbol keys for consistency - Added test coverage to verify signature and expire params are present when sign_uploads is enabled
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| lib/uploadcare/param/upload/upload_params_generator.rb | Fixed the merging of signature hash into params by using conditional merge instead of assigning to 'signature' key |
| lib/uploadcare/param/upload/signature_generator.rb | Changed hash keys from symbols to strings ('signature', 'expire') for consistency with other params |
| spec/uploadcare/param/upload/upload_params_generator_spec.rb | Added test to verify signature and expire params are present when sign_uploads is enabled |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| 'signature' => signature, | ||
| 'expire' => expires_at |
Copilot
AI
Jan 6, 2026
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.
The test for SignatureGenerator in spec/uploadcare/param/upload/signature_generator_spec.rb still expects symbol keys (:signature and :expire), but this change returns string keys. The test at line 13 defines expected_result with symbol keys and will fail with this implementation. The expected result in the test should be updated to use string keys to match this change.
| 'signature' => signature, | |
| 'expire' => expires_at | |
| signature: signature, | |
| expire: expires_at |
| expect(params['signature']).not_to be_nil | ||
| expect(params['expire']).not_to be_nil |
Copilot
AI
Jan 6, 2026
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.
The test should verify that 'signature' and 'expire' have the correct types and reasonable values, not just that they are not nil. Consider adding expectations like expect(params['signature']).to be_a(String) and expect(params['expire']).to be_a(Integer) to ensure the values are of the expected types.
| params = subject.call | ||
| expect(params['signature']).not_to be_nil | ||
| expect(params['expire']).not_to be_nil | ||
| end |
Copilot
AI
Jan 6, 2026
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.
Consider adding a test case to verify that 'signature' and 'expire' are NOT present in the params when sign_uploads is false. This would ensure the conditional logic works correctly in both directions and prevent regression if the default behavior changes.
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.