This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if @env == :test do | |
| defp send_unauthorized_if_not_faked(conn) do | |
| # Implement testing backdoor | |
| conn | |
| end | |
| else | |
| defp send_unauthorized_if_not_faked(conn) do | |
| send_unauthorized_response(conn) | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @spec send_unauthorized_if_not_faked(Plug.Conn.t) :: Plug.Conn.t | |
| if @env == :test do | |
| defp send_unauthorized_if_not_faked(conn) do | |
| conn |> append_testing_backdoor() | |
| end | |
| else | |
| defp send_unauthorized_if_not_faked(conn) do | |
| conn |> send_unauthorized_response() | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| test "accessing a protected route" do | |
| user = insert(:user, [username: "Sven"]) | |
| conn = conn |> get(user_path(conn, :show, "self") <> with_user(user)) | |
| # assert results | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| defmodule Rayman do | |
| @moduledoc """ | |
| Rayman is a pure Elixir implementation of MQTT for educational purposes. | |
| """ | |
| def decode_packet(packet) do | |
| IO.inspect packet | |
| end | |
| def encode_packet(data) do |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| defmodule RaymanPlayground.Application do | |
| @moduledoc false | |
| use Application | |
| def start(_type, _args) do | |
| {:ok, pid} = :gen_tcp.listen(1883, [ | |
| :binary, | |
| active: false, | |
| reuseaddr: true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| defp deps do | |
| [ | |
| # NOTE: You would have to adjust this to your local path | |
| {:rayman, path: "/Users/sgehring/development/blog/rayman"} | |
| ] | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| config :myapp, MyApp.Endpoint, | |
| server: true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if @env == :test do | |
| forward("end-to-end", MyApp.Plug.TestEndToEnd) | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| defmodule MyApp.Plug.TestEndToEnd do | |
| use Plug.Router | |
| plug :match | |
| plug :dispatch | |
| match _, do: send_resp(conn, 404, "not found") | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| defp checkout_shared_db_conn do | |
| :ok = Ecto.Adapters.SQL.Sandbox.checkout(Repo, ownership_timeout: :infinity) | |
| :ok = Ecto.Adapters.SQL.Sandbox.mode(Repo, {:shared, self()}) | |
| end | |
| defp checkin_shared_db_conn(_) do | |
| :ok = Ecto.Adapters.SQL.Sandbox.checkin(Repo) | |
| end |