-
Notifications
You must be signed in to change notification settings - Fork 3
/
format_test.go
50 lines (38 loc) · 1.16 KB
/
format_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
package macaroon
import (
"testing"
"github.com/alecthomas/assert/v2"
)
func TestTokenFormat(t *testing.T) {
var (
kid = rbuf(10)
ka = NewEncryptionKey()
key = NewSigningKey()
)
m, err := New(kid, "root", key)
assert.NoError(t, err)
m.Add(cavParent(ActionRead, 110))
m.Add3P(ka, "auth")
buf, err := m.Encode()
assert.NoError(t, err)
found, dcavs, dm, err := dischargeMacaroon(ka, "auth", buf)
assert.NoError(t, err)
assert.True(t, found)
assert.Equal(t, 0, len(dcavs))
dbuf, err := dm.Encode()
assert.NoError(t, err)
tokenHdr := encodeTokens(buf, dbuf)
authHdr := ToAuthorizationHeader(buf, dbuf)
t.Logf("%s", authHdr)
permissionToken, dischargeTokens, err := ParsePermissionAndDischargeTokens(authHdr, "root")
assert.Equal(t, permissionToken, buf)
assert.Equal(t, 1, len(dischargeTokens))
assert.Equal(t, dbuf, dischargeTokens[0])
assert.NoError(t, err)
permissionToken, dischargeTokens, err = ParsePermissionAndDischargeTokens(tokenHdr, "root")
assert.Equal(t, permissionToken, buf)
assert.Equal(t, 1, len(dischargeTokens))
assert.Equal(t, dbuf, dischargeTokens[0])
assert.NoError(t, err)
t.Logf("%v %v", permissionToken, dischargeTokens)
}