mirror of
https://github.com/volatiletech/authboss.git
synced 2025-01-24 05:17:10 +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.Core.Logger = mockLogger{}
|
||||||
ab.Storage.Server = &mockServerStorer{
|
ab.Storage.Server = &mockServerStorer{
|
||||||
Users: map[string]*mockUser{
|
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.SessionState = newMockClientStateRW(SessionKey, "george-pid")
|
||||||
ab.Storage.Server = &mockServerStorer{
|
ab.Storage.Server = &mockServerStorer{
|
||||||
Users: map[string]*mockUser{
|
Users: map[string]*mockUser{
|
||||||
"george-pid": &mockUser{Email: "george-pid", Password: "unreadable"},
|
"george-pid": {Email: "george-pid", Password: "unreadable"},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
r := httptest.NewRequest("GET", "/", nil)
|
r := httptest.NewRequest("GET", "/", nil)
|
||||||
|
@ -12,7 +12,7 @@ func TestRouter(t *testing.T) {
|
|||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
r := NewRouter()
|
r := NewRouter()
|
||||||
var get, post, delete string
|
var get, post, del string
|
||||||
wantGet, wantPost, wantDelete := "testget", "testpost", "testdelete"
|
wantGet, wantPost, wantDelete := "testget", "testpost", "testdelete"
|
||||||
|
|
||||||
r.Get("/test", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
r.Get("/test", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
@ -37,7 +37,7 @@ func TestRouter(t *testing.T) {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
delete = string(b)
|
del = string(b)
|
||||||
}))
|
}))
|
||||||
|
|
||||||
wr := httptest.NewRecorder()
|
wr := httptest.NewRecorder()
|
||||||
@ -46,8 +46,8 @@ func TestRouter(t *testing.T) {
|
|||||||
if get != wantGet {
|
if get != wantGet {
|
||||||
t.Error("want:", wantGet, "got:", get)
|
t.Error("want:", wantGet, "got:", get)
|
||||||
}
|
}
|
||||||
if len(post) != 0 || len(delete) != 0 {
|
if len(post) != 0 || len(del) != 0 {
|
||||||
t.Error("should be empty:", post, delete)
|
t.Error("should be empty:", post, del)
|
||||||
}
|
}
|
||||||
|
|
||||||
wr = httptest.NewRecorder()
|
wr = httptest.NewRecorder()
|
||||||
@ -56,15 +56,15 @@ func TestRouter(t *testing.T) {
|
|||||||
if post != wantPost {
|
if post != wantPost {
|
||||||
t.Error("want:", wantPost, "got:", post)
|
t.Error("want:", wantPost, "got:", post)
|
||||||
}
|
}
|
||||||
if len(delete) != 0 {
|
if len(del) != 0 {
|
||||||
t.Error("should be empty:", delete)
|
t.Error("should be empty:", del)
|
||||||
}
|
}
|
||||||
|
|
||||||
wr = httptest.NewRecorder()
|
wr = httptest.NewRecorder()
|
||||||
req = httptest.NewRequest("DELETE", "/test", strings.NewReader("testdelete"))
|
req = httptest.NewRequest("DELETE", "/test", strings.NewReader("testdelete"))
|
||||||
r.ServeHTTP(wr, req)
|
r.ServeHTTP(wr, req)
|
||||||
if delete != wantDelete {
|
if del != wantDelete {
|
||||||
t.Error("want:", wantDelete, "got:", delete)
|
t.Error("want:", wantDelete, "got:", del)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,11 +15,11 @@ func TestValidate(t *testing.T) {
|
|||||||
"email": "john@john.com",
|
"email": "john@john.com",
|
||||||
},
|
},
|
||||||
Ruleset: []Rules{
|
Ruleset: []Rules{
|
||||||
Rules{
|
{
|
||||||
FieldName: "username",
|
FieldName: "username",
|
||||||
MinLength: 5,
|
MinLength: 5,
|
||||||
},
|
},
|
||||||
Rules{
|
{
|
||||||
FieldName: "missing_field",
|
FieldName: "missing_field",
|
||||||
Required: true,
|
Required: true,
|
||||||
},
|
},
|
||||||
@ -76,7 +76,7 @@ func TestValidate_Confirm(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
errs = authboss.ErrorList(validator.Validate())
|
errs = validator.Validate()
|
||||||
if len(errs) != 0 {
|
if len(errs) != 0 {
|
||||||
t.Error("Expected no errors:", errs)
|
t.Error("Expected no errors:", errs)
|
||||||
}
|
}
|
||||||
|
@ -174,7 +174,7 @@ func NewHTTPBodyReader(readJSON, useUsernameNotEmail bool) *HTTPBodyReader {
|
|||||||
pidRules = Rules{
|
pidRules = Rules{
|
||||||
FieldName: pid, Required: true,
|
FieldName: pid, Required: true,
|
||||||
MatchError: "Must be a valid e-mail address",
|
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},
|
"recover_end": {FormValuePassword, authboss.ConfirmPrefix + FormValuePassword},
|
||||||
},
|
},
|
||||||
Whitelist: map[string][]string{
|
Whitelist: map[string][]string{
|
||||||
"register": []string{FormValueEmail, FormValuePassword},
|
"register": {FormValueEmail, FormValuePassword},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -76,7 +76,7 @@ func TestModuleLoadedMiddleware(t *testing.T) {
|
|||||||
"oauth2": nil,
|
"oauth2": nil,
|
||||||
}
|
}
|
||||||
ab.Config.Modules.OAuth2Providers = map[string]OAuth2Provider{
|
ab.Config.Modules.OAuth2Providers = map[string]OAuth2Provider{
|
||||||
"google": OAuth2Provider{},
|
"google": {},
|
||||||
}
|
}
|
||||||
|
|
||||||
var mods map[string]bool
|
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)
|
authboss.DelSession(w, authboss.SessionOAuth2Params)
|
||||||
}
|
}
|
||||||
|
|
||||||
url := cfg.OAuth2Config.AuthCodeURL(state)
|
authCodeUrl := cfg.OAuth2Config.AuthCodeURL(state)
|
||||||
|
|
||||||
extraParams := cfg.AdditionalParams.Encode()
|
extraParams := cfg.AdditionalParams.Encode()
|
||||||
if len(extraParams) > 0 {
|
if len(extraParams) > 0 {
|
||||||
url = fmt.Sprintf("%s&%s", url, extraParams)
|
authCodeUrl = fmt.Sprintf("%s&%s", authCodeUrl, extraParams)
|
||||||
}
|
}
|
||||||
|
|
||||||
ro := authboss.RedirectOptions{
|
ro := authboss.RedirectOptions{
|
||||||
Code: http.StatusTemporaryRedirect,
|
Code: http.StatusTemporaryRedirect,
|
||||||
RedirectPath: url,
|
RedirectPath: authCodeUrl,
|
||||||
}
|
}
|
||||||
return o.Authboss.Core.Redirector.Redirect(w, r, ro)
|
return o.Authboss.Core.Redirector.Redirect(w, r, ro)
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var testProviders = map[string]authboss.OAuth2Provider{
|
var testProviders = map[string]authboss.OAuth2Provider{
|
||||||
"google": authboss.OAuth2Provider{
|
"google": {
|
||||||
OAuth2Config: &oauth2.Config{
|
OAuth2Config: &oauth2.Config{
|
||||||
ClientID: `jazz`,
|
ClientID: `jazz`,
|
||||||
ClientSecret: `hands`,
|
ClientSecret: `hands`,
|
||||||
@ -35,7 +35,7 @@ var testProviders = map[string]authboss.OAuth2Provider{
|
|||||||
FindUserDetails: GoogleUserDetails,
|
FindUserDetails: GoogleUserDetails,
|
||||||
AdditionalParams: url.Values{"include_requested_scopes": []string{"true"}},
|
AdditionalParams: url.Values{"include_requested_scopes": []string{"true"}},
|
||||||
},
|
},
|
||||||
"facebook": authboss.OAuth2Provider{
|
"facebook": {
|
||||||
OAuth2Config: &oauth2.Config{
|
OAuth2Config: &oauth2.Config{
|
||||||
ClientID: `jazz`,
|
ClientID: `jazz`,
|
||||||
ClientSecret: `hands`,
|
ClientSecret: `hands`,
|
||||||
@ -131,11 +131,11 @@ func TestStart(t *testing.T) {
|
|||||||
t.Error("code was wrong:", h.redirector.Options.Code)
|
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 {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
query := url.Query()
|
query := redirectPathUrl.Query()
|
||||||
if state := query.Get("state"); len(state) == 0 {
|
if state := query.Get("state"); len(state) == 0 {
|
||||||
t.Error("our nonce should have been here")
|
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" {
|
if clientID := query.Get("client_id"); clientID != "jazz" {
|
||||||
t.Error("clientID was wrong:", clientID)
|
t.Error("clientID was wrong:", clientID)
|
||||||
}
|
}
|
||||||
if url.Host != "accounts.google.com" {
|
if redirectPathUrl.Host != "accounts.google.com" {
|
||||||
t.Error("host was wrong:", url.Host)
|
t.Error("host was wrong:", redirectPathUrl.Host)
|
||||||
}
|
}
|
||||||
|
|
||||||
if h.session.ClientValues[authboss.SessionOAuth2State] != query.Get("state") {
|
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()
|
number := smsVals.GetPhoneNumber()
|
||||||
if len(number) == 0 {
|
if len(number) == 0 {
|
||||||
data := authboss.HTMLData{
|
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)
|
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())
|
logger.Infof("user %s sms 2fa failure (wrong code)", user.GetPID())
|
||||||
data := authboss.HTMLData{
|
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)
|
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")
|
t.Error("should have sent a code")
|
||||||
}
|
}
|
||||||
|
|
||||||
*h.sender = smsHolderSender("")
|
*h.sender = ""
|
||||||
|
|
||||||
// When action is confirm, it retrieves the phone number from
|
// When action is confirm, it retrieves the phone number from
|
||||||
// the session, not the user.
|
// 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)
|
ok = totp.Validate(inputCode, totpSecret)
|
||||||
if !ok {
|
if !ok {
|
||||||
data := authboss.HTMLData{
|
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,
|
DataTOTPSecret: totpSecret,
|
||||||
}
|
}
|
||||||
return t.Authboss.Core.Responder.Respond(w, r, http.StatusOK, PageTOTPConfirm, data)
|
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
|
return err
|
||||||
case !ok:
|
case !ok:
|
||||||
data := authboss.HTMLData{
|
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)
|
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())
|
logger.Infof("user %s totp 2fa failure (wrong code)", user.GetPID())
|
||||||
data := authboss.HTMLData{
|
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)
|
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.ViewRenderer = renderer
|
||||||
ab.Config.Core.ErrorHandler = errHandler
|
ab.Config.Core.ErrorHandler = errHandler
|
||||||
|
|
||||||
totp := &TOTP{Authboss: ab}
|
totpNew := &TOTP{Authboss: ab}
|
||||||
if err := totp.Setup(); err != nil {
|
if err := totpNew.Setup(); err != nil {
|
||||||
t.Fatal(err)
|
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 {
|
func (r *Recover) invalidToken(page string, w http.ResponseWriter, req *http.Request) error {
|
||||||
errors := []error{errors.New("recovery token is invalid")}
|
errorsAll := []error{errors.New("recovery token is invalid")}
|
||||||
data := authboss.HTMLData{authboss.DataValidation: authboss.ErrorMap(errors)}
|
data := authboss.HTMLData{authboss.DataValidation: authboss.ErrorMap(errorsAll)}
|
||||||
return r.Authboss.Core.Responder.Respond(w, req, http.StatusOK, PageRecoverEnd, data)
|
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
|
// GenerateToken creates a remember me token
|
||||||
func GenerateToken(pid string) (hash string, token string, err error) {
|
func GenerateToken(pid string) (hash string, token string, err error) {
|
||||||
rawToken := make([]byte, nNonceSize+len(pid)+1)
|
rawToken := make([]byte, nNonceSize+len(pid)+1)
|
||||||
copy(rawToken, []byte(pid))
|
copy(rawToken, pid)
|
||||||
rawToken[len(pid)] = ';'
|
rawToken[len(pid)] = ';'
|
||||||
|
|
||||||
if _, err := io.ReadFull(rand.Reader, rawToken[len(pid)+1:]); err != nil {
|
if _, err := io.ReadFull(rand.Reader, rawToken[len(pid)+1:]); err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user