Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion deploy/filepack.service
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ ExecStart=/usr/local/bin/filepack \
--https \
--redirect www.filepack.com \
--redirect-http-to-https \
--restrict-uploads
--restrict-writes
Group=filepack
LimitNOFILE=65536
MemoryDenyWriteExecute=true
Expand Down
2 changes: 1 addition & 1 deletion src/authenticated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ impl<S: Send + Sync> FromRequestParts<S> for Authenticated {
return Ok(Self);
};

let admin = auth.admin.context(server_error::UploadForbidden)?;
let admin = auth.admin.context(server_error::WriteForbidden)?;

let TypedHeader(Authorization(bearer)) = parts
.extract::<TypedHeader<Authorization<Bearer>>>()
Expand Down
10 changes: 5 additions & 5 deletions src/server_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,10 @@ pub enum ServerError {
PageNotFound,
#[snafu(display("error reading body of upload with hash {hash}"))]
UploadBodyRead { hash: Hash, source: axum::Error },
#[snafu(display("uploads forbidden"))]
UploadForbidden,
#[snafu(display("expected upload with hash {expected} but got {actual}"))]
UploadHashMismatch { actual: Hash, expected: Hash },
#[snafu(display("writes forbidden"))]
WriteForbidden,
}

impl ServerError {
Expand Down Expand Up @@ -169,8 +169,8 @@ impl ServerError {
| Self::PackageRootUnverified { .. }
| Self::PageNotFound
| Self::UploadBodyRead { .. }
| Self::UploadForbidden
| Self::UploadHashMismatch { .. } => self.to_string(),
| Self::UploadHashMismatch { .. }
| Self::WriteForbidden => self.to_string(),
Self::Database { .. }
| Self::DatabaseCommit { .. }
| Self::DatabaseStorage { .. }
Expand Down Expand Up @@ -221,7 +221,7 @@ impl ServerError {
| Self::PackageNotFound { .. }
| Self::PackageNotMounted { .. }
| Self::PageNotFound => StatusCode::NOT_FOUND,
Self::UploadForbidden => StatusCode::FORBIDDEN,
Self::WriteForbidden => StatusCode::FORBIDDEN,
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/subcommand/serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ pub(crate) struct Serve {
#[arg(
help = "Admin public key",
long,
requires = "restrict_uploads",
requires = "restrict_writes",
value_name = "KEY"
)]
admin_key: Option<KeyIdentifier>,
Expand Down Expand Up @@ -150,8 +150,8 @@ pub(crate) struct Serve {
value_name = "DOMAIN"
)]
redirects: Vec<String>,
#[arg(help = "Restrict uploads to admin", long)]
restrict_uploads: bool,
#[arg(help = "Restrict writes to admin", long)]
restrict_writes: bool,
}

impl Serve {
Expand Down Expand Up @@ -415,7 +415,7 @@ impl Serve {
}
}

let auth_config = if self.restrict_uploads {
let auth_config = if self.restrict_writes {
let admin = if let Some(identifier) = &self.admin_key {
Some(Keychain::load(&options)?.identifier_public_key(identifier)?)
} else {
Expand Down Expand Up @@ -604,7 +604,7 @@ impl Default for Serve {
ready_address: None,
redirect_http_to_https: false,
redirects: Vec::new(),
restrict_uploads: false,
restrict_writes: false,
}
}
}
12 changes: 6 additions & 6 deletions src/subcommand/serve/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ impl TestServerBuilder {
}

#[test]
fn admin_key_requires_restrict_upload() {
fn admin_key_requires_restrict_writes() {
let err = Serve::try_parse_from(["filepack", "--admin-key", test::PUBLIC_KEY]).unwrap_err();
assert_eq!(err.kind(), clap::error::ErrorKind::MissingRequiredArgument);
}
Expand Down Expand Up @@ -527,7 +527,7 @@ fn artwork_response() {
}

#[test]
fn closed_server_forbids_uploads() {
fn closed_server_forbids_writes() {
TestServer::builder()
.auth_config(AuthConfig {
admin: None,
Expand All @@ -537,7 +537,7 @@ fn closed_server_forbids_uploads() {
.put(format!("/file/{}", Hash::bytes(b"bar")))
.body("bar")
.status(StatusCode::FORBIDDEN)
.assert_body("uploads forbidden")
.assert_body("writes forbidden")
.send();
}

Expand Down Expand Up @@ -2450,7 +2450,7 @@ fn redirect_omits_default_ports() {
}

#[test]
fn restricted_upload_accepts_admin_token() {
fn restricted_write_accepts_admin_token() {
let admin = PrivateKey::generate();
let hash = Hash::bytes(b"bar");
let token = Token::encode(&admin, "filepack.example").unwrap();
Expand All @@ -2472,7 +2472,7 @@ fn restricted_upload_accepts_admin_token() {
}

#[test]
fn restricted_upload_rejects_missing_header() {
fn restricted_write_rejects_missing_header() {
let admin = PrivateKey::generate();
let server = TestServer::builder()
.auth_config(AuthConfig {
Expand All @@ -2492,7 +2492,7 @@ fn restricted_upload_rejects_missing_header() {
}

#[test]
fn restricted_upload_rejects_others() {
fn restricted_write_rejects_others() {
let admin = PrivateKey::generate();
let other = PrivateKey::generate();
let server = TestServer::builder()
Expand Down
2 changes: 1 addition & 1 deletion tests/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ fn restricted_delete_succeeds_with_auth() {
"0",
"--domain",
"127.0.0.1",
"--restrict-uploads",
"--restrict-writes",
"--admin-key",
"master",
])
Expand Down
6 changes: 3 additions & 3 deletions tests/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fn restricted_upload_succeeds_with_auth() {
"0",
"--domain",
"127.0.0.1",
"--restrict-uploads",
"--restrict-writes",
"--admin-key",
"master",
])
Expand Down Expand Up @@ -95,7 +95,7 @@ fn serve_admin_key_by_name() {
"0",
"--domain",
"127.0.0.1",
"--restrict-uploads",
"--restrict-writes",
"--admin-key",
"master",
])
Expand Down Expand Up @@ -124,7 +124,7 @@ fn serve_admin_key_by_public_key() {
"0",
"--domain",
"127.0.0.1",
"--restrict-uploads",
"--restrict-writes",
"--admin-key",
PUBLIC_KEY,
])
Expand Down