Skip to content
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

Merged
merged 3 commits into from
Feb 22, 2023

Conversation

elia
Copy link
Member

@elia elia commented Feb 20, 2023

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:

  • 📖 I have updated the README to account for my changes.
  • 📑 I have documented new code with YARD.
  • 🛣️ I have opened a PR to update the guides.
  • ✅ I have added automated tests to cover my changes.
  • 📸 I have attached screenshots to demo visual changes.

@elia elia self-assigned this Feb 20, 2023
@github-actions github-actions bot added the changelog:solidus_core Changes to the solidus_core gem label Feb 20, 2023
@codecov
Copy link

codecov bot commented Feb 20, 2023

Codecov Report

Merging #4950 (2804ce2) into master (0d89c89) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master    #4950   +/-   ##
=======================================
  Coverage   86.69%   86.69%           
=======================================
  Files         578      578           
  Lines       14674    14681    +7     
=======================================
+ Hits        12721    12728    +7     
  Misses       1953     1953           
Impacted Files Coverage Δ
core/app/models/spree/log_entry.rb 100.00% <100.00%> (ø)
core/app/models/spree/payment/processing.rb 98.03% <100.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@elia elia marked this pull request as ready for review February 20, 2023 14:15
@elia elia requested a review from a team as a code owner February 20, 2023 14:15
Copy link
Contributor

@waiting-for-dev waiting-for-dev left a 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)
Copy link
Contributor

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)
Copy link
Contributor

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?

@elia
Copy link
Member Author

elia commented Feb 20, 2023

@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 safe_dump when using parsed_details=. We don't have backward compatibility concerns as parsed_details= is a new method.

I adapted all the tests for #parsed_details and shared the error handling between the two methods.

creating another method like Spree::LogEntry.log or similar?

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 😅

@elia elia requested a review from waiting-for-dev February 20, 2023 15:16
@elia elia force-pushed the elia/payment-log-entries-yaml-cleanup branch from 273c68b to 468810b Compare February 20, 2023 15:46
@elia elia marked this pull request as draft February 20, 2023 16:07
This will prevent from saving values that are now allowed in the
serialized column.
@elia elia force-pushed the elia/payment-log-entries-yaml-cleanup branch from 468810b to 2804ce2 Compare February 20, 2023 16:11
@github-actions github-actions bot added the changelog:solidus_api Changes to the solidus_api gem label Feb 20, 2023
@elia elia marked this pull request as ready for review February 20, 2023 16:41
Copy link
Member

@kennyadsl kennyadsl left a comment

Choose a reason for hiding this comment

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

Nice, thanks @elia!

@kennyadsl kennyadsl added the type:enhancement Proposed or newly added feature label Feb 22, 2023
@kennyadsl kennyadsl merged commit 0c52edf into master Feb 22, 2023
@kennyadsl kennyadsl deleted the elia/payment-log-entries-yaml-cleanup branch February 22, 2023 08:20
@kennyadsl kennyadsl changed the title Keep all the LogEntry serialization logic in one place Ensure LogEntry only saves safe data Feb 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog:solidus_api Changes to the solidus_api gem changelog:solidus_core Changes to the solidus_core gem type:enhancement Proposed or newly added feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants