Skip to content

Commit

Permalink
Removing check_valid_with_no_dupes()
Browse files Browse the repository at this point in the history
It's a deprecated function and not used in either the iOS or Android
wrappers.  I think we can just ditch it.
  • Loading branch information
bendk committed Oct 22, 2021
1 parent 73b922e commit da937fb
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 135 deletions.
118 changes: 0 additions & 118 deletions components/logins/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -596,16 +596,6 @@ impl LoginDb {
}
}

pub fn check_valid_with_no_dupes(
&self,
guid: &Guid,
entry: &LoginEntry,
encdec: &EncryptorDecryptor,
) -> Result<()> {
entry.check_valid()?;
self.check_for_dupes(guid, entry, encdec)
}

pub fn fixup_and_check_for_dupes(
&self,
guid: &Guid,
Expand Down Expand Up @@ -1037,114 +1027,6 @@ mod tests {
use crate::sync::LocalLogin;
use crate::SecureLoginFields;

#[test]
fn test_check_valid_with_no_dupes() {
let db = LoginDb::open_in_memory().unwrap();
let added = db
.add(
LoginEntry {
fields: LoginFields {
form_action_origin: Some("https://www.example.com".into()),
origin: "https://www.example.com".into(),
http_realm: None,
..Default::default()
},
sec_fields: SecureLoginFields {
username: "test".into(),
password: "test".into(),
},
},
&TEST_ENCRYPTOR,
)
.unwrap();

let unique_login = LoginEntry {
fields: LoginFields {
form_action_origin: None,
origin: "https://www.example.com".into(),
http_realm: Some("https://www.example.com".into()),
..Default::default()
},
sec_fields: SecureLoginFields {
username: "test".into(),
password: "test".into(),
},
};

let duplicate_login = LoginEntry {
fields: LoginFields {
form_action_origin: Some("https://www.example.com".into()),
origin: "https://www.example.com".into(),
http_realm: None,
..Default::default()
},
sec_fields: SecureLoginFields {
username: "test".into(),
password: "test2".into(),
},
};

let updated_login = LoginEntry {
fields: LoginFields {
form_action_origin: None,
origin: "https://www.example.com".into(),
http_realm: Some("https://www.example.com".into()),
..Default::default()
},
sec_fields: SecureLoginFields {
username: "test".into(),
password: "test4".into(),
},
};

struct TestCase {
guid: Guid,
entry: LoginEntry,
should_err: bool,
expected_err: &'static str,
}

let test_cases = [
TestCase {
guid: "unique_value".into(),
// unique_login should not error because it does not share the same origin,
// username, and formActionOrigin or httpRealm with the pre-existing login
// (login with guid `added.id`).
entry: unique_login,
should_err: false,
expected_err: "",
},
TestCase {
guid: "unique_value".into(),
// duplicate_login has the same origin, username, and formActionOrigin as a pre-existing
// login (guid `added.id`) and duplicate_login has no guid value, i.e. its guid
// doesn't match with that of a pre-existing record so it can't be considered update,
// so it should error.
entry: duplicate_login,
should_err: true,
expected_err: "Invalid login: Login already exists",
},
TestCase {
// updated_login is an update to the existing record (has the same guid) so it is not a dupe
// and should not error.
guid: added.record.id.into(),
entry: updated_login,
should_err: false,
expected_err: "",
},
];

for tc in &test_cases {
let login_check = db.check_valid_with_no_dupes(&tc.guid, &tc.entry, &TEST_ENCRYPTOR);
if tc.should_err {
assert!(&login_check.is_err());
assert_eq!(&login_check.unwrap_err().to_string(), tc.expected_err)
} else {
assert!(&login_check.is_ok())
}
}
}

#[test]
fn test_username_dupe_semantics() {
let mut login = LoginEntry {
Expand Down
4 changes: 0 additions & 4 deletions components/logins/src/logins.udl
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,6 @@ interface LoginStore {
[Throws=LoginsStorageError]
constructor(string path);

// XXX - Can we kill this, and just fix the semantics of add/update?
[Throws=LoginsStorageError]
void check_valid_with_no_dupes([ByRef] string id, [ByRef] LoginEntry login, [ByRef] string encryption_key);

[Throws=LoginsStorageError]
EncryptedLogin add(LoginEntry login, [ByRef]string encryption_key);

Expand Down
13 changes: 0 additions & 13 deletions components/logins/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,19 +131,6 @@ impl LoginStore {
Ok(serde_json::to_string(&metrics)?)
}

pub fn check_valid_with_no_dupes(
&self,
id: &str,
entry: &LoginEntry,
enc_key: &str,
) -> Result<()> {
let encdec = crate::encryption::EncryptorDecryptor::new(enc_key)?;
self.db
.lock()
.unwrap()
.check_valid_with_no_dupes(&Guid::new(id), entry, &encdec)
}

/// A convenience wrapper around sync_multiple.
// Unfortunately, iOS still uses this until they use the sync manager
// This can almost die later - consumers should never call it (they should
Expand Down

0 comments on commit da937fb

Please sign in to comment.