2019-12-07 16:40:42 +00:00
|
|
|
package handlers
|
|
|
|
|
|
|
|
import (
|
2020-04-05 12:37:21 +00:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
|
2020-04-03 23:11:33 +00:00
|
|
|
"github.com/authelia/authelia/internal/configuration/schema"
|
2019-12-24 02:14:52 +00:00
|
|
|
"github.com/authelia/authelia/internal/mocks"
|
2020-04-03 23:11:33 +00:00
|
|
|
"github.com/authelia/authelia/internal/session"
|
2019-12-07 16:40:42 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type ConfigurationSuite struct {
|
|
|
|
suite.Suite
|
|
|
|
|
|
|
|
mock *mocks.MockAutheliaCtx
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ConfigurationSuite) SetupTest() {
|
|
|
|
s.mock = mocks.NewMockAutheliaCtx(s.T())
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ConfigurationSuite) TearDownTest() {
|
|
|
|
s.mock.Close()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ConfigurationSuite) TestShouldReturnConfiguredGATrackingID() {
|
|
|
|
GATrackingID := "ABC"
|
|
|
|
s.mock.Ctx.Configuration.GoogleAnalyticsTrackingID = GATrackingID
|
2020-04-03 23:11:33 +00:00
|
|
|
s.mock.Ctx.Configuration.Session.RememberMeDuration = schema.DefaultSessionConfiguration.RememberMeDuration
|
2019-12-07 16:40:42 +00:00
|
|
|
|
|
|
|
expectedBody := ConfigurationBody{
|
|
|
|
GoogleAnalyticsTrackingID: GATrackingID,
|
2020-04-04 23:28:09 +00:00
|
|
|
RememberMe: true,
|
|
|
|
ResetPassword: true,
|
2019-12-07 16:40:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ConfigurationGet(s.mock.Ctx)
|
|
|
|
s.mock.Assert200OK(s.T(), expectedBody)
|
|
|
|
}
|
2020-04-03 23:11:33 +00:00
|
|
|
|
|
|
|
func (s *ConfigurationSuite) TestShouldDisableRememberMe() {
|
|
|
|
GATrackingID := "ABC"
|
|
|
|
s.mock.Ctx.Configuration.GoogleAnalyticsTrackingID = GATrackingID
|
|
|
|
s.mock.Ctx.Configuration.Session.RememberMeDuration = "0"
|
|
|
|
s.mock.Ctx.Providers.SessionProvider = session.NewProvider(
|
|
|
|
s.mock.Ctx.Configuration.Session)
|
|
|
|
expectedBody := ConfigurationBody{
|
|
|
|
GoogleAnalyticsTrackingID: GATrackingID,
|
2020-04-04 23:28:09 +00:00
|
|
|
RememberMe: false,
|
|
|
|
ResetPassword: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
ConfigurationGet(s.mock.Ctx)
|
|
|
|
s.mock.Assert200OK(s.T(), expectedBody)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ConfigurationSuite) TestShouldDisableResetPassword() {
|
|
|
|
GATrackingID := "ABC"
|
|
|
|
s.mock.Ctx.Configuration.GoogleAnalyticsTrackingID = GATrackingID
|
|
|
|
s.mock.Ctx.Configuration.AuthenticationBackend.DisableResetPassword = true
|
|
|
|
expectedBody := ConfigurationBody{
|
|
|
|
GoogleAnalyticsTrackingID: GATrackingID,
|
|
|
|
RememberMe: true,
|
|
|
|
ResetPassword: false,
|
2020-04-03 23:11:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ConfigurationGet(s.mock.Ctx)
|
|
|
|
s.mock.Assert200OK(s.T(), expectedBody)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRunHandlerConfigurationSuite(t *testing.T) {
|
|
|
|
s := new(ConfigurationSuite)
|
|
|
|
suite.Run(t, s)
|
|
|
|
}
|