Skip to content

Commit

Permalink
Installer - generate CSRF meta with csrf_token_value (#4804)
Browse files Browse the repository at this point in the history
  • Loading branch information
leandrocp committed Apr 28, 2022
1 parent 2b5556f commit de142f3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<%%= csrf_meta_tag() %>
<meta name="csrf-token" content={csrf_token_value()}>
<%%= live_title_tag assigns[:page_title] || "<%= @app_module %>", suffix: " · Phoenix Framework" %>
<link phx-track-static rel="stylesheet" href={Routes.static_path(@conn, "/assets/app.css")}/>
<script defer phx-track-static type="text/javascript" src={Routes.static_path(@conn, "/assets/app.js")}></script>
Expand Down
5 changes: 4 additions & 1 deletion installer/test/phx_new_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,10 @@ defmodule Mix.Tasks.Phx.NewTest do
assert file =~ ~s|plug Phoenix.LiveDashboard.RequestLogger|
end

assert_file "phx_blog/lib/phx_blog_web/templates/layout/root.html.heex"
assert_file "phx_blog/lib/phx_blog_web/templates/layout/root.html.heex", fn file ->
assert file =~ ~s|<meta name="csrf-token" content={csrf_token_value()}>|
end

assert_file "phx_blog/lib/phx_blog_web/templates/layout/app.html.heex"

assert_file "phx_blog/lib/phx_blog_web/templates/page/index.html.heex", fn file ->
Expand Down
6 changes: 5 additions & 1 deletion installer/test/phx_new_umbrella_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,11 @@ defmodule Mix.Tasks.Phx.New.UmbrellaTest do
~r/defmodule PhxUmbWeb.PageView/

assert_file web_path(@app, "lib/#{@app}_web/router.ex"), "defmodule PhxUmbWeb.Router"
assert_file web_path(@app, "lib/#{@app}_web/templates/layout/root.html.heex")

assert_file web_path(@app, "lib/#{@app}_web/templates/layout/root.html.heex"), fn file ->
assert file =~ ~s|<meta name="csrf-token" content={csrf_token_value()}>|
end

assert_file web_path(@app, "lib/#{@app}_web/templates/layout/app.html.heex")
assert_file web_path(@app, "test/#{@app}_web/views/page_view_test.exs"),
"defmodule PhxUmbWeb.PageViewTest"
Expand Down

0 comments on commit de142f3

Please sign in to comment.