mirror of
https://github.com/chatmail/relay.git
synced 2026-05-19 12:28:06 +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")
|
return open(self._inipath, "rb")
|
||||||
|
|
||||||
def get_user_maildir(self, addr):
|
def get_user_maildir(self, addr):
|
||||||
if not addr or "/" in addr:
|
if addr and addr != "." and "/" not in addr:
|
||||||
raise ValueError(addr)
|
res = self.mail_basedir.joinpath(addr).resolve()
|
||||||
return self.mail_basedir.joinpath(addr)
|
if res.is_relative_to(self.mail_basedir):
|
||||||
|
return res
|
||||||
|
raise ValueError(f"invalid address {addr!r}")
|
||||||
|
|
||||||
|
|
||||||
def write_initial_config(inipath, mail_domain):
|
def write_initial_config(inipath, mail_domain):
|
||||||
|
|||||||
@@ -43,7 +43,15 @@ def test_get_user_maildir(make_config):
|
|||||||
|
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError):
|
||||||
config.get_user_maildir("")
|
config.get_user_maildir("")
|
||||||
|
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError):
|
||||||
config.get_user_maildir(None)
|
config.get_user_maildir(None)
|
||||||
|
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError):
|
||||||
config.get_user_maildir("../some@something.testrun.org")
|
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