+ #[test]\r
+ fn sign_up_then_send_validation_then_sign_in() -> Result<()> {\r
+ let connection = Connection::new_in_memory()?;\r
+\r
+ let password = "12345";\r
+ let email = "paul@test.org";\r
+\r
+ // Sign up.\r
+ let validation_token =\r
+ match connection.sign_up(password, email)? {\r
+ SignUpResult::UserCreatedWaitingForValidation(token) => token, // Nominal case.\r
+ other => panic!("{:?}", other),\r
+ };\r
+\r
+ // Validation.\r
+ match connection.validation(&validation_token, Duration::hours(1), "127.0.0.1", "Mozilla/5.0")? {\r
+ ValidationResult::Ok(_, _) => (),\r
+ other => panic!("{:?}", other),\r
+ };\r
+\r
+ // Sign in.\r
+ match connection.sign_in(password, email, "127.0.0.1", "Mozilla/5.0")? {\r
+ SignInResult::Ok(_, _) => (), // Nominal case.\r
+ other => panic!("{:?}", other),\r
+ }\r
+\r
+ Ok(())\r
+ }\r
+\r
+ #[test]\r
+ fn sign_up_then_send_validation_then_authentication() -> Result<()> {\r
+ let connection = Connection::new_in_memory()?;\r
+\r
+ let password = "12345";\r
+ let email = "paul@test.org";\r
+\r
+ // Sign up.\r
+ let validation_token =\r
+ match connection.sign_up(password, email)? {\r
+ SignUpResult::UserCreatedWaitingForValidation(token) => token, // Nominal case.\r
+ other => panic!("{:?}", other),\r
+ };\r
+\r
+ // Validation.\r
+ let (authentication_token, user_id) = match connection.validation(&validation_token, Duration::hours(1), "127.0.0.1", "Mozilla")? {\r
+ ValidationResult::Ok(token, user_id) => (token, user_id),\r
+ other => panic!("{:?}", other),\r
+ };\r
+\r
+ // Check user login information.\r
+ let user_login_info_1 = connection.get_user_login_info(&authentication_token)?;\r
+ assert_eq!(user_login_info_1.ip, "127.0.0.1");\r
+ assert_eq!(user_login_info_1.user_agent, "Mozilla");\r
+\r
+ // Authentication.\r
+ let _user_id =\r
+ match connection.authentication(&authentication_token, "192.168.1.1", "Chrome")? {\r
+ AuthenticationResult::Ok(user_id) => user_id, // Nominal case.\r
+ other => panic!("{:?}", other),\r
+ };\r
+\r
+ // Check user login information.\r
+ let user_login_info_2 = connection.get_user_login_info(&authentication_token)?;\r
+ assert_eq!(user_login_info_2.ip, "192.168.1.1");\r
+ assert_eq!(user_login_info_2.user_agent, "Chrome");\r
+\r
+ Ok(())\r
+ }\r
+\r
+ #[test]\r
+ fn sign_up_then_send_validation_then_sign_out_then_sign_in() -> Result<()> {\r
+ let connection = Connection::new_in_memory()?;\r
+\r
+ let password = "12345";\r
+ let email = "paul@test.org";\r
+\r
+ // Sign up.\r
+ let validation_token =\r
+ match connection.sign_up(password, email)? {\r
+ SignUpResult::UserCreatedWaitingForValidation(token) => token, // Nominal case.\r
+ other => panic!("{:?}", other),\r
+ };\r
+\r
+ // Validation.\r
+ let (authentication_token_1, user_id_1) =\r
+ match connection.validation(&validation_token, Duration::hours(1), "127.0.0.1", "Mozilla")? {\r
+ ValidationResult::Ok(token, user_id) => (token, user_id),\r
+ other => panic!("{:?}", other),\r
+ };\r
+\r
+ // Check user login information.\r
+ let user_login_info_1 = connection.get_user_login_info(&authentication_token_1)?;\r
+ assert_eq!(user_login_info_1.ip, "127.0.0.1");\r
+ assert_eq!(user_login_info_1.user_agent, "Mozilla");\r
+\r
+ // Sign out.\r
+ connection.sign_out(&authentication_token_1)?;\r
+\r
+ // Sign in.\r
+ let (authentication_token_2, user_id_2) =\r
+ match connection.sign_in(password, email, "192.168.1.1", "Chrome")? {\r
+ SignInResult::Ok(token, user_id) => (token, user_id),\r
+ other => panic!("{:?}", other),\r
+ };\r
+\r
+ assert_eq!(user_id_1, user_id_2);\r
+ assert_ne!(authentication_token_1, authentication_token_2);\r
+\r
+ // Check user login information.\r
+ let user_login_info_2 = connection.get_user_login_info(&authentication_token_2)?;\r
+\r
+ assert_eq!(user_login_info_2.ip, "192.168.1.1");\r
+ assert_eq!(user_login_info_2.user_agent, "Chrome");\r
+\r
+ Ok(())\r
+ }\r