Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion avatar/avatar.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ func GetGravatarURL(email string) (res string, err error) {
}

func retry(retries int, delay time.Duration, fn func() error) (err error) {
for i := 0; i < retries; i++ {
for range retries {
if err = fn(); err == nil {
return nil
}
Expand Down
10 changes: 5 additions & 5 deletions logger/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ import "log"

// L defined logger interface used everywhere in the package
type L interface {
Logf(format string, args ...interface{})
Logf(format string, args ...any)
}

// Func type is an adapter to allow the use of ordinary functions as Logger.
type Func func(format string, args ...interface{})
type Func func(format string, args ...any)

// Logf calls f(id)
func (f Func) Logf(format string, args ...interface{}) { f(format, args...) }
func (f Func) Logf(format string, args ...any) { f(format, args...) }

// NoOp logger
var NoOp = Func(func(string, ...interface{}) {})
var NoOp = Func(func(string, ...any) {})

// Std logger sends to std default logger directly
var Std = Func(func(format string, args ...interface{}) { log.Printf(format, args...) })
var Std = Func(func(format string, args ...any) { log.Printf(format, args...) })
2 changes: 1 addition & 1 deletion logger/interface_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

func TestLogger(t *testing.T) {
buff := bytes.NewBufferString("")
lg := Func(func(format string, args ...interface{}) {
lg := Func(func(format string, args ...any) {
fmt.Fprintf(buff, format, args...)
})

Expand Down
6 changes: 3 additions & 3 deletions middleware/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ type Authenticator struct {

// RefreshCache defines interface storing and retrieving refreshed tokens
type RefreshCache interface {
Get(key interface{}) (value interface{}, ok bool)
Set(key, value interface{})
Get(key any) (value any, ok bool)
Set(key, value any)
}

// TokenService defines interface accessing tokens
Expand All @@ -49,7 +49,7 @@ type BasicAuthFunc func(user, passwd string) (ok bool, userInfo token.User, err
var adminUser = token.User{
ID: "admin",
Name: "admin",
Attributes: map[string]interface{}{
Attributes: map[string]any{
"admin": true,
},
}
Expand Down
14 changes: 7 additions & 7 deletions middleware/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestAuthJWTCookie(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, token.User{Name: "name1", ID: "provider1_id1", Picture: "http://example.com/pic.png",
IP: "127.0.0.1", Email: "me@example.com", Audience: "test_sys",
Attributes: map[string]interface{}{"boola": true, "stra": "stra-val"}}, u)
Attributes: map[string]any{"boola": true, "stra": "stra-val"}}, u)
w.WriteHeader(201)
}
mux.Handle("/auth", a.Auth(http.HandlerFunc(handler)))
Expand Down Expand Up @@ -178,7 +178,7 @@ func TestAuthJWTRefreshConcurrentWithCache(t *testing.T) {
var wg sync.WaitGroup
a.RefreshCache = newTestRefreshCache()
wg.Add(100)
for i := 0; i < 100; i++ {
for range 100 {
time.Sleep(1 * time.Millisecond) // TODO! not sure how testRefreshCache may have misses without this delay
go func() {
defer wg.Done()
Expand Down Expand Up @@ -449,7 +449,7 @@ func TestRBAC(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, token.User{Name: "name1", ID: "provider1_id1", Picture: "http://example.com/pic.png",
IP: "127.0.0.1", Email: "me@example.com", Audience: "test_sys",
Attributes: map[string]interface{}{"boola": true, "stra": "stra-val"},
Attributes: map[string]any{"boola": true, "stra": "stra-val"},
Role: "employee"}, u)
w.WriteHeader(201)
})
Expand Down Expand Up @@ -540,16 +540,16 @@ func makeTestAuth(_ *testing.T) Authenticator {
}

type testRefreshCache struct {
data map[interface{}]interface{}
data map[any]any
sync.RWMutex
hits, misses int32
}

func newTestRefreshCache() *testRefreshCache {
return &testRefreshCache{data: make(map[interface{}]interface{})}
return &testRefreshCache{data: make(map[any]any)}
}

func (c *testRefreshCache) Get(key interface{}) (value interface{}, ok bool) {
func (c *testRefreshCache) Get(key any) (value any, ok bool) {
c.RLock()
defer c.RUnlock()
value, ok = c.data[key]
Expand All @@ -561,7 +561,7 @@ func (c *testRefreshCache) Get(key interface{}) (value interface{}, ok bool) {
return value, ok
}

func (c *testRefreshCache) Set(key, value interface{}) {
func (c *testRefreshCache) Set(key, value any) {
c.Lock()
defer c.Unlock()
c.data[key] = value
Expand Down
4 changes: 2 additions & 2 deletions provider/apple.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ type AppleConfig struct {
ResponseMode string // changes method of receiving data in callback. Default value "form_post" (https://developer.apple.com/documentation/sign_in_with_apple/request_an_authorization_to_the_sign_in_with_apple_server?changes=_1_2#4066168)

scopes []string // for this package allow only username scope and UID in token claims. Apple service API provide only "email" and "name" scope values (https://developer.apple.com/documentation/sign_in_with_apple/clientconfigi/3230955-scope)
privateKey interface{} // private key from Apple obtained in developer account (the keys section). Required for create the Client Secret (https://developer.apple.com/documentation/sign_in_with_apple/generate_and_validate_tokens#3262048)
privateKey any // private key from Apple obtained in developer account (the keys section). Required for create the Client Secret (https://developer.apple.com/documentation/sign_in_with_apple/generate_and_validate_tokens#3262048)
publicKey crypto.PublicKey // need for validate sign of token
clientSecret string // is the JWT client secret will create after first call and then used until expired
jwkURL string // URL for fetch JWK Apple keys, need redefine for tests
Expand Down Expand Up @@ -228,7 +228,7 @@ func (ah *AppleHandler) initPrivateKey() error {
}

// tokenKeyFunc use for verify JWT sign, it receives the parsed token and should return the key for validating.
func (ah *AppleHandler) tokenKeyFunc(jwtToken *jwt.Token) (interface{}, error) {
func (ah *AppleHandler) tokenKeyFunc(jwtToken *jwt.Token) (any, error) {
if jwtToken == nil {
return nil, fmt.Errorf("failed to call token keyFunc, because token is nil")
}
Expand Down
2 changes: 1 addition & 1 deletion provider/apple_pubkeys.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func (aks *appleKeySet) get(kid string) (keys *applePublicKey, err error) {
}

// keyFunc use for JWT verify with specific public key
func (aks *appleKeySet) keyFunc(token *jwt.Token) (interface{}, error) {
func (aks *appleKeySet) keyFunc(token *jwt.Token) (any, error) {

keyID, ok := token.Header["kid"].(string)
if !ok {
Expand Down
2 changes: 1 addition & 1 deletion provider/apple_pubkeys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func TestAppleKeySet_Get(t *testing.T) {

func TestAppleKeySet_KeyFunc(t *testing.T) {

tokenHdr := map[string]interface{}{"kid": "86D88Kf"}
tokenHdr := map[string]any{"kid": "86D88Kf"}
validToken := jwt.Token{Header: tokenHdr}
testKeySet, err := parseAppleJWK([]byte(`{"keys":[{
"kty": "RSA",
Expand Down
2 changes: 1 addition & 1 deletion provider/apple_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ func prepareAppleOauthTest(t *testing.T, loginPort, authPort int, testToken *str
}
}

func createTestResponseToken(privKey interface{}) (string, error) {
func createTestResponseToken(privKey any) (string, error) {
claims := &jwt.MapClaims{
"iss": "http://go.localhost.test",
"iat": time.Now().Unix(),
Expand Down
3 changes: 1 addition & 2 deletions provider/custom_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@ func TestCustomProvider(t *testing.T) {
router.Handle("/auth/customprov/", http.HandlerFunc(s.Handler))
ts := &http.Server{Addr: fmt.Sprintf("127.0.0.1:%d", 8080), Handler: router} //nolint:gosec

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()

go prov.Run(ctx)
go ts.ListenAndServe()
Expand Down
2 changes: 1 addition & 1 deletion provider/oauth1.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func (h Oauth1Handler) AuthHandler(w http.ResponseWriter, r *http.Request) {
return
}

jData := map[string]interface{}{}
jData := map[string]any{}
if e := json.Unmarshal(data, &jData); e != nil {
rest.SendErrorJSON(w, r, h.L, http.StatusInternalServerError, err, "failed to unmarshal user info")
return
Expand Down
2 changes: 1 addition & 1 deletion provider/oauth1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func TestOauth1Login(t *testing.T) {
err = json.Unmarshal(body, &u)
assert.NoError(t, err)
assert.Equal(t, token.User{Name: "blah", ID: "mock_myuser2", Picture: "http://example.com/ava12345.png",
Attributes: map[string]interface{}{"admin": true}}, u)
Attributes: map[string]any{"admin": true}}, u)

}

Expand Down
4 changes: 2 additions & 2 deletions provider/oauth2.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ type Params struct {
}

// UserData is type for user information returned from oauth2 providers /info API method
type UserData map[string]interface{}
type UserData map[string]any

// Value returns value for key or empty string if not found
func (u UserData) Value(key string) string {
Expand Down Expand Up @@ -189,7 +189,7 @@ func (p Oauth2Handler) AuthHandler(w http.ResponseWriter, r *http.Request) {
return
}

jData := map[string]interface{}{}
jData := map[string]any{}
if e := json.Unmarshal(data, &jData); e != nil {
rest.SendErrorJSON(w, r, p.L, http.StatusInternalServerError, err, "failed to unmarshal user info")
return
Expand Down
2 changes: 1 addition & 1 deletion provider/oauth2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func TestOauth2Login(t *testing.T) {
err = json.Unmarshal(body, &u)
assert.NoError(t, err)
assert.Equal(t, token.User{Name: "blah", ID: "mock_myuser2", Picture: "http://example.com/ava12345.png",
Attributes: map[string]interface{}{"admin": true}}, u)
Attributes: map[string]any{"admin": true}}, u)
}

func TestOauth2LoginBearerTokenHook(t *testing.T) {
Expand Down
8 changes: 4 additions & 4 deletions provider/providers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TestProviders_NewGoogle(t *testing.T) {
"email": "test@email.com"}
user := r.mapUser(udata, nil)
assert.Equal(t, token.User{Name: "test user", ID: "google_01b307acba4f54f55aafc33bb06bbbf6ca803e9a",
Picture: "http://demo.remark42.com/blah.png", IP: "", Attributes: map[string]interface{}{"email": "test@email.com"}}, user, "got %+v", user)
Picture: "http://demo.remark42.com/blah.png", IP: "", Attributes: map[string]any{"email": "test@email.com"}}, user, "got %+v", user)
})
}

Expand Down Expand Up @@ -65,7 +65,7 @@ func TestProviders_NewGithub(t *testing.T) {
"email": "test@email.com"}
user := r.mapUser(udata, nil)
assert.Equal(t, token.User{Name: "test user", ID: "github_e80b2d2608711cbb3312db7c4727a46fbad9601a",
Picture: "http://demo.remark42.com/blah.png", IP: "", Attributes: map[string]interface{}{"email": "test@email.com"}}, user, "got %+v", user)
Picture: "http://demo.remark42.com/blah.png", IP: "", Attributes: map[string]any{"email": "test@email.com"}}, user, "got %+v", user)
})
}

Expand Down Expand Up @@ -94,7 +94,7 @@ func TestProviders_NewFacebook(t *testing.T) {
udata := UserData{"id": "myid", "name": "test user", "email": "test@email.com"}
user := r.mapUser(udata, []byte(`{"picture": {"data": {"url": "http://demo.remark42.com/blah.png"} }}`))
assert.Equal(t, token.User{Name: "test user", ID: "facebook_6e34471f84557e1713012d64a7477c71bfdac631",
Picture: "http://demo.remark42.com/blah.png", IP: "", Attributes: map[string]interface{}{"email": "test@email.com"}},
Picture: "http://demo.remark42.com/blah.png", IP: "", Attributes: map[string]any{"email": "test@email.com"}},
user, "got %+v", user)

})
Expand Down Expand Up @@ -202,7 +202,7 @@ func TestProviders_NewPatreon(t *testing.T) {
assert.Equal(
t,
token.User{Name: "Corgi The Dev", ID: "patreon_4e079d0555e5a2b460969c789d3ad968a795921f",
Picture: "https://c8.patreon.com/2/400/0000000", IP: "", Attributes: map[string]interface{}{"is_paid_sub": true}},
Picture: "https://c8.patreon.com/2/400/0000000", IP: "", Attributes: map[string]any{"is_paid_sub": true}},
user,
"got %+v",
user,
Expand Down
2 changes: 1 addition & 1 deletion provider/telegram.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ func (tg *tgAPI) BotInfo(ctx context.Context) (*botInfo, error) {
return resp.Result, nil
}

func (tg *tgAPI) request(ctx context.Context, method string, data interface{}) error {
func (tg *tgAPI) request(ctx context.Context, method string, data any) error {
return repeater.NewFixed(3, time.Millisecond*50).Do(ctx, func() error {
url := fmt.Sprintf("https://api.telegram.org/bot%s/%s", tg.token, method)

Expand Down
2 changes: 1 addition & 1 deletion token/jwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func (j *Service) Parse(tokenString string) (Claims, error) {
return Claims{}, fmt.Errorf("can't get secret: %w", err)
}

token, err := parser.ParseWithClaims(tokenString, &Claims{}, func(token *jwt.Token) (interface{}, error) {
token, err := parser.ParseWithClaims(tokenString, &Claims{}, func(token *jwt.Token) (any, error) {
if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok {
return nil, fmt.Errorf("unexpected signing method: %v", token.Header["alg"])
}
Expand Down
10 changes: 5 additions & 5 deletions token/jwt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func TestJWT_Parse(t *testing.T) {
assert.NoError(t, err)
assert.False(t, j.IsExpired(claims))
assert.Equal(t, &User{Name: "name1", ID: "id1", Picture: "http://example.com/pic.png", IP: "127.0.0.1",
Email: "me@example.com", Attributes: map[string]interface{}{"boola": true, "stra": "stra-val"}}, claims.User)
Email: "me@example.com", Attributes: map[string]any{"boola": true, "stra": "stra-val"}}, claims.User)

claims, err = j.Parse(testJwtExpired)
assert.NoError(t, err)
Expand Down Expand Up @@ -348,7 +348,7 @@ func TestJWT_GetFromHeader(t *testing.T) {
assert.False(t, j.IsExpired(claims))
assert.Equal(t, &User{Name: "name1", ID: "id1", Picture: "http://example.com/pic.png", IP: "127.0.0.1",
Email: "me@example.com", Audience: "test_sys",
Attributes: map[string]interface{}{"boola": true, "stra": "stra-val"}}, claims.User)
Attributes: map[string]any{"boola": true, "stra": "stra-val"}}, claims.User)
assert.Equal(t, "remark42", claims.Issuer)

req = httptest.NewRequest("GET", "/", nil)
Expand Down Expand Up @@ -380,7 +380,7 @@ func TestJWT_GetFromQuery(t *testing.T) {
assert.False(t, j.IsExpired(claims))
assert.Equal(t, &User{Name: "name1", ID: "id1", Picture: "http://example.com/pic.png", IP: "127.0.0.1",
Email: "me@example.com", Audience: "test_sys",
Attributes: map[string]interface{}{"boola": true, "stra": "stra-val"}}, claims.User)
Attributes: map[string]any{"boola": true, "stra": "stra-val"}}, claims.User)
assert.Equal(t, "remark42", claims.Issuer)

req = httptest.NewRequest("GET", "/blah?token="+testJwtExpired, nil)
Expand Down Expand Up @@ -435,7 +435,7 @@ func TestJWT_SetAndGetWithCookies(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, &User{Name: "name1", ID: "id1", Picture: "http://example.com/pic.png", IP: "127.0.0.1",
Email: "me@example.com", Audience: "test_sys",
Attributes: map[string]interface{}{"boola": true, "stra": "stra-val"}}, r.User)
Attributes: map[string]any{"boola": true, "stra": "stra-val"}}, r.User)
assert.Equal(t, "remark42", claims.Issuer)
assert.Equal(t, true, claims.SessionOnly)
t.Log(resp.Cookies())
Expand Down Expand Up @@ -666,7 +666,7 @@ func TestParseWithAud(t *testing.T) {
assert.NoError(t, err)
assert.False(t, j.IsExpired(claims))
assert.Equal(t, &User{Name: "name1", ID: "id1", Picture: "http://example.com/pic.png", IP: "127.0.0.1",
Email: "me@example.com", Attributes: map[string]interface{}{"boola": true, "stra": "stra-val"}}, claims.User)
Email: "me@example.com", Attributes: map[string]any{"boola": true, "stra": "stra-val"}}, claims.User)

claims, err = j.Parse(testJwtValidAud)
assert.NoError(t, err)
Expand Down
14 changes: 7 additions & 7 deletions token/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,24 @@ type User struct {
Audience string `json:"aud,omitempty"`

// set by client
IP string `json:"ip,omitempty"`
Email string `json:"email,omitempty"`
Attributes map[string]interface{} `json:"attrs,omitempty"`
Role string `json:"role,omitempty"`
IP string `json:"ip,omitempty"`
Email string `json:"email,omitempty"`
Attributes map[string]any `json:"attrs,omitempty"`
Role string `json:"role,omitempty"`
}

// SetBoolAttr sets boolean attribute
func (u *User) SetBoolAttr(key string, val bool) {
if u.Attributes == nil {
u.Attributes = map[string]interface{}{}
u.Attributes = map[string]any{}
}
u.Attributes[key] = val
}

// SetStrAttr sets string attribute
func (u *User) SetStrAttr(key, val string) {
if u.Attributes == nil {
u.Attributes = map[string]interface{}{}
u.Attributes = map[string]any{}
}
u.Attributes[key] = val
}
Expand Down Expand Up @@ -100,7 +100,7 @@ func (u *User) SliceAttr(key string) []string {
// SetSliceAttr sets slice attribute for given key
func (u *User) SetSliceAttr(key string, val []string) {
if u.Attributes == nil {
u.Attributes = map[string]interface{}{}
u.Attributes = map[string]any{}
}
u.Attributes[key] = val
}
Expand Down
2 changes: 1 addition & 1 deletion v2/avatar/avatar.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ func GetGravatarURL(email string) (res string, err error) {
}

func retry(retries int, delay time.Duration, fn func() error) (err error) {
for i := 0; i < retries; i++ {
for range retries {
if err = fn(); err == nil {
return nil
}
Expand Down
10 changes: 5 additions & 5 deletions v2/logger/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ import "log"

// L defined logger interface used everywhere in the package
type L interface {
Logf(format string, args ...interface{})
Logf(format string, args ...any)
}

// Func type is an adapter to allow the use of ordinary functions as Logger.
type Func func(format string, args ...interface{})
type Func func(format string, args ...any)

// Logf calls f(id)
func (f Func) Logf(format string, args ...interface{}) { f(format, args...) }
func (f Func) Logf(format string, args ...any) { f(format, args...) }

// NoOp logger
var NoOp = Func(func(string, ...interface{}) {})
var NoOp = Func(func(string, ...any) {})

// Std logger sends to std default logger directly
var Std = Func(func(format string, args ...interface{}) { log.Printf(format, args...) })
var Std = Func(func(format string, args ...any) { log.Printf(format, args...) })
2 changes: 1 addition & 1 deletion v2/logger/interface_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

func TestLogger(t *testing.T) {
buff := bytes.NewBufferString("")
lg := Func(func(format string, args ...interface{}) {
lg := Func(func(format string, args ...any) {
fmt.Fprintf(buff, format, args...)
})

Expand Down
Loading
Loading