Skip to content

Commit

Permalink
formatter uptake
Browse files Browse the repository at this point in the history
  • Loading branch information
handnot2 committed Nov 6, 2017
1 parent 913eb1f commit 42e8fb3
Show file tree
Hide file tree
Showing 19 changed files with 112 additions and 90 deletions.
11 changes: 11 additions & 0 deletions .formatter.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[
inputs: [
"mix.exs",
"{config,lib,test}/**/*.{ex,exs}"
],

locals_without_parens: [
plug: 1,
plug: 2
]
]
5 changes: 2 additions & 3 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ config :samly_howto, SamlyHowtoWeb.Endpoint,
url: [host: "localhost"],
secret_key_base: "xyC3UIJzAYfuGyQXTYCHeWiD90ziZBPuk07QQFWURvXTRDSFaurxcjcxFPwj1h2Z",
render_errors: [view: SamlyHowtoWeb.ErrorView, accepts: ~w(html json)],
pubsub: [name: SamlyHowto.PubSub,
adapter: Phoenix.PubSub.PG2]
pubsub: [name: SamlyHowto.PubSub, adapter: Phoenix.PubSub.PG2]

# Configures Elixir's Logger
config :logger, :console,
Expand All @@ -20,4 +19,4 @@ config :logger, :console,

# Import environment specific config. This must remain at the bottom
# of this file so it overrides the configuration defined above.
import_config "#{Mix.env}.exs"
import_config "#{Mix.env()}.exs"
75 changes: 42 additions & 33 deletions config/dev.exs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,14 @@ config :samly_howto, SamlyHowtoWeb.Endpoint,
debug_errors: true,
code_reloader: true,
check_origin: false,
watchers: [node: ["node_modules/brunch/bin/brunch", "watch", "--stdin",
cd: Path.expand("../assets", __DIR__)]]
watchers: [
node: [
"node_modules/brunch/bin/brunch",
"watch",
"--stdin",
cd: Path.expand("../assets", __DIR__)
]
]

# ## SSL Support
#
Expand Down Expand Up @@ -49,9 +55,12 @@ config :logger, :console, format: "[$level] $message\n"
# in production as building large stacktraces may be expensive.
config :phoenix, :stacktrace_depth, 20

# #### Identity Provider ID choices
#
# IdP ID from `:path_segment` is used OOTB.
# Set this to `:subdomain` when sub-domain in the hostname is to be treated as IdP ID.
config :samly, Samly.Provider,
idp_id_from: :path_segment,
#idp_id_from: :subdomain,
service_providers: [
%{
id: "sp1",
Expand All @@ -68,23 +77,23 @@ config :samly, Samly.Provider,
id: "sp2",
entity_id: "urn:idp2.samly.howto:sp2",
certfile: "samly.crt",
keyfile: "samly.pem",
#contact_name: "Samly Howto SP2 Admin",
#contact_email: "sp2-admin@samly.howto",
#org_name: "Samly Howto SP2",
#org_displayname: "Samly Howto SP2 Displayname",
#org_url: "http://idp2.samly.howto:4003"
keyfile: "samly.pem"
# contact_name: "Samly Howto SP2 Admin",
# contact_email: "sp2-admin@samly.howto",
# org_name: "Samly Howto SP2",
# org_displayname: "Samly Howto SP2 Displayname",
# org_url: "http://idp2.samly.howto:4003"
},
%{
id: "sp3",
entity_id: "urn:idp3.samly.howto:sp3",
certfile: "samly.crt",
keyfile: "samly.pem",
#contact_name: "Samly Howto SP3 Admin",
#contact_email: "sp3-admin@samly.howto",
#org_name: "Samly Howto SP3",
#org_displayname: "Samly Howto SP3 Displayname",
#org_url: "http://idp3.samly.howto:4003"
keyfile: "samly.pem"
# contact_name: "Samly Howto SP3 Admin",
# contact_email: "sp3-admin@samly.howto",
# org_name: "Samly Howto SP3",
# org_displayname: "Samly Howto SP3 Displayname",
# org_url: "http://idp3.samly.howto:4003"
}
],
identity_providers: [
Expand All @@ -93,35 +102,35 @@ config :samly, Samly.Provider,
sp_id: "sp1",
base_url: "http://samly.howto:4003/sso",
metadata_file: "idp_metadata.xml",
pre_session_create_pipeline: SamlyHowtoWeb.Plugs.SamlyPipeline,
#use_redirect_for_req: false,
#sign_requests: true,
#sign_metadata: true,
#signed_assertion_in_resp: true,
#signed_envelopes_in_resp: true
pre_session_create_pipeline: SamlyHowtoWeb.Plugs.SamlyPipeline
# use_redirect_for_req: false,
# sign_requests: true,
# sign_metadata: true,
# signed_assertion_in_resp: true,
# signed_envelopes_in_resp: true
},
%{
id: "idp2",
sp_id: "sp2",
base_url: "http://idp2.samly.howto:4003/sso",
metadata_file: "idp_metadata.xml",
pre_session_create_pipeline: SamlyHowtoWeb.Plugs.SamlyPipeline,
#use_redirect_for_req: false,
#sign_requests: true,
#sign_metadata: true,
#signed_assertion_in_resp: true,
#signed_envelopes_in_resp: true
pre_session_create_pipeline: SamlyHowtoWeb.Plugs.SamlyPipeline
# use_redirect_for_req: false,
# sign_requests: true,
# sign_metadata: true,
# signed_assertion_in_resp: true,
# signed_envelopes_in_resp: true
},
%{
id: "idp3",
sp_id: "sp3",
base_url: "http://idp3.samly.howto:4003/sso",
metadata_file: "idp_metadata.xml",
pre_session_create_pipeline: SamlyHowtoWeb.Plugs.SamlyPipeline,
#use_redirect_for_req: false,
#sign_requests: true,
#sign_metadata: true,
#signed_assertion_in_resp: true,
#signed_envelopes_in_resp: true
pre_session_create_pipeline: SamlyHowtoWeb.Plugs.SamlyPipeline
# use_redirect_for_req: false,
# sign_requests: true,
# sign_metadata: true,
# signed_assertion_in_resp: true,
# signed_envelopes_in_resp: true
}
]
2 changes: 1 addition & 1 deletion lib/samly_howto/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ defmodule SamlyHowto.Application do
supervisor(SamlyHowtoWeb.Endpoint, []),
# Start your own worker by calling: SamlyHowto.Worker.start_link(arg1, arg2, arg3)
# worker(SamlyHowto.Worker, [arg1, arg2, arg3]),
worker(Samly.Provider, []),
worker(Samly.Provider, [])
]

# See https://hexdocs.pm/elixir/Supervisor.html
Expand Down
5 changes: 3 additions & 2 deletions lib/samly_howto_web.ex
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ defmodule SamlyHowtoWeb do

def view do
quote do
use Phoenix.View, root: "lib/samly_howto_web/templates",
namespace: SamlyHowtoWeb
use Phoenix.View,
root: "lib/samly_howto_web/templates",
namespace: SamlyHowtoWeb

# Import convenience functions from controllers
import Phoenix.Controller, only: [get_flash: 2, view_module: 1]
Expand Down
2 changes: 1 addition & 1 deletion lib/samly_howto_web/channels/user_socket.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ defmodule SamlyHowtoWeb.UserSocket do
# channel "room:*", SamlyHowtoWeb.RoomChannel

## Transports
transport :websocket, Phoenix.Transports.WebSocket
transport(:websocket, Phoenix.Transports.WebSocket)
# transport :longpoll, Phoenix.Transports.LongPoll

# Socket params are passed from the client and can
Expand Down
20 changes: 13 additions & 7 deletions lib/samly_howto_web/controllers/page_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,20 @@ defmodule SamlyHowtoWeb.PageController do
def index(conn, _params) do
assertion = Samly.get_active_assertion(conn)
uid = Samly.get_attribute(assertion, "uid")
{idp_id, attributes, computed} = if assertion do
{assertion.idp_id, assertion.attributes, assertion.computed}
else
{nil, nil, nil}
end

{idp_id, attributes, computed} =
if assertion do
{assertion.idp_id, assertion.attributes, assertion.computed}
else
{nil, nil, nil}
end

target_url = "/?a=value1&b=value two" |> URI.encode_www_form()
{metadata_uri, signin_uri, signout_uri} = get_samly_uris()
render conn, "index.html", [

render(
conn,
"index.html",
idp_id: idp_id,
uid: uid,
attributes: attributes,
Expand All @@ -21,11 +26,12 @@ defmodule SamlyHowtoWeb.PageController do
metadata_uri: metadata_uri,
signin_uri: signin_uri,
signout_uri: signout_uri
]
)
end

defp get_samly_uris() do
opts = Application.get_env(:samly, Samly.Provider, [])

if opts[:idp_id_from] == :subdomain do
{
"/sso/sp/metadata",
Expand Down
8 changes: 5 additions & 3 deletions lib/samly_howto_web/endpoint.ex
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
defmodule SamlyHowtoWeb.Endpoint do
use Phoenix.Endpoint, otp_app: :samly_howto

socket "/socket", SamlyHowtoWeb.UserSocket
socket("/socket", SamlyHowtoWeb.UserSocket)

# Serve at "/" the static files from "priv/static" directory.
#
# You should set gzip to true if you are running phoenix.digest
# when deploying your static files in production.
plug Plug.Static,
at: "/", from: :samly_howto, gzip: false,
at: "/",
from: :samly_howto,
gzip: false,
only: ~w(css fonts images js favicon.ico robots.txt)

# Code reloading can be explicitly enabled under the
# :code_reloader configuration of your endpoint.
if code_reloading? do
socket "/phoenix/live_reload/socket", Phoenix.LiveReloader.Socket
socket("/phoenix/live_reload/socket", Phoenix.LiveReloader.Socket)
plug Phoenix.LiveReloader
plug Phoenix.CodeReloader
end
Expand Down
5 changes: 3 additions & 2 deletions lib/samly_howto_web/plugs/samly_pipeline.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ defmodule SamlyHowtoWeb.Plugs.SamlyPipeline do
assertion = conn.private[:samly_assertion]

first_name = Map.get(assertion.attributes, "first_name")
last_name = Map.get(assertion.attributes, "last_name")
last_name = Map.get(assertion.attributes, "last_name")

computed = %{"full_name" => "#{first_name} #{last_name}"}

assertion = %Assertion{assertion | computed: computed}

conn
|> put_private(:samly_assertion, assertion)
|> put_private(:samly_assertion, assertion)

# |> send_resp(404, "attribute mapping failed")
# |> halt()
end
Expand Down
7 changes: 4 additions & 3 deletions lib/samly_howto_web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ defmodule SamlyHowtoWeb.Router do
end

scope "/sso" do
forward "/", Samly.Router
forward("/", Samly.Router)
end

scope "/", SamlyHowtoWeb do
pipe_through :browser # Use the default browser stack
# Use the default browser stack
pipe_through(:browser)

get "/", PageController, :index
get("/", PageController, :index)
end

# Other scopes may use custom stacks.
Expand Down
4 changes: 2 additions & 2 deletions lib/samly_howto_web/views/error_helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ defmodule SamlyHowtoWeb.ErrorHelpers do
Generates tag for inlined form input errors.
"""
def error_tag(form, field) do
Enum.map(Keyword.get_values(form.errors, field), fn (error) ->
content_tag :span, translate_error(error), class: "help-block"
Enum.map(Keyword.get_values(form.errors, field), fn error ->
content_tag(:span, translate_error(error), class: "help-block")
end)
end

Expand Down
2 changes: 1 addition & 1 deletion lib/samly_howto_web/views/error_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ defmodule SamlyHowtoWeb.ErrorView do
# In case no render clause matches or no
# template is found, let's render it as 500
def template_not_found(_template, assigns) do
render "500.html", assigns
render("500.html", assigns)
end
end
12 changes: 6 additions & 6 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ defmodule SamlyHowto.Mixfile do
def project do
[
app: :samly_howto,
version: "0.6.0",
version: "0.6.1",
elixir: "~> 1.4",
elixirc_paths: elixirc_paths(Mix.env),
compilers: [:phoenix, :gettext] ++ Mix.compilers,
start_permanent: Mix.env == :prod,
elixirc_paths: elixirc_paths(Mix.env()),
compilers: [:phoenix, :gettext] ++ Mix.compilers(),
start_permanent: Mix.env() == :prod,
deps: deps()
]
end
Expand All @@ -25,7 +25,7 @@ defmodule SamlyHowto.Mixfile do

# Specifies which paths to compile per environment.
defp elixirc_paths(:test), do: ["lib", "test/support"]
defp elixirc_paths(_), do: ["lib"]
defp elixirc_paths(_), do: ["lib"]

# Specifies your project dependencies.
#
Expand All @@ -38,7 +38,7 @@ defmodule SamlyHowto.Mixfile do
{:phoenix_live_reload, "~> 1.0", only: :dev},
{:gettext, "~> 0.11"},
{:cowboy, "~> 1.0"},
{:samly, "~> 0.8"},
{:samly, "~> 0.8"}
]
end
end
28 changes: 14 additions & 14 deletions mix.lock
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
%{"cowboy": {:hex, :cowboy, "1.1.2", "61ac29ea970389a88eca5a65601460162d370a70018afe6f949a29dca91f3bb0", [], [{:cowlib, "~> 1.0.2", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "~> 1.3.2", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm"},
"cowlib": {:hex, :cowlib, "1.0.2", "9d769a1d062c9c3ac753096f868ca121e2730b9a377de23dec0f7e08b1df84ee", [], [], "hexpm"},
"esaml": {:hex, :esaml, "3.1.0", "76337f00b5953a6c249fa8c322905c7a069b7c20339ece3756072279e6dcb41c", [], [{:cowboy, "1.1.2", [hex: :cowboy, repo: "hexpm", optional: false]}], "hexpm"},
"file_system": {:hex, :file_system, "0.2.2", "7f1e9de4746f4eb8a4ca8f2fbab582d84a4e40fa394cce7bfcb068b988625b06", [], [], "hexpm"},
"gettext": {:hex, :gettext, "0.13.1", "5e0daf4e7636d771c4c71ad5f3f53ba09a9ae5c250e1ab9c42ba9edccc476263", [], [], "hexpm"},
"mime": {:hex, :mime, "1.1.0", "01c1d6f4083d8aa5c7b8c246ade95139620ef8effb009edde934e0ec3b28090a", [], [], "hexpm"},
"phoenix": {:hex, :phoenix, "1.3.0", "1c01124caa1b4a7af46f2050ff11b267baa3edb441b45dbf243e979cd4c5891b", [], [{:cowboy, "~> 1.0", [hex: :cowboy, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 1.0", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:plug, "~> 1.3.3 or ~> 1.4", [hex: :plug, repo: "hexpm", optional: false]}, {:poison, "~> 2.2 or ~> 3.0", [hex: :poison, repo: "hexpm", optional: false]}], "hexpm"},
"phoenix_html": {:hex, :phoenix_html, "2.10.4", "d4f99c32d5dc4918b531fdf163e1fd7cf20acdd7703f16f5d02d4db36de803b7", [], [{:plug, "~> 1.0", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm"},
"phoenix_live_reload": {:hex, :phoenix_live_reload, "1.1.3", "1d178429fc8950b12457d09c6afec247bfe1fcb6f36209e18fbb0221bdfe4d41", [], [{:file_system, "~> 0.2.1 or ~> 0.3", [hex: :file_system, repo: "hexpm", optional: false]}, {:phoenix, "~> 1.0 or ~> 1.2 or ~> 1.3", [hex: :phoenix, repo: "hexpm", optional: false]}], "hexpm"},
"phoenix_pubsub": {:hex, :phoenix_pubsub, "1.0.2", "bfa7fd52788b5eaa09cb51ff9fcad1d9edfeb68251add458523f839392f034c1", [], [], "hexpm"},
"plug": {:hex, :plug, "1.4.3", "236d77ce7bf3e3a2668dc0d32a9b6f1f9b1f05361019946aae49874904be4aed", [], [{:cowboy, "~> 1.0.1 or ~> 1.1", [hex: :cowboy, repo: "hexpm", optional: true]}, {:mime, "~> 1.0", [hex: :mime, repo: "hexpm", optional: false]}], "hexpm"},
"poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [], [], "hexpm"},
"ranch": {:hex, :ranch, "1.3.2", "e4965a144dc9fbe70e5c077c65e73c57165416a901bd02ea899cfd95aa890986", [], [], "hexpm"},
"samly": {:hex, :samly, "0.8.0", "c690b454b1d1e1d583961807824a84ff5a49b2c25ae5eb80e21dc31af5d335b7", [], [{:esaml, "~> 3.1", [hex: :esaml, repo: "hexpm", optional: false]}, {:plug, "~> 1.4", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm"}}
%{"cowboy": {:hex, :cowboy, "1.1.2", "61ac29ea970389a88eca5a65601460162d370a70018afe6f949a29dca91f3bb0", [:rebar3], [{:cowlib, "~> 1.0.2", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "~> 1.3.2", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm"},
"cowlib": {:hex, :cowlib, "1.0.2", "9d769a1d062c9c3ac753096f868ca121e2730b9a377de23dec0f7e08b1df84ee", [:make], [], "hexpm"},
"esaml": {:hex, :esaml, "3.1.0", "76337f00b5953a6c249fa8c322905c7a069b7c20339ece3756072279e6dcb41c", [:rebar3], [{:cowboy, "1.1.2", [hex: :cowboy, repo: "hexpm", optional: false]}], "hexpm"},
"file_system": {:hex, :file_system, "0.2.2", "7f1e9de4746f4eb8a4ca8f2fbab582d84a4e40fa394cce7bfcb068b988625b06", [:mix], [], "hexpm"},
"gettext": {:hex, :gettext, "0.13.1", "5e0daf4e7636d771c4c71ad5f3f53ba09a9ae5c250e1ab9c42ba9edccc476263", [:mix], [], "hexpm"},
"mime": {:hex, :mime, "1.1.0", "01c1d6f4083d8aa5c7b8c246ade95139620ef8effb009edde934e0ec3b28090a", [:mix], [], "hexpm"},
"phoenix": {:hex, :phoenix, "1.3.0", "1c01124caa1b4a7af46f2050ff11b267baa3edb441b45dbf243e979cd4c5891b", [:mix], [{:cowboy, "~> 1.0", [hex: :cowboy, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 1.0", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:plug, "~> 1.3.3 or ~> 1.4", [hex: :plug, repo: "hexpm", optional: false]}, {:poison, "~> 2.2 or ~> 3.0", [hex: :poison, repo: "hexpm", optional: false]}], "hexpm"},
"phoenix_html": {:hex, :phoenix_html, "2.10.4", "d4f99c32d5dc4918b531fdf163e1fd7cf20acdd7703f16f5d02d4db36de803b7", [:mix], [{:plug, "~> 1.0", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm"},
"phoenix_live_reload": {:hex, :phoenix_live_reload, "1.1.3", "1d178429fc8950b12457d09c6afec247bfe1fcb6f36209e18fbb0221bdfe4d41", [:mix], [{:file_system, "~> 0.2.1 or ~> 0.3", [hex: :file_system, repo: "hexpm", optional: false]}, {:phoenix, "~> 1.0 or ~> 1.2 or ~> 1.3", [hex: :phoenix, repo: "hexpm", optional: false]}], "hexpm"},
"phoenix_pubsub": {:hex, :phoenix_pubsub, "1.0.2", "bfa7fd52788b5eaa09cb51ff9fcad1d9edfeb68251add458523f839392f034c1", [:mix], [], "hexpm"},
"plug": {:hex, :plug, "1.4.3", "236d77ce7bf3e3a2668dc0d32a9b6f1f9b1f05361019946aae49874904be4aed", [:mix], [{:cowboy, "~> 1.0.1 or ~> 1.1", [hex: :cowboy, repo: "hexpm", optional: true]}, {:mime, "~> 1.0", [hex: :mime, repo: "hexpm", optional: false]}], "hexpm"},
"poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [:mix], [], "hexpm"},
"ranch": {:hex, :ranch, "1.3.2", "e4965a144dc9fbe70e5c077c65e73c57165416a901bd02ea899cfd95aa890986", [:rebar3], [], "hexpm"},
"samly": {:hex, :samly, "0.8.1", "483aaa0191eaf9f0c00c1896da5e7bbd3376804b9a8db88282a27eb20d94e432", [], [{:esaml, "~> 3.1", [hex: :esaml, repo: "hexpm", optional: false]}, {:plug, "~> 1.4", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm"}}
2 changes: 1 addition & 1 deletion test/samly_howto_web/controllers/page_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ defmodule SamlyHowtoWeb.PageControllerTest do
use SamlyHowtoWeb.ConnCase

test "GET /", %{conn: conn} do
conn = get conn, "/"
conn = get(conn, "/")
assert html_response(conn, 200) =~ "Welcome to Phoenix!"
end
end
9 changes: 3 additions & 6 deletions test/samly_howto_web/views/error_view_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,14 @@ defmodule SamlyHowtoWeb.ErrorViewTest do
import Phoenix.View

test "renders 404.html" do
assert render_to_string(SamlyHowtoWeb.ErrorView, "404.html", []) ==
"Page not found"
assert render_to_string(SamlyHowtoWeb.ErrorView, "404.html", []) == "Page not found"
end

test "render 500.html" do
assert render_to_string(SamlyHowtoWeb.ErrorView, "500.html", []) ==
"Internal server error"
assert render_to_string(SamlyHowtoWeb.ErrorView, "500.html", []) == "Internal server error"
end

test "render any other" do
assert render_to_string(SamlyHowtoWeb.ErrorView, "505.html", []) ==
"Internal server error"
assert render_to_string(SamlyHowtoWeb.ErrorView, "505.html", []) == "Internal server error"
end
end
Loading

0 comments on commit 42e8fb3

Please sign in to comment.