mirror of
https://github.com/0rangebananaspy/authelia.git
synced 2024-09-14 22:47:21 +07:00
8aade7f40e
* added regulation validator * made regulations find_time and ban_time values duration notation strings * added DefaultRegulationConfiguration for the validator * made session expiration and inactivity values duration notation strings * TOTP period does not need to be converted because adjustment should be discouraged * moved TOTP defaults to DefaultTOTPConfiguration and removed the consts * arranged the root config validator in configuration file order * adjusted tests for the changes * moved duration notation docs to root of configuration * added references to duration notation where applicable * project wide gofmt and goimports: * run gofmt * run goimports -local github.com/authelia/authelia -w on all files * Make jwt_secret error uniform and add tests * now at 100% coverage for internal/configuration/validator/configuration.go
89 lines
2.0 KiB
Go
89 lines
2.0 KiB
Go
package handlers
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
|
|
"github.com/authelia/authelia/internal/mocks"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
"github.com/authelia/authelia/internal/authentication"
|
|
)
|
|
|
|
type StateGetSuite struct {
|
|
suite.Suite
|
|
|
|
mock *mocks.MockAutheliaCtx
|
|
}
|
|
|
|
func (s *StateGetSuite) SetupTest() {
|
|
s.mock = mocks.NewMockAutheliaCtx(s.T())
|
|
}
|
|
|
|
func (s *StateGetSuite) TearDownTest() {
|
|
s.mock.Close()
|
|
}
|
|
|
|
func (s *StateGetSuite) TestShouldReturnUsernameFromSession() {
|
|
userSession := s.mock.Ctx.GetSession()
|
|
userSession.Username = "username"
|
|
s.mock.Ctx.SaveSession(userSession)
|
|
|
|
StateGet(s.mock.Ctx)
|
|
|
|
type Response struct {
|
|
Status string
|
|
Data StateResponse
|
|
}
|
|
|
|
expectedBody := Response{
|
|
Status: "OK",
|
|
Data: StateResponse{
|
|
Username: "username",
|
|
DefaultRedirectionURL: "",
|
|
AuthenticationLevel: authentication.NotAuthenticated,
|
|
},
|
|
}
|
|
actualBody := Response{}
|
|
|
|
json.Unmarshal(s.mock.Ctx.Response.Body(), &actualBody)
|
|
assert.Equal(s.T(), 200, s.mock.Ctx.Response.StatusCode())
|
|
assert.Equal(s.T(), []byte("application/json"), s.mock.Ctx.Response.Header.ContentType())
|
|
assert.Equal(s.T(), expectedBody, actualBody)
|
|
}
|
|
|
|
func (s *StateGetSuite) TestShouldReturnAuthenticationLevelFromSession() {
|
|
userSession := s.mock.Ctx.GetSession()
|
|
userSession.AuthenticationLevel = authentication.OneFactor
|
|
s.mock.Ctx.SaveSession(userSession)
|
|
|
|
StateGet(s.mock.Ctx)
|
|
|
|
type Response struct {
|
|
Status string
|
|
Data StateResponse
|
|
}
|
|
|
|
expectedBody := Response{
|
|
Status: "OK",
|
|
Data: StateResponse{
|
|
Username: "",
|
|
DefaultRedirectionURL: "",
|
|
AuthenticationLevel: authentication.OneFactor,
|
|
},
|
|
}
|
|
actualBody := Response{}
|
|
|
|
json.Unmarshal(s.mock.Ctx.Response.Body(), &actualBody)
|
|
assert.Equal(s.T(), 200, s.mock.Ctx.Response.StatusCode())
|
|
assert.Equal(s.T(), []byte("application/json"), s.mock.Ctx.Response.Header.ContentType())
|
|
assert.Equal(s.T(), expectedBody, actualBody)
|
|
}
|
|
|
|
func TestRunStateGetSuite(t *testing.T) {
|
|
s := new(StateGetSuite)
|
|
suite.Run(t, s)
|
|
}
|