2019-04-24 21:52:08 +00:00
|
|
|
package handlers
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2020-12-16 01:47:31 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2019-04-24 21:52:08 +00:00
|
|
|
"github.com/stretchr/testify/suite"
|
2020-05-01 06:56:42 +00:00
|
|
|
|
2021-08-11 01:04:35 +00:00
|
|
|
"github.com/authelia/authelia/v4/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-12-16 01:47:31 +00:00
|
|
|
err := s.mock.Ctx.SaveSession(userSession)
|
|
|
|
require.NoError(s.T(), err)
|
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)
|
|
|
|
}
|