mirror of
https://github.com/Nutomic/ibis.git
synced 2025-01-11 10:45:48 +00:00
Speed up tests by using a single static keypair
This commit is contained in:
parent
0868db9210
commit
b64a3e948a
3 changed files with 23 additions and 10 deletions
|
@ -5,6 +5,7 @@ use crate::{
|
|||
IbisData,
|
||||
},
|
||||
error::MyResult,
|
||||
utils::generate_keypair,
|
||||
},
|
||||
common::{
|
||||
newtypes::PersonId,
|
||||
|
@ -15,11 +16,7 @@ use crate::{
|
|||
LocalUserView,
|
||||
},
|
||||
};
|
||||
use activitypub_federation::{
|
||||
config::Data,
|
||||
fetch::object_id::ObjectId,
|
||||
http_signatures::generate_actor_keypair,
|
||||
};
|
||||
use activitypub_federation::{config::Data, fetch::object_id::ObjectId};
|
||||
use bcrypt::{hash, DEFAULT_COST};
|
||||
use chrono::{DateTime, Utc};
|
||||
use diesel::{
|
||||
|
@ -83,7 +80,7 @@ impl DbPerson {
|
|||
http_protocol_str()
|
||||
))?;
|
||||
let inbox_url = format!("{}://{domain}/inbox", http_protocol_str());
|
||||
let keypair = generate_actor_keypair()?;
|
||||
let keypair = generate_keypair()?;
|
||||
let person_form = DbPersonForm {
|
||||
username,
|
||||
ap_id,
|
||||
|
@ -185,7 +182,7 @@ impl DbPerson {
|
|||
http_protocol_str()
|
||||
))?;
|
||||
let inbox_url = format!("{}://{domain}/inbox", http_protocol_str());
|
||||
let keypair = generate_actor_keypair()?;
|
||||
let keypair = generate_keypair()?;
|
||||
let person_form = DbPersonForm {
|
||||
username: username.to_string(),
|
||||
ap_id,
|
||||
|
|
|
@ -21,7 +21,6 @@ use crate::{
|
|||
use activitypub_federation::{
|
||||
config::{Data, FederationConfig, FederationMiddleware},
|
||||
fetch::object_id::ObjectId,
|
||||
http_signatures::generate_actor_keypair,
|
||||
};
|
||||
use api::api_routes;
|
||||
use assets::file_and_error_handler;
|
||||
|
@ -54,6 +53,7 @@ use std::net::SocketAddr;
|
|||
use tokio::{net::TcpListener, sync::oneshot};
|
||||
use tower_http::cors::CorsLayer;
|
||||
use tower_layer::Layer;
|
||||
use utils::generate_keypair;
|
||||
|
||||
pub mod api;
|
||||
mod assets;
|
||||
|
@ -156,7 +156,7 @@ async fn setup(data: &Data<IbisData>) -> Result<(), Error> {
|
|||
let domain = &data.config.federation.domain;
|
||||
let ap_id = ObjectId::parse(&format!("{}://{domain}", http_protocol_str()))?;
|
||||
let inbox_url = format!("{}://{domain}/inbox", http_protocol_str());
|
||||
let keypair = generate_actor_keypair()?;
|
||||
let keypair = generate_keypair()?;
|
||||
let form = DbInstanceForm {
|
||||
domain: domain.to_string(),
|
||||
ap_id,
|
||||
|
|
|
@ -2,10 +2,14 @@ use crate::{
|
|||
backend::{database::IbisData, error::MyResult},
|
||||
common::{utils, DbEdit, EditVersion},
|
||||
};
|
||||
use activitypub_federation::config::Data;
|
||||
use activitypub_federation::{
|
||||
config::Data,
|
||||
http_signatures::{generate_actor_keypair, Keypair},
|
||||
};
|
||||
use anyhow::anyhow;
|
||||
use diffy::{apply, Patch};
|
||||
use rand::{distributions::Alphanumeric, thread_rng, Rng};
|
||||
use std::sync::LazyLock;
|
||||
use url::{ParseError, Url};
|
||||
|
||||
pub fn generate_activity_id(data: &Data<IbisData>) -> Result<Url, ParseError> {
|
||||
|
@ -101,3 +105,15 @@ mod test {
|
|||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
/// Use a single static keypair during testing which is signficantly faster than
|
||||
/// generating dozens of keys from scratch.
|
||||
pub fn generate_keypair() -> MyResult<Keypair> {
|
||||
if cfg!(debug_assertions) {
|
||||
static KEYPAIR: LazyLock<Keypair> =
|
||||
LazyLock::new(|| generate_actor_keypair().expect("generate keypair"));
|
||||
Ok(KEYPAIR.clone())
|
||||
} else {
|
||||
Ok(generate_actor_keypair()?)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue