Skip to content

Commit f8a7873

Browse files
authored
fix: perms on dufs -A -a @/:ro (#619)
1 parent 7f82698 commit f8a7873

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

src/auth.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ lazy_static! {
3030

3131
#[derive(Debug, Clone, PartialEq)]
3232
pub struct AccessControl {
33+
empty: bool,
3334
use_hashed_password: bool,
3435
users: IndexMap<String, (String, AccessPaths)>,
3536
anonymous: Option<AccessPaths>,
@@ -38,6 +39,7 @@ pub struct AccessControl {
3839
impl Default for AccessControl {
3940
fn default() -> Self {
4041
AccessControl {
42+
empty: true,
4143
use_hashed_password: false,
4244
users: IndexMap::new(),
4345
anonymous: Some(AccessPaths::new(AccessPerm::ReadWrite)),
@@ -48,7 +50,7 @@ impl Default for AccessControl {
4850
impl AccessControl {
4951
pub fn new(raw_rules: &[&str]) -> Result<Self> {
5052
if raw_rules.is_empty() {
51-
return Ok(Default::default());
53+
return Ok(Self::default());
5254
}
5355
let new_raw_rules = split_rules(raw_rules);
5456
let mut use_hashed_password = false;
@@ -93,13 +95,14 @@ impl AccessControl {
9395
}
9496

9597
Ok(Self {
98+
empty: false,
9699
use_hashed_password,
97100
users,
98101
anonymous,
99102
})
100103
}
101104

102-
pub fn exist(&self) -> bool {
105+
pub fn has_users(&self) -> bool {
103106
!self.users.is_empty()
104107
}
105108

@@ -111,7 +114,7 @@ impl AccessControl {
111114
token: Option<&String>,
112115
guard_options: bool,
113116
) -> (Option<String>, Option<AccessPaths>) {
114-
if self.users.is_empty() {
117+
if self.empty {
115118
return (None, Some(AccessPaths::new(AccessPerm::ReadWrite)));
116119
}
117120

src/server.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -962,7 +962,7 @@ impl Server {
962962
uri_prefix: self.args.uri_prefix.clone(),
963963
allow_upload: self.args.allow_upload,
964964
allow_delete: self.args.allow_delete,
965-
auth: self.args.auth.exist(),
965+
auth: self.args.auth.has_users(),
966966
user,
967967
editable,
968968
};
@@ -1226,7 +1226,7 @@ impl Server {
12261226
allow_search: self.args.allow_search,
12271227
allow_archive: self.args.allow_archive,
12281228
dir_exists: exist,
1229-
auth: self.args.auth.exist(),
1229+
auth: self.args.auth.has_users(),
12301230
user,
12311231
paths,
12321232
};

tests/auth.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,24 @@ fn auth_skip_if_no_auth_user(server: TestServer) -> Result<(), Error> {
125125
Ok(())
126126
}
127127

128+
#[rstest]
129+
fn auth_no_skip_if_anonymous(
130+
#[with(&["--auth", "@/:ro"])] server: TestServer,
131+
) -> Result<(), Error> {
132+
let url = format!("{}index.html", server.url());
133+
let resp = fetch!(b"GET", &url)
134+
.basic_auth("user", Some("pass"))
135+
.send()?;
136+
assert_eq!(resp.status(), 401);
137+
let resp = fetch!(b"GET", &url).send()?;
138+
assert_eq!(resp.status(), 200);
139+
let resp = fetch!(b"DELETE", &url)
140+
.basic_auth("user", Some("pass"))
141+
.send()?;
142+
assert_eq!(resp.status(), 401);
143+
Ok(())
144+
}
145+
128146
#[rstest]
129147
fn auth_check(
130148
#[with(&["--auth", "user:pass@/:rw", "--auth", "user2:pass2@/", "-A"])] server: TestServer,

0 commit comments

Comments
 (0)