Ugh
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use axum::http::{HeaderMap, HeaderValue};
|
||||
use crate::modes::server::common::check_auth;
|
||||
use axum::http::{HeaderMap, HeaderValue};
|
||||
|
||||
#[test]
|
||||
fn test_auth_with_no_password_required() {
|
||||
let headers = HeaderMap::new();
|
||||
let password = None;
|
||||
|
||||
|
||||
// When no password is required, auth should pass
|
||||
assert!(check_auth(&headers, &password));
|
||||
}
|
||||
@@ -15,10 +15,13 @@ mod tests {
|
||||
#[test]
|
||||
fn test_auth_with_bearer_token() {
|
||||
let mut headers = HeaderMap::new();
|
||||
headers.insert("authorization", HeaderValue::from_static("Bearer secret123"));
|
||||
|
||||
headers.insert(
|
||||
"authorization",
|
||||
HeaderValue::from_static("Bearer secret123"),
|
||||
);
|
||||
|
||||
let password = Some("secret123".to_string());
|
||||
|
||||
|
||||
// Valid bearer token should pass
|
||||
assert!(check_auth(&headers, &password));
|
||||
}
|
||||
@@ -26,10 +29,13 @@ mod tests {
|
||||
#[test]
|
||||
fn test_auth_with_invalid_bearer_token() {
|
||||
let mut headers = HeaderMap::new();
|
||||
headers.insert("authorization", HeaderValue::from_static("Bearer wrongtoken"));
|
||||
|
||||
headers.insert(
|
||||
"authorization",
|
||||
HeaderValue::from_static("Bearer wrongtoken"),
|
||||
);
|
||||
|
||||
let password = Some("secret123".to_string());
|
||||
|
||||
|
||||
// Invalid bearer token should fail
|
||||
assert!(!check_auth(&headers, &password));
|
||||
}
|
||||
@@ -38,10 +44,13 @@ mod tests {
|
||||
fn test_auth_with_basic_auth() {
|
||||
let mut headers = HeaderMap::new();
|
||||
// Basic auth for "keep:secret123" base64 encoded
|
||||
headers.insert("authorization", HeaderValue::from_static("Basic a2VlcDpzZWNyZXQxMjM="));
|
||||
|
||||
headers.insert(
|
||||
"authorization",
|
||||
HeaderValue::from_static("Basic a2VlcDpzZWNyZXQxMjM="),
|
||||
);
|
||||
|
||||
let password = Some("secret123".to_string());
|
||||
|
||||
|
||||
// Valid basic auth should pass
|
||||
assert!(check_auth(&headers, &password));
|
||||
}
|
||||
@@ -50,10 +59,13 @@ mod tests {
|
||||
fn test_auth_with_invalid_basic_auth() {
|
||||
let mut headers = HeaderMap::new();
|
||||
// Basic auth for "keep:wrongpass" base64 encoded
|
||||
headers.insert("authorization", HeaderValue::from_static("Basic a2VlcDp3cm9uZ3Bhc3M="));
|
||||
|
||||
headers.insert(
|
||||
"authorization",
|
||||
HeaderValue::from_static("Basic a2VlcDp3cm9uZ3Bhc3M="),
|
||||
);
|
||||
|
||||
let password = Some("secret123".to_string());
|
||||
|
||||
|
||||
// Invalid basic auth should fail
|
||||
assert!(!check_auth(&headers, &password));
|
||||
}
|
||||
@@ -62,7 +74,7 @@ mod tests {
|
||||
fn test_auth_with_missing_auth_header() {
|
||||
let headers = HeaderMap::new();
|
||||
let password = Some("secret123".to_string());
|
||||
|
||||
|
||||
// Missing auth header should fail when password is required
|
||||
assert!(!check_auth(&headers, &password));
|
||||
}
|
||||
@@ -71,9 +83,9 @@ mod tests {
|
||||
fn test_auth_with_malformed_auth_header() {
|
||||
let mut headers = HeaderMap::new();
|
||||
headers.insert("authorization", HeaderValue::from_static("Invalid header"));
|
||||
|
||||
|
||||
let password = Some("secret123".to_string());
|
||||
|
||||
|
||||
// Malformed auth header should fail
|
||||
assert!(!check_auth(&headers, &password));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user