This repository has been archived by the owner on Dec 14, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
debianupdate_test.go
209 lines (180 loc) · 5.61 KB
/
debianupdate_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
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
package debianupdate
import (
"flag"
"os"
"runtime/pprof"
"strconv"
"testing"
"time"
"github.com/dedis/simul/monitor"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gopkg.in/dedis/onet.v1"
"gopkg.in/dedis/onet.v1/crypto"
"gopkg.in/dedis/onet.v1/log"
)
func init() {
initGlobals()
}
func TestMain(m *testing.M) {
os.RemoveAll("config")
rc := map[string]string{}
mon := monitor.NewMonitor(monitor.NewStats(rc))
go func() { log.ErrFatal(mon.Listen()) }()
local := "localhost:" + strconv.Itoa(monitor.DefaultSinkPort)
log.ErrFatal(monitor.ConnectSink(local))
flag.Parse()
log.TestOutput(testing.Verbose(), 2)
done := make(chan int)
go func() {
code := m.Run()
done <- code
}()
select {
case code := <-done:
monitor.EndAndCleanup()
log.AfterTest(nil)
os.Exit(code)
case <-time.After(log.MainTestWait):
log.Error("Didn't finish in time")
pprof.Lookup("goroutine").WriteTo(os.Stdout, 1)
os.Exit(1)
}
}
func TestDebianUpdate_RepositorySC(t *testing.T) {
local := onet.NewLocalTest()
defer local.CloseAll()
_, roster, s := local.MakeHELS(5, debianUpdateService)
service := s.(*DebianUpdate)
release := chain1.blocks[0].release
crr, err := service.CreateRepository(nil,
&CreateRepository{roster, release, 2, 10})
log.ErrFatal(err)
repoChain := crr.(*CreateRepositoryRet).RepositoryChain
reposcret, err := service.RepositorySC(nil, &RepositorySC{"unknown"})
require.NotNil(t, err)
reposcret, err = service.RepositorySC(nil,
&RepositorySC{release.Repository.GetName()})
log.ErrFatal(err)
sc2 := reposcret.(*RepositorySCRet).Last
require.Equal(t, repoChain.Data.Hash, sc2.Hash)
sc3 := service.Storage.RepositoryChain[release.Repository.GetName()]
require.Equal(t, repoChain.Data.Hash, sc3.Data.Hash)
}
func TestDebianUpdate_CreateRepository(t *testing.T) {
local := onet.NewLocalTest()
defer local.CloseAll()
_, roster, s := local.MakeHELS(5, debianUpdateService)
service := s.(*DebianUpdate)
release1 := chain1.blocks[0].release
rootHash := chain2.blocks[1].release.RootID
repo1 := chain1.blocks[0].repo
// This should fail as the signatures are wrong
createRepo, err := service.CreateRepository(nil,
&CreateRepository{
Roster: roster,
Release: &Release{repo1, rootHash, release1.Proofs},
Base: 2,
Height: 10,
})
assert.NotNil(t, err, "Accepted wrong root")
createRepo, err = service.CreateRepository(nil,
&CreateRepository{roster, release1, 2, 10})
log.ErrFatal(err)
repoChain := createRepo.(*CreateRepositoryRet).RepositoryChain
assert.NotNil(t, repoChain.Data)
repo := repoChain.Release.Repository
assert.Equal(t, *repo1, *repo)
assert.Equal(t, *repo1,
*service.Storage.RepositoryChain[repo.GetName()].Release.Repository)
assert.Equal(t, release1.RootID,
service.Storage.RepositoryChain[repo.GetName()].Release.RootID)
}
func TestDebianUpdate_UpdateRepository(t *testing.T) {
local := onet.NewLocalTest()
defer local.CloseAll()
_, roster, s := local.MakeHELS(5, debianUpdateService)
service := s.(*DebianUpdate)
release1 := chain1.blocks[0].release
release2 := chain1.blocks[1].release
repo, err := service.CreateRepository(nil,
&CreateRepository{roster, release1, 2, 10})
log.ErrFatal(err)
repoChain := repo.(*CreateRepositoryRet).RepositoryChain
updateRepo, err := service.UpdateRepository(nil,
&UpdateRepository{
RepositoryChain: repoChain,
Release: release2,
})
log.ErrFatal(err)
repoChain = updateRepo.(*UpdateRepositoryRet).RepositoryChain
assert.NotNil(t, repoChain)
assert.Equal(t, *chain1.blocks[1].repo, *repoChain.Release.Repository)
}
func TestDebianUpdate_PropagateBlock(t *testing.T) {
local := onet.NewLocalTest()
defer local.CloseAll()
_, roster, s := local.MakeHELS(5, debianUpdateService)
service := s.(*DebianUpdate)
createRepo, err := service.CreateRepository(nil,
&CreateRepository{roster, chain1.blocks[0].release, 2, 10})
assert.Nil(t, err)
log.ErrFatal(err)
repoChain := createRepo.(*CreateRepositoryRet).RepositoryChain
assert.Equal(t, repoChain.Release, chain1.blocks[0].release)
}
// repositoryChain tracks all test releases for one fake repo
type repositoryChain struct {
repo string
blocks []*repositoryBlock
}
// packageBlock tracks all information on one release of a package
type repositoryBlock struct {
repo *Repository
release *Release
}
var chain1 *repositoryChain
var chain2 *repositoryChain
func initGlobals() {
createBlock := func(origin, suite, version string, packages []*Package) *repositoryBlock {
repo := &Repository{
Origin: origin,
Suite: suite,
Version: version,
Packages: packages,
SourceUrl: "http://mirror.switch.ch/ftp/mirror/debian/dists/stable" +
"/main/binary-amd64/",
}
hashes := make([]crypto.HashID, len(repo.Packages))
for i, p := range repo.Packages {
hashes[i] = crypto.HashID(p.Hash)
}
root, proofs := crypto.ProofTree(HashFunc(), hashes)
return &repositoryBlock{
repo: repo,
release: &Release{repo, root, proofs},
}
}
createChain := func(origin string, suite string, packages []*Package) *repositoryChain {
b1 := createBlock(origin, suite, "1.2", packages)
b2 := createBlock(origin, suite, "1.3", packages)
return &repositoryChain{
repo: origin + "-" + suite,
blocks: []*repositoryBlock{b1, b2},
}
}
packages1 := []*Package{
{"test1", "0.1", "0000"},
{"test2", "0.1", "0101"},
{"test3", "0.1", "1010"},
{"test4", "0.1", "1111"},
}
packages2 := []*Package{
{"test1", "0.1", "000a"},
{"test2", "0.1", "0101"},
{"test3", "0.1", "1010"},
{"test4", "0.1", "1111"},
}
chain1 = createChain("debian", "stable", packages1)
chain2 = createChain("debian", "stable-update", packages2)
}