fix: support issuer host with path

This commit is contained in:
Sebastiao Pamplona 2022-02-10 12:57:54 +00:00
parent 219ba4e038
commit 648fe9c11d
6 changed files with 183 additions and 16 deletions

121
pkg/op/op_test.go Normal file
View file

@ -0,0 +1,121 @@
package op
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestGetIssuerHost(t *testing.T) {
type args struct {
issuer string
}
type res struct {
path string
}
tests := []struct {
name string
args args
res res
}{
{
name: "just domain, without trailing forward slash",
args: args{
issuer: "https://localhost",
},
res: res{
path: "https://localhost",
},
},
{
name: "just domain, with trailing forward slash",
args: args{
issuer: "https://localhost/",
},
res: res{
path: "https://localhost",
},
},
{
name: "domain with path 1",
args: args{
issuer: "https://localhost/custompath",
},
res: res{
path: "https://localhost",
},
},
{
name: "domain with path 2",
args: args{
issuer: "https://localhost/custom/path",
},
res: res{
path: "https://localhost",
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
gotPath := getIssuerHost(tt.args.issuer)
assert.Equal(t, tt.res.path, gotPath)
})
}
}
func TestGetIssuerPath(t *testing.T) {
type args struct {
issuer string
}
type res struct {
path string
}
tests := []struct {
name string
args args
res res
}{
{
name: "just domain, without trailing forward slash",
args: args{
issuer: "https://localhost",
},
res: res{
path: "",
},
},
{
name: "just domain, with trailing forward slash",
args: args{
issuer: "https://localhost/",
},
res: res{
path: "",
},
},
{
name: "domain with path 1",
args: args{
issuer: "https://localhost/custompath",
},
res: res{
path: "custompath",
},
},
{
name: "domain with path 2",
args: args{
issuer: "https://localhost/custom/path",
},
res: res{
path: "custom/path",
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
gotPath := getIssuerPath(tt.args.issuer)
assert.Equal(t, tt.res.path, gotPath)
})
}
}