mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-10-21 10:56:10 +08:00
Persist app password in stamp metadata (#2550)
This commit is contained in:
parent
b1661da884
commit
4c6869d69c
4 changed files with 42 additions and 14 deletions
|
@ -408,6 +408,7 @@ defmodule Livebook.LiveMarkdown.Export do
|
||||||
# If there are any :file file entries, we want to generate a stamp
|
# If there are any :file file entries, we want to generate a stamp
|
||||||
# to make sure the entries are not tampered with. We also want to
|
# to make sure the entries are not tampered with. We also want to
|
||||||
# store the information about file entries already in quarantine
|
# store the information about file entries already in quarantine
|
||||||
|
metadata =
|
||||||
if Enum.any?(notebook.file_entries, &(&1.type == :file)) do
|
if Enum.any?(notebook.file_entries, &(&1.type == :file)) do
|
||||||
Map.put(
|
Map.put(
|
||||||
metadata,
|
metadata,
|
||||||
|
@ -417,6 +418,12 @@ defmodule Livebook.LiveMarkdown.Export do
|
||||||
else
|
else
|
||||||
metadata
|
metadata
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if notebook.app_settings.slug != nil and notebook.app_settings.access_type == :protected do
|
||||||
|
Map.put(metadata, :app_settings_password, notebook.app_settings.password)
|
||||||
|
else
|
||||||
|
metadata
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defp ensure_order(%{} = map) do
|
defp ensure_order(%{} = map) do
|
||||||
|
|
|
@ -686,6 +686,9 @@ defmodule Livebook.LiveMarkdown.Import do
|
||||||
{:quarantine_file_entry_names, quarantine_file_entry_names}, notebook ->
|
{:quarantine_file_entry_names, quarantine_file_entry_names}, notebook ->
|
||||||
%{notebook | quarantine_file_entry_names: MapSet.new(quarantine_file_entry_names)}
|
%{notebook | quarantine_file_entry_names: MapSet.new(quarantine_file_entry_names)}
|
||||||
|
|
||||||
|
{:app_settings_password, password}, notebook ->
|
||||||
|
put_in(notebook.app_settings.password, password)
|
||||||
|
|
||||||
_entry, notebook ->
|
_entry, notebook ->
|
||||||
notebook
|
notebook
|
||||||
end)
|
end)
|
||||||
|
|
|
@ -1293,7 +1293,7 @@ defmodule Livebook.LiveMarkdown.ExportTest do
|
||||||
assert expected_document == document
|
assert expected_document == document
|
||||||
end
|
end
|
||||||
|
|
||||||
test "does not persist password" do
|
test "stores password in stamp metadata when app settings are configured with protected access" do
|
||||||
notebook = %{
|
notebook = %{
|
||||||
Notebook.new()
|
Notebook.new()
|
||||||
| name: "My Notebook",
|
| name: "My Notebook",
|
||||||
|
@ -1305,15 +1305,9 @@ defmodule Livebook.LiveMarkdown.ExportTest do
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
expected_document = """
|
|
||||||
<!-- livebook:{"app_settings":{"slug":"app"}} -->
|
|
||||||
|
|
||||||
# My Notebook
|
|
||||||
"""
|
|
||||||
|
|
||||||
{document, []} = Export.notebook_to_livemd(notebook)
|
{document, []} = Export.notebook_to_livemd(notebook)
|
||||||
|
|
||||||
assert expected_document == document
|
assert stamp_metadata(notebook, document) == %{app_settings_password: "verylongpass"}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -814,6 +814,30 @@ defmodule Livebook.LiveMarkdown.ImportTest do
|
||||||
app_settings: %{slug: "app", access_type: :protected}
|
app_settings: %{slug: "app", access_type: :protected}
|
||||||
} = notebook
|
} = notebook
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "imports password from stamp metadata" do
|
||||||
|
{markdown, []} =
|
||||||
|
%{
|
||||||
|
Notebook.new()
|
||||||
|
| name: "My Notebook",
|
||||||
|
app_settings: %{
|
||||||
|
Notebook.AppSettings.new()
|
||||||
|
| slug: "app",
|
||||||
|
access_type: :protected,
|
||||||
|
password: "verylongpass"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|> Livebook.LiveMarkdown.Export.notebook_to_livemd()
|
||||||
|
|
||||||
|
{notebook, %{warnings: []}} = Import.notebook_from_livemd(markdown)
|
||||||
|
|
||||||
|
assert %Notebook{
|
||||||
|
app_settings: %{
|
||||||
|
access_type: :protected,
|
||||||
|
password: "verylongpass"
|
||||||
|
}
|
||||||
|
} = notebook
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "backward compatibility" do
|
describe "backward compatibility" do
|
||||||
|
|
Loading…
Add table
Reference in a new issue