From 85b29df4208b83c1949032db56c8d76e8c76b705 Mon Sep 17 00:00:00 2001 From: alpaylan Date: Wed, 14 Apr 2021 16:36:42 +0300 Subject: embed user passwds to the code structs. --- tests/route_tests.rs | 4 +++- tests/schema_tests.rs | 28 ++++++++++++++++++---------- 2 files changed, 21 insertions(+), 11 deletions(-) (limited to 'tests') diff --git a/tests/route_tests.rs b/tests/route_tests.rs index 7c0651f..5c2d891 100644 --- a/tests/route_tests.rs +++ b/tests/route_tests.rs @@ -12,7 +12,7 @@ mod tests { db.users.write().insert( "mock_transaction_source".to_owned(), User { - user_id: MetuId::new("e254275".to_owned()).unwrap(), + user_id: MetuId::new("e254275".to_owned(), "DtNX1qk4YF4saRH".to_owned()).unwrap(), public_key: "-----BEGIN PUBLIC KEY----- MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA4nU0G4WjkmcQUx0hq6LQ uV5Q+ACmUFL/OjoYMDwC/O/6pCd1UZgCfgHN2xEffDPznzcTn8OiFRxr4oWyBiny @@ -56,6 +56,7 @@ sQIDAQAB fn priviliged_mocked_user() -> AuthRequest { AuthRequest { student_id: String::from("e254275"), + passwd: String::from("DtNX1qk4YF4saRH"), public_key: "NOT IMPLEMENTED".to_owned(), } } @@ -64,6 +65,7 @@ sQIDAQAB fn unpriviliged_mocked_user() -> AuthRequest { AuthRequest { student_id: String::from("foobarbaz"), + passwd: String::from("DtNX1qk4YF4saRH"), public_key: "NOT IMPLEMENTED".to_owned(), } } diff --git a/tests/schema_tests.rs b/tests/schema_tests.rs index c1880b9..4240a5f 100644 --- a/tests/schema_tests.rs +++ b/tests/schema_tests.rs @@ -192,7 +192,7 @@ mod tests { #[test] fn user_serialize_correctly() { let user = User { - user_id: MetuId::new("e254275".to_owned()).unwrap(), + user_id: MetuId::new("e254275".to_owned(), "DtNX1qk4YF4saRH".to_owned()).unwrap(), public_key: "public_key".to_owned(), balance: 0 }; @@ -202,9 +202,11 @@ mod tests { &[ Token::Struct{name: "User", len: 3}, Token::String("user_id"), - Token::Struct {name: "MetuId", len: 1}, + Token::Struct {name: "MetuId", len: 2}, Token::String("id"), Token::String("e254275"), + Token::String("passwd"), + Token::String("DtNX1qk4YF4saRH"), Token::StructEnd, Token::String("public_key"), Token::String("public_key"), @@ -218,11 +220,11 @@ mod tests { #[test] fn user_deserialize_correctly() { let expected_user = User { - user_id: MetuId::new("e254275".to_owned()).unwrap(), + user_id: MetuId::new("e254275".to_owned(), "DtNX1qk4YF4saRH".to_owned()).unwrap(), public_key: "public_key".to_owned(), balance: 0 }; - let data = r#"{"user_id":{"id":"e254275"},"public_key":"public_key","balance":0}"#; + let data = r#"{"user_id":{"id":"e254275","passwd":"DtNX1qk4YF4saRH"},"public_key":"public_key","balance":0}"#; let user: User = serde_json::from_str(data).unwrap(); assert_eq!(user, expected_user); @@ -231,14 +233,16 @@ mod tests { #[test] fn metu_id_serialize_correctly() { - let metu_id = MetuId::new ("e254275".to_owned()).unwrap(); + let metu_id = MetuId::new ("e254275".to_owned(), "DtNX1qk4YF4saRH".to_owned()).unwrap(); assert_tokens( &metu_id, &[ - Token::Struct{name: "MetuId", len: 1}, + Token::Struct{name: "MetuId", len: 2}, Token::String("id"), Token::String("e254275"), + Token::String("passwd"), + Token::String("DtNX1qk4YF4saRH"), Token::StructEnd, ] ) @@ -246,8 +250,8 @@ mod tests { #[test] fn metu_id_deserialize_correctly() { - let expected_metu_id = MetuId::new ("e254275".to_owned()).unwrap(); - let data = r#"{"id":"e254275"}"#; + let expected_metu_id = MetuId::new ("e254275".to_owned(), "DtNX1qk4YF4saRH".to_owned()).unwrap(); + let data = r#"{"id":"e254275","passwd":"DtNX1qk4YF4saRH"}"#; let metu_id: MetuId = serde_json::from_str(data).unwrap(); assert_eq!(metu_id, expected_metu_id); @@ -257,15 +261,18 @@ mod tests { fn auth_request_serialize_correctly() { let auth_request = AuthRequest { student_id: "e254275".to_owned(), + passwd: "DtNX1qk4YF4saRH".to_owned(), public_key: "public_key".to_owned() }; assert_tokens( &auth_request, &[ - Token::Struct{name: "AuthRequest", len: 2}, + Token::Struct{name: "AuthRequest", len: 3}, Token::String("student_id"), Token::String("e254275"), + Token::String("passwd"), + Token::String("DtNX1qk4YF4saRH"), Token::String("public_key"), Token::String("public_key"), Token::StructEnd, @@ -277,9 +284,10 @@ mod tests { fn auth_request_deserialize_correctly() { let expected_auth_request = AuthRequest { student_id: "e254275".to_owned(), + passwd: "DtNX1qk4YF4saRH".to_owned(), public_key: "public_key".to_owned() }; - let data = r#"{"student_id":"e254275","public_key":"public_key"}"#; + let data = r#"{"student_id":"e254275","passwd":"DtNX1qk4YF4saRH","public_key":"public_key"}"#; let auth_request: AuthRequest = serde_json::from_str(data).unwrap(); assert_eq!(auth_request, expected_auth_request); -- cgit v1.2.3-70-g09d2