forked from drew/smtprelay
add test coverage for scheme validation
This commit is contained in:
@@ -11,6 +11,7 @@ func AssertRemoteUrlEquals(t *testing.T, expected *Remote, remotUrl string) {
|
|||||||
actual, err := ParseRemote(remotUrl)
|
actual, err := ParseRemote(remotUrl)
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.NotNil(t, actual)
|
assert.NotNil(t, actual)
|
||||||
|
assert.Equal(t, expected.Scheme, actual.Scheme, "Scheme %s", remotUrl)
|
||||||
assert.Equal(t, expected.Addr, actual.Addr, "Addr %s", remotUrl)
|
assert.Equal(t, expected.Addr, actual.Addr, "Addr %s", remotUrl)
|
||||||
assert.Equal(t, expected.Hostname, actual.Hostname, "Hostname %s", remotUrl)
|
assert.Equal(t, expected.Hostname, actual.Hostname, "Hostname %s", remotUrl)
|
||||||
assert.Equal(t, expected.Port, actual.Port, "Port %s", remotUrl)
|
assert.Equal(t, expected.Port, actual.Port, "Port %s", remotUrl)
|
||||||
@@ -26,6 +27,7 @@ func AssertRemoteUrlEquals(t *testing.T, expected *Remote, remotUrl string) {
|
|||||||
|
|
||||||
func TestValidRemoteUrls(t *testing.T) {
|
func TestValidRemoteUrls(t *testing.T) {
|
||||||
AssertRemoteUrlEquals(t, &Remote{
|
AssertRemoteUrlEquals(t, &Remote{
|
||||||
|
Scheme: "smtp",
|
||||||
SkipVerify: false,
|
SkipVerify: false,
|
||||||
Auth: nil,
|
Auth: nil,
|
||||||
Hostname: "email.com",
|
Hostname: "email.com",
|
||||||
@@ -35,6 +37,7 @@ func TestValidRemoteUrls(t *testing.T) {
|
|||||||
}, "smtp://email.com")
|
}, "smtp://email.com")
|
||||||
|
|
||||||
AssertRemoteUrlEquals(t, &Remote{
|
AssertRemoteUrlEquals(t, &Remote{
|
||||||
|
Scheme: "smtp",
|
||||||
SkipVerify: true,
|
SkipVerify: true,
|
||||||
Auth: nil,
|
Auth: nil,
|
||||||
Hostname: "email.com",
|
Hostname: "email.com",
|
||||||
@@ -44,6 +47,7 @@ func TestValidRemoteUrls(t *testing.T) {
|
|||||||
}, "smtp://email.com?skipVerify")
|
}, "smtp://email.com?skipVerify")
|
||||||
|
|
||||||
AssertRemoteUrlEquals(t, &Remote{
|
AssertRemoteUrlEquals(t, &Remote{
|
||||||
|
Scheme: "smtp",
|
||||||
SkipVerify: false,
|
SkipVerify: false,
|
||||||
Auth: smtp.PlainAuth("", "user", "pass", ""),
|
Auth: smtp.PlainAuth("", "user", "pass", ""),
|
||||||
Hostname: "email.com",
|
Hostname: "email.com",
|
||||||
@@ -53,6 +57,7 @@ func TestValidRemoteUrls(t *testing.T) {
|
|||||||
}, "smtp://user:pass@email.com")
|
}, "smtp://user:pass@email.com")
|
||||||
|
|
||||||
AssertRemoteUrlEquals(t, &Remote{
|
AssertRemoteUrlEquals(t, &Remote{
|
||||||
|
Scheme: "smtp",
|
||||||
SkipVerify: false,
|
SkipVerify: false,
|
||||||
Auth: LoginAuth("user", "pass"),
|
Auth: LoginAuth("user", "pass"),
|
||||||
Hostname: "email.com",
|
Hostname: "email.com",
|
||||||
@@ -62,6 +67,7 @@ func TestValidRemoteUrls(t *testing.T) {
|
|||||||
}, "smtp://user:pass@email.com?auth=login")
|
}, "smtp://user:pass@email.com?auth=login")
|
||||||
|
|
||||||
AssertRemoteUrlEquals(t, &Remote{
|
AssertRemoteUrlEquals(t, &Remote{
|
||||||
|
Scheme: "smtp",
|
||||||
SkipVerify: false,
|
SkipVerify: false,
|
||||||
Auth: LoginAuth("user", "pass"),
|
Auth: LoginAuth("user", "pass"),
|
||||||
Hostname: "email.com",
|
Hostname: "email.com",
|
||||||
@@ -71,6 +77,7 @@ func TestValidRemoteUrls(t *testing.T) {
|
|||||||
}, "smtp://user:pass@email.com/sender@website.com?auth=login")
|
}, "smtp://user:pass@email.com/sender@website.com?auth=login")
|
||||||
|
|
||||||
AssertRemoteUrlEquals(t, &Remote{
|
AssertRemoteUrlEquals(t, &Remote{
|
||||||
|
Scheme: "smtps",
|
||||||
SkipVerify: false,
|
SkipVerify: false,
|
||||||
Auth: LoginAuth("user", "pass"),
|
Auth: LoginAuth("user", "pass"),
|
||||||
Hostname: "email.com",
|
Hostname: "email.com",
|
||||||
@@ -80,11 +87,28 @@ func TestValidRemoteUrls(t *testing.T) {
|
|||||||
}, "smtps://user:pass@email.com/sender@website.com?auth=login")
|
}, "smtps://user:pass@email.com/sender@website.com?auth=login")
|
||||||
|
|
||||||
AssertRemoteUrlEquals(t, &Remote{
|
AssertRemoteUrlEquals(t, &Remote{
|
||||||
|
Scheme: "smtps",
|
||||||
SkipVerify: true,
|
SkipVerify: true,
|
||||||
Auth: LoginAuth("user", "pass"),
|
Auth: LoginAuth("user", "pass"),
|
||||||
Hostname: "email.com",
|
Hostname: "email.com",
|
||||||
Port: "8425",
|
Port: "8425",
|
||||||
Addr: "email.com:8425",
|
Addr: "email.com:8425",
|
||||||
Sender: "sender@website.com",
|
Sender: "sender@website.com",
|
||||||
}, "smtp://user:pass@email.com:8425/sender@website.com?auth=login&skipVerify")
|
}, "smtps://user:pass@email.com:8425/sender@website.com?auth=login&skipVerify")
|
||||||
|
|
||||||
|
AssertRemoteUrlEquals(t, &Remote{
|
||||||
|
Scheme: "starttls",
|
||||||
|
SkipVerify: true,
|
||||||
|
Auth: LoginAuth("user", "pass"),
|
||||||
|
Hostname: "email.com",
|
||||||
|
Port: "8425",
|
||||||
|
Addr: "email.com:8425",
|
||||||
|
Sender: "sender@website.com",
|
||||||
|
}, "starttls://user:pass@email.com:8425/sender@website.com?auth=login&skipVerify")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestMissingScheme(t *testing.T) {
|
||||||
|
_, err := ParseRemote("http://user:pass@email.com:8425/sender@website.com")
|
||||||
|
assert.NotNil(t, err, "Err must be present")
|
||||||
|
assert.Equal(t, err.Error(), "'http' is not a supported relay scheme")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user