Uh oh!
There was an error while loading. Please reload this page.
Add Desktop Checks to check_valid - #2262
Conversation
dd6aed0 to
4369a4eCompare
thomcc
left a comment
There was a problem hiding this comment.
Looks good, I'd like to see the error names in particular changed to something that's a little bit more clear for external consumers, though (and the other nits, ideally).
| throw!(InvalidLogin::NoTarget); | ||
| } | ||
| let field_data = [ |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
| }); | ||
| } | ||
| // An origin with "\ \(" won't roundtrip. |
There was a problem hiding this comment.
This is a comment taken from desktop, and it's almost entirely devoid of meaning here (and on desktop too, these days, as it refers to a file format that is no longer in use). Something like "Desktop doesn't like origins with this pattern", or whatever, might be better.
Ditto for the comment above about a single "."
| #[fail(display = "Neither `formSubmitUrl` or `httpRealm` are present")] | ||
| NoTarget, | ||
| #[fail(display = "`{}` contains null", _0)] | ||
| NullValue { field_name: String }, |
There was a problem hiding this comment.
Honestly this and NewLineValue should be combined into InvalidCharacter, or something.
Also, it's probably better to refer to the nul character as NUL (as man ascii, the rust stdlib, and others do), in situations where it can be confused with e.g. JSON null.
There was a problem hiding this comment.
Also the field names are all static strings, so we should be able to use &'static str (or even an enum) for them, not that it particularly matters that much.
| #[fail(display = "`{}` contains newline", _0)] | ||
| NewLineValue { field_name: String }, | ||
| #[fail(display = "`{}` is a period", _0)] | ||
| PeriodValue { field_name: String }, |
There was a problem hiding this comment.
I'd also probably say this and MalformedOriginParens should be combined into 'IllegalFieldValue' or something, as-is I don't think anybody would understand this without reading the source (or possibly documetnation in the future).
There was a problem hiding this comment.
@thomcc I'll use the INVALID_LOGIN_UNSPECIFIED error@rfk created. I wasn't sure how specific these errors needed to be.
There was a problem hiding this comment.
FWIW I like the name IllegalFieldValue better, "unspecified" was entirely me punting on a good name until we had a conversation like this one ^
There was a problem hiding this comment.
I'm starting to wonder whether I should be throwing errors here at all. Maybe it makes more sense for this PR to be based on the fixup code with logic that strips these invalid characters from the respective fields. I guess this is a larger question of how important it is for this code to be similar in behavior to the desktop logic.
There was a problem hiding this comment.
I think we should throw errors here. We should indicate if we're unable to insert directly. If they'd like us to add an API that attempts fixup I'd be open to that though.
There was a problem hiding this comment.
Sounds good. I'll make the requested updates and finalize this PR--thanks!
4369a4e to
c771d6eCompare9c7bad9 to
3e5dc6dCompare
rfk
left a comment
There was a problem hiding this comment.
Looks good to me, with a couple of nits 👍
| ### What's new | ||
| - Added invalid character checks from Desktop to `LoginsStorage.ensureValid`. ([#2262](https://github.com/mozilla/application-services/pull/2262)) |
There was a problem hiding this comment.
I wonder if it's worth calling out the new error type, which calling code might want to catch and log or handle.
| "Invalid login: Login has illegal field: Origin is Malformed", | ||
| InvalidLoginReason.ILLEGAL_FIELD_VALUE) | ||
| } | ||
| } |
There was a problem hiding this comment.
Oh. I'm sad you had to duplicate all of this logic into here, and I wonder if we still need this separate implementation. The only consumer I could find from some quick rging around was the Lockwise android app, where is seems to be used for testing. I wonder if we could replace this with e.g. an in-memory or tempfile-based SQLite DB. @thomcc thoughts?
(That would be for a separate PR in any case)
There was a problem hiding this comment.
Oh. I'm sad you had to duplicate all of this logic into here, and I wonder if we still need this separate implementation. The only consumer I could find from some quick
rging around was the Lockwise android app, where is seems to be used for testing. I wonder if we could replace this with e.g. an in-memory or tempfile-based SQLite DB. @thomcc thoughts?(That would be for a separate PR in any case)
@rfk I hope this is possible. I felt really bad duplicating this logic, particularly because it deviates from the original rust code a tad to appease the android linter.
There was a problem hiding this comment.
@rfk the goal is so that this could be used in cases where calling into Rust wasn't possible. This effectively precludes any implementation other than completely duplicating the Rust code in Kotlin.
That said I'd love to see it go, I've never liked it, and really understand why we were providing it in the first place (especially since the other products just mock things on their own usually, and you can call driectly into the rust now).
I also imagine it's not 100% compatible with the real impl (probably merely in the high-90s). Moreover, it forces us to have to have an interface defining things, which complicates our API compatibility story (every addition is a breaking change), as well as complicating the android-components mirror of this API (slightly). And, as you mention, much of its functionality can be emulated by using an in-memory DB, which can be done by passing ":memory:" as the path to the database (https://www.sqlite.org/inmemorydb.html).
That said, it shouldn't be done as part of this PR.
| hostname = "https://www.test.org", | ||
| httpRealm = "Some Other Realm", | ||
| password = "MyPassword", | ||
| username = "\u0000MyUsername2") |
There was a problem hiding this comment.
nit: this is named newlineLogin but it looks like it's actually testing NUL bytes rather than newlines.
| id: "", | ||
| password: "hunter3", | ||
| hostname: "https://www.example6.com", | ||
| username: "\0cooluser56", |
There was a problem hiding this comment.
ditto here re: newlineLogin naming versus null byte.
3e5dc6d to
46155b0Compare| "Invalid login: Login has illegal field: Origin is Malformed", | ||
| InvalidLoginReason.ILLEGAL_FIELD_VALUE) | ||
| } | ||
| } |
There was a problem hiding this comment.
@rfk the goal is so that this could be used in cases where calling into Rust wasn't possible. This effectively precludes any implementation other than completely duplicating the Rust code in Kotlin.
That said I'd love to see it go, I've never liked it, and really understand why we were providing it in the first place (especially since the other products just mock things on their own usually, and you can call driectly into the rust now).
I also imagine it's not 100% compatible with the real impl (probably merely in the high-90s). Moreover, it forces us to have to have an interface defining things, which complicates our API compatibility story (every addition is a breaking change), as well as complicating the android-components mirror of this API (slightly). And, as you mention, much of its functionality can be emulated by using an in-memory DB, which can be done by passing ":memory:" as the path to the database (https://www.sqlite.org/inmemorydb.html).
That said, it shouldn't be done as part of this PR.
Fixes#1781
Pull Request checklist
cargo test --allproduces no test failurescargo clippy --all --all-targets --all-featuresruns without emitting any warningscargo fmtdoes not produce any changes to the code./gradlew ktlint detektruns without emitting any warningsswiftformat --swiftversion 4 megazords components/*/ios && swiftlintruns without emitting any warnings or producing changes[ci full]to the PR title.