mirror of
https://github.com/zyycn/codex-proxy-rs.git
synced 2026-11-06 08:06:19 +00:00
55 lines
1.6 KiB
Rust
55 lines
1.6 KiB
Rust
use axum::http::{header::AUTHORIZATION, HeaderMap, HeaderValue};
|
|
use codex_proxy_rs::proxy::auth::{bearer_client_api_key, ClientApiKeyAuthError};
|
|
|
|
#[test]
|
|
fn bearer_client_api_key_should_report_missing_authorization() {
|
|
let headers = HeaderMap::new();
|
|
|
|
let result = bearer_client_api_key(&headers);
|
|
|
|
assert_eq!(result, Err(ClientApiKeyAuthError::MissingAuthorization));
|
|
}
|
|
|
|
#[test]
|
|
fn bearer_client_api_key_should_report_malformed_authorization() {
|
|
let mut headers = HeaderMap::new();
|
|
headers.insert(AUTHORIZATION, HeaderValue::from_static("Token sk_test"));
|
|
|
|
let result = bearer_client_api_key(&headers);
|
|
|
|
assert_eq!(result, Err(ClientApiKeyAuthError::MalformedAuthorization));
|
|
}
|
|
|
|
#[test]
|
|
fn bearer_client_api_key_should_report_empty_bearer_token() {
|
|
let mut headers = HeaderMap::new();
|
|
headers.insert(AUTHORIZATION, HeaderValue::from_static("Bearer "));
|
|
|
|
let result = bearer_client_api_key(&headers);
|
|
|
|
assert_eq!(result, Err(ClientApiKeyAuthError::MalformedAuthorization));
|
|
}
|
|
|
|
#[test]
|
|
fn bearer_client_api_key_should_report_invalid_key_format() {
|
|
let mut headers = HeaderMap::new();
|
|
headers.insert(
|
|
AUTHORIZATION,
|
|
HeaderValue::from_static("Bearer admin-secret"),
|
|
);
|
|
|
|
let result = bearer_client_api_key(&headers);
|
|
|
|
assert_eq!(result, Err(ClientApiKeyAuthError::InvalidKeyFormat));
|
|
}
|
|
|
|
#[test]
|
|
fn bearer_client_api_key_should_extract_trimmed_client_key() {
|
|
let mut headers = HeaderMap::new();
|
|
headers.insert(AUTHORIZATION, HeaderValue::from_static("Bearer sk_test "));
|
|
|
|
let result = bearer_client_api_key(&headers);
|
|
|
|
assert_eq!(result, Ok("sk_test"));
|
|
}
|