@@ -550,3 +550,91 @@ func TestCompileWithKnownPlatformNotInstalled(t *testing.T) {
550
550
// Verifies command to fix error is shown to user
551
551
require .Contains (t , string (stderr ), "Try running `arduino-cli core install arduino:avr`" )
552
552
}
553
+
554
+ func TestCompileWithFakeSecureBootCore (t * testing.T ) {
555
+ env , cli := integrationtest .CreateArduinoCLIWithEnvironment (t )
556
+ defer env .CleanUp ()
557
+
558
+ _ , _ , err := cli .Run ("update" )
559
+ require .NoError (t , err )
560
+
561
+ _ , _ , err = cli .Run ("core" , "install" , "arduino:avr@1.8.3" )
562
+ require .NoError (t , err )
563
+
564
+ sketchName := "SketchSimple"
565
+ sketchPath := cli .SketchbookDir ().Join (sketchName )
566
+ fqbn := "arduino:avr:uno"
567
+
568
+ _ , _ , err = cli .Run ("sketch" , "new" , sketchPath .String ())
569
+ require .NoError (t , err )
570
+
571
+ // Verifies compilation works
572
+ _ , _ , err = cli .Run ("compile" , "--clean" , "-b" , fqbn , sketchPath .String ())
573
+ require .NoError (t , err )
574
+
575
+ // Overrides default platform adding secure_boot support using platform.local.txt
576
+ avrPlatformPath := cli .DataDir ().Join ("packages" , "arduino" , "hardware" , "avr" , "1.8.3" , "platform.local.txt" )
577
+ testPlatformName := "platform_with_secure_boot"
578
+ wd , err := paths .Getwd ()
579
+ require .NoError (t , err )
580
+ err = wd .Parent ().Join ("testdata" , testPlatformName , "platform.local.txt" ).CopyTo (avrPlatformPath )
581
+ require .NoError (t , err )
582
+
583
+ // Overrides default board adding secure boot support using board.local.txt
584
+ avrBoardPath := cli .DataDir ().Join ("packages" , "arduino" , "hardware" , "avr" , "1.8.3" , "boards.local.txt" )
585
+ err = wd .Parent ().Join ("testdata" , testPlatformName , "boards.local.txt" ).CopyTo (avrBoardPath )
586
+ require .NoError (t , err )
587
+
588
+ // Verifies compilation works with secure boot disabled
589
+ stdout , _ , err := cli .Run ("compile" , "--clean" , "-b" , fqbn + ":security=none" , sketchPath .String (), "-v" )
590
+ require .NoError (t , err )
591
+ require .Contains (t , string (stdout ), "echo exit" )
592
+
593
+ // Verifies compilation works with secure boot enabled
594
+ stdout , _ , err = cli .Run ("compile" , "--clean" , "-b" , fqbn + ":security=sien" , sketchPath .String (), "-v" )
595
+ require .NoError (t , err )
596
+ require .Contains (t , string (stdout ), "Default_Keys/default-signing-key.pem" )
597
+ require .Contains (t , string (stdout ), "Default_Keys/default-encrypt-key.pem" )
598
+
599
+ // Verifies compilation does not work with secure boot enabled and using only one flag
600
+ _ , stderr , err := cli .Run (
601
+ "compile" ,
602
+ "--clean" ,
603
+ "-b" ,
604
+ fqbn + ":security=sien" ,
605
+ sketchPath .String (),
606
+ "--keys-keychain" ,
607
+ cli .SketchbookDir ().String (),
608
+ "-v" ,
609
+ )
610
+ require .Error (t , err )
611
+ require .Contains (t , string (stderr ), "Flag --sign-key is mandatory when used in conjunction with flag --keys-keychain" )
612
+
613
+ // Verifies compilation works with secure boot enabled and when overriding the sign key and encryption key used
614
+ keysDir := cli .SketchbookDir ().Join ("keys_dir" )
615
+ err = keysDir .Mkdir ()
616
+ require .NoError (t , err )
617
+ signKeyPath := keysDir .Join ("my-sign-key.pem" )
618
+ _ , err = signKeyPath .Create ()
619
+ require .NoError (t , err )
620
+ encryptKeyPath := cli .SketchbookDir ().Join ("my-encrypt-key.pem" )
621
+ _ , err = encryptKeyPath .Create ()
622
+ require .NoError (t , err )
623
+ stdout , _ , err = cli .Run (
624
+ "compile" ,
625
+ "--clean" ,
626
+ "-b" ,
627
+ fqbn + ":security=sien" ,
628
+ sketchPath .String (),
629
+ "--keys-keychain" ,
630
+ keysDir .String (),
631
+ "--sign-key" ,
632
+ "my-sign-key.pem" ,
633
+ "--encrypt-key" ,
634
+ "my-encrypt-key.pem" ,
635
+ "-v" ,
636
+ )
637
+ require .NoError (t , err )
638
+ require .Contains (t , string (stdout ), "my-sign-key.pem" )
639
+ require .Contains (t , string (stdout ), "my-encrypt-key.pem" )
640
+ }
0 commit comments