diff --git a/client/src/main.rs b/client/src/main.rs index a955f12..a125652 100644 --- a/client/src/main.rs +++ b/client/src/main.rs @@ -9,12 +9,12 @@ fn main() -> std::io::Result<()> { let mut stream = UnixStream::connect(&OPTIONS.socket_name)?; println!("Connected to server"); - let request = Request { - userid: OPTIONS.username.clone(), - password: OPTIONS.password.clone(), - service: "ignore-this".to_string(), - realm: "also-ignore-this".to_string(), - }; + let request = Request::new( + &OPTIONS.username, + &OPTIONS.password, + "ignore-this", + "also-ignore-this", + ); request.write_to_stream(&mut stream)?; let response = read_string(&mut stream)?; diff --git a/server/src/handler.rs b/server/src/handler.rs index 9121022..93b7140 100644 --- a/server/src/handler.rs +++ b/server/src/handler.rs @@ -45,7 +45,7 @@ mod tests { const TEST_PATH: &str = "./test_passwords"; #[test] - fn it_communicates_ok() { + fn it_handles_a_request() { let repository = PasswordDirectory::new(TEST_PATH); let request = Request::new("bp", "some-rad-password", "ignore-this", "also-ignore-this"); diff --git a/server/src/repository.rs b/server/src/repository.rs index 3cc0821..f2b9389 100644 --- a/server/src/repository.rs +++ b/server/src/repository.rs @@ -48,12 +48,8 @@ mod tests { #[test] fn it_checks_good_password() { let repository = PasswordDirectory::new(TEST_PATH); - let request = Request { - userid: "bp".to_string(), - password: "some-rad-password".to_string(), - service: "ignore-this".to_string(), - realm: "also-ignore-this".to_string(), - }; + + let request = Request::new("bp", "some-rad-password", "ignore-this", "also-ignore-this"); assert_eq!(repository.check_auth(&request), true); } @@ -61,12 +57,8 @@ mod tests { #[test] fn it_fails_bad_password() { let repository = PasswordDirectory::new(TEST_PATH); - let request = Request { - userid: "bp".to_string(), - password: "not-correct".to_string(), - service: "ignore-this".to_string(), - realm: "also-ignore-this".to_string(), - }; + + let request = Request::new("bp", "not-correct", "ignore-this", "also-ignore-this"); assert_eq!(repository.check_auth(&request), false); } @@ -74,12 +66,13 @@ mod tests { #[test] fn it_fails_bad_userid() { let repository = PasswordDirectory::new(TEST_PATH); - let request = Request { - userid: "bp-xxx".to_string(), - password: "some-rad-password".to_string(), - service: "ignore-this".to_string(), - realm: "also-ignore-this".to_string(), - }; + + let request = Request::new( + "bp-xxx", + "some-rad-password", + "ignore-this", + "also-ignore-this", + ); assert_eq!(repository.check_auth(&request), false); } @@ -87,12 +80,8 @@ mod tests { #[test] fn it_ignores_comments() { let repository = PasswordDirectory::new(TEST_PATH); - let request = Request { - userid: "bp".to_string(), - password: "commented-out".to_string(), - service: "ignore-this".to_string(), - realm: "also-ignore-this".to_string(), - }; + + let request = Request::new("bp-xxx", "commented-out", "ignore-this", "also-ignore-this"); assert_eq!(repository.check_auth(&request), false); } diff --git a/tests/common_io_test.rs b/tests/common_io_test.rs index 4624496..2ba4899 100644 --- a/tests/common_io_test.rs +++ b/tests/common_io_test.rs @@ -5,10 +5,9 @@ use std::io::Cursor; fn it_reads_strings() { let buffer = [0x0, 0x3, b'F', b'o', b'o']; - assert_eq!( - read_string(&mut buffer.as_ref()).unwrap(), - "Foo".to_string() - ); + let result = read_string(&mut buffer.as_ref()).unwrap(); + + assert_eq!(result, "Foo"); } #[test] @@ -17,8 +16,5 @@ fn it_writes_strings() { write_string(&mut buffer, "Foo").unwrap(); - // Should have written exactly 5 bytes - assert_eq!(buffer.get_ref().len(), 5usize); - - assert_eq!(&buffer.get_ref()[0..5], [0x0, 0x3, b'F', b'o', b'o']); + assert_eq!(buffer.into_inner(), [0x0, 0x3, b'F', b'o', b'o']); }