mirror of
https://github.com/fluxerapp/fluxer
synced 2026-10-18 21:45:31 +09:00
chore(repo): remove dead code and useless tests (#3375)
This commit is contained in:
1 parent
7e177a1c90
commit
1cd62eb661
1391 files changed
+783
-120415
No files matched your search
@@ -50,82 +50,6 @@ fn requires_secret_key() {
|
||||
assert!(err.to_string().contains("FLUXER_MEDIA_PROXY_SECRET_KEY"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn default_config_matches_media_service() {
|
||||
let cfg = Config::load_from_iter(base_env()).unwrap();
|
||||
assert_eq!("0.0.0.0", cfg.bind_host);
|
||||
assert_eq!(8080, cfg.port);
|
||||
assert_eq!(StorageBackend::Local, cfg.storage.backend);
|
||||
assert_eq!(DeploymentMode::Mp, cfg.mode);
|
||||
assert_eq!("cdn", cfg.storage.bucket_cdn);
|
||||
assert_eq!("uploads", cfg.storage.bucket_uploads);
|
||||
assert_eq!("static", cfg.storage.bucket_static);
|
||||
assert!(cfg.media.max_native_transforms >= 2);
|
||||
assert_eq!(
|
||||
cfg.media.max_native_transforms * 8,
|
||||
cfg.media.worker_queue_capacity
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn blank_values_fall_back_to_the_defaults() {
|
||||
let cfg = Config::load_from_iter(env_with(&[
|
||||
("FLUXER_MEDIA_PROXY_MODE", ""),
|
||||
("FLUXER_MEDIA_PROXY_HOST", " "),
|
||||
("FLUXER_MEDIA_PROXY_PORT", ""),
|
||||
("FLUXER_MEDIA_PROXY_READ_ONLY", ""),
|
||||
("FLUXER_MEDIA_PROXY_STORAGE_BACKEND", ""),
|
||||
("FLUXER_MEDIA_PROXY_NSFW_THRESHOLD", " "),
|
||||
("FLUXER_MEDIA_PROXY_CORS_MODE", ""),
|
||||
("FLUXER_MEDIA_PROXY_ATTACHMENT_SIGNATURE_MODE", " "),
|
||||
("FLUXER_S3_REGION", ""),
|
||||
("FLUXER_S3_BUCKET_CDN", ""),
|
||||
]))
|
||||
.unwrap();
|
||||
assert_eq!(DeploymentMode::Mp, cfg.mode);
|
||||
assert_eq!("0.0.0.0", cfg.bind_host);
|
||||
assert_eq!(8080, cfg.port);
|
||||
assert!(!cfg.read_only);
|
||||
assert_eq!(StorageBackend::Local, cfg.storage.backend);
|
||||
assert_eq!(0.85, cfg.media.nsfw_threshold);
|
||||
assert_eq!(PolicyMode::Off, cfg.cors.mode);
|
||||
assert_eq!(PolicyMode::Off, cfg.attachment_signature.mode);
|
||||
assert_eq!("us-east-1", cfg.storage.s3_region);
|
||||
assert_eq!("cdn", cfg.storage.bucket_cdn);
|
||||
|
||||
let err = Config::load_from_iter([("FLUXER_MEDIA_PROXY_SECRET_KEY", " ")]).unwrap_err();
|
||||
assert!(err.to_string().contains("FLUXER_MEDIA_PROXY_SECRET_KEY"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn canonical_media_proxy_env_overrides_apply() {
|
||||
let cfg = Config::load_from_iter([
|
||||
("FLUXER_MEDIA_PROXY_SECRET_KEY", "secret"),
|
||||
("FLUXER_MEDIA_PROXY_STORAGE_BACKEND", "s3"),
|
||||
("FLUXER_MEDIA_PROXY_STORAGE_ROOT", "/srv/fluxer-media"),
|
||||
("FLUXER_MEDIA_PROXY_READ_ONLY", "true"),
|
||||
("FLUXER_S3_FORCE_PATH_STYLE", "false"),
|
||||
("FLUXER_S3_SESSION_TOKEN", "token"),
|
||||
("FLUXER_MEDIA_PROXY_MAX_NATIVE_TRANSFORMS", "3"),
|
||||
("FLUXER_MEDIA_PROXY_WORKER_QUEUE_CAPACITY", "24"),
|
||||
("FLUXER_MEDIA_PROXY_TRANSFORM_TIMEOUT_MS", "2000"),
|
||||
("FLUXER_NSFW_SERVICE_ENDPOINT", "http://nsfw:8000"),
|
||||
("FLUXER_MEDIA_PROXY_NSFW_THRESHOLD", "0.7"),
|
||||
])
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(StorageBackend::S3, cfg.storage.backend);
|
||||
assert_eq!("/srv/fluxer-media", cfg.storage.root);
|
||||
assert!(cfg.read_only);
|
||||
assert!(!cfg.storage.s3_force_path_style);
|
||||
assert_eq!("token", cfg.storage.s3_session_token);
|
||||
assert_eq!(3, cfg.media.max_native_transforms);
|
||||
assert_eq!(24, cfg.media.worker_queue_capacity);
|
||||
assert_eq!(2_000, cfg.media.transform_timeout_ms);
|
||||
assert_eq!("http://nsfw:8000", cfg.media.nsfw_service_endpoint);
|
||||
assert!((cfg.media.nsfw_threshold - 0.7).abs() < f32::EPSILON);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn upload_mode_requires_relay_secret() {
|
||||
let err = Config::load_from_iter([
|
||||
@@ -152,29 +76,6 @@ fn relay_mode_requires_the_relay_secret() {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn serves_upload_relay_is_true_only_for_upload_and_relay() {
|
||||
assert!(!DeploymentMode::Mp.serves_upload_relay());
|
||||
assert!(!DeploymentMode::Static.serves_upload_relay());
|
||||
assert!(DeploymentMode::Upload.serves_upload_relay());
|
||||
assert!(DeploymentMode::Relay.serves_upload_relay());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parses_upload_relay_secret() {
|
||||
let secret = general_purpose::STANDARD.encode([7u8; 32]);
|
||||
let cfg = Config::load_from_iter([
|
||||
("FLUXER_MEDIA_PROXY_SECRET_KEY", "secret"),
|
||||
("FLUXER_MEDIA_PROXY_MODE", "upload"),
|
||||
(
|
||||
"FLUXER_MEDIA_PROXY_UPLOAD_RELAY_SECRET_BASE64",
|
||||
secret.as_str(),
|
||||
),
|
||||
])
|
||||
.unwrap();
|
||||
assert_eq!(&[7u8; 32][..], cfg.upload_relay.secret.expose());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rejects_a_body_limit_above_the_spool_budget() {
|
||||
let err = Config::load_from_iter([
|
||||
@@ -217,68 +118,6 @@ fn accepts_a_body_limit_equal_to_the_spool_budget() {
|
||||
assert_eq!(4096, cfg.upload_relay.spool_max_total_bytes);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rejects_invalid_mode_env() {
|
||||
let err = Config::load_from_iter([
|
||||
("FLUXER_MEDIA_PROXY_SECRET_KEY", "secret"),
|
||||
("FLUXER_MEDIA_PROXY_MODE", "worker"),
|
||||
])
|
||||
.unwrap_err();
|
||||
assert_eq!(
|
||||
"FLUXER_MEDIA_PROXY_MODE must be one of: mp, static, upload, relay",
|
||||
err.to_string()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rejects_invalid_storage_backend_env() {
|
||||
let err = Config::load_from_iter([
|
||||
("FLUXER_MEDIA_PROXY_SECRET_KEY", "secret"),
|
||||
("FLUXER_MEDIA_PROXY_STORAGE_BACKEND", "filesystem"),
|
||||
])
|
||||
.unwrap_err();
|
||||
assert!(
|
||||
err.to_string()
|
||||
.contains("FLUXER_MEDIA_PROXY_STORAGE_BACKEND")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rejects_invalid_bool_env() {
|
||||
let err = Config::load_from_iter([
|
||||
("FLUXER_MEDIA_PROXY_SECRET_KEY", "secret"),
|
||||
("FLUXER_MEDIA_PROXY_READ_ONLY", "maybe"),
|
||||
])
|
||||
.unwrap_err();
|
||||
assert!(err.to_string().contains("FLUXER_MEDIA_PROXY_READ_ONLY"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rejects_invalid_number_env() {
|
||||
let err = Config::load_from_iter([
|
||||
("FLUXER_MEDIA_PROXY_SECRET_KEY", "secret"),
|
||||
("FLUXER_MEDIA_PROXY_WORKER_QUEUE_CAPACITY", "many"),
|
||||
])
|
||||
.unwrap_err();
|
||||
assert!(
|
||||
err.to_string()
|
||||
.contains("FLUXER_MEDIA_PROXY_WORKER_QUEUE_CAPACITY")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rejects_out_of_range_number_env() {
|
||||
let err = Config::load_from_iter([
|
||||
("FLUXER_MEDIA_PROXY_SECRET_KEY", "secret"),
|
||||
("FLUXER_MEDIA_PROXY_TRANSFORM_TIMEOUT_MS", "999999"),
|
||||
])
|
||||
.unwrap_err();
|
||||
assert!(
|
||||
err.to_string()
|
||||
.contains("FLUXER_MEDIA_PROXY_TRANSFORM_TIMEOUT_MS")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn production_media_proxy_release_env_loads() {
|
||||
let cfg = Config::load_from_iter(with_shared_runtime_env(&[
|
||||
@@ -397,126 +236,6 @@ fn production_uploads_release_env_loads() {
|
||||
assert_eq!(&[9u8; 48][..], cfg.upload_relay.secret.expose());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_transform_cache_entry_ceiling_above_the_capacity_still_boots() {
|
||||
let cfg = Config::load_from_iter([
|
||||
("FLUXER_MEDIA_PROXY_SECRET_KEY", "secret"),
|
||||
("FLUXER_MEDIA_PROXY_TRANSFORM_CACHE_BYTES", "1048576"),
|
||||
(
|
||||
"FLUXER_MEDIA_PROXY_TRANSFORM_CACHE_MAX_ENTRY_BYTES",
|
||||
"2097152",
|
||||
),
|
||||
])
|
||||
.unwrap();
|
||||
assert_eq!(1024 * 1024, cfg.media.transform_cache_capacity_bytes);
|
||||
assert_eq!(2 * 1024 * 1024, cfg.media.transform_cache_max_entry_bytes);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn both_transform_cache_env_keys_accept_their_whole_range() {
|
||||
let cfg = Config::load_from_iter([
|
||||
("FLUXER_MEDIA_PROXY_SECRET_KEY", "secret"),
|
||||
("FLUXER_MEDIA_PROXY_TRANSFORM_CACHE_BYTES", "4294967296"),
|
||||
(
|
||||
"FLUXER_MEDIA_PROXY_TRANSFORM_CACHE_MAX_ENTRY_BYTES",
|
||||
"536870912",
|
||||
),
|
||||
])
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
4 * 1024 * 1024 * 1024,
|
||||
cfg.media.transform_cache_capacity_bytes
|
||||
);
|
||||
assert_eq!(512 * 1024 * 1024, cfg.media.transform_cache_max_entry_bytes);
|
||||
|
||||
let cfg = Config::load_from_iter([
|
||||
("FLUXER_MEDIA_PROXY_SECRET_KEY", "secret"),
|
||||
("FLUXER_MEDIA_PROXY_TRANSFORM_CACHE_BYTES", "0"),
|
||||
("FLUXER_MEDIA_PROXY_TRANSFORM_CACHE_MAX_ENTRY_BYTES", "0"),
|
||||
])
|
||||
.unwrap();
|
||||
assert_eq!(0, cfg.media.transform_cache_capacity_bytes);
|
||||
assert_eq!(0, cfg.media.transform_cache_max_entry_bytes);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_disabled_transform_cache_ignores_the_entry_ceiling() {
|
||||
let cfg = Config::load_from_iter([
|
||||
("FLUXER_MEDIA_PROXY_SECRET_KEY", "secret"),
|
||||
("FLUXER_MEDIA_PROXY_TRANSFORM_CACHE_BYTES", "0"),
|
||||
])
|
||||
.unwrap();
|
||||
assert_eq!(0, cfg.media.transform_cache_capacity_bytes);
|
||||
assert_eq!(64 * 1024 * 1024, cfg.media.transform_cache_max_entry_bytes);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn every_deployment_mode_and_storage_backend_variant_parses() {
|
||||
let relay_secret = general_purpose::STANDARD.encode([3u8; 32]);
|
||||
for (raw, expected) in [
|
||||
("mp", DeploymentMode::Mp),
|
||||
("MP", DeploymentMode::Mp),
|
||||
("static", DeploymentMode::Static),
|
||||
("Static", DeploymentMode::Static),
|
||||
("upload", DeploymentMode::Upload),
|
||||
(" UPLOAD ", DeploymentMode::Upload),
|
||||
("relay", DeploymentMode::Relay),
|
||||
(" RELAY ", DeploymentMode::Relay),
|
||||
] {
|
||||
let cfg = Config::load_from_iter([
|
||||
("FLUXER_MEDIA_PROXY_SECRET_KEY", "secret"),
|
||||
("FLUXER_MEDIA_PROXY_MODE", raw),
|
||||
(
|
||||
"FLUXER_MEDIA_PROXY_UPLOAD_RELAY_SECRET_BASE64",
|
||||
relay_secret.as_str(),
|
||||
),
|
||||
])
|
||||
.unwrap();
|
||||
assert_eq!(expected, cfg.mode);
|
||||
}
|
||||
|
||||
for (raw, expected) in [
|
||||
("local", StorageBackend::Local),
|
||||
("Local", StorageBackend::Local),
|
||||
("s3", StorageBackend::S3),
|
||||
(" S3 ", StorageBackend::S3),
|
||||
] {
|
||||
let cfg = Config::load_from_iter([
|
||||
("FLUXER_MEDIA_PROXY_SECRET_KEY", "secret"),
|
||||
("FLUXER_MEDIA_PROXY_STORAGE_BACKEND", raw),
|
||||
])
|
||||
.unwrap();
|
||||
assert_eq!(expected, cfg.storage.backend);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn upload_relay_spool_keys_apply() {
|
||||
let cfg = Config::load_from_iter([
|
||||
("FLUXER_MEDIA_PROXY_SECRET_KEY", "secret"),
|
||||
(
|
||||
"FLUXER_MEDIA_PROXY_UPLOAD_RELAY_SPOOL_DIR",
|
||||
"/var/spool/flx",
|
||||
),
|
||||
(
|
||||
"FLUXER_MEDIA_PROXY_UPLOAD_RELAY_SPOOL_CHUNK_BYTES",
|
||||
"2097152",
|
||||
),
|
||||
(
|
||||
"FLUXER_MEDIA_PROXY_UPLOAD_RELAY_SPOOL_MAX_TOTAL_BYTES",
|
||||
"1073741824",
|
||||
),
|
||||
])
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(
|
||||
std::path::Path::new("/var/spool/flx"),
|
||||
cfg.upload_relay.spool_dir
|
||||
);
|
||||
assert_eq!(2 << 20, cfg.upload_relay.spool_chunk_bytes);
|
||||
assert_eq!(1 << 30, cfg.upload_relay.spool_max_total_bytes);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn debug_output_never_reveals_a_secret() {
|
||||
let relay_secret = general_purpose::STANDARD.encode(b"relay-secret-material-0123456789");
|
||||
|
||||
Reference in new issue
Block a user