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