Compare commits

...

4 Commits

Author SHA1 Message Date
_ da581f452d remove that stupid bad passwords file 2022-04-20 12:31:35 +00:00
_ c2299ab39a fix up the tests 2022-04-20 12:25:44 +00:00
_ daec2b3887 ⬆️ use newer Rust in relay app packages 2022-04-20 12:21:17 +00:00
_ 2ccd5167d9 🔧 allow hiding the audit log on the relay 2022-04-20 12:14:06 +00:00
6 changed files with 23 additions and 46 deletions

View File

@ -1,8 +1,8 @@
# https://whitfin.io/speeding-up-rust-docker-builds/ # https://whitfin.io/speeding-up-rust-docker-builds/
# TODO: https://stackoverflow.com/questions/57389547/how-to-define-the-context-for-a-docker-build-as-a-specific-commit-on-one-of-the # TODO: https://stackoverflow.com/questions/57389547/how-to-define-the-context-for-a-docker-build-as-a-specific-commit-on-one-of-the
# rust:1.50-slim-buster # rust:1.60-slim-buster
FROM rust@sha256:5dd85eb0c60bbdea14a6ecba1f6fe4a0f5c878bcf06d2cdfae0aff3a19ed4b10 as build FROM rust@sha256:c0f26a0b299a8a74cd87be0b4bd291d55aa292198bab1bafd906edd8665edb82 as build
WORKDIR / WORKDIR /
ENV USER root ENV USER root

View File

@ -143,6 +143,7 @@ pub mod file {
pub scraper_keys: Option <Vec <ScraperKey>>, pub scraper_keys: Option <Vec <ScraperKey>>,
pub news_url: Option <String>, pub news_url: Option <String>,
pub hide_audit_log: Option <bool>,
} }
} }
@ -156,6 +157,7 @@ pub struct Config {
pub servers: HashMap <String, file::Server>, pub servers: HashMap <String, file::Server>,
pub scraper_keys: HashMap <String, ScraperKey>, pub scraper_keys: HashMap <String, ScraperKey>,
pub news_url: Option <String>, pub news_url: Option <String>,
pub hide_audit_log: bool,
} }
impl Default for Config { impl Default for Config {
@ -167,6 +169,7 @@ impl Default for Config {
servers: Default::default (), servers: Default::default (),
scraper_keys: Default::default (), scraper_keys: Default::default (),
news_url: None, news_url: None,
hide_audit_log: false,
} }
} }
} }
@ -195,6 +198,7 @@ impl TryFrom <file::Config> for Config {
servers, servers,
scraper_keys, scraper_keys,
news_url: f.news_url, news_url: f.news_url,
hide_audit_log: f.hide_audit_log.unwrap_or (false),
}) })
} }
} }

View File

@ -433,6 +433,13 @@ async fn handle_audit_log (
handlebars: Arc <Handlebars <'static>> handlebars: Arc <Handlebars <'static>>
) -> Result <Response <Body>, RequestError> ) -> Result <Response <Body>, RequestError>
{ {
{
let cfg = state.config.read ().await;
if cfg.hide_audit_log {
return Ok (error_reply (StatusCode::FORBIDDEN, "Forbidden")?);
}
}
let page = handle_audit_log_internal (state).await; let page = handle_audit_log_internal (state).await;
let s = handlebars.render ("audit_log", &page)?; let s = handlebars.render ("audit_log", &page)?;

File diff suppressed because one or more lines are too long

View File

@ -67,29 +67,25 @@ fn file_server () {
let rt = Runtime::new ().expect ("Can't create runtime"); let rt = Runtime::new ().expect ("Can't create runtime");
rt.block_on (async { rt.block_on (async {
let file_server_root = PathBuf::from ("./"); let files_root = PathBuf::from ("./");
let dirs_roots = Default::default ();
let file_server_root = internal::FileRoots {
files: &files_root,
dirs: &dirs_roots,
};
let headers = Default::default (); let headers = Default::default ();
{ {
use internal::Response::*; use internal::Response::*;
use crate::file_server::FileServerError; use crate::file_server::FileServerError;
let bad_passwords_path = "/files/src/bad_passwords.txt";
for (uri_path, expected) in vec! [ for (uri_path, expected) in vec! [
("/", Root), ("/", Root),
("/files", NotFound), ("/files", NotFound),
("/files/?", InvalidQuery), ("/files/?", InvalidQuery),
("/files/src", Redirect ("src/".to_string ())), ("/files/src", Redirect ("src/".to_string ())),
("/files/src/?", InvalidQuery), ("/files/src/?", InvalidQuery),
(bad_passwords_path, ServeFile (internal::ServeFileParams {
send_body: true,
range: range::ValidParsed {
range: 0..1_048_576,
range_requested: false,
},
file: AlwaysEqual::testing_blank (),
})),
("/files/test/test.md", ServeFile (internal::ServeFileParams { ("/files/test/test.md", ServeFile (internal::ServeFileParams {
send_body: true, send_body: true,
range: range::ValidParsed { range: range::ValidParsed {
@ -100,7 +96,7 @@ fn file_server () {
})), })),
] { ] {
let resp = internal::serve_all ( let resp = internal::serve_all (
&file_server_root, file_server_root,
Method::Get, Method::Get,
uri_path, uri_path,
&headers, &headers,
@ -117,7 +113,7 @@ fn file_server () {
}), }),
] { ] {
let resp = internal::serve_all ( let resp = internal::serve_all (
&file_server_root, file_server_root,
Method::Get, Method::Get,
uri_path, uri_path,
&headers, &headers,
@ -126,35 +122,6 @@ fn file_server () {
checker (resp.unwrap_err ()); checker (resp.unwrap_err ());
} }
let resp = internal::serve_all (
&file_server_root,
Method::Get,
bad_passwords_path,
&hashmap! {
"range".into () => b"bytes=0-2000000".to_vec (),
},
None
).await;
assert_eq! (resp.expect ("Should be Ok (_)"), RangeNotSatisfiable (1_048_576));
let resp = internal::serve_all (
&file_server_root,
Method::Head,
bad_passwords_path,
&headers,
None
).await;
assert_eq! (resp.expect ("Should be Ok (_)"), ServeFile (internal::ServeFileParams {
send_body: false,
range: range::ValidParsed {
range: 0..1_048_576,
range_requested: false,
},
file: AlwaysEqual::testing_blank (),
}));
} }
}); });
} }

View File

@ -151,7 +151,7 @@ impl TestingServer {
let (stop_tx, stop_rx) = oneshot::channel (); let (stop_tx, stop_rx) = oneshot::channel ();
let task = { let task = {
spawn (async move { spawn (async move {
ptth_server::run_server (config_file, stop_rx, None, None).await ptth_server::run_server (config_file, stop_rx, None, None, None).await
}) })
}; };