* en/decoding abstraction * some comments * fix token validation and error messages * fix: audience mapping (single aud string) * fix tests with VerifyIdToken * reformat imports * go mod tidy * Update pkg/oidc/authorization.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update pkg/oidc/authorization.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update pkg/op/authrequest_test.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * fix capitalization Co-authored-by: Silvan <silvan.reusser@gmail.com>
95 lines
1.6 KiB
Go
95 lines
1.6 KiB
Go
package op
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
)
|
|
|
|
func TestValidateIssuer(t *testing.T) {
|
|
type args struct {
|
|
issuer string
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
wantErr bool
|
|
}{
|
|
{
|
|
"missing issuer fails",
|
|
args{""},
|
|
true,
|
|
},
|
|
{
|
|
"invalid url for issuer fails",
|
|
args{":issuer"},
|
|
true,
|
|
},
|
|
{
|
|
"invalid url for issuer fails",
|
|
args{":issuer"},
|
|
true,
|
|
},
|
|
{
|
|
"host for issuer missing fails",
|
|
args{"https:///issuer"},
|
|
true,
|
|
},
|
|
{
|
|
"host for not https fails",
|
|
args{"http://issuer.com"},
|
|
true,
|
|
},
|
|
{
|
|
"host with fragment fails",
|
|
args{"https://issuer.com/#issuer"},
|
|
true,
|
|
},
|
|
{
|
|
"host with query fails",
|
|
args{"https://issuer.com?issuer=me"},
|
|
true,
|
|
},
|
|
{
|
|
"host with https ok",
|
|
args{"https://issuer.com"},
|
|
false,
|
|
},
|
|
{
|
|
"localhost with http fails",
|
|
args{"http://localhost:9999"},
|
|
true,
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
if err := ValidateIssuer(tt.args.issuer); (err != nil) != tt.wantErr {
|
|
t.Errorf("ValidateIssuer() error = %v, wantErr %v", err, tt.wantErr)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestValidateIssuerDevLocalAllowed(t *testing.T) {
|
|
type args struct {
|
|
issuer string
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
wantErr bool
|
|
}{
|
|
{
|
|
"localhost with http with dev ok",
|
|
args{"http://localhost:9999"},
|
|
false,
|
|
},
|
|
}
|
|
os.Setenv("CAOS_OIDC_DEV", "")
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
if err := ValidateIssuer(tt.args.issuer); (err != nil) != tt.wantErr {
|
|
t.Errorf("ValidateIssuer() error = %v, wantErr %v", err, tt.wantErr)
|
|
}
|
|
})
|
|
}
|
|
}
|