-
Notifications
You must be signed in to change notification settings - Fork 0
/
webfinger_test.go
109 lines (87 loc) · 2.29 KB
/
webfinger_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package webfinger_test
import (
"net/http/httptest"
"testing"
"github.com/stretchr/testify/assert"
"github.com/thegrumpylion/webfinger"
)
func getTestDB() webfinger.DB {
return webfinger.NewMemDB(map[string][]byte{
"http://blog.example.com/article/id/314": []byte(`
{
"subject" : "http://blog.example.com/article/id/314",
"aliases" :
[
"http://blog.example.com/cool_new_thing",
"http://blog.example.com/steve/article/7"
],
"properties" :
{
"http://blgx.example.net/ns/version" : "1.3",
"http://blgx.example.net/ns/ext" : null
},
"links" :
[
{
"rel" : "copyright",
"href" : "http://www.example.com/copyright"
},
{
"rel" : "author",
"href" : "http://blog.example.com/author/steve",
"titles" :
{
"en-us" : "The Magical World of Steve",
"fr" : "Le Monde Magique de Steve"
},
"properties" :
{
"http://example.com/role" : "editor"
}
}
]
}
`),
})
}
func TestHandler(t *testing.T) {
assert := assert.New(t)
h := webfinger.NewHandler(getTestDB(), webfinger.WithAllowOrigin("*"))
s := httptest.NewServer(h)
c, err := webfinger.NewClient(s.URL)
assert.Nil(err)
q := webfinger.NewQuery("http://blog.example.com/article/id/314")
r, err := c.Query(q)
assert.Nil(err)
assert.Equal("http://blog.example.com/article/id/314", r.Subject)
assert.Equal([]string{
"http://blog.example.com/cool_new_thing",
"http://blog.example.com/steve/article/7",
}, r.Aliases)
p, ok := r.Properties["http://blgx.example.net/ns/version"]
assert.True(ok)
assert.NotNil(p)
assert.Equal("1.3", *p)
p, ok = r.Properties["http://blgx.example.net/ns/ext"]
assert.True(ok)
assert.Nil(p)
assert.Len(r.Links, 2)
l0 := r.Links[0]
assert.Equal("copyright", l0.Rel)
assert.Equal("http://www.example.com/copyright", l0.Href)
assert.Equal("copyright", l0.Rel)
assert.Equal("copyright", l0.Rel)
l1 := r.Links[1]
assert.Equal("author", l1.Rel)
assert.Equal("http://blog.example.com/author/steve", l1.Href)
t1, ok := l1.Titles["en-us"]
assert.True(ok)
assert.Equal("The Magical World of Steve", t1)
t2, ok := l1.Titles["fr"]
assert.True(ok)
assert.Equal("Le Monde Magique de Steve", t2)
p, ok = l1.Properties["http://example.com/role"]
assert.True(ok)
assert.NotNil(p)
assert.Equal("editor", *p)
}