mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-10-16 00:15:59 +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,12 +408,19 @@ defmodule Livebook.LiveMarkdown.Export do
|
|||
# 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
|
||||
# store the information about file entries already in quarantine
|
||||
if Enum.any?(notebook.file_entries, &(&1.type == :file)) do
|
||||
Map.put(
|
||||
metadata,
|
||||
:quarantine_file_entry_names,
|
||||
MapSet.to_list(notebook.quarantine_file_entry_names)
|
||||
)
|
||||
metadata =
|
||||
if Enum.any?(notebook.file_entries, &(&1.type == :file)) do
|
||||
Map.put(
|
||||
metadata,
|
||||
:quarantine_file_entry_names,
|
||||
MapSet.to_list(notebook.quarantine_file_entry_names)
|
||||
)
|
||||
else
|
||||
metadata
|
||||
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
|
||||
|
|
|
@ -686,6 +686,9 @@ defmodule Livebook.LiveMarkdown.Import do
|
|||
{:quarantine_file_entry_names, quarantine_file_entry_names}, notebook ->
|
||||
%{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 ->
|
||||
notebook
|
||||
end)
|
||||
|
|
|
@ -1293,7 +1293,7 @@ defmodule Livebook.LiveMarkdown.ExportTest do
|
|||
assert expected_document == document
|
||||
end
|
||||
|
||||
test "does not persist password" do
|
||||
test "stores password in stamp metadata when app settings are configured with protected access" do
|
||||
notebook = %{
|
||||
Notebook.new()
|
||||
| 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)
|
||||
|
||||
assert expected_document == document
|
||||
assert stamp_metadata(notebook, document) == %{app_settings_password: "verylongpass"}
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -814,6 +814,30 @@ defmodule Livebook.LiveMarkdown.ImportTest do
|
|||
app_settings: %{slug: "app", access_type: :protected}
|
||||
} = notebook
|
||||
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
|
||||
|
||||
describe "backward compatibility" do
|
||||
|
|
Loading…
Add table
Reference in a new issue