mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-15 12:27:59 +00:00
f680dd934d
* chore: rename package errors to zerrors * rename package errors to gerrors * fix error related linting issues * fix zitadel error assertion * fix gosimple linting issues * fix deprecated linting issues * resolve gci linting issues * fix import structure --------- Co-authored-by: Elio Bischof <elio@zitadel.com>
67 lines
1.3 KiB
Go
67 lines
1.3 KiB
Go
package authz
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/zitadel/zitadel/internal/zerrors"
|
|
)
|
|
|
|
func Test_extractBearerToken(t *testing.T) {
|
|
|
|
type args struct {
|
|
ctx context.Context
|
|
token string
|
|
verifier AccessTokenVerifier
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
wantErr bool
|
|
}{
|
|
{
|
|
name: "no auth header set",
|
|
args: args{
|
|
ctx: context.Background(),
|
|
token: "",
|
|
},
|
|
wantErr: true,
|
|
},
|
|
{
|
|
name: "wrong auth header set",
|
|
args: args{
|
|
ctx: context.Background(),
|
|
token: "Basic sds",
|
|
},
|
|
wantErr: true,
|
|
},
|
|
{
|
|
name: "auth header set",
|
|
args: args{
|
|
ctx: context.Background(),
|
|
token: "Bearer AUTH",
|
|
verifier: AccessTokenVerifierFunc(func(context.Context, string) (string, string, string, string, string, error) {
|
|
return "", "", "", "", "", nil
|
|
}),
|
|
},
|
|
wantErr: false,
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
_, err := extractBearerToken(tt.args.token)
|
|
if tt.wantErr && err == nil {
|
|
t.Errorf("got wrong result, should get err: actual: %v ", err)
|
|
}
|
|
|
|
if !tt.wantErr && err != nil {
|
|
t.Errorf("got wrong result, should not get err: actual: %v ", err)
|
|
}
|
|
|
|
if tt.wantErr && !zerrors.IsUnauthenticated(err) {
|
|
t.Errorf("got wrong err: %v ", err)
|
|
}
|
|
})
|
|
}
|
|
}
|