Skip to content

Commit de34a89

Browse files
Migrate TestInstallGitUrlAndZipPathFlagsVisibility from test_lib.py to lib_test.go
1 parent f2d57d5 commit de34a89

File tree

2 files changed

+60
-47
lines changed

2 files changed

+60
-47
lines changed

Diff for: internal/integrationtest/lib/lib_test.go

+60
Original file line numberDiff line numberDiff line change
@@ -1332,3 +1332,63 @@ func TestUpgradeDoesNotTryToUpgradeBundledCoreLibraries(t *testing.T) {
13321332
// Empty output means nothing has been updated as expected
13331333
require.Empty(t, stdout)
13341334
}
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+
}

Diff for: test/test_lib.py

-47
Original file line numberDiff line numberDiff line change
@@ -49,53 +49,6 @@ def download_lib(url, download_dir):
4949
z.close()
5050

5151

52-
def test_install_git_url_and_zip_path_flags_visibility(run_command, data_dir, downloads_dir):
53-
# Verifies installation fail because flags are not found
54-
git_url = "https://github.com/arduino-libraries/WiFi101.git"
55-
res = run_command(["lib", "install", "--git-url", git_url])
56-
assert res.failed
57-
assert "--git-url and --zip-path are disabled by default, for more information see:" in res.stderr
58-
59-
# Download library
60-
url = "https://github.com/arduino-libraries/AudioZero/archive/refs/tags/1.1.1.zip"
61-
zip_path = Path(downloads_dir, "libraries", "AudioZero.zip")
62-
zip_path.parent.mkdir(parents=True, exist_ok=True)
63-
download_lib(url, zip_path)
64-
65-
res = run_command(["lib", "install", "--zip-path", zip_path])
66-
assert res.failed
67-
assert "--git-url and --zip-path are disabled by default, for more information see:" in res.stderr
68-
69-
env = {
70-
"ARDUINO_DATA_DIR": data_dir,
71-
"ARDUINO_DOWNLOADS_DIR": downloads_dir,
72-
"ARDUINO_SKETCHBOOK_DIR": data_dir,
73-
"ARDUINO_ENABLE_UNSAFE_LIBRARY_INSTALL": "true",
74-
}
75-
# Verifies installation is successful when flags are enabled with env var
76-
res = run_command(["lib", "install", "--git-url", git_url], custom_env=env)
77-
assert res.ok
78-
assert "--git-url and --zip-path flags allow installing untrusted files, use it at your own risk." in res.stdout
79-
80-
res = run_command(["lib", "install", "--zip-path", zip_path], custom_env=env)
81-
assert res.ok
82-
assert "--git-url and --zip-path flags allow installing untrusted files, use it at your own risk." in res.stdout
83-
84-
# Uninstall libraries to install them again
85-
assert run_command(["lib", "uninstall", "WiFi101", "AudioZero"])
86-
87-
# Verifies installation is successful when flags are enabled with settings file
88-
assert run_command(["config", "init", "--dest-dir", "."], custom_env=env)
89-
90-
res = run_command(["lib", "install", "--git-url", git_url])
91-
assert res.ok
92-
assert "--git-url and --zip-path flags allow installing untrusted files, use it at your own risk." in res.stdout
93-
94-
res = run_command(["lib", "install", "--zip-path", zip_path])
95-
assert res.ok
96-
assert "--git-url and --zip-path flags allow installing untrusted files, use it at your own risk." in res.stdout
97-
98-
9952
def test_install_with_zip_path(run_command, data_dir, downloads_dir):
10053
# Initialize configs to enable --zip-path flag
10154
env = {

0 commit comments

Comments
 (0)