Bring back browser/config.xml

This commit is contained in:
Andrew Dryga
2023-04-26 12:13:00 -06:00
parent bcdeae3f9e
commit 92a7c505e3
7 changed files with 78 additions and 2 deletions

View File

@@ -39,7 +39,7 @@ defmodule Web do
def controller do
quote do
use Phoenix.Controller,
formats: [:html, :json],
formats: [:html, :json, :xml],
layouts: [html: Web.Layouts]
import Plug.Conn
@@ -67,6 +67,19 @@ defmodule Web do
end
end
def xml do
quote do
import Phoenix.Template, only: [embed_templates: 1]
# Import convenience functions from controllers
import Phoenix.Controller,
only: [get_csrf_token: 0, view_module: 1, view_template: 1]
# Include general helpers for rendering HTML
unquote(html_helpers())
end
end
def html do
quote do
use Phoenix.Component

View File

@@ -0,0 +1,7 @@
defmodule Web.BrowserController do
use Web, :controller
def config(conn, _params) do
render(conn, "config.xml", layout: false)
end
end

View File

@@ -0,0 +1,5 @@
defmodule Web.BrowserXML do
use Web, :xml
embed_templates "browser_xml/*"
end

View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<browserconfig>
<msapplication>
<tile>
<square150x150logo src="<%= ~p"/images/mstile-150x150.png" %>" />
<TileColor>331700</TileColor>
</tile>
</msapplication>
</browserconfig>

View File

@@ -0,0 +1,19 @@
defmodule Web.ErrorXML do
use Web, :xml
# If you want to customize your error pages,
# uncomment the embed_templates/1 call below
# and add pages to the error directory:
#
# * lib/web_web/controllers/error_xml/404.xml.heex
# * lib/web_web/controllers/error_xml/500.xml.heex
#
# embed_templates "error_xml/*"
# The default is to render a plain text page based on
# the template name. For example, "404.xml" becomes
# "Not Found".
def render(template, _assigns) do
Phoenix.Controller.status_message_from_template(template)
end
end

View File

@@ -0,0 +1,15 @@
defmodule Web.BrowserControllerTest do
use Web.ConnCase, async: true
describe "config/2" do
test "returns valid XML browser config", %{conn: conn} do
test_conn =
conn
# |> put_req_header("accept", "application/xml")
|> get(~p"/browser/config.xml")
assert response(test_conn, 200) =~ "<?xml"
assert response(test_conn, 200) =~ "src=\"/images/mstile-150x150.png\""
end
end
end

View File

@@ -88,7 +88,11 @@ config :web, Web.Endpoint,
path: nil
],
render_errors: [
formats: [html: Web.ErrorHTML, json: Web.ErrorJSON],
formats: [
html: Web.ErrorHTML,
json: Web.ErrorJSON,
xml: Web.ErrorXML
],
layout: false
],
pubsub_server: Domain.PubSub,
@@ -97,6 +101,10 @@ config :web, Web.Endpoint,
signing_salt: "t01wa0K4lUd7mKa0HAtZdE+jFOPDDejX"
]
config :mime, :types, %{
"application/xml" => ["xml"]
}
config :web, Web.SAML,
entity_id: "urn:firezone.dev:firezone-app",
certfile_path: Path.expand("../apps/web/priv/cert/saml_selfsigned.pem", __DIR__),