-
Notifications
You must be signed in to change notification settings - Fork 601
/
Copy pathassets_test.go
3019 lines (2651 loc) · 109 KB
/
assets_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
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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// -*- Mode: Go; indent-tabs-mode: t -*-
/*
* Copyright (C) 2020-2024 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package boot_test
import (
"fmt"
"os"
"path/filepath"
"syscall"
. "gopkg.in/check.v1"
"github.com/snapcore/snapd/arch/archtest"
"github.com/snapcore/snapd/asserts"
"github.com/snapcore/snapd/boot"
"github.com/snapcore/snapd/boot/boottest"
"github.com/snapcore/snapd/bootloader"
"github.com/snapcore/snapd/bootloader/bootloadertest"
"github.com/snapcore/snapd/dirs"
"github.com/snapcore/snapd/gadget"
"github.com/snapcore/snapd/gadget/device"
"github.com/snapcore/snapd/logger"
"github.com/snapcore/snapd/secboot"
"github.com/snapcore/snapd/seed"
"github.com/snapcore/snapd/snap"
"github.com/snapcore/snapd/testutil"
"github.com/snapcore/snapd/timings"
)
type assetsSuite struct {
baseBootenvSuite
}
var _ = Suite(&assetsSuite{})
func (s *assetsSuite) SetUpTest(c *C) {
s.baseBootenvSuite.SetUpTest(c)
restore := boot.MockResealKeyForBootChains(func(unlocker boot.Unlocker, method device.SealingMethod, rootdir string, params *boot.ResealKeyForBootChainsParams, expectReseal bool) error {
return nil
})
s.AddCleanup(restore)
c.Assert(os.MkdirAll(boot.InitramfsUbuntuBootDir, 0755), IsNil)
c.Assert(os.MkdirAll(boot.InitramfsUbuntuSeedDir, 0755), IsNil)
s.AddCleanup(archtest.MockArchitecture("amd64"))
}
func checkContentGlob(c *C, glob string, expected []string) {
l, err := filepath.Glob(glob)
c.Assert(err, IsNil)
c.Check(l, DeepEquals, expected)
}
func (s *assetsSuite) uc20UpdateObserverEncryptedSystemMockedBootloader(c *C) (*boot.TrustedAssetsUpdateObserver, *asserts.Model) {
// checked by TrustedAssetsUpdateObserverForModel and
// resealKeyToModeenv
s.stampSealedKeys(c, dirs.GlobalRootDir)
return s.uc20UpdateObserver(c, c.MkDir())
}
func (s *assetsSuite) uc20UpdateObserver(c *C, gadgetDir string) (*boot.TrustedAssetsUpdateObserver, *asserts.Model) {
uc20Model := boottest.MakeMockUC20Model()
obs, err := boot.TrustedAssetsUpdateObserverForModel(uc20Model, gadgetDir)
c.Assert(obs, NotNil)
c.Assert(err, IsNil)
s.AddCleanup(obs.Done)
return obs, uc20Model
}
func (s *assetsSuite) bootloaderWithTrustedAssets(trustedAssets map[string]string) *bootloadertest.MockTrustedAssetsBootloader {
tab := bootloadertest.Mock("trusted", "").WithTrustedAssets()
bootloader.Force(tab)
tab.TrustedAssetsMap = trustedAssets
s.AddCleanup(func() { bootloader.Force(nil) })
return tab
}
func (s *assetsSuite) TestAssetsCacheAddRemove(c *C) {
cacheDir := c.MkDir()
d := c.MkDir()
cache := boot.NewTrustedAssetsCache(cacheDir)
data := []byte("foobar")
// SHA3-384
hash := "0fa8abfbdaf924ad307b74dd2ed183b9a4a398891a2f6bac8fd2db7041b77f068580f9c6c66f699b496c2da1cbcc7ed8"
err := os.WriteFile(filepath.Join(d, "foobar"), data, 0644)
c.Assert(err, IsNil)
// add a new file
ta, err := cache.Add(filepath.Join(d, "foobar"), "grub", "grubx64.efi")
c.Assert(err, IsNil)
c.Check(filepath.Join(cacheDir, "grub", fmt.Sprintf("grubx64.efi-%s", hash)), testutil.FileEquals, string(data))
c.Check(ta, NotNil)
// try the same file again
taAgain, err := cache.Add(filepath.Join(d, "foobar"), "grub", "grubx64.efi")
c.Assert(err, IsNil)
// file already cached
c.Check(filepath.Join(cacheDir, "grub", fmt.Sprintf("grubx64.efi-%s", hash)), testutil.FileEquals, string(data))
// and there's just one entry in the cache
checkContentGlob(c, filepath.Join(cacheDir, "grub", "*"), []string{
filepath.Join(cacheDir, "grub", fmt.Sprintf("grubx64.efi-%s", hash)),
})
// let go-check do the deep equals check
c.Check(taAgain, DeepEquals, ta)
// same data but different asset name
taDifferentAsset, err := cache.Add(filepath.Join(d, "foobar"), "grub", "bootx64.efi")
c.Assert(err, IsNil)
// new entry in cache
c.Check(filepath.Join(cacheDir, "grub", fmt.Sprintf("bootx64.efi-%s", hash)), testutil.FileEquals, string(data))
// 2 files now
checkContentGlob(c, filepath.Join(cacheDir, "grub", "*"), []string{
filepath.Join(cacheDir, "grub", fmt.Sprintf("bootx64.efi-%s", hash)),
filepath.Join(cacheDir, "grub", fmt.Sprintf("grubx64.efi-%s", hash)),
})
c.Check(taDifferentAsset, NotNil)
// same source, data (new hash), existing asset name
newData := []byte("new foobar")
newHash := "5aa87615f6613a37d63c9a29746ef57457286c37148a4ae78493b0face5976c1fea940a19486e6bef65d43aec6b8f5a2"
err = os.WriteFile(filepath.Join(d, "foobar"), newData, 0644)
c.Assert(err, IsNil)
taExistingAssetName, err := cache.Add(filepath.Join(d, "foobar"), "grub", "bootx64.efi")
c.Assert(err, IsNil)
// new entry in cache
c.Check(taExistingAssetName, NotNil)
// we have both new and old asset
c.Check(filepath.Join(cacheDir, "grub", fmt.Sprintf("bootx64.efi-%s", newHash)), testutil.FileEquals, string(newData))
c.Check(filepath.Join(cacheDir, "grub", fmt.Sprintf("bootx64.efi-%s", hash)), testutil.FileEquals, string(data))
// 3 files in total
checkContentGlob(c, filepath.Join(cacheDir, "grub", "*"), []string{
filepath.Join(cacheDir, "grub", fmt.Sprintf("bootx64.efi-%s", hash)),
filepath.Join(cacheDir, "grub", fmt.Sprintf("bootx64.efi-%s", newHash)),
filepath.Join(cacheDir, "grub", fmt.Sprintf("grubx64.efi-%s", hash)),
})
// drop
err = cache.Remove("grub", "bootx64.efi", newHash)
c.Assert(err, IsNil)
// asset bootx64.efi with given hash was dropped
c.Check(filepath.Join(cacheDir, "grub", fmt.Sprintf("bootx64.efi-%s", newHash)), testutil.FileAbsent)
// the other file still exists
c.Check(filepath.Join(cacheDir, "grub", fmt.Sprintf("bootx64.efi-%s", hash)), testutil.FileEquals, string(data))
// remove it too
err = cache.Remove("grub", "bootx64.efi", hash)
c.Assert(err, IsNil)
c.Check(filepath.Join(cacheDir, "grub", fmt.Sprintf("bootx64.efi-%s", hash)), testutil.FileAbsent)
// what is left is the grub assets only
checkContentGlob(c, filepath.Join(cacheDir, "grub", "*"), []string{
filepath.Join(cacheDir, "grub", fmt.Sprintf("grubx64.efi-%s", hash)),
})
}
func (s *assetsSuite) TestAssetsCacheAddErr(c *C) {
cacheDir := c.MkDir()
d := c.MkDir()
cache := boot.NewTrustedAssetsCache(cacheDir)
defer os.Chmod(cacheDir, 0755)
err := os.Chmod(cacheDir, 0000)
c.Assert(err, IsNil)
if os.Geteuid() != 0 {
err = os.WriteFile(filepath.Join(d, "foobar"), []byte("foo"), 0644)
c.Assert(err, IsNil)
// cannot create bootloader subdirectory
ta, err := cache.Add(filepath.Join(d, "foobar"), "grub", "grubx64.efi")
c.Assert(err, ErrorMatches, "cannot create cache directory: mkdir .*/grub: permission denied")
c.Check(ta, IsNil)
}
// fix it now
err = os.Chmod(cacheDir, 0755)
c.Assert(err, IsNil)
_, err = cache.Add(filepath.Join(d, "no-file"), "grub", "grubx64.efi")
c.Assert(err, ErrorMatches, "cannot open asset file: open .*/no-file: no such file or directory")
if os.Geteuid() != 0 {
blDir := filepath.Join(cacheDir, "grub")
defer os.Chmod(blDir, 0755)
err = os.Chmod(blDir, 0000)
c.Assert(err, IsNil)
_, err = cache.Add(filepath.Join(d, "foobar"), "grub", "grubx64.efi")
c.Assert(err, ErrorMatches, `cannot create temporary cache file: open .*/grub/grubx64\.efi\.temp\.[a-zA-Z0-9]+~: permission denied`)
}
}
func (s *assetsSuite) TestAssetsCacheRemoveErr(c *C) {
cacheDir := c.MkDir()
d := c.MkDir()
cache := boot.NewTrustedAssetsCache(cacheDir)
data := []byte("foobar")
dataHash := "0fa8abfbdaf924ad307b74dd2ed183b9a4a398891a2f6bac8fd2db7041b77f068580f9c6c66f699b496c2da1cbcc7ed8"
err := os.WriteFile(filepath.Join(d, "foobar"), data, 0644)
c.Assert(err, IsNil)
// cannot create bootloader subdirectory
_, err = cache.Add(filepath.Join(d, "foobar"), "grub", "grubx64.efi")
c.Assert(err, IsNil)
// validity
c.Check(filepath.Join(cacheDir, "grub", fmt.Sprintf("grubx64.efi-%s", dataHash)), testutil.FileEquals, string(data))
err = cache.Remove("grub", "no file", "some-hash")
c.Assert(err, IsNil)
// different asset name but known hash
err = cache.Remove("grub", "different-name", dataHash)
c.Assert(err, IsNil)
c.Check(filepath.Join(cacheDir, "grub", fmt.Sprintf("grubx64.efi-%s", dataHash)), testutil.FileEquals, string(data))
}
func (s *assetsSuite) TestInstallObserverNew(c *C) {
d := c.MkDir()
// bootloader in gadget cannot be identified
uc20Model := boottest.MakeMockUC20Model()
for _, encryption := range []bool{true, false} {
obs, err := boot.TrustedAssetsInstallObserverForModel(uc20Model, d, encryption)
c.Assert(err, ErrorMatches, "cannot find bootloader: cannot determine bootloader")
c.Assert(obs, IsNil)
}
// pretend grub is used
c.Assert(os.WriteFile(filepath.Join(d, "grub.conf"), nil, 0755), IsNil)
for _, encryption := range []bool{true, false} {
obs, err := boot.TrustedAssetsInstallObserverForModel(uc20Model, d, encryption)
c.Assert(err, IsNil)
c.Assert(obs, NotNil)
}
// but nil for non UC20
nonUC20Model := boottest.MakeMockModel()
nonUC20obs, err := boot.TrustedAssetsInstallObserverForModel(nonUC20Model, d, false)
c.Assert(err, Equals, boot.ErrObserverNotApplicable)
c.Assert(nonUC20obs, IsNil)
// listing trusted assets fails
tab := s.bootloaderWithTrustedAssets(map[string]string{
"asset": "asset",
})
tab.TrustedAssetsErr = fmt.Errorf("fail")
obs, err := boot.TrustedAssetsInstallObserverForModel(uc20Model, d, true)
c.Assert(err, ErrorMatches, `cannot list "trusted" bootloader trusted assets: fail`)
c.Assert(obs, IsNil)
// failed when listing run bootloader assets
c.Check(tab.TrustedAssetsCalls, Equals, 1)
// force an error
bootloader.ForceError(fmt.Errorf("fail bootloader"))
obs, err = boot.TrustedAssetsInstallObserverForModel(uc20Model, d, true)
c.Assert(err, ErrorMatches, `cannot find bootloader: fail bootloader`)
c.Assert(obs, IsNil)
}
func (s *assetsSuite) TestInstallObserverObserveSystemBootRealGrub(c *C) {
d := c.MkDir()
// mock a bootloader that uses trusted assets
err := os.WriteFile(filepath.Join(d, "grub.conf"), nil, 0644)
c.Assert(err, IsNil)
// we get an observer for UC20
uc20Model := boottest.MakeMockUC20Model()
useEncryption := true
obs, err := boot.TrustedAssetsInstallObserverForModel(uc20Model, d, useEncryption)
c.Assert(err, IsNil)
c.Assert(obs, NotNil)
data := []byte("foobar")
// SHA3-384
dataHash := "0fa8abfbdaf924ad307b74dd2ed183b9a4a398891a2f6bac8fd2db7041b77f068580f9c6c66f699b496c2da1cbcc7ed8"
err = os.WriteFile(filepath.Join(d, "foobar"), data, 0644)
c.Assert(err, IsNil)
otherData := []byte("other foobar")
err = os.WriteFile(filepath.Join(d, "other-foobar"), otherData, 0644)
c.Assert(err, IsNil)
writeChange := &gadget.ContentChange{
// file that contains the data of the installed file
After: filepath.Join(d, "foobar"),
// there is no original file in place
Before: "",
}
// only grubx64.efi gets installed to system-boot
res, err := obs.Observe(gadget.ContentWrite, gadget.SystemBoot, boot.InitramfsUbuntuBootDir,
"EFI/boot/grubx64.efi", writeChange)
c.Assert(err, IsNil)
c.Check(res, Equals, gadget.ChangeApply)
// Observe is called when populating content, but one can freely specify
// overlapping content entries, so a same file may be observed more than
// once
res, err = obs.Observe(gadget.ContentWrite, gadget.SystemBoot, boot.InitramfsUbuntuBootDir,
"EFI/boot/grubx64.efi", writeChange)
c.Assert(err, IsNil)
c.Check(res, Equals, gadget.ChangeApply)
// try with one more file, which is not a trusted asset of a run mode, so it is ignored
res, err = obs.Observe(gadget.ContentWrite, gadget.SystemBoot, boot.InitramfsUbuntuBootDir,
"EFI/boot/bootx64.efi", writeChange)
c.Assert(err, IsNil)
c.Check(res, Equals, gadget.ChangeApply)
// a managed boot asset is to be held
res, err = obs.Observe(gadget.ContentWrite, gadget.SystemBoot, boot.InitramfsUbuntuBootDir,
"EFI/ubuntu/grub.cfg", writeChange)
c.Assert(err, IsNil)
c.Check(res, Equals, gadget.ChangeIgnore)
// a single file in cache
checkContentGlob(c, filepath.Join(dirs.SnapBootAssetsDir, "grub", "*"), []string{
filepath.Join(dirs.SnapBootAssetsDir, "grub", fmt.Sprintf("grubx64.efi-%s", dataHash)),
})
// and one more, a non system-boot structure, so the file is ignored
otherWriteChange := &gadget.ContentChange{
After: filepath.Join(d, "other-foobar"),
}
// set a non system-boot structure, so the file is ignored
res, err = obs.Observe(gadget.ContentWrite, gadget.SystemSeed, boot.InitramfsUbuntuBootDir,
"EFI/boot/grubx64.efi", otherWriteChange)
c.Assert(err, IsNil)
c.Check(res, Equals, gadget.ChangeApply)
// still, only one entry in the cache
checkContentGlob(c, filepath.Join(dirs.SnapBootAssetsDir, "grub", "*"), []string{
filepath.Join(dirs.SnapBootAssetsDir, "grub", fmt.Sprintf("grubx64.efi-%s", dataHash)),
})
observerImpl, ok := obs.(*boot.TrustedAssetsInstallObserverImpl)
c.Assert(ok, Equals, true)
// let's see what the observer has tracked
tracked := observerImpl.CurrentTrustedBootAssetsMap()
c.Check(tracked, DeepEquals, boot.BootAssetsMap{
"grubx64.efi": []string{dataHash},
})
}
func (s *assetsSuite) TestInstallObserverObserveSystemBootMocked(c *C) {
d := c.MkDir()
tab := s.bootloaderWithTrustedAssets(map[string]string{
"asset": "asset",
"nested/other-asset": "other-asset",
})
// we get an observer for UC20
uc20Model := boottest.MakeMockUC20Model()
useEncryption := true
obs, err := boot.TrustedAssetsInstallObserverForModel(uc20Model, d, useEncryption)
c.Assert(err, IsNil)
c.Assert(obs, NotNil)
// the list of trusted assets was asked for run and recovery bootloaders
c.Check(tab.TrustedAssetsCalls, Equals, 2)
data := []byte("foobar")
// SHA3-384
dataHash := "0fa8abfbdaf924ad307b74dd2ed183b9a4a398891a2f6bac8fd2db7041b77f068580f9c6c66f699b496c2da1cbcc7ed8"
err = os.WriteFile(filepath.Join(d, "foobar"), data, 0644)
c.Assert(err, IsNil)
writeChange := &gadget.ContentChange{
// file that contains the data of the installed file
After: filepath.Join(d, "foobar"),
// there is no original file in place
Before: "",
}
res, err := obs.Observe(gadget.ContentWrite, gadget.SystemBoot, boot.InitramfsUbuntuBootDir,
"asset", writeChange)
c.Assert(err, IsNil)
c.Check(res, Equals, gadget.ChangeApply)
// observe same asset again
res, err = obs.Observe(gadget.ContentWrite, gadget.SystemBoot, boot.InitramfsUbuntuBootDir,
"asset", writeChange)
c.Assert(err, IsNil)
c.Check(res, Equals, gadget.ChangeApply)
// different one
res, err = obs.Observe(gadget.ContentWrite, gadget.SystemBoot, boot.InitramfsUbuntuBootDir,
"nested/other-asset", writeChange)
c.Assert(err, IsNil)
c.Check(res, Equals, gadget.ChangeApply)
// a non trusted asset
res, err = obs.Observe(gadget.ContentWrite, gadget.SystemBoot, boot.InitramfsUbuntuBootDir,
"non-trusted", writeChange)
c.Assert(err, IsNil)
c.Check(res, Equals, gadget.ChangeApply)
// a single file in cache
checkContentGlob(c, filepath.Join(dirs.SnapBootAssetsDir, "trusted", "*"), []string{
filepath.Join(dirs.SnapBootAssetsDir, "trusted", fmt.Sprintf("asset-%s", dataHash)),
filepath.Join(dirs.SnapBootAssetsDir, "trusted", fmt.Sprintf("other-asset-%s", dataHash)),
})
observerImpl, ok := obs.(*boot.TrustedAssetsInstallObserverImpl)
c.Assert(ok, Equals, true)
// let's see what the observer has tracked
tracked := observerImpl.CurrentTrustedBootAssetsMap()
c.Check(tracked, DeepEquals, boot.BootAssetsMap{
"asset": []string{dataHash},
"other-asset": []string{dataHash},
})
}
func (s *assetsSuite) TestInstallObserverObserveSystemBootMockedNoEncryption(c *C) {
d := c.MkDir()
s.bootloaderWithTrustedAssets(map[string]string{
"asset": "asset",
})
uc20Model := boottest.MakeMockUC20Model()
useEncryption := false
obs, err := boot.TrustedAssetsInstallObserverForModel(uc20Model, d, useEncryption)
c.Assert(err, Equals, boot.ErrObserverNotApplicable)
c.Assert(obs, IsNil)
}
func (s *assetsSuite) TestInstallObserverObserveSystemBootMockedUnencryptedWithManaged(c *C) {
d := c.MkDir()
tab := s.bootloaderWithTrustedAssets(map[string]string{
"asset": "asset",
})
tab.ManagedAssetsList = []string{"managed"}
uc20Model := boottest.MakeMockUC20Model()
useEncryption := false
obs, err := boot.TrustedAssetsInstallObserverForModel(uc20Model, d, useEncryption)
c.Assert(err, IsNil)
c.Assert(obs, NotNil)
c.Assert(os.WriteFile(filepath.Join(d, "foobar"), nil, 0755), IsNil)
writeChange := &gadget.ContentChange{
// file that contains the data of the installed file
After: filepath.Join(d, "foobar"),
// there is no original file in place
Before: "",
}
res, err := obs.Observe(gadget.ContentWrite, gadget.SystemBoot, boot.InitramfsUbuntuBootDir,
"managed", writeChange)
c.Assert(err, IsNil)
c.Check(res, Equals, gadget.ChangeIgnore)
}
func (s *assetsSuite) TestInstallObserverNonTrustedBootloader(c *C) {
// bootloader is not a trusted assets one, but we use encryption, one
// may try setting encryption key on the observer
d := c.MkDir()
// MockBootloader does not implement trusted assets
bootloader.Force(bootloadertest.Mock("mock", ""))
defer bootloader.Force(nil)
// we get an observer for UC20
uc20Model := boottest.MakeMockUC20Model()
useEncryption := true
obs, err := boot.TrustedAssetsInstallObserverForModel(uc20Model, d, useEncryption)
c.Assert(err, IsNil)
c.Assert(obs, NotNil)
dataBootstrappedContainer := secboot.CreateMockBootstrappedContainer()
saveBootstrappedContainer := secboot.CreateMockBootstrappedContainer()
c.Assert(dataBootstrappedContainer, Not(Equals), saveBootstrappedContainer)
obs.SetBootstrappedContainersAndPrimaryKey(dataBootstrappedContainer, saveBootstrappedContainer, nil)
observerImpl, ok := obs.(*boot.TrustedAssetsInstallObserverImpl)
c.Assert(ok, Equals, true)
c.Check(observerImpl.CurrentDataBootstrappedContainer(), DeepEquals, dataBootstrappedContainer)
c.Check(observerImpl.CurrentSaveBootstrappedContainer(), DeepEquals, saveBootstrappedContainer)
}
func (s *assetsSuite) TestInstallObserverTrustedButNoAssets(c *C) {
// bootloader has no trusted assets, but encryption is enabled, and one
// may try setting a key on the observer
d := c.MkDir()
tab := bootloadertest.Mock("trusted-assets", "").WithTrustedAssets()
bootloader.Force(tab)
defer bootloader.Force(nil)
// we get an observer for UC20
uc20Model := boottest.MakeMockUC20Model()
useEncryption := true
obs, err := boot.TrustedAssetsInstallObserverForModel(uc20Model, d, useEncryption)
c.Assert(err, IsNil)
c.Assert(obs, NotNil)
dataBootstrappedContainer := secboot.CreateMockBootstrappedContainer()
saveBootstrappedContainer := secboot.CreateMockBootstrappedContainer()
obs.SetBootstrappedContainersAndPrimaryKey(dataBootstrappedContainer, saveBootstrappedContainer, nil)
observerImpl, ok := obs.(*boot.TrustedAssetsInstallObserverImpl)
c.Assert(ok, Equals, true)
c.Check(observerImpl.CurrentDataBootstrappedContainer(), DeepEquals, dataBootstrappedContainer)
c.Check(observerImpl.CurrentSaveBootstrappedContainer(), DeepEquals, saveBootstrappedContainer)
}
func (s *assetsSuite) TestInstallObserverTrustedReuseNameErr(c *C) {
d := c.MkDir()
tab := s.bootloaderWithTrustedAssets(map[string]string{
"asset": "asset",
"nested/asset": "asset",
})
// we get an observer for UC20
uc20Model := boottest.MakeMockUC20Model()
useEncryption := true
obs, err := boot.TrustedAssetsInstallObserverForModel(uc20Model, d, useEncryption)
c.Assert(err, IsNil)
c.Assert(obs, NotNil)
// the list of trusted assets was asked for run and recovery bootloaders
c.Check(tab.TrustedAssetsCalls, Equals, 2)
err = os.WriteFile(filepath.Join(d, "foobar"), []byte("foobar"), 0644)
c.Assert(err, IsNil)
err = os.WriteFile(filepath.Join(d, "other"), []byte("other"), 0644)
c.Assert(err, IsNil)
res, err := obs.Observe(gadget.ContentWrite, gadget.SystemBoot, boot.InitramfsUbuntuBootDir, "asset",
&gadget.ContentChange{After: filepath.Join(d, "foobar")})
c.Assert(err, IsNil)
c.Check(res, Equals, gadget.ChangeApply)
// same asset name but different content
res, err = obs.Observe(gadget.ContentWrite, gadget.SystemBoot, boot.InitramfsUbuntuBootDir, "nested/asset",
&gadget.ContentChange{After: filepath.Join(d, "other")})
c.Assert(err, ErrorMatches, `cannot reuse asset name "asset"`)
c.Check(res, Equals, gadget.ChangeAbort)
}
func (s *assetsSuite) TestInstallObserverObserveExistingRecoveryMocked(c *C) {
d := c.MkDir()
tab := s.bootloaderWithTrustedAssets(map[string]string{
"asset": "asset",
"nested/other-asset": "other-asset",
"shim": "shim",
})
// we get an observer for UC20
uc20Model := boottest.MakeMockUC20Model()
useEncryption := true
obs, err := boot.TrustedAssetsInstallObserverForModel(uc20Model, d, useEncryption)
c.Assert(err, IsNil)
c.Assert(obs, NotNil)
// trusted assets for the run and recovery bootloaders were asked for
c.Check(tab.TrustedAssetsCalls, Equals, 2)
data := []byte("foobar")
// SHA3-384
dataHash := "0fa8abfbdaf924ad307b74dd2ed183b9a4a398891a2f6bac8fd2db7041b77f068580f9c6c66f699b496c2da1cbcc7ed8"
err = os.WriteFile(filepath.Join(d, "asset"), data, 0644)
c.Assert(err, IsNil)
err = os.Mkdir(filepath.Join(d, "nested"), 0755)
c.Assert(err, IsNil)
err = os.WriteFile(filepath.Join(d, "nested/other-asset"), data, 0644)
c.Assert(err, IsNil)
shim := []byte("shim")
shimHash := "dac0063e831d4b2e7a330426720512fc50fa315042f0bb30f9d1db73e4898dcb89119cac41fdfa62137c8931a50f9d7b"
err = os.WriteFile(filepath.Join(d, "shim"), shim, 0644)
c.Assert(err, IsNil)
err = obs.ObserveExistingTrustedRecoveryAssets(d)
c.Assert(err, IsNil)
checkContentGlob(c, filepath.Join(dirs.SnapBootAssetsDir, "trusted", "*"), []string{
filepath.Join(dirs.SnapBootAssetsDir, "trusted", fmt.Sprintf("asset-%s", dataHash)),
filepath.Join(dirs.SnapBootAssetsDir, "trusted", fmt.Sprintf("other-asset-%s", dataHash)),
filepath.Join(dirs.SnapBootAssetsDir, "trusted", fmt.Sprintf("shim-%s", shimHash)),
})
// the list of trusted assets for recovery was asked for
c.Check(tab.TrustedAssetsCalls, Equals, 2)
observerImpl, ok := obs.(*boot.TrustedAssetsInstallObserverImpl)
c.Assert(ok, Equals, true)
// let's see what the observer has tracked
tracked := observerImpl.CurrentTrustedRecoveryBootAssetsMap()
c.Check(tracked, DeepEquals, boot.BootAssetsMap{
"asset": []string{dataHash},
"other-asset": []string{dataHash},
"shim": []string{shimHash},
})
}
func (s *assetsSuite) TestInstallObserverObserveExistingRecoveryReuseNameErr(c *C) {
d := c.MkDir()
tab := s.bootloaderWithTrustedAssets(map[string]string{
"asset": "asset",
"nested/asset": "asset",
})
// we get an observer for UC20
uc20Model := boottest.MakeMockUC20Model()
useEncryption := true
obs, err := boot.TrustedAssetsInstallObserverForModel(uc20Model, d, useEncryption)
c.Assert(err, IsNil)
c.Assert(obs, NotNil)
// got the list of trusted assets for run and recovery bootloaders
c.Check(tab.TrustedAssetsCalls, Equals, 2)
err = os.WriteFile(filepath.Join(d, "asset"), []byte("foobar"), 0644)
c.Assert(err, IsNil)
err = os.MkdirAll(filepath.Join(d, "nested"), 0755)
c.Assert(err, IsNil)
// same asset name but different content
err = os.WriteFile(filepath.Join(d, "nested/asset"), []byte("other"), 0644)
c.Assert(err, IsNil)
err = obs.ObserveExistingTrustedRecoveryAssets(d)
// same asset name but different content
c.Assert(err, ErrorMatches, `cannot reuse recovery asset name "asset"`)
// got the list of trusted assets for recovery bootloader
c.Check(tab.TrustedAssetsCalls, Equals, 2)
}
func (s *assetsSuite) TestUpdateObserverNew(c *C) {
tab := s.bootloaderWithTrustedAssets(nil)
uc20Model := boottest.MakeMockUC20Model()
gadgetDir := c.MkDir()
// no trusted or managed assets
obs, err := boot.TrustedAssetsUpdateObserverForModel(uc20Model, gadgetDir)
c.Assert(err, Equals, boot.ErrObserverNotApplicable)
c.Check(obs, IsNil)
// no managed, some trusted assets, but we are not tracking them
tab.TrustedAssetsMap = map[string]string{"asset": "asset"}
obs, err = boot.TrustedAssetsUpdateObserverForModel(uc20Model, gadgetDir)
c.Assert(err, Equals, boot.ErrObserverNotApplicable)
c.Check(obs, IsNil)
// let's see some managed assets, but not trusted assets
tab.ManagedAssetsList = []string{"managed"}
tab.TrustedAssetsMap = nil
obs, err = boot.TrustedAssetsUpdateObserverForModel(uc20Model, gadgetDir)
c.Assert(err, IsNil)
c.Check(obs, NotNil)
// no managed, some trusted which we need to track
s.stampSealedKeys(c, dirs.GlobalRootDir)
tab.ManagedAssetsList = nil
tab.TrustedAssetsMap = map[string]string{"asset": "asset"}
obs, err = boot.TrustedAssetsUpdateObserverForModel(uc20Model, gadgetDir)
c.Assert(err, IsNil)
c.Assert(obs, NotNil)
// but nil for non UC20
nonUC20Model := boottest.MakeMockModel()
nonUC20obs, err := boot.TrustedAssetsUpdateObserverForModel(nonUC20Model, gadgetDir)
c.Assert(err, Equals, boot.ErrObserverNotApplicable)
c.Assert(nonUC20obs, IsNil)
}
func (s *assetsSuite) TestUpdateObserverUpdateMockedWithResealSeed(c *C) {
s.testUpdateObserverUpdateMockedWithReseal(c, gadget.SystemSeed)
}
func (s *assetsSuite) TestUpdateObserverUpdateMockedWithResealSeedNull(c *C) {
s.testUpdateObserverUpdateMockedWithReseal(c, gadget.SystemSeedNull)
}
func (s *assetsSuite) testUpdateObserverUpdateMockedWithReseal(c *C, seedRole string) {
// observe an update where some of the assets exist and some are new,
// followed by reseal
d := c.MkDir()
backups := c.MkDir()
root := c.MkDir()
// try to arrange the backups like the updater would do it
before := []byte("before")
beforeHash := "2df0976fd45ba2392dc7985cdfb7c2d096c1ea4917929dd7a0e9bffae90a443271e702663fc6a4189c1f4ab3ce7daee3"
err := os.WriteFile(filepath.Join(backups, "asset.backup"), before, 0644)
c.Assert(err, IsNil)
data := []byte("foobar")
// SHA3-384
dataHash := "0fa8abfbdaf924ad307b74dd2ed183b9a4a398891a2f6bac8fd2db7041b77f068580f9c6c66f699b496c2da1cbcc7ed8"
err = os.WriteFile(filepath.Join(d, "foobar"), data, 0644)
c.Assert(err, IsNil)
shim := []byte("shim")
shimHash := "dac0063e831d4b2e7a330426720512fc50fa315042f0bb30f9d1db73e4898dcb89119cac41fdfa62137c8931a50f9d7b"
err = os.WriteFile(filepath.Join(d, "shim"), shim, 0644)
c.Assert(err, IsNil)
m := boot.Modeenv{
Mode: "run",
CurrentTrustedBootAssets: boot.BootAssetsMap{
"asset": []string{beforeHash},
"shim": []string{"shim-hash"},
},
CurrentTrustedRecoveryBootAssets: boot.BootAssetsMap{
"asset": []string{beforeHash},
},
}
err = m.WriteTo("")
c.Assert(err, IsNil)
tab := s.bootloaderWithTrustedAssets(map[string]string{
"asset": "asset",
"nested/other-asset": "other-asset",
"shim": "shim",
})
tab.ManagedAssetsList = []string{
"managed-asset",
}
// we get an observer for UC20
obs, _ := s.uc20UpdateObserverEncryptedSystemMockedBootloader(c)
// the list of trusted assets is obtained upfront
c.Check(tab.TrustedAssetsCalls, Equals, 2)
res, err := obs.Observe(gadget.ContentUpdate, gadget.SystemBoot, root, "asset",
&gadget.ContentChange{
After: filepath.Join(d, "foobar"),
// original content would get backed up by the updater
Before: filepath.Join(backups, "asset.backup"),
})
c.Assert(err, IsNil)
c.Check(res, Equals, gadget.ChangeApply)
res, err = obs.Observe(gadget.ContentUpdate, gadget.SystemBoot, root, "shim",
&gadget.ContentChange{After: filepath.Join(d, "shim")})
c.Assert(err, IsNil)
c.Check(res, Equals, gadget.ChangeApply)
// observe the recovery struct
res, err = obs.Observe(gadget.ContentUpdate, seedRole, root, "shim",
&gadget.ContentChange{After: filepath.Join(d, "shim")})
c.Assert(err, IsNil)
c.Check(res, Equals, gadget.ChangeApply)
res, err = obs.Observe(gadget.ContentUpdate, seedRole, root, "asset",
&gadget.ContentChange{
After: filepath.Join(d, "foobar"),
// original content
Before: filepath.Join(backups, "asset.backup"),
})
c.Assert(err, IsNil)
c.Check(res, Equals, gadget.ChangeApply)
res, err = obs.Observe(gadget.ContentUpdate, seedRole, root, "nested/other-asset",
&gadget.ContentChange{After: filepath.Join(d, "foobar")})
c.Assert(err, IsNil)
c.Check(res, Equals, gadget.ChangeApply)
// all files are in cache
checkContentGlob(c, filepath.Join(dirs.SnapBootAssetsDir, "trusted", "*"), []string{
filepath.Join(dirs.SnapBootAssetsDir, "trusted", fmt.Sprintf("asset-%s", dataHash)),
filepath.Join(dirs.SnapBootAssetsDir, "trusted", fmt.Sprintf("asset-%s", beforeHash)),
filepath.Join(dirs.SnapBootAssetsDir, "trusted", fmt.Sprintf("other-asset-%s", dataHash)),
filepath.Join(dirs.SnapBootAssetsDir, "trusted", fmt.Sprintf("shim-%s", shimHash)),
})
// check modeenv
newM, err := boot.ReadModeenv("")
c.Assert(err, IsNil)
c.Check(newM.CurrentTrustedBootAssets, DeepEquals, boot.BootAssetsMap{
"asset": []string{beforeHash, dataHash},
"shim": []string{"shim-hash", shimHash},
})
c.Check(newM.CurrentTrustedRecoveryBootAssets, DeepEquals, boot.BootAssetsMap{
"asset": []string{beforeHash, dataHash},
"shim": []string{shimHash},
"other-asset": []string{dataHash},
})
// verify that managed assets are to be preserved
res, err = obs.Observe(gadget.ContentUpdate, seedRole, root, "managed-asset",
&gadget.ContentChange{After: filepath.Join(d, "foobar")})
c.Assert(err, IsNil)
c.Check(res, Equals, gadget.ChangeIgnore)
// everything is set up, trigger a reseal
resealCalls := 0
restore := boot.MockResealKeyForBootChains(func(unlocker boot.Unlocker, method device.SealingMethod, rootdir string, params *boot.ResealKeyForBootChainsParams, expectReseal bool) error {
resealCalls++
return nil
})
defer restore()
err = obs.BeforeWrite()
c.Assert(err, IsNil)
c.Check(resealCalls, Equals, 1)
}
func (s *assetsSuite) TestUpdateObserverUpdateExistingAssetMocked(c *C) {
d := c.MkDir()
root := c.MkDir()
tab := s.bootloaderWithTrustedAssets(map[string]string{
"asset": "asset",
"shim": "shim",
})
tab.ManagedAssetsList = []string{
"managed-asset",
"nested/managed-asset",
}
data := []byte("foobar")
// SHA3-384
dataHash := "0fa8abfbdaf924ad307b74dd2ed183b9a4a398891a2f6bac8fd2db7041b77f068580f9c6c66f699b496c2da1cbcc7ed8"
err := os.WriteFile(filepath.Join(d, "foobar"), data, 0644)
c.Assert(err, IsNil)
shim := []byte("shim")
shimHash := "dac0063e831d4b2e7a330426720512fc50fa315042f0bb30f9d1db73e4898dcb89119cac41fdfa62137c8931a50f9d7b"
err = os.WriteFile(filepath.Join(d, "shim"), shim, 0644)
c.Assert(err, IsNil)
// add one file to the cache, as if the system got rebooted before
// modeenv got updated
cache := boot.NewTrustedAssetsCache(dirs.SnapBootAssetsDir)
_, err = cache.Add(filepath.Join(d, "foobar"), "trusted", "asset")
c.Assert(err, IsNil)
// file is in the cache
checkContentGlob(c, filepath.Join(dirs.SnapBootAssetsDir, "trusted", "*"), []string{
filepath.Join(dirs.SnapBootAssetsDir, "trusted", fmt.Sprintf("asset-%s", dataHash)),
})
m := boot.Modeenv{
Mode: "run",
CurrentTrustedBootAssets: boot.BootAssetsMap{
"asset": []string{"asset-hash"},
},
CurrentTrustedRecoveryBootAssets: boot.BootAssetsMap{
// shim with same hash is listed as trusted, but missing
// from cache
"shim": []string{shimHash},
},
}
err = m.WriteTo("")
c.Assert(err, IsNil)
// we get an observer for UC20
obs, _ := s.uc20UpdateObserverEncryptedSystemMockedBootloader(c)
// observe the updates
res, err := obs.Observe(gadget.ContentUpdate, gadget.SystemBoot, root, "asset",
&gadget.ContentChange{After: filepath.Join(d, "foobar")})
c.Assert(err, IsNil)
c.Check(res, Equals, gadget.ChangeApply)
res, err = obs.Observe(gadget.ContentUpdate, gadget.SystemSeed, root, "asset",
&gadget.ContentChange{After: filepath.Join(d, "foobar")})
c.Assert(err, IsNil)
c.Check(res, Equals, gadget.ChangeApply)
res, err = obs.Observe(gadget.ContentUpdate, gadget.SystemSeed, root, "shim",
&gadget.ContentChange{After: filepath.Join(d, "shim")})
c.Assert(err, IsNil)
c.Check(res, Equals, gadget.ChangeApply)
// trusted assets were asked for
c.Check(tab.TrustedAssetsCalls, Equals, 2)
// file is in the cache
checkContentGlob(c, filepath.Join(dirs.SnapBootAssetsDir, "trusted", "*"), []string{
filepath.Join(dirs.SnapBootAssetsDir, "trusted", fmt.Sprintf("asset-%s", dataHash)),
// shim was added to cache
filepath.Join(dirs.SnapBootAssetsDir, "trusted", fmt.Sprintf("shim-%s", shimHash)),
})
// check modeenv
newM, err := boot.ReadModeenv("")
c.Assert(err, IsNil)
c.Check(newM.CurrentTrustedBootAssets, DeepEquals, boot.BootAssetsMap{
"asset": []string{"asset-hash", dataHash},
})
c.Check(newM.CurrentTrustedRecoveryBootAssets, DeepEquals, boot.BootAssetsMap{
"asset": []string{dataHash},
"shim": []string{shimHash},
})
// verify that managed assets are to be preserved
res, err = obs.Observe(gadget.ContentUpdate, gadget.SystemSeed, root, "managed-asset",
&gadget.ContentChange{After: filepath.Join(d, "foobar")})
c.Assert(err, IsNil)
c.Check(res, Equals, gadget.ChangeIgnore)
res, err = obs.Observe(gadget.ContentUpdate, gadget.SystemSeed, root, "nested/managed-asset",
&gadget.ContentChange{After: filepath.Join(d, "foobar")})
c.Assert(err, IsNil)
c.Check(res, Equals, gadget.ChangeIgnore)
// everything is set up, trigger reseal
resealCalls := 0
restore := boot.MockResealKeyForBootChains(func(unlocker boot.Unlocker, method device.SealingMethod, rootdir string, params *boot.ResealKeyForBootChainsParams, expectReseal bool) error {
resealCalls++
return nil
})
defer restore()
// execute before-write action
err = obs.BeforeWrite()
c.Assert(err, IsNil)
c.Check(resealCalls, Equals, 1)
}
func (s *assetsSuite) TestUpdateObserverUpdateNothingTrackedMocked(c *C) {
d := c.MkDir()
root := c.MkDir()
tab := s.bootloaderWithTrustedAssets(map[string]string{
"asset": "asset",
})
data := []byte("foobar")
// SHA3-384
dataHash := "0fa8abfbdaf924ad307b74dd2ed183b9a4a398891a2f6bac8fd2db7041b77f068580f9c6c66f699b496c2da1cbcc7ed8"
err := os.WriteFile(filepath.Join(d, "foobar"), data, 0644)
c.Assert(err, IsNil)
m := boot.Modeenv{
Mode: "run",
// nothing is tracked in modeenv yet
}
err = m.WriteTo("")
c.Assert(err, IsNil)
// we get an observer for UC20
obs, _ := s.uc20UpdateObserverEncryptedSystemMockedBootloader(c)
// observe the updates
res, err := obs.Observe(gadget.ContentUpdate, gadget.SystemBoot, root, "asset",
&gadget.ContentChange{After: filepath.Join(d, "foobar")})
c.Assert(err, IsNil)
c.Check(res, Equals, gadget.ChangeApply)
res, err = obs.Observe(gadget.ContentUpdate, gadget.SystemSeed, root, "asset",
&gadget.ContentChange{After: filepath.Join(d, "foobar")})
c.Assert(err, IsNil)
c.Check(res, Equals, gadget.ChangeApply)
// trusted assets were asked for
c.Check(tab.TrustedAssetsCalls, Equals, 2)
// file is in the cache
checkContentGlob(c, filepath.Join(dirs.SnapBootAssetsDir, "trusted", "*"), []string{
filepath.Join(dirs.SnapBootAssetsDir, "trusted", fmt.Sprintf("asset-%s", dataHash)),
})
// check modeenv
newM, err := boot.ReadModeenv("")
c.Assert(err, IsNil)
c.Check(newM.CurrentTrustedBootAssets, DeepEquals, boot.BootAssetsMap{
"asset": []string{dataHash},
})
c.Check(newM.CurrentTrustedRecoveryBootAssets, DeepEquals, boot.BootAssetsMap{
"asset": []string{dataHash},
})
// reseal does nothing
err = obs.BeforeWrite()
c.Assert(err, IsNil)
c.Check(tab.RecoveryBootChainCalls, HasLen, 0)
c.Check(tab.BootChainKernelPath, HasLen, 0)
}
func (s *assetsSuite) TestUpdateObserverUpdateOtherRoleStructMocked(c *C) {
d := c.MkDir()
root := c.MkDir()
tab := s.bootloaderWithTrustedAssets(map[string]string{
"asset": "asset",
})
// modeenv is not set up, but the observer should not care
// we get an observer for UC20
obs, _ := s.uc20UpdateObserverEncryptedSystemMockedBootloader(c)
// and once again for the recovery bootloader
c.Check(tab.TrustedAssetsCalls, Equals, 2)
// observe the updates (system-data gets ignored)
res, err := obs.Observe(gadget.ContentUpdate, gadget.SystemData, root, "asset",
&gadget.ContentChange{After: filepath.Join(d, "foobar")})
c.Assert(err, IsNil)
c.Check(res, Equals, gadget.ChangeApply)
}
func (s *assetsSuite) TestUpdateObserverUpdateTrivialErr(c *C) {
// test trivial error scenarios of the update observer
s.stampSealedKeys(c, dirs.GlobalRootDir)
d := c.MkDir()
root := c.MkDir()
gadgetDir := c.MkDir()
uc20Model := boottest.MakeMockUC20Model()
// first no bootloader
bootloader.ForceError(fmt.Errorf("bootloader fail"))
obs, err := boot.TrustedAssetsUpdateObserverForModel(uc20Model, gadgetDir)