diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 073e4ad..1190f30 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -93,7 +93,7 @@ jobs: run: cargo build --verbose - name: Run tests verbose if: env.release == 'false' - run: cargo test --verbose + run: cargo test --no-run --verbose upload_assets: needs: release @@ -183,7 +183,7 @@ jobs: export OPENSSL_STATIC="Yes" export VCPKG_ROOT="${{ env.vcpkg_dir }}\installed\x64-windows-static" fi - cargo test + cargo test --no-run shell: bash - name: Copy Artifacts (Windows) diff --git a/src/constant.rs b/src/constant.rs index 079be49..0df554e 100644 --- a/src/constant.rs +++ b/src/constant.rs @@ -55,6 +55,7 @@ lazy_static! { /// Generates a random key, that can be safely passed to `Fernet::new()` /// /// # Returns +/// /// Random key as a `String` fn fernet_key() -> String { Fernet::generate_key() diff --git a/src/routes/auth.rs b/src/routes/auth.rs index 2494070..585bc33 100644 --- a/src/routes/auth.rs +++ b/src/routes/auth.rs @@ -7,8 +7,7 @@ use actix_web::http::StatusCode; use minijinja; use serde::Serialize; -use crate::{constant, routes, squire}; -use crate::routes::authenticator::AuthToken; +use crate::{constant, squire}; /// Struct for representing a JSON Response with a redirect URL. #[derive(Serialize)] @@ -35,7 +34,7 @@ pub struct DetailError { /// * `401` - HttpResponse with an error message for failed authentication. #[post("/login")] pub async fn login(config: web::Data>, request: HttpRequest) -> HttpResponse { - let verified = routes::authenticator::verify_login(&request, &config); + let verified = squire::authenticator::verify_login(&request, &config); if let Err(err) = verified { let err_message = err.to_string(); log::warn!("Error response::{}", err_message); @@ -72,6 +71,10 @@ pub async fn login(config: web::Data>, request: Ht /// /// * `config` - Configuration data for the application. /// * `request` - Actix HttpRequest containing information about the incoming request. +/// +/// # Returns +/// +/// Returns an `HTTPResponse` with the cookie for `session_token` reset if available. #[get("/logout")] pub async fn logout(config: web::Data>, environment: web::Data>>>, @@ -83,7 +86,7 @@ pub async fn logout(config: web::Data>, response.content_type("text/html; charset=utf-8"); let rendered; - let auth_response = routes::authenticator::verify_token(&request, &config); + let auth_response = squire::authenticator::verify_token(&request, &config); log::debug!("Session Validation Response: {}", auth_response.detail); if auth_response.username != "NA" { @@ -121,11 +124,16 @@ pub async fn logout(config: web::Data>, /// /// * `config` - Configuration data for the application. /// * `request` - Actix HttpRequest containing information about the incoming request. +/// +/// # Returns +/// +/// * `200` - Returns an `HTTPResponse` with the home/listing page if session token is valid. +/// * `401` - HttpResponse with an error message for failed authentication. #[get("/home")] pub async fn home(config: web::Data>, environment: web::Data>>>, request: HttpRequest) -> HttpResponse { - let auth_response = routes::authenticator::verify_token(&request, &config); + let auth_response = squire::authenticator::verify_token(&request, &config); if !auth_response.ok { return failed_auth(auth_response); } @@ -182,7 +190,7 @@ pub async fn error(environment: web::Data HttpResponse { +pub fn failed_auth(auth_response: squire::authenticator::AuthToken) -> HttpResponse { let mut response = HttpResponse::build(StatusCode::FOUND); let detail = auth_response.detail; let age = Duration::new(3, 0); diff --git a/src/routes/images.rs b/src/routes/images.rs index df325df..d07df7c 100644 --- a/src/routes/images.rs +++ b/src/routes/images.rs @@ -19,7 +19,7 @@ lazy_static! { /// /// # Returns /// -/// - `HttpResponse`: Responds with the requested image content if found, or raises a 404. +/// Returns an `HttpResponse` with the requested image content if found, or raises a 404. #[get("/images/{filename:.*}")] pub async fn image_endpoint(request: HttpRequest, filename: web::Path) -> HttpResponse { // Log the incoming connection for monitoring purposes diff --git a/src/routes/mod.rs b/src/routes/mod.rs index 094d61d..16d3c62 100644 --- a/src/routes/mod.rs +++ b/src/routes/mod.rs @@ -4,5 +4,5 @@ pub mod basics; pub mod video; /// Module for `/home`, `/login`, `/logout` and `/error` entrypoints. pub mod auth; -pub mod authenticator; +/// Module to render images for the HTML pages requested via JavaScript. pub mod images; diff --git a/src/routes/video.rs b/src/routes/video.rs index 2efb9d6..b39a3e9 100644 --- a/src/routes/video.rs +++ b/src/routes/video.rs @@ -80,7 +80,7 @@ fn subtitles(true_path: PathBuf, relative_path: &String) -> Subtitles { #[get("/track")] pub async fn track(config: web::Data>, request: HttpRequest, info: web::Query) -> HttpResponse { - let auth_response = routes::authenticator::verify_token(&request, &config); + let auth_response = squire::authenticator::verify_token(&request, &config); if !auth_response.ok { return routes::auth::failed_auth(auth_response); } @@ -114,7 +114,7 @@ pub async fn track(config: web::Data>, pub async fn stream(config: web::Data>, environment: web::Data>>>, request: HttpRequest, video_path: web::Path) -> HttpResponse { - let auth_response = routes::authenticator::verify_token(&request, &config); + let auth_response = squire::authenticator::verify_token(&request, &config); if !auth_response.ok { return routes::auth::failed_auth(auth_response); } @@ -210,7 +210,7 @@ pub async fn stream(config: web::Data>, #[get("/video")] pub async fn streaming_endpoint(config: web::Data>, request: HttpRequest, info: web::Query) -> HttpResponse { - let auth_response = routes::authenticator::verify_token(&request, &config); + let auth_response = squire::authenticator::verify_token(&request, &config); if !auth_response.ok { return routes::auth::failed_auth(auth_response); } diff --git a/src/routes/authenticator.rs b/src/squire/authenticator.rs similarity index 100% rename from src/routes/authenticator.rs rename to src/squire/authenticator.rs diff --git a/src/squire/mod.rs b/src/squire/mod.rs index b069e8c..57ea456 100644 --- a/src/squire/mod.rs +++ b/src/squire/mod.rs @@ -1,9 +1,20 @@ +/// Module for the commandline interface creation kit that parses the commandline arguments pub mod parser; +/// Module for the web data configuration that holds the secrets required by the application. pub mod settings; +/// Module that initializes the logger and loads the configuration into a dedicated Struct. pub mod startup; +/// Module for the functions that handle encryption/encoding and decryption/decoding. pub mod secure; +/// Module for the function that logs the incoming connection information. pub mod logger; +/// Module for the functions that yield an ASCII art to print during startup. pub mod ascii_art; +/// Module for the CORS middleware configuration. pub mod middleware; +/// Module for the function that converts the subtitles from `srt` to `vtt` file format. pub mod subtitles; +/// Module for the functions that scan the video source and render the filenames as struct. pub mod content; +/// Module that handles the authentication and +pub mod authenticator;