Skip to content

Commit

Permalink
update to secret-service 1.0, move tests to lib.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
hwchen committed Apr 20, 2019
1 parent 35f9773 commit 6897583
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 54 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ version = "0.6.1"
security-framework = "0.3.0"

[target.'cfg(target_os = "linux")'.dependencies]
secret-service = "0.4.0"
secret-service = "1.0.0"

[target.'cfg(target_os = "windows")'.dependencies]
byteorder = "1.2.1"
Expand Down
49 changes: 49 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ pub use error::{KeyringError, Result};
mod tests {
use super::*;

static TEST_SERVICE: &'static str = "test.keychain-rs.io";
static TEST_USER: &'static str = "user@keychain-rs.io";
static TEST_ASCII_PASSWORD: &'static str = "my_password";
static TEST_NON_ASCII_PASSWORD: &'static str = "大根";

#[test]
fn test_empty_password_input() {
let pass = "";
Expand All @@ -46,4 +51,48 @@ mod tests {
keyring.delete_password().unwrap();
assert_eq!(pass, out);
}

#[test]
fn test_add_ascii_password() {
let keyring = Keyring::new(TEST_SERVICE, TEST_USER);

keyring.set_password(TEST_ASCII_PASSWORD).unwrap();

keyring.delete_password().unwrap();
}

#[test]
fn test_round_trip_ascii_password() {
let keyring = Keyring::new(TEST_SERVICE, TEST_USER);

keyring.set_password(TEST_ASCII_PASSWORD).unwrap();

let stored_password = keyring.get_password().unwrap();

assert_eq!(stored_password, TEST_ASCII_PASSWORD);

keyring.delete_password().unwrap();
}

#[test]
fn test_add_non_ascii_password() {
let keyring = Keyring::new(TEST_SERVICE, TEST_USER);

keyring.set_password(TEST_NON_ASCII_PASSWORD).unwrap();

keyring.delete_password().unwrap();
}

#[test]
fn test_round_trip_non_ascii_password() {
let keyring = Keyring::new(TEST_SERVICE, TEST_USER);

keyring.set_password(TEST_NON_ASCII_PASSWORD).unwrap();

let stored_password = keyring.get_password().unwrap();

assert_eq!(stored_password, TEST_NON_ASCII_PASSWORD);

keyring.delete_password().unwrap();
}
}
53 changes: 0 additions & 53 deletions src/macos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,56 +44,3 @@ impl<'a> Keyring<'a> {
}
}

#[cfg(test)]
mod test {
use super::*;

static TEST_SERVICE: &'static str = "test.keychain-rs.io";
static TEST_USER: &'static str = "user@keychain-rs.io";
static TEST_ASCII_PASSWORD: &'static str = "my_password";
static TEST_NON_ASCII_PASSWORD: &'static str = "大根";

#[test]
fn test_add_ascii_password() {
let keyring = Keyring::new(TEST_SERVICE, TEST_USER);

keyring.set_password(TEST_ASCII_PASSWORD).unwrap();

keyring.delete_password().unwrap();
}

#[test]
fn test_round_trip_ascii_password() {
let keyring = Keyring::new(TEST_SERVICE, TEST_USER);

keyring.set_password(TEST_ASCII_PASSWORD).unwrap();

let stored_password = keyring.get_password().unwrap();

assert_eq!(stored_password, TEST_ASCII_PASSWORD);

keyring.delete_password().unwrap();
}

#[test]
fn test_add_non_ascii_password() {
let keyring = Keyring::new(TEST_SERVICE, TEST_USER);

keyring.set_password(TEST_NON_ASCII_PASSWORD).unwrap();

keyring.delete_password().unwrap();
}

#[test]
fn test_round_trip_non_ascii_password() {
let keyring = Keyring::new(TEST_SERVICE, TEST_USER);

keyring.set_password(TEST_NON_ASCII_PASSWORD).unwrap();

let stored_password = keyring.get_password().unwrap();

assert_eq!(stored_password, TEST_NON_ASCII_PASSWORD);

keyring.delete_password().unwrap();
}
}

0 comments on commit 6897583

Please sign in to comment.