@@ -19,16 +19,17 @@ import (
1919 "testing"
2020
2121 "github.com/arduino/go-paths-helper"
22+ rice "github.com/cmaglie/go.rice"
2223 "github.com/stretchr/testify/require"
2324)
2425
2526var (
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" )
3233)
3334
3435func TestVerifyArduinoDetachedSignature (t * testing.T ) {
@@ -45,13 +46,34 @@ func TestVerifyArduinoDetachedSignature(t *testing.T) {
4546}
4647
4748func TestVerifyDetachedSignature (t * testing.T ) {
48- res , signer , err := VerifyDetachedSignature (BoardIndexPath , BoardSignaturePath , BoardKey )
49+ res , signer , err := VerifyDetachedSignature (ModuleFWIndexPath , ModuleFWSignaturePath , ModuleFWIndexKey )
4950 require .NoError (t , err )
5051 require .NotNil (t , signer )
5152 require .True (t , res )
5253 require .Equal (t , uint64 (0x82f2d7c7c5a22a73 ), signer .PrimaryKey .KeyId )
5354
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 )
5577 require .False (t , res )
5678 require .Nil (t , signer )
5779 require .Error (t , err )
0 commit comments