Compare commits

..

No commits in common. "da581f452df9d14b59f1b52ecd9ce5477da020ea" and "734602244d272ba2bb8dd97a6882d7145e3d701f" have entirely different histories.

6 changed files with 46 additions and 23 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.60-slim-buster # rust:1.50-slim-buster
FROM rust@sha256:c0f26a0b299a8a74cd87be0b4bd291d55aa292198bab1bafd906edd8665edb82 as build FROM rust@sha256:5dd85eb0c60bbdea14a6ecba1f6fe4a0f5c878bcf06d2cdfae0aff3a19ed4b10 as build
WORKDIR / WORKDIR /
ENV USER root ENV USER root

View File

@ -143,7 +143,6 @@ 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>,
} }
} }
@ -157,7 +156,6 @@ 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 {
@ -169,7 +167,6 @@ 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,
} }
} }
} }
@ -198,7 +195,6 @@ 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,13 +433,6 @@ 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,25 +67,29 @@ 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 files_root = PathBuf::from ("./"); let file_server_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 {
@ -96,7 +100,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,
@ -113,7 +117,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,
@ -122,6 +126,35 @@ 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, None).await ptth_server::run_server (config_file, stop_rx, None, None).await
}) })
}; };