🚨 Removed linter warnings
This commit is contained in:
parent
650a1ec975
commit
e2961e6642
|
@ -5,9 +5,14 @@ linters-settings:
|
||||||
lll:
|
lll:
|
||||||
tab-width: 8
|
tab-width: 8
|
||||||
gci:
|
gci:
|
||||||
local-prefixes: source.toby3d.me/
|
local-prefixes: source.toby3d.me
|
||||||
goimports:
|
goimports:
|
||||||
local-prefixes: source.toby3d.me/
|
local-prefixes: source.toby3d.me
|
||||||
linters:
|
linters:
|
||||||
enable-all: true
|
enable-all: true
|
||||||
|
issues:
|
||||||
|
exclude-rules:
|
||||||
|
- source: "^//go:generate "
|
||||||
|
linters:
|
||||||
|
- lll
|
||||||
fix: true
|
fix: true
|
||||||
|
|
|
@ -30,8 +30,7 @@ type (
|
||||||
)
|
)
|
||||||
|
|
||||||
// HeaderXCSRFToken describes the name of the header with the CSRF token.
|
// HeaderXCSRFToken describes the name of the header with the CSRF token.
|
||||||
//nolint: gosec
|
const HeaderXCSRFToken string = "X-CSRF-Token" //nolint: gosec
|
||||||
const HeaderXCSRFToken string = "X-CSRF-Token"
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ErrMissingFormToken = errors.New("missing csrf token in the form parameter")
|
ErrMissingFormToken = errors.New("missing csrf token in the form parameter")
|
||||||
|
@ -39,23 +38,23 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
// DefaultCSRFConfig contains the default CSRF middleware configuration.
|
// DefaultCSRFConfig contains the default CSRF middleware configuration.
|
||||||
//nolint: exhaustivestruct, gochecknoglobals, gomnd
|
//nolint: gochecknoglobals, gomnd
|
||||||
var DefaultCSRFConfig = CSRFConfig{
|
var DefaultCSRFConfig = CSRFConfig{
|
||||||
ContextKey: "csrf",
|
|
||||||
CookieHTTPOnly: false,
|
|
||||||
CookieMaxAge: 24 * time.Hour,
|
|
||||||
CookieName: "_csrf",
|
|
||||||
CookieSameSite: http.CookieSameSiteDefaultMode,
|
|
||||||
CookieSecure: false,
|
|
||||||
Skipper: DefaultSkipper,
|
Skipper: DefaultSkipper,
|
||||||
TokenLength: 32,
|
CookieMaxAge: 24 * time.Hour,
|
||||||
|
CookieSameSite: http.CookieSameSiteDefaultMode,
|
||||||
|
ContextKey: "csrf",
|
||||||
|
CookieDomain: "",
|
||||||
|
CookieName: "_csrf",
|
||||||
|
CookiePath: "",
|
||||||
TokenLookup: "header:" + HeaderXCSRFToken,
|
TokenLookup: "header:" + HeaderXCSRFToken,
|
||||||
|
TokenLength: 32,
|
||||||
|
CookieSecure: false,
|
||||||
|
CookieHTTPOnly: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
func CSRF() Interceptor {
|
func CSRF() Interceptor {
|
||||||
cfg := DefaultCSRFConfig
|
return CSRFWithConfig(DefaultCSRFConfig)
|
||||||
|
|
||||||
return CSRFWithConfig(cfg)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//nolint: funlen, cyclop
|
//nolint: funlen, cyclop
|
||||||
|
@ -130,7 +129,7 @@ func CSRFWithConfig(config CSRFConfig) Interceptor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set CSRF cookie
|
// NOTE(toby3d): set CSRF cookie
|
||||||
cookie := http.AcquireCookie()
|
cookie := http.AcquireCookie()
|
||||||
defer http.ReleaseCookie(cookie)
|
defer http.ReleaseCookie(cookie)
|
||||||
|
|
||||||
|
@ -172,12 +171,11 @@ func csrfTokenFromHeader(header string) csrfTokenExtractor {
|
||||||
|
|
||||||
func csrfTokenFromForm(param string) csrfTokenExtractor {
|
func csrfTokenFromForm(param string) csrfTokenExtractor {
|
||||||
return func(ctx *http.RequestCtx) ([]byte, error) {
|
return func(ctx *http.RequestCtx) ([]byte, error) {
|
||||||
token := ctx.FormValue(param)
|
if token := ctx.FormValue(param); token != nil {
|
||||||
if token == nil {
|
return token, nil
|
||||||
return nil, ErrMissingFormToken
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return token, nil
|
return nil, ErrMissingFormToken
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,13 +3,10 @@ package middleware
|
||||||
import http "github.com/valyala/fasthttp"
|
import http "github.com/valyala/fasthttp"
|
||||||
|
|
||||||
type (
|
type (
|
||||||
Chain []Interceptor
|
Chain []Interceptor
|
||||||
|
Interceptor func(*http.RequestCtx, http.RequestHandler)
|
||||||
Interceptor func(*http.RequestCtx, http.RequestHandler)
|
|
||||||
|
|
||||||
RequestHandler http.RequestHandler
|
RequestHandler http.RequestHandler
|
||||||
|
Skipper func(*http.RequestCtx) bool
|
||||||
Skipper func(*http.RequestCtx) bool
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// DefaultSkipper is the default skipper, which always returns false.
|
// DefaultSkipper is the default skipper, which always returns false.
|
||||||
|
|
|
@ -15,6 +15,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
|
//nolint: tagliatelle
|
||||||
Response struct {
|
Response struct {
|
||||||
DisplayName string `json:"display_name"`
|
DisplayName string `json:"display_name"`
|
||||||
Avatar string `json:"avatar"`
|
Avatar string `json:"avatar"`
|
||||||
|
@ -62,5 +63,6 @@ func (repo *mastodonProfileRepository) Get(ctx context.Context, token oauth2.Tok
|
||||||
Name: result.DisplayName,
|
Name: result.DisplayName,
|
||||||
URL: result.URL,
|
URL: result.URL,
|
||||||
Photo: result.Avatar,
|
Photo: result.Avatar,
|
||||||
|
Email: "",
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,7 @@ func (r *Random) String(length int, charsets ...string) string {
|
||||||
b := make([]byte, length)
|
b := make([]byte, length)
|
||||||
|
|
||||||
for i := range b {
|
for i := range b {
|
||||||
|
//nolint: gosec
|
||||||
b[i] = charset[rand.Int()%len(charset)]
|
b[i] = charset[rand.Int()%len(charset)]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,10 +31,10 @@ func TestServe(tb testing.TB, handler http.RequestHandler) (*http.Client, *http.
|
||||||
|
|
||||||
client := &http.Client{
|
client := &http.Client{
|
||||||
TLSConfig: &tls.Config{
|
TLSConfig: &tls.Config{
|
||||||
InsecureSkipVerify: true,
|
InsecureSkipVerify: true, //nolint: gosec
|
||||||
},
|
},
|
||||||
Dial: func(addr string) (net.Conn, error) {
|
Dial: func(addr string) (net.Conn, error) {
|
||||||
return ln.Dial()
|
return ln.Dial() //nolint: wrapcheck
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue