tinyrelayfile
tinyrelay/internal/gates/marmot_test.go/

internal/gates/marmot_test.go raw
1package gates
2
3import (
4 "encoding/base64"
5 "strings"
6 "testing"
7
8 "github.com/FelineStateMachine/tinyrelay/internal/event"
9)
10
11func TestMarmotGroupShape(t *testing.T) {
12 e := event.Event{Kind: event.KIND_MARMOT_GROUP, Content: base64.StdEncoding.EncodeToString(make([]byte, 28)), Tags: [][]string{{"h", strings.Repeat("a", 64)}}}
13 if err := MarmotShape(e); err != nil {
14 t.Fatal(err)
15 }
16 for _, tc := range []struct {
17 name string
18 mutate func(*event.Event)
19 }{
20 {"bad h", func(x *event.Event) { x.Tags[0][1] = strings.Repeat("A", 64) }},
21 {"short content", func(x *event.Event) { x.Content = base64.StdEncoding.EncodeToString([]byte("short")) }},
22 {"unknown tag", func(x *event.Event) { x.Tags = append(x.Tags, []string{"x", "y"}) }},
23 {"duplicate expiration", func(x *event.Event) {
24 x.Tags = append(x.Tags, []string{"expiration", "1"}, []string{"expiration", "2"})
25 }},
26 } {
27 t.Run(tc.name, func(t *testing.T) {
28 copy := e
29 copy.Tags = append([][]string(nil), e.Tags...)
30 for i := range copy.Tags {
31 copy.Tags[i] = append([]string(nil), copy.Tags[i]...)
32 }
33 tc.mutate(&copy)
34 if MarmotShape(copy) == nil {
35 t.Fatal("invalid shape accepted")
36 }
37 })
38 }
39}
40
41func TestMarmotKeyPackageShape(t *testing.T) {
42 e := event.Event{Kind: event.KIND_MARMOT_KEY_PACKAGE, Content: base64.StdEncoding.EncodeToString([]byte("package")), Tags: [][]string{{"d", strings.Repeat("a", 64)}, {"mls_protocol_version", "1.0"}, {"i", "01"}, {"mls_ciphersuite", "0x0001"}, {"mls_extensions", "0x0001"}, {"mls_proposals", "0x0001"}, {"app_components", "0x8009"}}}
43 if err := MarmotShape(e); err != nil {
44 t.Fatal(err)
45 }
46 e.Tags[3][1] = "0x0000"
47 if err := MarmotShape(e); err != nil {
48 t.Fatal(err)
49 }
50 e.Tags[6] = []string{"app_components", "0x8008"}
51 if MarmotShape(e) == nil {
52 t.Fatal("missing identity proof accepted")
53 }
54}

About

ownerc01503e8035f
visibilitypublic
headd730679639bf

Maintainers

  • c01503e8035f owner
  • ba1b5beed5b5 agent hermes

Clone

  • https://012.run/npub1cq2s86qrtadf36eqq3epm38wmhdynrrcwxf84eldk3f94dkv7ttsrulrz5/tinyrelay.git

Refs