1
0
mirror of https://github.com/lxc/incus.git synced 2026-02-05 09:46:19 +01:00

tests: Don't needlessly use format string functions

Signed-off-by: Nathan Chase <ntc477@utexas.edu>
This commit is contained in:
Nathan Chase
2025-05-23 01:23:43 -04:00
committed by Stéphane Graber
parent 48a2cd3f22
commit 79075b3e4a
2 changed files with 18 additions and 19 deletions

View File

@@ -5,7 +5,6 @@ import (
"crypto/rand"
"crypto/rsa"
"errors"
"fmt"
"math/big"
"strings"
"sync"
@@ -131,7 +130,7 @@ func (s *Storage) CheckUsernamePassword(username, password, id string) error {
defer s.lock.Unlock()
request, ok := s.authRequests[id]
if !ok {
return fmt.Errorf("request not found")
return errors.New("request not found")
}
// for demonstration purposes we'll check we'll have a simple user store and
@@ -149,7 +148,7 @@ func (s *Storage) CheckUsernamePassword(username, password, id string) error {
request.done = true
return nil
}
return fmt.Errorf("username or password wrong")
return errors.New("username or password wrong")
}
func (s *Storage) CheckUsernamePasswordSimple(username, password string) error {
@@ -160,7 +159,7 @@ func (s *Storage) CheckUsernamePasswordSimple(username, password string) error {
if user != nil && user.Password == password {
return nil
}
return fmt.Errorf("username or password wrong")
return errors.New("username or password wrong")
}
// CreateAuthRequest implements the op.Storage interface
@@ -195,7 +194,7 @@ func (s *Storage) AuthRequestByID(ctx context.Context, id string) (op.AuthReques
defer s.lock.Unlock()
request, ok := s.authRequests[id]
if !ok {
return nil, fmt.Errorf("request not found")
return nil, errors.New("request not found")
}
return request, nil
}
@@ -211,7 +210,7 @@ func (s *Storage) AuthRequestByCode(ctx context.Context, code string) (op.AuthRe
return requestID, ok
}()
if !ok {
return nil, fmt.Errorf("code invalid or expired")
return nil, errors.New("code invalid or expired")
}
return s.AuthRequestByID(ctx, requestID)
}
@@ -327,7 +326,7 @@ func (s *Storage) TokenRequestByRefreshToken(ctx context.Context, refreshToken s
defer s.lock.Unlock()
token, ok := s.refreshTokens[refreshToken]
if !ok {
return nil, fmt.Errorf("invalid refresh_token")
return nil, errors.New("invalid refresh_token")
}
return RefreshTokenRequestFromBusiness(token), nil
}
@@ -424,7 +423,7 @@ func (s *Storage) GetClientByClientID(ctx context.Context, clientID string) (op.
defer s.lock.Unlock()
client, ok := s.clients[clientID]
if !ok {
return nil, fmt.Errorf("client not found")
return nil, errors.New("client not found")
}
return RedirectGlobsClient(client), nil
}
@@ -436,12 +435,12 @@ func (s *Storage) AuthorizeClientIDSecret(ctx context.Context, clientID, clientS
defer s.lock.Unlock()
client, ok := s.clients[clientID]
if !ok {
return fmt.Errorf("client not found")
return errors.New("client not found")
}
// for this example we directly check the secret
// obviously you would not have the secret in plain text, but rather hashed and salted (e.g. using bcrypt)
if client.secret != clientSecret {
return fmt.Errorf("invalid secret")
return errors.New("invalid secret")
}
return nil
}
@@ -469,7 +468,7 @@ func (s *Storage) SetUserinfoFromToken(ctx context.Context, userinfo *oidc.UserI
return token, ok
}()
if !ok {
return fmt.Errorf("token is invalid or has expired")
return errors.New("token is invalid or has expired")
}
// the userinfo endpoint should support CORS. If it's not possible to specify a specific origin in the CORS handler,
// and you have to specify a wildcard (*) origin, then you could also check here if the origin which called the userinfo endpoint here directly
@@ -478,7 +477,7 @@ func (s *Storage) SetUserinfoFromToken(ctx context.Context, userinfo *oidc.UserI
// if origin != "" {
// client, ok := s.clients[token.ApplicationID]
// if !ok {
// return fmt.Errorf("client not found")
// return errors.New("client not found")
// }
// if err := checkAllowedOrigins(client.allowedOrigins, origin); err != nil {
// return err
@@ -497,7 +496,7 @@ func (s *Storage) SetIntrospectionFromToken(ctx context.Context, introspection *
return token, ok
}()
if !ok {
return fmt.Errorf("token is invalid or has expired")
return errors.New("token is invalid or has expired")
}
// check if the client is part of the requested audience
for _, aud := range token.Audience {
@@ -520,7 +519,7 @@ func (s *Storage) SetIntrospectionFromToken(ctx context.Context, introspection *
return nil
}
}
return fmt.Errorf("token is not valid for this client")
return errors.New("token is not valid for this client")
}
// GetPrivateClaimsFromScopes implements the op.Storage interface
@@ -546,11 +545,11 @@ func (s *Storage) GetKeyByIDAndClientID(ctx context.Context, keyID, clientID str
defer s.lock.Unlock()
service, ok := s.services[clientID]
if !ok {
return nil, fmt.Errorf("clientID not found")
return nil, errors.New("clientID not found")
}
key, ok := service.keys[keyID]
if !ok {
return nil, fmt.Errorf("key not found")
return nil, errors.New("key not found")
}
return &jose.JSONWebKey{
KeyID: keyID,
@@ -601,7 +600,7 @@ func (s *Storage) renewRefreshToken(currentRefreshToken string) (string, string,
defer s.lock.Unlock()
refreshToken, ok := s.refreshTokens[currentRefreshToken]
if !ok {
return "", "", fmt.Errorf("invalid refresh token")
return "", "", errors.New("invalid refresh token")
}
// deletes the refresh token and all access tokens which were issued based on this refresh token
delete(s.refreshTokens, currentRefreshToken)
@@ -642,7 +641,7 @@ func (s *Storage) setUserinfo(ctx context.Context, userInfo *oidc.UserInfo, user
defer s.lock.Unlock()
user := s.userStore.GetUserByID(userID)
if user == nil {
return fmt.Errorf("user not found")
return errors.New("user not found")
}
for _, scope := range scopes {
switch scope {

View File

@@ -61,6 +61,6 @@ func main() {
os.Exit(0)
}
fmt.Fprintf(os.Stderr, "Error: Couldn't sign the token (unsupported algorithm?)\n")
fmt.Fprint(os.Stderr, "Error: Couldn't sign the token (unsupported algorithm?)\n")
os.Exit(1)
}