1
0
mirror of https://github.com/jhillyerd/inbucket.git synced 2025-12-17 17:47:03 +00:00

Handle IP address domains (#285)

* Add basic TestRecipientAddress tests

* Handle forward-path route spec

* Validate IP addr "domains"

* Forward-path test cases

* Add integration test

* Add IPv4 recip swaks test

* Special case domain mailbox extraction

* add IPv6 swaks test

* Formatting

Signed-off-by: James Hillyerd <james@hillyerd.com>

* Update changelog
This commit is contained in:
James Hillyerd
2022-08-07 20:13:58 -07:00
committed by GitHub
parent 344c3ffb21
commit 1f1a8b4192
10 changed files with 269 additions and 24 deletions

View File

@@ -32,6 +32,8 @@ const (
smtpHost = "127.0.0.1:2500"
)
// TODO: Add suites for domain and full addressing modes.
func TestSuite(t *testing.T) {
stopServer, err := startServer()
if err != nil {
@@ -46,6 +48,8 @@ func TestSuite(t *testing.T) {
{"basic", testBasic},
{"fullname", testFullname},
{"encodedHeader", testEncodedHeader},
{"ipv4Recipient", testIPv4Recipient},
{"ipv6Recipient", testIPv6Recipient},
}
for _, tc := range testCases {
t.Run(tc.name, tc.test)
@@ -139,6 +143,64 @@ func testEncodedHeader(t *testing.T) {
goldiff.File(t, got, "testdata", "encodedheader.golden")
}
func testIPv4Recipient(t *testing.T) {
client, err := client.New(restBaseURL)
if err != nil {
t.Fatal(err)
}
from := "fromuser@inbucket.org"
to := []string{"ip4recipient@[192.168.123.123]"}
input := readTestData("no-to.txt")
// Send mail.
err = smtpclient.SendMail(smtpHost, nil, from, to, input)
if err != nil {
t.Fatal(err)
}
// Confirm receipt.
msg, err := client.GetMessage("ip4recipient", "latest")
if err != nil {
t.Fatal(err)
}
if msg == nil {
t.Errorf("Got nil message, wanted non-nil message.")
}
// Compare to golden.
got := formatMessage(msg)
goldiff.File(t, got, "testdata", "no-to-ipv4.golden")
}
func testIPv6Recipient(t *testing.T) {
client, err := client.New(restBaseURL)
if err != nil {
t.Fatal(err)
}
from := "fromuser@inbucket.org"
to := []string{"ip6recipient@[IPv6:2001:0db8:85a3:0000:0000:8a2e:0370:7334]"}
input := readTestData("no-to.txt")
// Send mail.
err = smtpclient.SendMail(smtpHost, nil, from, to, input)
if err != nil {
t.Fatal(err)
}
// Confirm receipt.
msg, err := client.GetMessage("ip6recipient", "latest")
if err != nil {
t.Fatal(err)
}
if msg == nil {
t.Errorf("Got nil message, wanted non-nil message.")
}
// Compare to golden.
got := formatMessage(msg)
goldiff.File(t, got, "testdata", "no-to-ipv6.golden")
}
func formatMessage(m *client.Message) []byte {
b := &bytes.Buffer{}
fmt.Fprintf(b, "Mailbox: %v\n", m.Mailbox)

12
pkg/test/testdata/no-to-ipv4.golden vendored Normal file
View File

@@ -0,0 +1,12 @@
Mailbox: ip4recipient
From: <fromuser@inbucket.org>
To: [<ip4recipient@[192.168.123.123]>]
Subject: basic subject
Size: 198
BODY TEXT:
No-To message.
BODY HTML:

12
pkg/test/testdata/no-to-ipv6.golden vendored Normal file
View File

@@ -0,0 +1,12 @@
Mailbox: ip6recipient
From: <fromuser@inbucket.org>
To: [<ip6recipient@[IPv6:2001:0db8:85a3:0000:0000:8a2e:0370:7334]>]
Subject: basic subject
Size: 227
BODY TEXT:
No-To message.
BODY HTML:

4
pkg/test/testdata/no-to.txt vendored Normal file
View File

@@ -0,0 +1,4 @@
From: fromuser@inbucket.org
Subject: basic subject
No-To message.