Critical bug fixes:
- save_item now returns real Item from database, not a hardcoded fake
- AsyncDataService::save() reuses self.sync_service instead of creating redundant instance
- GenerateStatus trait signature mismatch fixed (CLI/API decoupling)
Performance improvements (pipe path untouched):
- CompressionEngine::open() returns Box<dyn Read + Send> enabling true streaming
- mode_get eliminates triple full-file read (was sampling then re-reading entire file)
- FilteringReader adds fast-path bypass when no filters, pre-allocates temp buffer
- text.rs meta plugin processes &[u8] slice directly, eliminates data.to_vec() clone
API correctness:
- Tag parse errors now return 400 instead of being silently discarded
- compute_diff uses similar crate (LCS-based) instead of naive positional comparison
Cleanup:
- Modernize string formatting (format!({x})) across codebase
- Remove redundant DB query in get mode
- Derive Debug/ToSchema on public types
- Delete placeholder test files with no real assertions
- Extract parse_comma_tags utility function
93 lines
2.6 KiB
Rust
93 lines
2.6 KiB
Rust
#[cfg(all(test, feature = "server"))]
|
|
mod tests {
|
|
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));
|
|
}
|
|
|
|
#[test]
|
|
fn test_auth_with_bearer_token() {
|
|
let mut headers = HeaderMap::new();
|
|
headers.insert(
|
|
"authorization",
|
|
HeaderValue::from_static("Bearer secret123"),
|
|
);
|
|
|
|
let password = Some("secret123".to_string());
|
|
|
|
// Valid bearer token should pass
|
|
assert!(check_auth(&headers, &password));
|
|
}
|
|
|
|
#[test]
|
|
fn test_auth_with_invalid_bearer_token() {
|
|
let mut headers = HeaderMap::new();
|
|
headers.insert(
|
|
"authorization",
|
|
HeaderValue::from_static("Bearer wrongtoken"),
|
|
);
|
|
|
|
let password = Some("secret123".to_string());
|
|
|
|
// Invalid bearer token should fail
|
|
assert!(!check_auth(&headers, &password));
|
|
}
|
|
|
|
#[test]
|
|
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="),
|
|
);
|
|
|
|
let password = Some("secret123".to_string());
|
|
|
|
// Valid basic auth should pass
|
|
assert!(check_auth(&headers, &password));
|
|
}
|
|
|
|
#[test]
|
|
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="),
|
|
);
|
|
|
|
let password = Some("secret123".to_string());
|
|
|
|
// Invalid basic auth should fail
|
|
assert!(!check_auth(&headers, &password));
|
|
}
|
|
|
|
#[test]
|
|
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));
|
|
}
|
|
|
|
#[test]
|
|
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));
|
|
}
|
|
}
|