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
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
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
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
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
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
@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
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
def authenticate_user_token(conn, _opts) do | |
with ["Bearer " <> token] <- get_req_header(conn, "authorization"), | |
{:ok, %{:id => user_id}} <- Token.verify_user_for_token(token), | |
conn_assign_user_details(conn, user_id) | |
else | |
_ -> send_unauthorized_if_not_faked(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
docker rm -v $(docker ps -f status=dead -f status=exited -aq) | |
docker rmi $(docker images --no-trunc -qf dangling=true) | |
docker volume rm $(docker volume ls -qf dangling=true) |