From 3c2000317d6eeee2c2ef0be4544f03bda46a9aa2 Mon Sep 17 00:00:00 2001 From: Fina Wilke Date: Mon, 9 Sep 2024 18:12:01 +0200 Subject: [PATCH] core: Fix tests with passwords of too low entropy --- src/core.rs | 19 +++++-------------- src/core/test.rs | 8 +++----- 2 files changed, 8 insertions(+), 19 deletions(-) diff --git a/src/core.rs b/src/core.rs index f9433131..c0be20c4 100644 --- a/src/core.rs +++ b/src/core.rs @@ -151,11 +151,13 @@ impl MailboxConnection { /// /// # Examples /// + /// #[cfg(feature = "entropy")] /// ```no_run /// # fn main() -> eyre::Result<()> { async_std::task::block_on(async { /// use magic_wormhole::{transfer::APP_CONFIG, MailboxConnection}; /// let config = APP_CONFIG; - /// let mailbox_connection = MailboxConnection::create_with_password(config, "secret").await?; + /// let mailbox_connection = + /// MailboxConnection::create_with_password(config, "secret".parse().unwrap()).await?; /// # Ok(()) })} /// ``` /// @@ -177,17 +179,6 @@ impl MailboxConnection { /// /// * `config`: Application configuration /// * `password`: Free text password which will be appended to the nameplate number to form the `Code` - /// - /// # Examples - /// - /// ```no_run - /// # fn main() -> eyre::Result<()> { async_std::task::block_on(async { - /// use magic_wormhole::{transfer::APP_CONFIG, MailboxConnection}; - /// let config = APP_CONFIG; - /// let password: Password = "secret".parse()?; - /// let mailbox_connection = MailboxConnection::create_with_password(config, password).await?; - /// # Ok(()) })} - /// ``` async fn create_with_validated_password( config: AppConfig, password: Password, @@ -222,7 +213,7 @@ impl MailboxConnection { /// # fn main() -> eyre::Result<()> { async_std::task::block_on(async { /// use magic_wormhole::{transfer::APP_CONFIG, Code, MailboxConnection, Nameplate}; /// let config = APP_CONFIG; - /// let code = Code::new(&Nameplate::new("5"), "password"); + /// let code = "5-password".parse().unwrap(); /// let mailbox_connection = MailboxConnection::connect(config, code, false).await?; /// # Ok(()) })} /// ``` @@ -268,7 +259,7 @@ impl MailboxConnection { /// async_std::task::block_on(async { /// use magic_wormhole::{transfer::APP_CONFIG, MailboxConnection, Mood}; /// let config = APP_CONFIG; - /// let mailbox_connection = MailboxConnection::create_with_password(config, "secret") + /// let mailbox_connection = MailboxConnection::create_with_password(config, "secret-code-password".parse().unwrap()) /// .await?; /// mailbox_connection.shutdown(Mood::Happy).await?; /// # Ok(())})} diff --git a/src/core/test.rs b/src/core/test.rs index 22991264..b42bdaf3 100644 --- a/src/core/test.rs +++ b/src/core/test.rs @@ -7,9 +7,8 @@ use std::{borrow::Cow, str::FromStr, time::Duration}; #[cfg(feature = "transfer")] use crate::transfer; use crate::{ - self as magic_wormhole, - core::{MailboxConnection, Nameplate}, - transit, AppConfig, AppID, Code, Wormhole, WormholeError, + self as magic_wormhole, core::MailboxConnection, transit, AppConfig, AppID, Code, Wormhole, + WormholeError, }; use test_log::test; @@ -577,8 +576,7 @@ pub async fn test_connect_with_code_expecting_nameplate() -> eyre::Result<()> { fn generate_random_code() -> Code { let mut rng = rand::thread_rng(); let nameplate_string = format!("{}-guitarist-revenge", rng.gen_range(1000..10000)); - let nameplate = Nameplate::from_str(&nameplate_string).unwrap(); - Code::from_components(nameplate, "guitarist-revenge".parse().unwrap()) + Code::from_str(&nameplate_string).unwrap() } #[test]