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