2019-04-25 04:52:08 +07:00
|
|
|
package handlers
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2020-12-16 08:47:31 +07:00
|
|
|
"github.com/stretchr/testify/require"
|
2019-04-25 04:52:08 +07:00
|
|
|
"github.com/stretchr/testify/suite"
|
2020-05-01 13:56:42 +07:00
|
|
|
|
|
|
|
"github.com/authelia/authelia/internal/mocks"
|
2019-04-25 04:52:08 +07: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 23:20:40 +07:00
|
|
|
userSession.Username = testUsername
|
2020-12-16 08:47:31 +07:00
|
|
|
err := s.mock.Ctx.SaveSession(userSession)
|
|
|
|
require.NoError(s.T(), err)
|
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)
|
|
|
|
}
|