Files
codex-proxy-rs/backend/tests/api/client/auth.rs
T
zyycnandCodex 1e99c5037d refactor: migrate backend to Rust 1.97 and edition 2024
Unify the local, CI, release, and container toolchains on Rust 1.97.

Move update configuration, release caching, and event delivery into service-owned state, apply Edition 2024 idioms, and refresh repository ignore rules and documentation.

Co-authored-by: Codex <noreply@openai.com>
2026-07-12 19:10:56 +08:00

55 lines
1.6 KiB
Rust

use axum::http::{HeaderMap, HeaderValue, header::AUTHORIZATION};
use codex_proxy_rs::api::client::auth::{ClientApiKeyAuthError, bearer_client_api_key};
#[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"));
}