mirror of
https://github.com/zyycn/codex-proxy-rs.git
synced 2026-11-06 16:06:08 +00:00
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>
55 lines
1.6 KiB
Rust
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"));
|
|
}
|