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