mirror of
https://github.com/volatiletech/authboss.git
synced 2025-01-22 05:09:42 +02:00
Merge branches
'frederikhors/patch-1' 'frederikhors/Redundant-type-conversion' 'frederikhors/Redundant-types-in-composite-literals' 'frederikhors/Imported-pkg-name-as-name-identifier' 'frederikhors/Variable-'delete'-collides-with-builtin-function'
This commit is contained in:
commit
4d33b97b4f
@ -55,7 +55,7 @@ func TestAuthbossMiddleware(t *testing.T) {
|
||||
ab.Core.Logger = mockLogger{}
|
||||
ab.Storage.Server = &mockServerStorer{
|
||||
Users: map[string]*mockUser{
|
||||
"test@test.com": &mockUser{},
|
||||
"test@test.com": {},
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,7 @@ func testSetupContext() (*Authboss, *http.Request) {
|
||||
ab.Storage.SessionState = newMockClientStateRW(SessionKey, "george-pid")
|
||||
ab.Storage.Server = &mockServerStorer{
|
||||
Users: map[string]*mockUser{
|
||||
"george-pid": &mockUser{Email: "george-pid", Password: "unreadable"},
|
||||
"george-pid": {Email: "george-pid", Password: "unreadable"},
|
||||
},
|
||||
}
|
||||
r := httptest.NewRequest("GET", "/", nil)
|
||||
|
@ -12,7 +12,7 @@ func TestRouter(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
r := NewRouter()
|
||||
var get, post, delete string
|
||||
var get, post, del string
|
||||
wantGet, wantPost, wantDelete := "testget", "testpost", "testdelete"
|
||||
|
||||
r.Get("/test", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
@ -37,7 +37,7 @@ func TestRouter(t *testing.T) {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
delete = string(b)
|
||||
del = string(b)
|
||||
}))
|
||||
|
||||
wr := httptest.NewRecorder()
|
||||
@ -46,8 +46,8 @@ func TestRouter(t *testing.T) {
|
||||
if get != wantGet {
|
||||
t.Error("want:", wantGet, "got:", get)
|
||||
}
|
||||
if len(post) != 0 || len(delete) != 0 {
|
||||
t.Error("should be empty:", post, delete)
|
||||
if len(post) != 0 || len(del) != 0 {
|
||||
t.Error("should be empty:", post, del)
|
||||
}
|
||||
|
||||
wr = httptest.NewRecorder()
|
||||
@ -56,15 +56,15 @@ func TestRouter(t *testing.T) {
|
||||
if post != wantPost {
|
||||
t.Error("want:", wantPost, "got:", post)
|
||||
}
|
||||
if len(delete) != 0 {
|
||||
t.Error("should be empty:", delete)
|
||||
if len(del) != 0 {
|
||||
t.Error("should be empty:", del)
|
||||
}
|
||||
|
||||
wr = httptest.NewRecorder()
|
||||
req = httptest.NewRequest("DELETE", "/test", strings.NewReader("testdelete"))
|
||||
r.ServeHTTP(wr, req)
|
||||
if delete != wantDelete {
|
||||
t.Error("want:", wantDelete, "got:", delete)
|
||||
if del != wantDelete {
|
||||
t.Error("want:", wantDelete, "got:", del)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,11 +15,11 @@ func TestValidate(t *testing.T) {
|
||||
"email": "john@john.com",
|
||||
},
|
||||
Ruleset: []Rules{
|
||||
Rules{
|
||||
{
|
||||
FieldName: "username",
|
||||
MinLength: 5,
|
||||
},
|
||||
Rules{
|
||||
{
|
||||
FieldName: "missing_field",
|
||||
Required: true,
|
||||
},
|
||||
@ -76,7 +76,7 @@ func TestValidate_Confirm(t *testing.T) {
|
||||
}
|
||||
}()
|
||||
|
||||
errs = authboss.ErrorList(validator.Validate())
|
||||
errs = validator.Validate()
|
||||
if len(errs) != 0 {
|
||||
t.Error("Expected no errors:", errs)
|
||||
}
|
||||
|
@ -174,7 +174,7 @@ func NewHTTPBodyReader(readJSON, useUsernameNotEmail bool) *HTTPBodyReader {
|
||||
pidRules = Rules{
|
||||
FieldName: pid, Required: true,
|
||||
MatchError: "Must be a valid e-mail address",
|
||||
MustMatch: regexp.MustCompile(`.*@.*\.[a-z]{1,}`),
|
||||
MustMatch: regexp.MustCompile(`.*@.*\.[a-z]+`),
|
||||
}
|
||||
}
|
||||
|
||||
@ -204,7 +204,7 @@ func NewHTTPBodyReader(readJSON, useUsernameNotEmail bool) *HTTPBodyReader {
|
||||
"recover_end": {FormValuePassword, authboss.ConfirmPrefix + FormValuePassword},
|
||||
},
|
||||
Whitelist: map[string][]string{
|
||||
"register": []string{FormValueEmail, FormValuePassword},
|
||||
"register": {FormValueEmail, FormValuePassword},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -76,7 +76,7 @@ func TestModuleLoadedMiddleware(t *testing.T) {
|
||||
"oauth2": nil,
|
||||
}
|
||||
ab.Config.Modules.OAuth2Providers = map[string]OAuth2Provider{
|
||||
"google": OAuth2Provider{},
|
||||
"google": {},
|
||||
}
|
||||
|
||||
var mods map[string]bool
|
||||
|
@ -143,16 +143,16 @@ func (o *OAuth2) Start(w http.ResponseWriter, r *http.Request) error {
|
||||
authboss.DelSession(w, authboss.SessionOAuth2Params)
|
||||
}
|
||||
|
||||
url := cfg.OAuth2Config.AuthCodeURL(state)
|
||||
authCodeUrl := cfg.OAuth2Config.AuthCodeURL(state)
|
||||
|
||||
extraParams := cfg.AdditionalParams.Encode()
|
||||
if len(extraParams) > 0 {
|
||||
url = fmt.Sprintf("%s&%s", url, extraParams)
|
||||
authCodeUrl = fmt.Sprintf("%s&%s", authCodeUrl, extraParams)
|
||||
}
|
||||
|
||||
ro := authboss.RedirectOptions{
|
||||
Code: http.StatusTemporaryRedirect,
|
||||
RedirectPath: url,
|
||||
RedirectPath: authCodeUrl,
|
||||
}
|
||||
return o.Authboss.Core.Redirector.Redirect(w, r, ro)
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ func init() {
|
||||
}
|
||||
|
||||
var testProviders = map[string]authboss.OAuth2Provider{
|
||||
"google": authboss.OAuth2Provider{
|
||||
"google": {
|
||||
OAuth2Config: &oauth2.Config{
|
||||
ClientID: `jazz`,
|
||||
ClientSecret: `hands`,
|
||||
@ -35,7 +35,7 @@ var testProviders = map[string]authboss.OAuth2Provider{
|
||||
FindUserDetails: GoogleUserDetails,
|
||||
AdditionalParams: url.Values{"include_requested_scopes": []string{"true"}},
|
||||
},
|
||||
"facebook": authboss.OAuth2Provider{
|
||||
"facebook": {
|
||||
OAuth2Config: &oauth2.Config{
|
||||
ClientID: `jazz`,
|
||||
ClientSecret: `hands`,
|
||||
@ -131,11 +131,11 @@ func TestStart(t *testing.T) {
|
||||
t.Error("code was wrong:", h.redirector.Options.Code)
|
||||
}
|
||||
|
||||
url, err := url.Parse(h.redirector.Options.RedirectPath)
|
||||
redirectPathUrl, err := url.Parse(h.redirector.Options.RedirectPath)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
query := url.Query()
|
||||
query := redirectPathUrl.Query()
|
||||
if state := query.Get("state"); len(state) == 0 {
|
||||
t.Error("our nonce should have been here")
|
||||
}
|
||||
@ -145,8 +145,8 @@ func TestStart(t *testing.T) {
|
||||
if clientID := query.Get("client_id"); clientID != "jazz" {
|
||||
t.Error("clientID was wrong:", clientID)
|
||||
}
|
||||
if url.Host != "accounts.google.com" {
|
||||
t.Error("host was wrong:", url.Host)
|
||||
if redirectPathUrl.Host != "accounts.google.com" {
|
||||
t.Error("host was wrong:", redirectPathUrl.Host)
|
||||
}
|
||||
|
||||
if h.session.ClientValues[authboss.SessionOAuth2State] != query.Get("state") {
|
||||
|
@ -263,7 +263,7 @@ func (s *SMS) PostSetup(w http.ResponseWriter, r *http.Request) error {
|
||||
number := smsVals.GetPhoneNumber()
|
||||
if len(number) == 0 {
|
||||
data := authboss.HTMLData{
|
||||
authboss.DataValidation: map[string][]string{FormValuePhoneNumber: []string{"must provide a phone number"}},
|
||||
authboss.DataValidation: map[string][]string{FormValuePhoneNumber: {"must provide a phone number"}},
|
||||
}
|
||||
return s.Core.Responder.Respond(w, r, http.StatusOK, PageSMSSetup, data)
|
||||
}
|
||||
@ -401,7 +401,7 @@ func (s *SMSValidator) validateCode(w http.ResponseWriter, r *http.Request, user
|
||||
|
||||
logger.Infof("user %s sms 2fa failure (wrong code)", user.GetPID())
|
||||
data := authboss.HTMLData{
|
||||
authboss.DataValidation: map[string][]string{FormValueCode: []string{"2fa code was invalid"}},
|
||||
authboss.DataValidation: map[string][]string{FormValueCode: {"2fa code was invalid"}},
|
||||
}
|
||||
return s.Authboss.Core.Responder.Respond(w, r, http.StatusOK, s.Page, data)
|
||||
}
|
||||
|
@ -355,7 +355,7 @@ func TestValidatorPostSend(t *testing.T) {
|
||||
t.Error("should have sent a code")
|
||||
}
|
||||
|
||||
*h.sender = smsHolderSender("")
|
||||
*h.sender = ""
|
||||
|
||||
// When action is confirm, it retrieves the phone number from
|
||||
// the session, not the user.
|
||||
|
@ -262,7 +262,7 @@ func (t *TOTP) PostConfirm(w http.ResponseWriter, r *http.Request) error {
|
||||
ok = totp.Validate(inputCode, totpSecret)
|
||||
if !ok {
|
||||
data := authboss.HTMLData{
|
||||
authboss.DataValidation: map[string][]string{FormValueCode: []string{"2fa code was invalid"}},
|
||||
authboss.DataValidation: map[string][]string{FormValueCode: {"2fa code was invalid"}},
|
||||
DataTOTPSecret: totpSecret,
|
||||
}
|
||||
return t.Authboss.Core.Responder.Respond(w, r, http.StatusOK, PageTOTPConfirm, data)
|
||||
@ -310,7 +310,7 @@ func (t *TOTP) PostRemove(w http.ResponseWriter, r *http.Request) error {
|
||||
return err
|
||||
case !ok:
|
||||
data := authboss.HTMLData{
|
||||
authboss.DataValidation: map[string][]string{FormValueCode: []string{"2fa code was invalid"}},
|
||||
authboss.DataValidation: map[string][]string{FormValueCode: {"2fa code was invalid"}},
|
||||
}
|
||||
return t.Authboss.Core.Responder.Respond(w, r, http.StatusOK, PageTOTPRemove, data)
|
||||
}
|
||||
@ -355,7 +355,7 @@ func (t *TOTP) PostValidate(w http.ResponseWriter, r *http.Request) error {
|
||||
|
||||
logger.Infof("user %s totp 2fa failure (wrong code)", user.GetPID())
|
||||
data := authboss.HTMLData{
|
||||
authboss.DataValidation: map[string][]string{FormValueCode: []string{"2fa code was invalid"}},
|
||||
authboss.DataValidation: map[string][]string{FormValueCode: {"2fa code was invalid"}},
|
||||
}
|
||||
return t.Authboss.Core.Responder.Respond(w, r, http.StatusOK, PageTOTPValidate, data)
|
||||
}
|
||||
|
@ -28,8 +28,8 @@ func TestTOTPSetup(t *testing.T) {
|
||||
ab.Config.Core.ViewRenderer = renderer
|
||||
ab.Config.Core.ErrorHandler = errHandler
|
||||
|
||||
totp := &TOTP{Authboss: ab}
|
||||
if err := totp.Setup(); err != nil {
|
||||
totpNew := &TOTP{Authboss: ab}
|
||||
if err := totpNew.Setup(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
|
@ -271,8 +271,8 @@ func (r *Recover) EndPost(w http.ResponseWriter, req *http.Request) error {
|
||||
}
|
||||
|
||||
func (r *Recover) invalidToken(page string, w http.ResponseWriter, req *http.Request) error {
|
||||
errors := []error{errors.New("recovery token is invalid")}
|
||||
data := authboss.HTMLData{authboss.DataValidation: authboss.ErrorMap(errors)}
|
||||
errorsAll := []error{errors.New("recovery token is invalid")}
|
||||
data := authboss.HTMLData{authboss.DataValidation: authboss.ErrorMap(errorsAll)}
|
||||
return r.Authboss.Core.Responder.Respond(w, req, http.StatusOK, PageRecoverEnd, data)
|
||||
}
|
||||
|
||||
|
@ -166,7 +166,7 @@ func (r *Remember) AfterPasswordReset(w http.ResponseWriter, req *http.Request,
|
||||
// GenerateToken creates a remember me token
|
||||
func GenerateToken(pid string) (hash string, token string, err error) {
|
||||
rawToken := make([]byte, nNonceSize+len(pid)+1)
|
||||
copy(rawToken, []byte(pid))
|
||||
copy(rawToken, pid)
|
||||
rawToken[len(pid)] = ';'
|
||||
|
||||
if _, err := io.ReadFull(rand.Reader, rawToken[len(pid)+1:]); err != nil {
|
||||
|
Loading…
x
Reference in New Issue
Block a user