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

Prevent outgoing scrubbed credit card records #6143

Merged
merged 1 commit into from Feb 28, 2024

Conversation

lougeniaC64
Copy link
Contributor

@lougeniaC64 lougeniaC64 commented Feb 23, 2024

Fixes two issues:

  • Prevents the panic that was occurring in the common.rs/get_outgoing_records
  • Updates the outgoing credit card logic to exclude outgoing scrubbed credit card records

Pull Request checklist

  • Breaking changes: This PR follows our breaking change policy
    • This PR follows the breaking change policy:
      • This PR has no breaking API changes, or
      • There are corresponding PRs for our consumer applications that resolve the breaking changes and have been approved
  • Quality: This PR builds and tests run cleanly
    • Note:
      • For changes that need extra cross-platform testing, consider adding [ci full] to the PR title.
      • If this pull request includes a breaking change, consider cutting a new release after merging.
  • Tests: This PR includes thorough tests or an explanation of why it does not
  • Changelog: This PR includes a changelog entry in CHANGELOG.md or an explanation of why it does not need one
    • Any breaking changes to Swift or Kotlin binding APIs are noted explicitly
  • Dependencies: This PR follows our dependency management guidelines
    • Any new dependencies are accompanied by a summary of the due dilligence applied in selecting them.

Branch builds: add [firefox-android: branch-name] to the PR title.

@@ -20,12 +20,27 @@ pub(super) struct OutgoingCreditCardsImpl {
pub(super) encdec: EncryptorDecryptor,
}

// impl OutgoingCreditCardsImpl {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was my original change. As expected it still failed because the issue is that the local record doesn't have an associated mirror record.

@@ -201,7 +201,13 @@ fn get_outgoing_records(
Ok(conn
.prepare(sql)?
.query_map([], |row| {
Ok(record_from_data_row(row).unwrap()) // XXX - this unwrap()!
record_from_data_row(row).map_err(|e| -> rusqlite::Error {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This change prevents the panic.

"Failed to retrieve a record from a row with the following error: {}",
e
);
rusqlite::Error::QueryReturnedNoRows
Copy link
Member

Choose a reason for hiding this comment

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

not sure this is the right error though - can't we use the original error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's not. I think I need to implement rusqlite::Error: From<error::Error> to call e.into() here. One of the reasons I slapped a WIP on this.

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It doesn't for me.

Screenshot 2024-02-27 at 1 27 15 PM

Copy link
Member

Choose a reason for hiding this comment

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

The problem here is that query_map() want to return a rusqlite error, not one of ours. So the message is telling you we don't have the reverse - ie, we can't work out how to go from our error to a rusqlite error, which is expected.

Rust is complicated. It took me a long time to work this out, but I think you want something like:

fn get_outgoing_records(
    conn: &Connection,
    sql: &str,
    record_from_data_row: &dyn Fn(&Row<'_>) -> Result<(OutgoingBso, i64)>,
) -> anyhow::Result<Vec<(OutgoingBso, i64)>> {
    conn.prepare(sql)?
        .query_map([], |row| Ok(record_from_data_row(row)))?
        // So now we have Ok(Result<T, E: rusqlite::Error>) - unwrap the OK, then map the rusqlite error to ours.
        .map(|r| {
            r.unwrap().map_err(|e| {
                log::error!(
                    "Failed to retrieve a record from a row with the following error: {}",
                    e
                );
                e.into()
            })
        })
        .collect::<std::result::Result<Vec<_>, _>>()
}

although I suspect there's a better way,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! My rust is definitely rusty atm and I'm not sure if a better solution would have come to me when it wasn't. Either way I'll refactor this a bit and see if I can come up with a better solution.

@@ -78,6 +78,12 @@ pub fn add_credit_card(
Ok(s.get_credit_card(id).expect("Credit card has been added"))
}

pub fn scrub_credit_card(s: Arc<AutofillStore>) -> AutofillResult<()> {
AutofillStore::scrub_encrypted_data(s)
Copy link
Member

Choose a reason for hiding this comment

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

another possibility would be for scrub_encrypted_data to set the sync_change_counter to zero, and a mini-migration to set all cards with empty numbers to have a change counter of zero too. What you have above seems fine though.

@codecov-commenter
Copy link

codecov-commenter commented Feb 28, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.08%. Comparing base (592063c) to head (0611eea).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6143   +/-   ##
=======================================
  Coverage   84.08%   84.08%           
=======================================
  Files         117      117           
  Lines       15629    15629           
=======================================
  Hits        13141    13141           
  Misses       2488     2488           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@lougeniaC64 lougeniaC64 changed the title [WIP] Update autofill engine Prevent outgoing scrubbed credit card records Feb 28, 2024
@lougeniaC64 lougeniaC64 marked this pull request as ready for review February 28, 2024 20:42
Copy link
Member

@mhammond mhammond left a comment

Choose a reason for hiding this comment

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

Thanks!

@lougeniaC64 lougeniaC64 added this pull request to the merge queue Feb 28, 2024
Merged via the queue into main with commit c1bd7db Feb 28, 2024
16 checks passed
@lougeniaC64 lougeniaC64 deleted the update-autofill-engine branch February 28, 2024 23:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants