-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Ensure LogEntry only saves safe data #4950
Conversation
Codecov Report
@@ Coverage Diff @@
## master #4950 +/- ##
=======================================
Coverage 86.69% 86.69%
=======================================
Files 578 578
Lines 14674 14681 +7
=======================================
+ Hits 12721 12728 +7
Misses 1953 1953
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
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.
Thanks @elia, that's a nice improvements. I left two suggestions to your judgment 🙂
@@ -206,7 +206,7 @@ def handle_response(response) | |||
end | |||
|
|||
def record_response(response) | |||
log_entries.create!(details: response.to_yaml) | |||
log_entries.create!(parsed_details: response) |
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.
I had to double-check that create!
will accept the parsed_details
attribute even if it's not a table field. Non-blocking, but what do you think if we make the implementation and interface clearer by creating another method like Spree::LogEntry.log
or similar?
|
||
log_entry = described_class.new(parsed_details: value) | ||
|
||
expect(value).to have_received(:to_yaml) |
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.
Also non-blocking, but it's easy to decouple the test from the implementation by using any Ruby object as fixture (as Object#to_yaml
is part of core). Thoughts?
@waiting-for-dev I added a few more commits, because despite the change I ended up with an exception in solidus_stripe while trying to parse a serialized hash that had symbol keys. So now we'll also I adapted all the tests for
I think this is a great idea, although the interface should probably go on the association or on the associated object. I'd say this is beyond the scope of what I meant to fix with this PR 😅 |
273c68b
to
468810b
Compare
This will prevent from saving values that are now allowed in the serialized column.
468810b
to
2804ce2
Compare
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.
Nice, thanks @elia!
Summary
Moving all the serialization/deserialization of Spree::LogEntry details to one place and using a consistent proxy attribute.
This begs for proper ActiveRecord serialization but before doing that we need to think through the migration path for existing stores.
This change is intentionally minimal, enough to allow all writers of log entries to use the same serialization method.
Checklist
Check out our PR guidelines for more details.
The following are mandatory for all PRs:
The following are not always needed: