Skip to content

Commit

Permalink
core: Fix tests with passwords of too low entropy
Browse files Browse the repository at this point in the history
  • Loading branch information
felinira committed Oct 11, 2024
1 parent 162eee2 commit 7bee0f4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 19 deletions.
19 changes: 5 additions & 14 deletions src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,13 @@ impl<V: serde::Serialize + Send + Sync + 'static> MailboxConnection<V> {
///
/// # 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()?).await?;
/// # Ok(()) })}
/// ```
///
Expand All @@ -177,17 +179,6 @@ impl<V: serde::Serialize + Send + Sync + 'static> MailboxConnection<V> {
///
/// * `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<V>,
password: Password,
Expand Down Expand Up @@ -222,7 +213,7 @@ impl<V: serde::Serialize + Send + Sync + 'static> MailboxConnection<V> {
/// # 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()?;
/// let mailbox_connection = MailboxConnection::connect(config, code, false).await?;
/// # Ok(()) })}
/// ```
Expand Down Expand Up @@ -268,7 +259,7 @@ impl<V: serde::Serialize + Send + Sync + 'static> MailboxConnection<V> {
/// 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()?)
/// .await?;
/// mailbox_connection.shutdown(Mood::Happy).await?;
/// # Ok(())})}
Expand Down
8 changes: 3 additions & 5 deletions src/core/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit 7bee0f4

Please sign in to comment.