mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-13 21:42:34 +00:00
Sketch of an integration test
This commit is contained in:
@@ -14,7 +14,7 @@ use crate::config::{
|
|||||||
#[derive(Debug, Parser)]
|
#[derive(Debug, Parser)]
|
||||||
pub struct GenConfigArgs {}
|
pub struct GenConfigArgs {}
|
||||||
|
|
||||||
fn generate_frontend_secret() -> [u8; 64] {
|
pub fn generate_frontend_secret() -> [u8; 64] {
|
||||||
let mut rng = rand::thread_rng();
|
let mut rng = rand::thread_rng();
|
||||||
|
|
||||||
let mut secret = [0u8; 64];
|
let mut secret = [0u8; 64];
|
||||||
|
|||||||
64
src/main.rs
64
src/main.rs
@@ -115,3 +115,67 @@ async fn main() -> Result<()> {
|
|||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use crate::{app::make_app, commands::generate_frontend_secret, get_data_stores};
|
||||||
|
use actix_web::{http::StatusCode, test::TestRequest};
|
||||||
|
use async_trait::async_trait;
|
||||||
|
use rustical_frontend::FrontendConfig;
|
||||||
|
use rustical_store::auth::{AuthenticationProvider, UserStore};
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
struct MockUserStore;
|
||||||
|
|
||||||
|
#[async_trait]
|
||||||
|
impl UserStore for MockUserStore {
|
||||||
|
async fn get_user(
|
||||||
|
&self,
|
||||||
|
id: &str,
|
||||||
|
) -> Result<Option<rustical_store::auth::User>, rustical_store::Error> {
|
||||||
|
Err(rustical_store::Error::NotFound)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[async_trait]
|
||||||
|
impl AuthenticationProvider for MockUserStore {
|
||||||
|
async fn validate_user_token(
|
||||||
|
&self,
|
||||||
|
user_id: &str,
|
||||||
|
token: &str,
|
||||||
|
) -> Result<Option<rustical_store::auth::User>, rustical_store::Error> {
|
||||||
|
Err(rustical_store::Error::NotFound)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_main() {
|
||||||
|
let (addr_store, cal_store, subscription_store, update_recv) = get_data_stores(
|
||||||
|
true,
|
||||||
|
&crate::config::DataStoreConfig::Sqlite(crate::config::SqliteDataStoreConfig {
|
||||||
|
db_url: "".to_owned(),
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let user_store = Arc::new(MockUserStore);
|
||||||
|
|
||||||
|
let app = make_app(
|
||||||
|
addr_store,
|
||||||
|
cal_store,
|
||||||
|
subscription_store,
|
||||||
|
user_store.clone(),
|
||||||
|
user_store,
|
||||||
|
FrontendConfig {
|
||||||
|
enabled: false,
|
||||||
|
secret_key: generate_frontend_secret(),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
let app = actix_web::test::init_service(app).await;
|
||||||
|
let req = TestRequest::get().uri("/").to_request();
|
||||||
|
let resp = actix_web::test::call_service(&app, req).await;
|
||||||
|
assert_eq!(resp.status(), StatusCode::NOT_FOUND);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user