forked from drew/smtprelay
gofmt: Fix formatting
This commit is contained in:
8
auth.go
8
auth.go
@@ -14,8 +14,8 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type AuthUser struct {
|
type AuthUser struct {
|
||||||
username string
|
username string
|
||||||
passwordHash string
|
passwordHash string
|
||||||
allowedAddresses []string
|
allowedAddresses []string
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,8 +48,8 @@ func parseLine(line string) *AuthUser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
user := AuthUser{
|
user := AuthUser{
|
||||||
username: parts[0],
|
username: parts[0],
|
||||||
passwordHash: parts[1],
|
passwordHash: parts[1],
|
||||||
allowedAddresses: nil,
|
allowedAddresses: nil,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
50
auth_test.go
50
auth_test.go
@@ -8,7 +8,7 @@ func stringsEqual(a, b []string) bool {
|
|||||||
if len(a) != len(b) {
|
if len(a) != len(b) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
for i, _ := range a {
|
for i := range a {
|
||||||
if a[i] != b[i] {
|
if a[i] != b[i] {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@@ -18,50 +18,50 @@ func stringsEqual(a, b []string) bool {
|
|||||||
|
|
||||||
func TestParseLine(t *testing.T) {
|
func TestParseLine(t *testing.T) {
|
||||||
var tests = []struct {
|
var tests = []struct {
|
||||||
name string
|
name string
|
||||||
expectFail bool
|
expectFail bool
|
||||||
line string
|
line string
|
||||||
username string
|
username string
|
||||||
addrs []string
|
addrs []string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "Empty line",
|
name: "Empty line",
|
||||||
expectFail: true,
|
expectFail: true,
|
||||||
line: "",
|
line: "",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Too few fields",
|
name: "Too few fields",
|
||||||
expectFail: true,
|
expectFail: true,
|
||||||
line: "joe",
|
line: "joe",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Too many fields",
|
name: "Too many fields",
|
||||||
expectFail: true,
|
expectFail: true,
|
||||||
line: "joe xxx joe@example.com whatsthis",
|
line: "joe xxx joe@example.com whatsthis",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Normal case",
|
name: "Normal case",
|
||||||
line: "joe xxx joe@example.com",
|
line: "joe xxx joe@example.com",
|
||||||
username: "joe",
|
username: "joe",
|
||||||
addrs: []string{"joe@example.com"},
|
addrs: []string{"joe@example.com"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "No allowed addrs given",
|
name: "No allowed addrs given",
|
||||||
line: "joe xxx",
|
line: "joe xxx",
|
||||||
username: "joe",
|
username: "joe",
|
||||||
addrs: []string{},
|
addrs: []string{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Trailing comma",
|
name: "Trailing comma",
|
||||||
line: "joe xxx joe@example.com,",
|
line: "joe xxx joe@example.com,",
|
||||||
username: "joe",
|
username: "joe",
|
||||||
addrs: []string{"joe@example.com"},
|
addrs: []string{"joe@example.com"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Multiple allowed addrs",
|
name: "Multiple allowed addrs",
|
||||||
line: "joe xxx joe@example.com,@foo.example.com",
|
line: "joe xxx joe@example.com,@foo.example.com",
|
||||||
username: "joe",
|
username: "joe",
|
||||||
addrs: []string{"joe@example.com", "@foo.example.com"},
|
addrs: []string{"joe@example.com", "@foo.example.com"},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,12 +77,12 @@ func TestParseLine(t *testing.T) {
|
|||||||
|
|
||||||
if user.username != test.username {
|
if user.username != test.username {
|
||||||
t.Errorf("Testcase %d: Incorrect username: expected %v, got %v",
|
t.Errorf("Testcase %d: Incorrect username: expected %v, got %v",
|
||||||
i, test.username, user.username)
|
i, test.username, user.username)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !stringsEqual(user.allowedAddresses, test.addrs) {
|
if !stringsEqual(user.allowedAddresses, test.addrs) {
|
||||||
t.Errorf("Testcase %d: Incorrect addresses: expected %v, got %v",
|
t.Errorf("Testcase %d: Incorrect addresses: expected %v, got %v",
|
||||||
i, test.addrs, user.allowedAddresses)
|
i, test.addrs, user.allowedAddresses)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
22
main_test.go
22
main_test.go
@@ -24,17 +24,17 @@ func TestAddrAllowedSingle(t *testing.T) {
|
|||||||
|
|
||||||
func TestAddrAllowedDifferentCase(t *testing.T) {
|
func TestAddrAllowedDifferentCase(t *testing.T) {
|
||||||
allowedAddrs := []string{"joe@abc.com"}
|
allowedAddrs := []string{"joe@abc.com"}
|
||||||
testAddrs := []string{
|
testAddrs := []string{
|
||||||
"joe@ABC.com",
|
"joe@ABC.com",
|
||||||
"Joe@abc.com",
|
"Joe@abc.com",
|
||||||
"JOE@abc.com",
|
"JOE@abc.com",
|
||||||
"JOE@ABC.COM",
|
"JOE@ABC.COM",
|
||||||
}
|
}
|
||||||
for _, addr := range testAddrs {
|
for _, addr := range testAddrs {
|
||||||
if !addrAllowed(addr, allowedAddrs) {
|
if !addrAllowed(addr, allowedAddrs) {
|
||||||
t.Errorf("Address %v not allowed, but should be", addr)
|
t.Errorf("Address %v not allowed, but should be", addr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAddrAllowedLocal(t *testing.T) {
|
func TestAddrAllowedLocal(t *testing.T) {
|
||||||
|
|||||||
Reference in New Issue
Block a user