mirror of
https://github.com/chatmail/relay.git
synced 2026-05-10 16:04:37 +00:00
apply code review and also catch "." as username
This commit is contained in:
@@ -38,9 +38,11 @@ class Config:
|
||||
return open(self._inipath, "rb")
|
||||
|
||||
def get_user_maildir(self, addr):
|
||||
if not addr or "/" in addr:
|
||||
raise ValueError(addr)
|
||||
return self.mail_basedir.joinpath(addr)
|
||||
if addr and addr != "." and "/" not in addr:
|
||||
res = self.mail_basedir.joinpath(addr).resolve()
|
||||
if res.is_relative_to(self.mail_basedir):
|
||||
return res
|
||||
raise ValueError(f"invalid address {addr!r}")
|
||||
|
||||
|
||||
def write_initial_config(inipath, mail_domain):
|
||||
|
||||
@@ -43,7 +43,15 @@ def test_get_user_maildir(make_config):
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
config.get_user_maildir("")
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
config.get_user_maildir(None)
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
config.get_user_maildir("../some@something.testrun.org")
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
config.get_user_maildir("..")
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
config.get_user_maildir(".")
|
||||
|
||||
Reference in New Issue
Block a user