@@ -1332,3 +1332,63 @@ func TestUpgradeDoesNotTryToUpgradeBundledCoreLibraries(t *testing.T) {
1332
1332
// Empty output means nothing has been updated as expected
1333
1333
require .Empty (t , stdout )
1334
1334
}
1335
+
1336
+ func downloadLib (t * testing.T , url string , zipPath * paths.Path ) {
1337
+ response , err := http .Get (url )
1338
+ require .NoError (t , err )
1339
+ require .Equal (t , response .StatusCode , 200 )
1340
+ zip , err := zipPath .Create ()
1341
+ require .NoError (t , err )
1342
+ _ , err = io .Copy (zip , response .Body )
1343
+ require .NoError (t , err )
1344
+ require .NoError (t , response .Body .Close ())
1345
+ require .NoError (t , zip .Close ())
1346
+ }
1347
+
1348
+ func TestInstallGitUrlAndZipPathFlagsVisibility (t * testing.T ) {
1349
+ env , cli := integrationtest .CreateArduinoCLIWithEnvironment (t )
1350
+ defer env .CleanUp ()
1351
+
1352
+ // Verifies installation fail because flags are not found
1353
+ gitUrl := "https://github.com/arduino-libraries/WiFi101.git"
1354
+ _ , stderr , err := cli .Run ("lib" , "install" , "--git-url" , gitUrl )
1355
+ require .Error (t , err )
1356
+ require .Contains (t , string (stderr ), "--git-url and --zip-path are disabled by default, for more information see:" )
1357
+
1358
+ // Download library
1359
+ url := "https://github.com/arduino-libraries/AudioZero/archive/refs/tags/1.1.1.zip"
1360
+ zipPath := cli .DownloadDir ().Join ("libraries" , "AudioZero.zip" )
1361
+ require .NoError (t , zipPath .Parent ().MkdirAll ())
1362
+ downloadLib (t , url , zipPath )
1363
+
1364
+ _ , stderr , err = cli .Run ("lib" , "install" , "--zip-path" , zipPath .String ())
1365
+ require .Error (t , err )
1366
+ require .Contains (t , string (stderr ), "--git-url and --zip-path are disabled by default, for more information see:" )
1367
+
1368
+ envVar := cli .GetDefaultEnv ()
1369
+ envVar ["ARDUINO_ENABLE_UNSAFE_LIBRARY_INSTALL" ] = "true"
1370
+ // Verifies installation is successful when flags are enabled with env var
1371
+ stdout , _ , err := cli .RunWithCustomEnv (envVar , "lib" , "install" , "--git-url" , gitUrl )
1372
+ require .NoError (t , err )
1373
+ require .Contains (t , string (stdout ), "--git-url and --zip-path flags allow installing untrusted files, use it at your own risk." )
1374
+
1375
+ stdout , _ , err = cli .RunWithCustomEnv (envVar , "lib" , "install" , "--zip-path" , zipPath .String ())
1376
+ require .NoError (t , err )
1377
+ require .Contains (t , string (stdout ), "--git-url and --zip-path flags allow installing untrusted files, use it at your own risk." )
1378
+
1379
+ // Uninstall libraries to install them again
1380
+ _ , _ , err = cli .Run ("lib" , "uninstall" , "WiFi101" , "AudioZero" )
1381
+ require .NoError (t , err )
1382
+
1383
+ // Verifies installation is successful when flags are enabled with settings file
1384
+ _ , _ , err = cli .RunWithCustomEnv (envVar , "config" , "init" , "--dest-dir" , "." )
1385
+ require .NoError (t , err )
1386
+
1387
+ stdout , _ , err = cli .Run ("lib" , "install" , "--git-url" , gitUrl )
1388
+ require .NoError (t , err )
1389
+ require .Contains (t , string (stdout ), "--git-url and --zip-path flags allow installing untrusted files, use it at your own risk." )
1390
+
1391
+ stdout , _ , err = cli .Run ("lib" , "install" , "--zip-path" , zipPath .String ())
1392
+ require .NoError (t , err )
1393
+ require .Contains (t , string (stdout ), "--git-url and --zip-path flags allow installing untrusted files, use it at your own risk." )
1394
+ }
0 commit comments