1
0
mirror of https://github.com/0rangebananaspy/authelia.git synced 2024-09-14 22:47:21 +07:00
authelia/internal/notification/smtp_login_auth_test.go
James Elliott 8aade7f40e
[MISC] Update durations to notation format and housekeeping ()
* added regulation validator
* made regulations find_time and ban_time values duration notation strings
* added DefaultRegulationConfiguration for the validator
* made session expiration and inactivity values duration notation strings
* TOTP period does not need to be converted because adjustment should be discouraged
* moved TOTP defaults to DefaultTOTPConfiguration and removed the consts
* arranged the root config validator in configuration file order
* adjusted tests for the changes
* moved duration notation docs to root of configuration
* added references to duration notation where applicable
* project wide gofmt and goimports:
* run gofmt
* run goimports -local github.com/authelia/authelia -w on all files
* Make jwt_secret error uniform and add tests
* now at 100% coverage for internal/configuration/validator/configuration.go
2020-04-05 22:37:21 +10:00

77 lines
1.9 KiB
Go

package notification
import (
"fmt"
"net/smtp"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestFullLoginAuth(t *testing.T) {
username := "john"
password := "strongpw123"
serverInfo := &smtp.ServerInfo{
Name: "mail.authelia.com",
TLS: true,
Auth: nil,
}
auth := newLoginAuth(username, password, "mail.authelia.com")
proto, _, err := auth.Start(serverInfo)
assert.Equal(t, "LOGIN", proto)
require.NoError(t, err)
toServer, err := auth.Next([]byte("Username:"), true)
assert.Equal(t, []byte(username), toServer)
require.NoError(t, err)
toServer, err = auth.Next([]byte("Password:"), true)
assert.Equal(t, []byte(password), toServer)
require.NoError(t, err)
toServer, err = auth.Next([]byte(nil), false)
assert.Equal(t, []byte(nil), toServer)
require.NoError(t, err)
toServer, err = auth.Next([]byte("test"), true)
assert.Equal(t, []byte(nil), toServer)
assert.EqualError(t, err, fmt.Sprintf("unexpected server challenge: %s", []byte("test")))
}
func TestShouldHaveUnexpectedHostname(t *testing.T) {
serverInfo := &smtp.ServerInfo{
Name: "localhost",
TLS: true,
Auth: nil,
}
auth := newLoginAuth("john", "strongpw123", "mail.authelia.com")
_, _, err := auth.Start(serverInfo)
assert.EqualError(t, err, "unexpected hostname from server")
}
func TestTLSNotNeededForLocalhost(t *testing.T) {
serverInfo := &smtp.ServerInfo{
Name: "localhost",
TLS: false,
Auth: nil,
}
auth := newLoginAuth("john", "strongpw123", "localhost")
proto, _, err := auth.Start(serverInfo)
assert.Equal(t, "LOGIN", proto)
require.NoError(t, err)
}
func TestTLSNeededForNonLocalhost(t *testing.T) {
serverInfo := &smtp.ServerInfo{
Name: "mail.authelia.com",
TLS: false,
Auth: nil,
}
auth := newLoginAuth("john", "strongpw123", "mail.authelia.com")
_, _, err := auth.Start(serverInfo)
assert.EqualError(t, err, "connection over plain-text")
}