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
Conversation
@@ -20,12 +20,27 @@ pub(super) struct OutgoingCreditCardsImpl { | |||
pub(super) encdec: EncryptorDecryptor, | |||
} | |||
|
|||
// impl OutgoingCreditCardsImpl { |
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.
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 { |
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.
This change prevents the panic.
"Failed to retrieve a record from a row with the following error: {}", | ||
e | ||
); | ||
rusqlite::Error::QueryReturnedNoRows |
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.
not sure this is the right error though - can't we use the original error?
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.
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.
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.
It looks like that should work today - https://github.com/mozilla/application-services/blob/main/components/autofill/src/error.rs#L39-L40
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.
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 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,
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! 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) |
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.
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.
2b4103c
to
40c1e83
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
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. |
40c1e83
to
1e8fcc8
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.
Thanks!
1e8fcc8
to
0611eea
Compare
Fixes two issues:
Pull Request checklist
[ci full]
to the PR title.Branch builds: add
[firefox-android: branch-name]
to the PR title.