1
0
mirror of https://blitiri.com.ar/repos/chasquid synced 2026-01-05 17:37:03 +00:00

domaininfo: New package to track domain (security) information

This patch introduces a new "domaininfo" package, which implements a
database with information about domains.  In particular, it tracks
incoming and outgoing security levels.

That information is used in incoming and outgoing SMTP to prevent
downgrades.
This commit is contained in:
Alberto Bertogli
2016-10-13 02:28:30 +01:00
parent 1d7a207e00
commit c013c98283
8 changed files with 545 additions and 11 deletions

View File

@@ -2,12 +2,30 @@ package courier
import (
"bufio"
"io/ioutil"
"net"
"net/textproto"
"os"
"testing"
"time"
"blitiri.com.ar/go/chasquid/internal/domaininfo"
)
func newSMTP(t *testing.T) (*SMTP, string) {
dir, err := ioutil.TempDir("", "smtp_test")
if err != nil {
t.Fatal(err)
}
dinfo, err := domaininfo.New(dir)
if err != nil {
t.Fatal(err)
}
return &SMTP{dinfo}, dir
}
// Fake server, to test SMTP out.
func fakeServer(t *testing.T, responses map[string]string) string {
l, err := net.Listen("tcp", "localhost:0")
@@ -72,7 +90,8 @@ func TestSMTP(t *testing.T) {
fakeMX["to"] = host
*smtpPort = port
s := &SMTP{}
s, tmpDir := newSMTP(t)
defer os.Remove(tmpDir)
err, _ := s.Deliver("me@me", "to@to", []byte("data"))
if err != nil {
t.Errorf("deliver failed: %v", err)
@@ -132,7 +151,8 @@ func TestSMTPErrors(t *testing.T) {
fakeMX["to"] = host
*smtpPort = port
s := &SMTP{}
s, tmpDir := newSMTP(t)
defer os.Remove(tmpDir)
err, _ := s.Deliver("me@me", "to@to", []byte("data"))
if err == nil {
t.Errorf("deliver not failed in case %q: %v", rs["_welcome"], err)