-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgraph_test.go
More file actions
286 lines (270 loc) · 13.2 KB
/
graph_test.go
File metadata and controls
286 lines (270 loc) · 13.2 KB
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
package vcrypt
import (
"reflect"
"sort"
"testing"
"github.com/vcrypt/vcrypt/config"
"github.com/vcrypt/vcrypt/internal/test"
)
var (
// [secretbox "master key"] -> [secretbox "op 1 key"] -> [input "op 1 input"]
// | |
// | -> [material "op 1 data"]
// |
// -> [secretbox "op 2 key"] -> [input "op 2 input"]
// |
// -> [material "op 2 data"]
twoManGraph = buildGraph(test.TwoManPlanConfig)
// [secretbox "step 3"] -> [input "step 3 input"]
// |
// -> [secretbox "step 2"] -> [input "step 2 input"]
// |
// -> [secretbox "step 1"] -> [input "step 1 input"]
// |
// -> [material]
twoPartyGraph = buildGraph(test.TwoPartyPlanConfig)
// [secretbox "top"] -> [input "top input"]
// |
// -> [mux] -> [secretbox "left"] -> [input "left input"]
// | |
// | -> [demux] -> [secretbox "bottom"] -> [input "bottom input"]
// | | |
// -> [secretbox "right"] -> [input "right input"] -> [material "bottom data"]
diamondGraph = buildGraph(test.DiamondPlanConfig)
// [sss "five-of-seven"] -> [openpgp "[email protected]"] -> [openpgp-key "[email protected]"]
// | |
// | -> [material]
// |
// -> [openpgp "[email protected]"] -> [openpgp-key "[email protected]"]
// | |
// | -> [material]
// |
// -> [openpgp "[email protected]"] -> [openpgp-key "[email protected]"]
// | |
// | -> [material]
// |
// -> [openpgp "[email protected]"] -> [openpgp-key "[email protected]"]
// | |
// | -> [material]
// |
// -> [openpgp "[email protected]"] -> [openpgp-key "[email protected]"]
// | |
// | -> [material]
// |
// -> [openpgp "[email protected]"] -> [openpgp-key "[email protected]"]
// | |
// | -> [material]
// |
// -> [openpgp "[email protected]"] -> [openpgp-key "[email protected]"]
// |
// -> [material]
dnsSecGraph = buildGraph(test.DNSSecConfig)
// [sss "master-key"] -> [rsa "president"] -> [ssh-key "[email protected]"]
// | |
// | -> [material "alice material"]
// |
// -> [sss "vp quorum"] -> [*vote "bob:quorum"]
// | |
// | -> [*vote "claire:quorum"]
// | |
// | -> [*vote "david:quorum"]
// |
// -> [xor "vp consensus"] -> [*vote "bob:consenus"]
// | |
// | -> [*vote "claire:consensus"]
// | |
// | -> [*vote "david:consensus"]
// |
// -> [sss "so quorum"] -> [*vote "emily:quorum"]
// | |
// | -> [*vote "frank:quorum"]
// | |
// | -> [*vote "gloria:quorum"]
// |
// -> [xor "so consensus"] -> [*vote "emily:consenus"]
// |
// -> [*vote "frank:consensus"]
// |
// -> [*vote "gloria:consensus"]
//
//
// [*vote "<name>:quorum] : [secretbox "<name> quorum vote"] ------> [material "<name> quorum material"]
// |
// -> [demux "<name> votes"] -> [rsa "<name>"] -> [ssh-key "<name>@acme.bank"]
// | |
// | -> [material "<name> material"]
// |
// [*vote "<name>:conensus] : [secretbox "<name> consensus vote"] -> [material "<name> consensus material"]
//
acmeBankGraph = buildGraph(test.AcmeBankConfig)
)
func TestGraph(t *testing.T) {
tests := []struct {
*Graph
nodes []string
}{
{
Graph: twoManGraph,
nodes: []string{
"master key", // [secretbox "master key"]
"operator 1 key", // [secretbox "op 1 key"]
"operator 2 key", // [secretbox "op 2 key"]
"op 1 secret", // [input "op 1 input"]
"op 2 secret", // [input "op 2 input"]
"op 1 material", // [material "op 1 material"]
"op 2 material", // [material "op 2 material"]
},
},
{
Graph: twoPartyGraph,
nodes: []string{
"step 3", // [secretbox "step 3"]
"step 2", // [secretbox "step 2"]
"step 1", // [secretbox "step 1"]
"party 1 password 2", // [input "step 3 input"]
"party 2 password", // [input "step 2 input"]
"party 1 password 1", // [input "step 1 input"]
"", // [material]
},
},
{
Graph: diamondGraph,
nodes: []string{
"step 3", // [secretbox "top"]
"", // [mux]
"step 2a", // [secretbox "left"]
"step 2b", // [secretbox "right"]
"", // [demux]
"step 1", // [secretbox "bottom"]
"step 3 password", // [input "top input"]
"step 2a password", // [input "left input"]
"step 2b password", // [input "right input"]
"step 1 password", // [input "bottom input"]
"bottom material", // [material "bottom material"]
},
},
{
Graph: dnsSecGraph,
nodes: []string{
"five-of-seven", // [sss "five-of-seven"]
"[email protected]", // [openpgp "[email protected]"]
"[email protected]", // [openpgp "[email protected]"]
"[email protected]", // [openpgp "[email protected]"]
"[email protected]", // [openpgp "[email protected]"]
"[email protected]", // [openpgp "[email protected]"]
"[email protected]", // [openpgp "[email protected]"]
"[email protected]", // [openpgp "[email protected]"]
test.Users["alice"].OpenPGPKey.KeyID, // [openpgp-key "[email protected]"]
test.Users["bob"].OpenPGPKey.KeyID, // [openpgp-key "[email protected]"]
test.Users["claire"].OpenPGPKey.KeyID, // [openpgp-key "[email protected]"]
test.Users["david"].OpenPGPKey.KeyID, // [openpgp-key "[email protected]"]
test.Users["emily"].OpenPGPKey.KeyID, // [openpgp-key "[email protected]"]
test.Users["frank"].OpenPGPKey.KeyID, // [openpgp-key "[email protected]"]
test.Users["gloria"].OpenPGPKey.KeyID, // [openpgp-key "[email protected]"]
"alice material", // [material "[email protected]"]
"bob material", // [material "[email protected]"]
"claire material", // [material "[email protected]"]
"david material", // [material "[email protected]"]
"emily material", // [material "[email protected]"]
"frank material", // [material "[email protected]"]
"gloria material", // [material "[email protected]"]
},
},
{
Graph: acmeBankGraph,
nodes: []string{
"master-key", // [sss "master-key"]
"president", // [rsa "president"]
"[email protected]", // [ssh-key "[email protected]"]
"vp quorum", // [sss "vp quorum"]
"so quorum", // [sss "so quorum"]
"vp consensus", // [sss "vp consensus"]
"so consensus", // [sss "so consensus"]
"bob quorum vote", // [secretbox "bob quorum vote"]
"bob consensus vote", // [secretbox "bob consensus vote"]
"bob votes", // [demux "bob votes"]
"bob", // [rsa "bob"]
"[email protected]", // [ssh-key "[email protected]"]
"claire quorum vote", // [secretbox "claire quorum vote"]
"claire consensus vote", // [secretbox "claire consensus vote"]
"claire votes", // [demux "claire votes"]
"claire", // [rsa "claire"]
"[email protected]", // [ssh-key "[email protected]"]
"david quorum vote", // [secretbox "david quorum vote"]
"david consensus vote", // [secretbox "david consensus vote"]
"david votes", // [demux "david votes"]
"david", // [rsa "david"]
"[email protected]", // [ssh-key "[email protected]"]
"emily quorum vote", // [secretbox "emily quorum vote"]
"emily consensus vote", // [secretbox "emily consensus vote"]
"emily votes", // [demux "emily votes"]
"emily", // [rsa "emily"]
"[email protected]", // [ssh-key "[email protected]"]
"frank quorum vote", // [secretbox "frank quorum vote"]
"frank consensus vote", // [secretbox "frank consensus vote"]
"frank votes", // [demux "frank votes"]
"frank", // [rsa "frank"]
"[email protected]", // [ssh-key "[email protected]"]
"gloria quorum vote", // [secretbox "gloria quorum vote"]
"gloria consensus vote", // [secretbox "gloria consensus vote"]
"gloria votes", // [demux "gloria votes"]
"gloria", // [rsa "gloria"]
"[email protected]", // [ssh-key "[email protected]"]
"alice material", // [material "alice material"]
"bob quorum material", // [material "bob quorum material"]
"bob consensus material", // [material "bob consensus material"]
"bob material", // [material "bob material"]
"claire quorum material", // [material "claire quorum material"]
"claire consensus material", // [material "claire consensus material"]
"claire material", // [material "claire material"]
"david quorum material", // [material "david quorum material"]
"david consensus material", // [material "david consensus material"]
"david material", // [material "david material"]
"emily quorum material", // [material "emily quorum material"]
"emily consensus material", // [material "emily consensus material"]
"emily material", // [material "emily material"]
"frank quorum material", // [material "frank quorum material"]
"frank consensus material", // [material "frank consensus material"]
"frank material", // [material "frank material"]
"gloria quorum material", // [material "gloria quorum material"]
"gloria consensus material", // [material "gloria consensus material"]
"gloria material", // [material "gloria material"]
},
},
}
for _, test := range tests {
nodes, err := test.Graph.Nodes()
if err != nil {
t.Fatal(err)
}
want := test.nodes[:]
sort.Strings(want)
if len(nodes) != len(test.nodes) {
t.Errorf("want len(nodes) = %d, got %d", len(test.nodes), len(nodes))
continue
}
got := make([]string, 0, len(nodes))
for _, node := range nodes {
comment, err := node.Comment()
if err != nil {
t.Error(err)
}
got = append(got, comment)
}
sort.Strings(got)
if !reflect.DeepEqual(want, got) {
t.Errorf("want nodes %q, got %q", want, got)
}
}
}
func buildGraph(data []byte) *Graph {
cp := config.Plan{}
if err := config.Unmarshal(data, &cp); err != nil {
panic(err)
}
g, err := build(cp)
if err != nil {
panic(err)
}
return g
}