mirror of
https://github.com/fluxerapp/fluxer
synced 2026-10-17 21:15:32 +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
+1
-121
@@ -1,8 +1,7 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
use crate::manifest::{
|
||||
ANY_HOST, DEV_PROXY_GATEWAY_PORTS_ENV, DEV_PROXY_PORT, GATEWAY_PORT, LOCAL_APP_URL,
|
||||
PROXY_ROUTES, ProxyRoute,
|
||||
DEV_PROXY_GATEWAY_PORTS_ENV, GATEWAY_PORT, LOCAL_APP_URL, PROXY_ROUTES, ProxyRoute,
|
||||
};
|
||||
use anyhow::{Context, Result, bail};
|
||||
use axum::{
|
||||
@@ -664,122 +663,3 @@ pub fn rewrite_head(
|
||||
lines.push(String::new());
|
||||
lines.join("\r\n").into_bytes()
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn default_bind() -> (&'static str, u16) {
|
||||
(ANY_HOST, DEV_PROXY_PORT)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn routes_and_rewrites_prefixes() {
|
||||
let api = route_for_path("/api/users?x=1");
|
||||
assert_eq!(api.prefix, "/api");
|
||||
assert_eq!(rewrite_path("/api/users?x=1", api), "/users?x=1");
|
||||
let asset = route_for_path("/assets/app.js");
|
||||
assert_eq!(rewrite_path("/assets/app.js", asset), "/assets/app.js");
|
||||
let lazy = route_for_path("/lazy-compilation-using-foo");
|
||||
assert_eq!(lazy.prefix, "/lazy-compilation-using-");
|
||||
let devmail = route_for_path("/devmail/messages");
|
||||
assert_eq!(devmail.prefix, "/devmail");
|
||||
assert_eq!(
|
||||
rewrite_path("/devmail/messages?x=1", devmail),
|
||||
"/devmail/messages?x=1"
|
||||
);
|
||||
let admin = route_for_path("/admin/users");
|
||||
assert_eq!(admin.prefix, "/admin");
|
||||
assert_eq!(rewrite_path("/admin/users", admin), "/users");
|
||||
let absolute_gateway = route_for_path("https://dev.example.test/gateway?v=1&encoding=json");
|
||||
assert_eq!(absolute_gateway.prefix, "/gateway");
|
||||
assert_eq!(
|
||||
rewrite_path(
|
||||
"https://dev.example.test/gateway?v=1&encoding=json",
|
||||
absolute_gateway
|
||||
),
|
||||
"/?v=1&encoding=json"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rewrites_host_connection_and_forwarded_for() {
|
||||
let request = RequestHead {
|
||||
method: "GET".to_owned(),
|
||||
path: "/api/_health".to_owned(),
|
||||
version: "HTTP/1.1".to_owned(),
|
||||
headers: vec![
|
||||
("Host".to_owned(), "localhost:8088".to_owned()),
|
||||
("Connection".to_owned(), "keep-alive".to_owned()),
|
||||
("X-Forwarded-For".to_owned(), "1.1.1.1".to_owned()),
|
||||
],
|
||||
};
|
||||
let head = String::from_utf8(rewrite_head(
|
||||
&request,
|
||||
route_for_path("/api/_health"),
|
||||
Some("api"),
|
||||
Some(8080),
|
||||
Some("2.2.2.2"),
|
||||
))
|
||||
.unwrap();
|
||||
assert!(head.contains("GET /_health HTTP/1.1\r\n"));
|
||||
assert!(head.contains("Host: api:8080\r\n"));
|
||||
assert!(head.contains("Connection: close\r\n"));
|
||||
assert!(head.contains("X-Forwarded-For: 1.1.1.1, 2.2.2.2\r\n"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn redirects_local_html_navigation_to_public_tunnel_url() {
|
||||
let request = RequestHead {
|
||||
method: "GET".to_owned(),
|
||||
path: "/channels/@me?x=1".to_owned(),
|
||||
version: "HTTP/1.1".to_owned(),
|
||||
headers: vec![
|
||||
("Host".to_owned(), "localhost:8088".to_owned()),
|
||||
(
|
||||
"Accept".to_owned(),
|
||||
"text/html,application/xhtml+xml".to_owned(),
|
||||
),
|
||||
],
|
||||
};
|
||||
assert_eq!(
|
||||
redirect_location_for_public_url(&request, "https://dev.example.test"),
|
||||
Some("https://dev.example.test/channels/@me?x=1".to_owned())
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn public_tunnel_redirect_ignores_assets_and_local_public_url() {
|
||||
let asset = RequestHead {
|
||||
method: "GET".to_owned(),
|
||||
path: "/avatars/4.png".to_owned(),
|
||||
version: "HTTP/1.1".to_owned(),
|
||||
headers: vec![
|
||||
("Host".to_owned(), "localhost:8088".to_owned()),
|
||||
(
|
||||
"Accept".to_owned(),
|
||||
"image/avif,image/webp,image/apng,image/*,*/*;q=0.8".to_owned(),
|
||||
),
|
||||
],
|
||||
};
|
||||
assert_eq!(
|
||||
redirect_location_for_public_url(&asset, "https://dev.example.test"),
|
||||
None
|
||||
);
|
||||
|
||||
let local_public_url = RequestHead {
|
||||
method: "GET".to_owned(),
|
||||
path: "/channels/@me".to_owned(),
|
||||
version: "HTTP/1.1".to_owned(),
|
||||
headers: vec![
|
||||
("Host".to_owned(), "localhost:8088".to_owned()),
|
||||
("Accept".to_owned(), "text/html".to_owned()),
|
||||
],
|
||||
};
|
||||
assert_eq!(
|
||||
redirect_location_for_public_url(&local_public_url, LOCAL_APP_URL),
|
||||
None
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user