defmodule Fake do @moduledoc """ This module starts an application running an webserver that stubs CAS requests. ## Starting Start the GenServer by calling `Fake.start`. The TCP port Fake is running can be obtained by calling `Fake.port` ## Requests The server will validate requests do a `POST /v1/tickets` and validate credentials against the `valid_*` functions on `Fake` module The server will always return the same TGT It will also generate STs using the valid TGT for any service on `POST /v1/tickets/\#{valid_tgt}` Trying to validate the ST in `Fake.valid_st/0` will always succeed for any service: Any other value will fail. """ use Application @name :FakeServer @spec valid_username :: String.t @doc "The only username `Fake` server will consider valid" def valid_username, do: "example" @spec valid_password :: String.t @doc "The only password `Fake` server will consider valid" def valid_password, do: "secret" @spec valid_tgt :: String.t @doc "The only TGT `Fake` server will consider valid" def valid_tgt, do: "TGT-example-abcd" @spec valid_st :: String.t @doc "The only ST `Fake` server will consider valid" def valid_st, do: "ST-example-1234" @spec valid_token :: String.t @doc "The only ST `Fake` server will consider valid" def valid_token, do: "abdbdbdbdb" @doc false def start do start(:a, :b) end @doc false def start(_type, _args) do import Supervisor.Spec, warn: false children = [ worker(Fake.Server, [@name]) ] opts = [strategy: :one_for_one, name: Fake.Supervisor] Supervisor.start_link(children, opts) end @doc "Returns the TCP port Fake is running on" def port, do: Fake.Server.port(@name) end