@@ -19,16 +19,17 @@ import (
19
19
"testing"
20
20
21
21
"github.com/arduino/go-paths-helper"
22
+ rice "github.com/cmaglie/go.rice"
22
23
"github.com/stretchr/testify/require"
23
24
)
24
25
25
26
var (
26
- PackageIndexPath = paths .New ("testdata/package_index.json" )
27
- PackageSignaturePath = paths .New ("testdata/package_index.json.sig" )
28
- BoardIndexPath = paths .New ("testdata/module_firmware_index.json" )
29
- BoardSignaturePath = paths .New ("testdata/module_firmware_index.json.sig" )
30
- BoardKey = paths .New ("testdata/module_firmware_index_public.gpg.key" )
31
- InvalidIndexPath = paths .New ("testdata/invalid_file.json" )
27
+ PackageIndexPath = paths .New ("testdata/package_index.json" )
28
+ PackageSignaturePath = paths .New ("testdata/package_index.json.sig" )
29
+ ModuleFWIndexPath = paths .New ("testdata/module_firmware_index.json" )
30
+ ModuleFWSignaturePath = paths .New ("testdata/module_firmware_index.json.sig" )
31
+ ModuleFWIndexKey = paths .New ("testdata/module_firmware_index_public.gpg.key" )
32
+ InvalidIndexPath = paths .New ("testdata/invalid_file.json" )
32
33
)
33
34
34
35
func TestVerifyArduinoDetachedSignature (t * testing.T ) {
@@ -45,13 +46,34 @@ func TestVerifyArduinoDetachedSignature(t *testing.T) {
45
46
}
46
47
47
48
func TestVerifyDetachedSignature (t * testing.T ) {
48
- res , signer , err := VerifyDetachedSignature (BoardIndexPath , BoardSignaturePath , BoardKey )
49
+ res , signer , err := VerifyDetachedSignature (ModuleFWIndexPath , ModuleFWSignaturePath , ModuleFWIndexKey )
49
50
require .NoError (t , err )
50
51
require .NotNil (t , signer )
51
52
require .True (t , res )
52
53
require .Equal (t , uint64 (0x82f2d7c7c5a22a73 ), signer .PrimaryKey .KeyId )
53
54
54
- res , signer , err = VerifyDetachedSignature (InvalidIndexPath , PackageSignaturePath , BoardKey )
55
+ res , signer , err = VerifyDetachedSignature (InvalidIndexPath , PackageSignaturePath , ModuleFWIndexKey )
56
+ require .False (t , res )
57
+ require .Nil (t , signer )
58
+ require .Error (t , err )
59
+ }
60
+
61
+ func TestVerifySignature (t * testing.T ) {
62
+ keysBox , err := rice .FindBox ("keys" )
63
+ if err != nil {
64
+ panic ("could not find bundled signature keys" )
65
+ }
66
+ arduinoKeyringFile , err := keysBox .Open ("arduino_public.gpg.key" )
67
+ if err != nil {
68
+ panic ("could not find bundled signature keys" )
69
+ }
70
+ res , signer , err := VerifySignature (PackageIndexPath , PackageSignaturePath , arduinoKeyringFile )
71
+ require .NoError (t , err )
72
+ require .NotNil (t , signer )
73
+ require .True (t , res )
74
+ require .Equal (t , uint64 (0x7baf404c2dfab4ae ), signer .PrimaryKey .KeyId )
75
+
76
+ res , signer , err = VerifySignature (InvalidIndexPath , PackageSignaturePath , arduinoKeyringFile )
55
77
require .False (t , res )
56
78
require .Nil (t , signer )
57
79
require .Error (t , err )
0 commit comments