litellm/litellm-rust/crates/gateway-ui/tests/assets.rs
yuneng-jiang a6f6c64b6e
feat(ui): adopt the new LiteLLM logo and monogram (#43913)
* feat(ui): adopt the new LiteLLM logo and monogram

Swap the bundled admin UI logos for the new brand assets: the primary
logo in blue for light mode and white for dark mode, and the monogram for
the collapsed sidebar, favicons, and the built-in guardrail cards.

/get_image gains a variant=monogram query parameter so the collapsed
sidebar can request the monogram while admin-configured UI_LOGO_PATH /
UI_LOGO_PATH_DARK logos still take precedence. The bundled light logo
moves from JPEG to a transparent PNG.

* test(ui): query collapsed sidebar logos by role to stay within the lint budget

* fix: point remaining logo consumers at the new bundled assets

The Rust gateway UI served /get_image from the removed litellm_logo.jpg,
the non-root get_image tests pinned logo.jpg, and a cookbook script read
litellm/proxy/logo.jpg. Point them at the monogram and logo.png.

* fix(mcp): serve the BYOK OAuth page logo from /get_image

The page pointed at /ui/assets/logos/litellm_logo.jpg, which the rebrand
removes from the dashboard sources, so the next UI build would drop it.
/get_image?variant=monogram is always served by the proxy and follows any
admin-configured logo.

* fix(ui): invert the LiteLLM monogram on dark guardrail cards

The blue monogram has a transparent train cut-out, so on a dark card it
read as a muddy blue block. Inverting it yields the brand's white mark,
which the logo guidelines prescribe for dark backgrounds.

* fix(gateway-ui): serve theme and variant aware logos from the dashboard export

The Rust gateway served one monogram for every /get_image request, and the
committed export lacked it, so /get_image returned 404 until the next UI
release build. Pick the full or monogram logo in light or dark from the
query, ship those assets in the dashboard's public dir and the committed
export, and drop two comments that restated asserted paths.
2026-09-30 14:51:06 -07:00

217 lines
6.8 KiB
Rust

use axum::{
Router,
body::{Body, to_bytes},
http::{Request, StatusCode, header},
};
use rstest::{fixture, rstest};
use serde_json::Value;
use tempfile::TempDir;
use tower::ServiceExt;
struct App {
router: Router,
_directory: TempDir,
}
#[fixture]
fn directory() -> TempDir {
let directory = TempDir::new().unwrap();
let export = directory.path().join("public");
std::fs::create_dir_all(export.join("login")).unwrap();
std::fs::create_dir_all(export.join("assets")).unwrap();
std::fs::write(directory.path().join("outside.txt"), "private file").unwrap();
std::fs::write(export.join("index.html"), "dashboard").unwrap();
std::fs::write(export.join("login/index.html"), "login page").unwrap();
std::fs::write(export.join("assets/app.js"), "window.app = true;").unwrap();
std::fs::write(export.join("styles.css"), "body { color: black; }").unwrap();
directory
}
#[fixture]
fn app(directory: TempDir) -> App {
App {
router: litellm_gateway_ui::static_assets(directory.path().join("public")),
_directory: directory,
}
}
#[fixture]
fn dashboard(directory: TempDir) -> App {
let export = directory.path().join("public");
std::fs::create_dir_all(export.join("_next/static")).unwrap();
std::fs::create_dir_all(export.join("assets/logos")).unwrap();
for (file, bytes) in [
("litellm_logo.png", "logo bytes"),
("litellm_logo_dark.png", "dark logo bytes"),
("litellm_monogram.svg", "monogram bytes"),
("litellm_monogram_dark.svg", "dark monogram bytes"),
] {
std::fs::write(export.join("assets/logos").join(file), bytes).unwrap();
}
std::fs::write(export.join("favicon.ico"), "icon bytes").unwrap();
std::fs::write(export.join("_next/static/app.js"), "window.app = true;").unwrap();
App {
router: litellm_gateway_ui::dashboard_assets(export),
_directory: directory,
}
}
#[rstest]
#[case::dashboard("/ui/", "dashboard", "text/html")]
#[case::login("/ui/login/", "login page", "text/html")]
#[case::javascript("/ui/assets/app.js", "window.app = true;", "text/javascript")]
#[case::stylesheet("/ui/styles.css", "body { color: black; }", "text/css")]
#[tokio::test]
async fn serves_export_without_auth(
app: App,
#[case] path: &str,
#[case] expected: &str,
#[case] mime: &str,
) {
let response = app
.router
.oneshot(Request::get(path).body(Body::empty()).unwrap())
.await
.unwrap();
assert_eq!(response.status(), StatusCode::OK);
assert!(
response.headers()[header::CONTENT_TYPE]
.to_str()
.unwrap()
.starts_with(mime)
);
assert_eq!(
to_bytes(response.into_body(), 65536).await.unwrap(),
expected
);
}
#[rstest]
#[case::root("/ui?login=success", "/ui/?login=success")]
#[case::nested("/ui/login?redirect_to=%2Fui", "/ui/login/?redirect_to=%2Fui")]
#[tokio::test]
async fn directory_redirects_preserve_prefix_and_query(
app: App,
#[case] path: &str,
#[case] location: &str,
) {
let response = app
.router
.oneshot(Request::get(path).body(Body::empty()).unwrap())
.await
.unwrap();
assert!(response.status().is_redirection());
assert_eq!(response.headers()[header::LOCATION], location);
}
#[rstest]
#[case::missing("/ui/no-such-page")]
#[case::outside_ui("/v1/models")]
#[case::traversal("/ui/%2e%2e/outside.txt")]
#[case::encoded_separator("/ui/..%2foutside.txt")]
#[case::no_implicit_root_assets("/assets/app.js")]
#[case::no_implicit_dashboard_branding("/get_logo_url")]
#[tokio::test]
async fn missing_paths_never_fall_back_to_dashboard(app: App, #[case] path: &str) {
let response = app
.router
.oneshot(Request::get(path).body(Body::empty()).unwrap())
.await
.unwrap();
assert_eq!(response.status(), StatusCode::NOT_FOUND);
assert!(
!to_bytes(response.into_body(), 65536)
.await
.unwrap()
.windows(9)
.any(|part| part == b"dashboard")
);
}
#[rstest]
#[case::dashboard("/ui/", "dashboard", "text/html")]
#[case::asset_alias(
"/litellm-asset-prefix/_next/static/app.js",
"window.app = true;",
"text/javascript"
)]
#[case::root_assets("/_next/static/app.js", "window.app = true;", "text/javascript")]
#[case::nested_assets("/ui/_next/static/app.js", "window.app = true;", "text/javascript")]
#[case::logo("/get_image", "logo bytes", "image/png")]
#[case::logo_light("/get_image?theme=light", "logo bytes", "image/png")]
#[case::logo_dark("/get_image?theme=dark", "dark logo bytes", "image/png")]
#[case::monogram("/get_image?variant=monogram", "monogram bytes", "image/svg+xml")]
#[case::monogram_dark(
"/get_image?theme=dark&variant=monogram",
"dark monogram bytes",
"image/svg+xml"
)]
#[case::favicon("/get_favicon", "icon bytes", "image/x-icon")]
#[tokio::test]
async fn dashboard_adapter_preserves_existing_urls(
dashboard: App,
#[case] path: &str,
#[case] expected: &str,
#[case] mime: &str,
) {
let response = dashboard
.router
.oneshot(Request::get(path).body(Body::empty()).unwrap())
.await
.unwrap();
assert_eq!(response.status(), StatusCode::OK);
assert!(
response.headers()[header::CONTENT_TYPE]
.to_str()
.unwrap()
.starts_with(mime)
);
assert_eq!(
to_bytes(response.into_body(), 65536).await.unwrap(),
expected
);
}
#[rstest]
#[tokio::test]
async fn logo_discovery_points_to_served_image(dashboard: App) {
let response = dashboard
.router
.clone()
.oneshot(Request::get("/get_logo_url").body(Body::empty()).unwrap())
.await
.unwrap();
assert_eq!(response.status(), StatusCode::OK);
let config: Value =
serde_json::from_slice(&to_bytes(response.into_body(), 65536).await.unwrap()).unwrap();
let response = dashboard
.router
.oneshot(
Request::get(config["logo_url"].as_str().unwrap())
.body(Body::empty())
.unwrap(),
)
.await
.unwrap();
assert_eq!(response.status(), StatusCode::OK);
assert_eq!(
to_bytes(response.into_body(), 65536).await.unwrap(),
"logo bytes"
);
}
#[rstest]
#[case::logo("/get_image")]
#[case::logo_dark("/get_image?theme=dark")]
#[case::monogram("/get_image?variant=monogram")]
#[case::monogram_dark("/get_image?theme=dark&variant=monogram")]
#[tokio::test]
async fn committed_dashboard_export_serves_every_logo(#[case] path: &str) {
let export = std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
.join("../../../litellm/proxy/_experimental/out");
let response = litellm_gateway_ui::dashboard_assets(export)
.oneshot(Request::get(path).body(Body::empty()).unwrap())
.await
.unwrap();
assert_eq!(response.status(), StatusCode::OK);
}