Skip to content

Commit 8752648

Browse files
committed
add test coverage for scheme validation
1 parent 32d0206 commit 8752648

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

remotes_test.go

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ func AssertRemoteUrlEquals(t *testing.T, expected *Remote, remotUrl string) {
1111
actual, err := ParseRemote(remotUrl)
1212
assert.Nil(t, err)
1313
assert.NotNil(t, actual)
14+
assert.Equal(t, expected.Scheme, actual.Scheme, "Scheme %s", remotUrl)
1415
assert.Equal(t, expected.Addr, actual.Addr, "Addr %s", remotUrl)
1516
assert.Equal(t, expected.Hostname, actual.Hostname, "Hostname %s", remotUrl)
1617
assert.Equal(t, expected.Port, actual.Port, "Port %s", remotUrl)
@@ -26,6 +27,7 @@ func AssertRemoteUrlEquals(t *testing.T, expected *Remote, remotUrl string) {
2627

2728
func TestValidRemoteUrls(t *testing.T) {
2829
AssertRemoteUrlEquals(t, &Remote{
30+
Scheme: "smtp",
2931
SkipVerify: false,
3032
Auth: nil,
3133
Hostname: "email.com",
@@ -35,6 +37,7 @@ func TestValidRemoteUrls(t *testing.T) {
3537
}, "smtp://email.com")
3638

3739
AssertRemoteUrlEquals(t, &Remote{
40+
Scheme: "smtp",
3841
SkipVerify: true,
3942
Auth: nil,
4043
Hostname: "email.com",
@@ -44,6 +47,7 @@ func TestValidRemoteUrls(t *testing.T) {
4447
}, "smtp://email.com?skipVerify")
4548

4649
AssertRemoteUrlEquals(t, &Remote{
50+
Scheme: "smtp",
4751
SkipVerify: false,
4852
Auth: smtp.PlainAuth("", "user", "pass", ""),
4953
Hostname: "email.com",
@@ -53,6 +57,7 @@ func TestValidRemoteUrls(t *testing.T) {
5357
}, "smtp://user:[email protected]")
5458

5559
AssertRemoteUrlEquals(t, &Remote{
60+
Scheme: "smtp",
5661
SkipVerify: false,
5762
Auth: LoginAuth("user", "pass"),
5863
Hostname: "email.com",
@@ -62,6 +67,7 @@ func TestValidRemoteUrls(t *testing.T) {
6267
}, "smtp://user:[email protected]?auth=login")
6368

6469
AssertRemoteUrlEquals(t, &Remote{
70+
Scheme: "smtp",
6571
SkipVerify: false,
6672
Auth: LoginAuth("user", "pass"),
6773
Hostname: "email.com",
@@ -71,6 +77,7 @@ func TestValidRemoteUrls(t *testing.T) {
7177
}, "smtp://user:[email protected]/[email protected]?auth=login")
7278

7379
AssertRemoteUrlEquals(t, &Remote{
80+
Scheme: "smtps",
7481
SkipVerify: false,
7582
Auth: LoginAuth("user", "pass"),
7683
Hostname: "email.com",
@@ -80,11 +87,28 @@ func TestValidRemoteUrls(t *testing.T) {
8087
}, "smtps://user:[email protected]/[email protected]?auth=login")
8188

8289
AssertRemoteUrlEquals(t, &Remote{
90+
Scheme: "smtps",
8391
SkipVerify: true,
8492
Auth: LoginAuth("user", "pass"),
8593
Hostname: "email.com",
8694
Port: "8425",
8795
Addr: "email.com:8425",
8896
Sender: "[email protected]",
89-
}, "smtp://user:[email protected]:8425/[email protected]?auth=login&skipVerify")
97+
}, "smtps://user:[email protected]:8425/[email protected]?auth=login&skipVerify")
98+
99+
AssertRemoteUrlEquals(t, &Remote{
100+
Scheme: "starttls",
101+
SkipVerify: true,
102+
Auth: LoginAuth("user", "pass"),
103+
Hostname: "email.com",
104+
Port: "8425",
105+
Addr: "email.com:8425",
106+
Sender: "[email protected]",
107+
}, "starttls://user:[email protected]:8425/[email protected]?auth=login&skipVerify")
108+
}
109+
110+
func TestMissingScheme(t *testing.T) {
111+
_, err := ParseRemote("http://user:[email protected]:8425/[email protected]")
112+
assert.NotNil(t, err, "Err must be present")
113+
assert.Equal(t, err.Error(), "'http' is not a supported relay scheme")
90114
}

0 commit comments

Comments
 (0)