2019-04-24 21:52:08 +00:00
|
|
|
package handlers
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/suite"
|
2020-05-01 06:56:42 +00:00
|
|
|
|
|
|
|
"github.com/authelia/authelia/internal/mocks"
|
2019-04-24 21:52:08 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type LogoutSuite struct {
|
|
|
|
suite.Suite
|
|
|
|
|
|
|
|
mock *mocks.MockAutheliaCtx
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *LogoutSuite) SetupTest() {
|
|
|
|
s.mock = mocks.NewMockAutheliaCtx(s.T())
|
|
|
|
userSession := s.mock.Ctx.GetSession()
|
2020-05-02 16:20:40 +00:00
|
|
|
userSession.Username = testUsername
|
2020-04-22 03:33:14 +00:00
|
|
|
s.mock.Ctx.SaveSession(userSession) //nolint:errcheck // TODO: Legacy code, consider refactoring time permitting.
|
2019-04-24 21:52:08 +00: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)
|
|
|
|
}
|