2019-12-07 23:40:42 +07:00
|
|
|
package handlers
|
|
|
|
|
|
|
|
import (
|
2020-04-05 19:37:21 +07:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
|
2020-04-04 06:11:33 +07:00
|
|
|
"github.com/authelia/authelia/internal/configuration/schema"
|
2019-12-24 09:14:52 +07:00
|
|
|
"github.com/authelia/authelia/internal/mocks"
|
2020-04-04 06:11:33 +07:00
|
|
|
"github.com/authelia/authelia/internal/session"
|
2019-12-07 23:40:42 +07: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() {
|
2020-05-02 23:20:40 +07:00
|
|
|
GATrackingID := testGATrackingID
|
2019-12-07 23:40:42 +07:00
|
|
|
s.mock.Ctx.Configuration.GoogleAnalyticsTrackingID = GATrackingID
|
2020-04-04 06:11:33 +07:00
|
|
|
s.mock.Ctx.Configuration.Session.RememberMeDuration = schema.DefaultSessionConfiguration.RememberMeDuration
|
2019-12-07 23:40:42 +07:00
|
|
|
|
|
|
|
expectedBody := ConfigurationBody{
|
|
|
|
GoogleAnalyticsTrackingID: GATrackingID,
|
2020-04-05 06:28:09 +07:00
|
|
|
RememberMe: true,
|
|
|
|
ResetPassword: true,
|
2019-12-07 23:40:42 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
ConfigurationGet(s.mock.Ctx)
|
|
|
|
s.mock.Assert200OK(s.T(), expectedBody)
|
|
|
|
}
|
2020-04-04 06:11:33 +07:00
|
|
|
|
|
|
|
func (s *ConfigurationSuite) TestShouldDisableRememberMe() {
|
2020-05-02 23:20:40 +07:00
|
|
|
GATrackingID := testGATrackingID
|
2020-04-04 06:11:33 +07:00
|
|
|
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-05 06:28:09 +07:00
|
|
|
RememberMe: false,
|
|
|
|
ResetPassword: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
ConfigurationGet(s.mock.Ctx)
|
|
|
|
s.mock.Assert200OK(s.T(), expectedBody)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ConfigurationSuite) TestShouldDisableResetPassword() {
|
2020-05-02 23:20:40 +07:00
|
|
|
GATrackingID := testGATrackingID
|
2020-04-05 06:28:09 +07:00
|
|
|
s.mock.Ctx.Configuration.GoogleAnalyticsTrackingID = GATrackingID
|
|
|
|
s.mock.Ctx.Configuration.AuthenticationBackend.DisableResetPassword = true
|
|
|
|
expectedBody := ConfigurationBody{
|
|
|
|
GoogleAnalyticsTrackingID: GATrackingID,
|
|
|
|
RememberMe: true,
|
|
|
|
ResetPassword: false,
|
2020-04-04 06:11:33 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
ConfigurationGet(s.mock.Ctx)
|
|
|
|
s.mock.Assert200OK(s.T(), expectedBody)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRunHandlerConfigurationSuite(t *testing.T) {
|
|
|
|
s := new(ConfigurationSuite)
|
|
|
|
suite.Run(t, s)
|
|
|
|
}
|