Initial QSfera import
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
package relations
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/qsfera/server/pkg/oidc"
|
||||
"github.com/qsfera/server/services/webfinger/pkg/config"
|
||||
"github.com/qsfera/server/services/webfinger/pkg/webfinger"
|
||||
)
|
||||
|
||||
func TestQsferaInstanceErr(t *testing.T) {
|
||||
_, err := QsferaInstance([]config.Instance{}, "http://\n\rinvalid")
|
||||
if err == nil {
|
||||
t.Errorf("provider did not err on invalid url: %v", err)
|
||||
}
|
||||
_, err = QsferaInstance([]config.Instance{{Regex: "("}}, "http://qsfera.tld")
|
||||
if err == nil {
|
||||
t.Errorf("provider did not err on invalid regex: %v", err)
|
||||
}
|
||||
_, err = QsferaInstance([]config.Instance{{Href: "{{invalid}}ee"}}, "http://qsfera.tld")
|
||||
if err == nil {
|
||||
t.Errorf("provider did not err on invalid href template: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestQsferaInstanceAddLink(t *testing.T) {
|
||||
provider, err := QsferaInstance([]config.Instance{{
|
||||
Claim: "customclaim",
|
||||
Regex: ".+@.+\\..+",
|
||||
Href: "https://{{.otherclaim}}.domain.tld",
|
||||
Titles: map[string]string{
|
||||
"foo": "bar",
|
||||
},
|
||||
Break: true,
|
||||
}}, "http://qsfera.tld")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = oidc.NewContext(ctx, map[string]any{
|
||||
"customclaim": "some@fizz.buzz",
|
||||
"otherclaim": "someone",
|
||||
})
|
||||
jrd := webfinger.JSONResourceDescriptor{}
|
||||
provider.Add(ctx, "", &jrd)
|
||||
|
||||
if len(jrd.Links) != 1 {
|
||||
t.Errorf("provider returned wrong number of links: %v, expected 1", len(jrd.Links))
|
||||
}
|
||||
if jrd.Links[0].Href != "https://someone.domain.tld" {
|
||||
t.Errorf("provider returned wrong issuer link href: %v, expected %v", jrd.Links[0].Href, "https://someone.domain.tld")
|
||||
}
|
||||
if jrd.Links[0].Rel != QsferaInstanceRel {
|
||||
t.Errorf("provider returned qsfera server instance rel: %v, expected %v", jrd.Links[0].Rel, QsferaInstanceRel)
|
||||
}
|
||||
if len(jrd.Links[0].Titles) != 1 {
|
||||
t.Errorf("provider returned wrong number of titles: %v, expected 1", len(jrd.Links[0].Titles))
|
||||
}
|
||||
if jrd.Links[0].Titles["foo"] != "bar" {
|
||||
t.Errorf("provider returned wrong title: %v, expected bar", len(jrd.Links[0].Titles["foo"]))
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user