auth: refactor errors to have prefix
This commit is contained in:
parent
6223c43cd7
commit
9db1f304fa
3 changed files with 7 additions and 7 deletions
|
|
@ -8,8 +8,8 @@ import (
|
|||
"github.com/openshift-online/ocm-sdk-go/authentication"
|
||||
)
|
||||
|
||||
var NoJWTError = errors.New("request doesn't contain JWT")
|
||||
var NoKeyError = errors.New("cannot find key in jwt claims")
|
||||
var ErrNoJWT = errors.New("request doesn't contain JWT")
|
||||
var ErrNoKey = errors.New("cannot find key in jwt claims")
|
||||
|
||||
// GetFromClaims returns a value of JWT claim with the specified key
|
||||
//
|
||||
|
|
@ -22,7 +22,7 @@ func GetFromClaims(ctx context.Context, keys []string) (string, error) {
|
|||
if err != nil {
|
||||
return "", err
|
||||
} else if token == nil {
|
||||
return "", NoJWTError
|
||||
return "", ErrNoJWT
|
||||
}
|
||||
|
||||
claims := token.Claims.(jwt.MapClaims)
|
||||
|
|
@ -35,5 +35,5 @@ func GetFromClaims(ctx context.Context, keys []string) (string, error) {
|
|||
|
||||
}
|
||||
|
||||
return "", NoKeyError
|
||||
return "", ErrNoKey
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ func TestChannelFromContext(t *testing.T) {
|
|||
token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.e30.AmoXfoVMgoq4H-XsD7lTGgY6QJCW1914aYlmGnj7wtY",
|
||||
value: "",
|
||||
expectedFields: []string{"rh-org-id"},
|
||||
err: auth.NoKeyError,
|
||||
err: auth.ErrNoKey,
|
||||
},
|
||||
{
|
||||
name: "no rh-org-id but account_id=123",
|
||||
|
|
@ -60,7 +60,7 @@ func TestChannelFromContext(t *testing.T) {
|
|||
|
||||
t.Run("no jwt token in context", func(t *testing.T) {
|
||||
channel, err := auth.GetFromClaims(context.Background(), []string{"osbuild!"})
|
||||
require.ErrorIs(t, err, auth.NoJWTError)
|
||||
require.ErrorIs(t, err, auth.ErrNoJWT)
|
||||
require.Equal(t, "", channel)
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ func TenantChannelMiddleware(tenantProviderFields []string, onFail error) func(n
|
|||
return func(ctx echo.Context) error {
|
||||
tenant, err := GetFromClaims(ctx.Request().Context(), tenantProviderFields)
|
||||
// Allowlisted paths won't have a token
|
||||
if err != nil && !errors.Is(err, NoJWTError) {
|
||||
if err != nil && !errors.Is(err, ErrNoJWT) {
|
||||
return onFail
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue