mirror of
https://blitiri.com.ar/repos/chasquid
synced 2026-01-05 17:37:03 +00:00
chasquid: Fail at RCPT TO time if a user does not exist
It's more convenient and in line with standard practice to fail RCPT TO if the user does not exist. This involves making the server and client aware of aliases, but it doesn't end up being very convoluted, and simplifies other code.
This commit is contained in:
@@ -202,6 +202,14 @@ func (db *DB) RemoveUser(name string) bool {
|
||||
return present
|
||||
}
|
||||
|
||||
// HasUser returns true if the user is present, False otherwise.
|
||||
func (db *DB) HasUser(name string) bool {
|
||||
db.mu.Lock()
|
||||
_, present := db.db.Users[name]
|
||||
db.mu.Unlock()
|
||||
return present
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
// Encryption schemes
|
||||
//
|
||||
|
||||
@@ -283,3 +283,29 @@ func TestRemoveUser(t *testing.T) {
|
||||
t.Errorf("removal of unknown user succeeded")
|
||||
}
|
||||
}
|
||||
|
||||
func TestHasUser(t *testing.T) {
|
||||
fname := mustCreateDB(t, "")
|
||||
defer removeIfSuccessful(t, fname)
|
||||
db := mustLoad(t, fname)
|
||||
|
||||
if ok := db.HasUser("unknown"); ok {
|
||||
t.Errorf("unknown user exists")
|
||||
}
|
||||
|
||||
if err := db.AddUser("user", "passwd"); err != nil {
|
||||
t.Fatalf("error adding user: %v", err)
|
||||
}
|
||||
|
||||
if ok := db.HasUser("unknown"); ok {
|
||||
t.Errorf("unknown user exists")
|
||||
}
|
||||
|
||||
if ok := db.HasUser("user"); !ok {
|
||||
t.Errorf("known user does not exist")
|
||||
}
|
||||
|
||||
if ok := db.HasUser("user"); !ok {
|
||||
t.Errorf("known user does not exist")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user