summaryrefslogtreecommitdiff
path: root/internal/handlers/handler_configuration_test.go
blob: 20d85deef0ac1c52152a63d607fbf3de52cb48db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package handlers

import (
	"testing"

	"github.com/stretchr/testify/suite"

	"github.com/authelia/authelia/internal/configuration/schema"
	"github.com/authelia/authelia/internal/mocks"
	"github.com/authelia/authelia/internal/session"
)

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
	s.mock.Ctx.Configuration.Session.RememberMeDuration = schema.DefaultSessionConfiguration.RememberMeDuration

	expectedBody := ConfigurationBody{
		GoogleAnalyticsTrackingID: GATrackingID,
		RememberMe:                true,
		ResetPassword:             true,
	}

	ConfigurationGet(s.mock.Ctx)
	s.mock.Assert200OK(s.T(), expectedBody)
}

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,
		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,
	}

	ConfigurationGet(s.mock.Ctx)
	s.mock.Assert200OK(s.T(), expectedBody)
}

func TestRunHandlerConfigurationSuite(t *testing.T) {
	s := new(ConfigurationSuite)
	suite.Run(t, s)
}