2019-04-25 04:52:08 +07:00
|
|
|
package handlers
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
2019-12-24 09:14:52 +07:00
|
|
|
"github.com/authelia/authelia/internal/mocks"
|
2019-04-25 04:52:08 +07:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
)
|
|
|
|
|
|
|
|
type LogoutSuite struct {
|
|
|
|
suite.Suite
|
|
|
|
|
|
|
|
mock *mocks.MockAutheliaCtx
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *LogoutSuite) SetupTest() {
|
|
|
|
s.mock = mocks.NewMockAutheliaCtx(s.T())
|
|
|
|
userSession := s.mock.Ctx.GetSession()
|
|
|
|
userSession.Username = "john"
|
2020-04-22 10:33:14 +07:00
|
|
|
s.mock.Ctx.SaveSession(userSession) //nolint:errcheck // TODO: Legacy code, consider refactoring time permitting.
|
2019-04-25 04:52:08 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *LogoutSuite) TearDownTest() {
|
|
|
|
s.mock.Close()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *LogoutSuite) TestShouldDestroySession() {
|
|
|
|
LogoutPost(s.mock.Ctx)
|
|
|
|
b := s.mock.Ctx.Response.Header.PeekCookie("authelia_session")
|
|
|
|
|
|
|
|
// Reset the cookie, meaning it resets the value and expires the cookie by setting
|
|
|
|
// date to one minute in the past.
|
|
|
|
assert.True(s.T(), strings.HasPrefix(string(b), "authelia_session=;"))
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRunLogoutSuite(t *testing.T) {
|
|
|
|
s := new(LogoutSuite)
|
|
|
|
suite.Run(t, s)
|
|
|
|
}
|