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
|
|
|
|
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())
|
2023-01-25 09:36:40 +00:00
|
|
|
provider, err := s.mock.Ctx.GetSessionProvider()
|
|
|
|
s.Assert().NoError(err)
|
|
|
|
|
|
|
|
userSession, err := provider.GetSession(s.mock.Ctx.RequestCtx)
|
|
|
|
s.Assert().NoError(err)
|
|
|
|
|
2020-05-02 16:20:40 +00:00
|
|
|
userSession.Username = testUsername
|
2023-01-25 09:36:40 +00:00
|
|
|
s.Assert().NoError(provider.SaveSession(s.mock.Ctx.RequestCtx, userSession))
|
2019-04-24 21:52:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *LogoutSuite) TearDownTest() {
|
|
|
|
s.mock.Close()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *LogoutSuite) TestShouldDestroySession() {
|
2022-04-08 04:13:47 +00:00
|
|
|
LogoutPOST(s.mock.Ctx)
|
2019-04-24 21:52:08 +00:00
|
|
|
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)
|
|
|
|
}
|