Add warning when deploying protected apps from dir without password override (#2153)

This commit is contained in:
Jonatan Kłosko 2023-08-09 21:23:02 +02:00 committed by GitHub
parent 2919f3018b
commit 74ca662bf3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 6 deletions

View file

@ -216,6 +216,13 @@ defmodule Livebook.Apps do
if password = opts[:password] do if password = opts[:password] do
put_in(notebook.app_settings.password, password) put_in(notebook.app_settings.password, password)
else else
if notebook.app_settings.access_type == :protected do
Logger.warning(
"The app at #{info.relative_path} will use a random password." <>
" You may want to set LIVEBOOK_APPS_PATH_PASSWORD or make the app public."
)
end
notebook notebook
end end

View file

@ -11,13 +11,13 @@ defmodule Livebook.AppsTest do
app2_path = Path.join(tmp_dir, "app2.livemd") app2_path = Path.join(tmp_dir, "app2.livemd")
File.write!(app1_path, """ File.write!(app1_path, """
<!-- livebook:{"app_settings":{"slug":"app1"}} --> <!-- livebook:{"app_settings":{"access_type":"public","slug":"app1"}} -->
# App 1 # App 1
""") """)
File.write!(app2_path, """ File.write!(app2_path, """
<!-- livebook:{"app_settings":{"slug":"app2"}} --> <!-- livebook:{"app_settings":{"access_type":"public","slug":"app2"}} -->
# App 2 # App 2
""") """)
@ -100,6 +100,7 @@ defmodule Livebook.AppsTest do
Livebook.App.close(pid) Livebook.App.close(pid)
end end
@tag :capture_log
@tag :tmp_dir @tag :tmp_dir
test "deploys apps with offline hub secrets", %{tmp_dir: tmp_dir} do test "deploys apps with offline hub secrets", %{tmp_dir: tmp_dir} do
app_path = Path.join(tmp_dir, "app1.livemd") app_path = Path.join(tmp_dir, "app1.livemd")
@ -162,6 +163,28 @@ defmodule Livebook.AppsTest do
"Skipping deployment for app at app.livemd. The deployment settings are missing or invalid. Please configure them under the notebook deploy panel." "Skipping deployment for app at app.livemd. The deployment settings are missing or invalid. Please configure them under the notebook deploy panel."
end end
@tag :tmp_dir
test "warns when a notebook is protected and no :password is set", %{tmp_dir: tmp_dir} do
app_path = Path.join(tmp_dir, "app.livemd")
File.write!(app_path, """
<!-- livebook:{"app_settings":{"slug":"app"}} -->
# App
""")
Livebook.Apps.subscribe()
assert ExUnit.CaptureLog.capture_log(fn ->
Livebook.Apps.deploy_apps_in_dir(tmp_dir)
end) =~
"The app at app.livemd will use a random password. You may want to set LIVEBOOK_APPS_PATH_PASSWORD or make the app public."
assert_receive {:app_created, %{slug: "app"} = app}
Livebook.App.close(app.pid)
end
@tag :tmp_dir @tag :tmp_dir
test "overrides apps password when :password is set", %{tmp_dir: tmp_dir} do test "overrides apps password when :password is set", %{tmp_dir: tmp_dir} do
app_path = Path.join(tmp_dir, "app.livemd") app_path = Path.join(tmp_dir, "app.livemd")
@ -183,13 +206,12 @@ defmodule Livebook.AppsTest do
Livebook.App.close(app.pid) Livebook.App.close(app.pid)
end end
@tag :capture_log
@tag :tmp_dir @tag :tmp_dir
test "deploys with import warnings", %{tmp_dir: tmp_dir} do test "deploys with import warnings", %{tmp_dir: tmp_dir} do
app_path = Path.join(tmp_dir, "app.livemd") app_path = Path.join(tmp_dir, "app.livemd")
File.write!(app_path, """ File.write!(app_path, """
<!-- livebook:{"app_settings":{"slug":"app"}} --> <!-- livebook:{"app_settings":{"access_type":"public","slug":"app"}} -->
# App # App
@ -198,7 +220,9 @@ defmodule Livebook.AppsTest do
Livebook.Apps.subscribe() Livebook.Apps.subscribe()
Livebook.Apps.deploy_apps_in_dir(tmp_dir) assert ExUnit.CaptureLog.capture_log(fn ->
Livebook.Apps.deploy_apps_in_dir(tmp_dir)
end) =~ "line 5 - fenced Code Block opened with"
assert_receive {:app_created, %{slug: "app", warnings: warnings} = app} assert_receive {:app_created, %{slug: "app", warnings: warnings} = app}
@ -218,7 +242,7 @@ defmodule Livebook.AppsTest do
File.write!(image_path, "content") File.write!(image_path, "content")
File.write!(app_path, """ File.write!(app_path, """
<!-- livebook:{"app_settings":{"slug":"app"},"file_entries":[{"name":"image.jpg","type":"attachment"}]} --> <!-- livebook:{"app_settings":{"access_type":"public","slug":"app"},"file_entries":[{"name":"image.jpg","type":"attachment"}]} -->
# App # App
""") """)