@@ -18,6 +18,8 @@ package lib_test
18
18
import (
19
19
"encoding/json"
20
20
"fmt"
21
+ "io"
22
+ "net/http"
21
23
"strings"
22
24
"testing"
23
25
"time"
@@ -1254,3 +1256,63 @@ func TestUpgradeDoesNotTryToUpgradeBundledCoreLibraries(t *testing.T) {
1254
1256
// Empty output means nothing has been updated as expected
1255
1257
require .Empty (t , stdout )
1256
1258
}
1259
+
1260
+ func downloadLib (t * testing.T , url string , zipPath * paths.Path ) {
1261
+ response , err := http .Get (url )
1262
+ require .NoError (t , err )
1263
+ require .Equal (t , response .StatusCode , 200 )
1264
+ zip , err := zipPath .Create ()
1265
+ require .NoError (t , err )
1266
+ _ , err = io .Copy (zip , response .Body )
1267
+ require .NoError (t , err )
1268
+ require .NoError (t , response .Body .Close ())
1269
+ require .NoError (t , zip .Close ())
1270
+ }
1271
+
1272
+ func TestInstallGitUrlAndZipPathFlagsVisibility (t * testing.T ) {
1273
+ env , cli := integrationtest .CreateArduinoCLIWithEnvironment (t )
1274
+ defer env .CleanUp ()
1275
+
1276
+ // Verifies installation fail because flags are not found
1277
+ gitUrl := "https://github.com/arduino-libraries/WiFi101.git"
1278
+ _ , stderr , err := cli .Run ("lib" , "install" , "--git-url" , gitUrl )
1279
+ require .Error (t , err )
1280
+ require .Contains (t , string (stderr ), "--git-url and --zip-path are disabled by default, for more information see:" )
1281
+
1282
+ // Download library
1283
+ url := "https://github.com/arduino-libraries/AudioZero/archive/refs/tags/1.1.1.zip"
1284
+ zipPath := cli .DownloadDir ().Join ("libraries" , "AudioZero.zip" )
1285
+ require .NoError (t , zipPath .Parent ().MkdirAll ())
1286
+ downloadLib (t , url , zipPath )
1287
+
1288
+ _ , stderr , err = cli .Run ("lib" , "install" , "--zip-path" , zipPath .String ())
1289
+ require .Error (t , err )
1290
+ require .Contains (t , string (stderr ), "--git-url and --zip-path are disabled by default, for more information see:" )
1291
+
1292
+ envVar := cli .GetDefaultEnv ()
1293
+ envVar ["ARDUINO_ENABLE_UNSAFE_LIBRARY_INSTALL" ] = "true"
1294
+ // Verifies installation is successful when flags are enabled with env var
1295
+ stdout , _ , err := cli .RunWithCustomEnv (envVar , "lib" , "install" , "--git-url" , gitUrl )
1296
+ require .NoError (t , err )
1297
+ require .Contains (t , string (stdout ), "--git-url and --zip-path flags allow installing untrusted files, use it at your own risk." )
1298
+
1299
+ stdout , _ , err = cli .RunWithCustomEnv (envVar , "lib" , "install" , "--zip-path" , zipPath .String ())
1300
+ require .NoError (t , err )
1301
+ require .Contains (t , string (stdout ), "--git-url and --zip-path flags allow installing untrusted files, use it at your own risk." )
1302
+
1303
+ // Uninstall libraries to install them again
1304
+ _ , _ , err = cli .Run ("lib" , "uninstall" , "WiFi101" , "AudioZero" )
1305
+ require .NoError (t , err )
1306
+
1307
+ // Verifies installation is successful when flags are enabled with settings file
1308
+ _ , _ , err = cli .RunWithCustomEnv (envVar , "config" , "init" , "--dest-dir" , "." )
1309
+ require .NoError (t , err )
1310
+
1311
+ stdout , _ , err = cli .Run ("lib" , "install" , "--git-url" , gitUrl )
1312
+ require .NoError (t , err )
1313
+ require .Contains (t , string (stdout ), "--git-url and --zip-path flags allow installing untrusted files, use it at your own risk." )
1314
+
1315
+ stdout , _ , err = cli .Run ("lib" , "install" , "--zip-path" , zipPath .String ())
1316
+ require .NoError (t , err )
1317
+ require .Contains (t , string (stdout ), "--git-url and --zip-path flags allow installing untrusted files, use it at your own risk." )
1318
+ }
0 commit comments