• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

source-academy / backend / e0330f2cf38b2d8af12bffd20f4cac2158d607fc-PR-1236

31 Mar 2025 09:12AM UTC coverage: 19.982% (-73.6%) from 93.607%
e0330f2cf38b2d8af12bffd20f4cac2158d607fc-PR-1236

Pull #1236

github

RichDom2185
Redate migrations to maintain total ordering
Pull Request #1236: Added Exam mode

12 of 57 new or added lines in 8 files covered. (21.05%)

2430 existing lines in 97 files now uncovered.

671 of 3358 relevant lines covered (19.98%)

3.03 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

66.67
/lib/cadet/auth/guardian.ex
1
defmodule Cadet.Auth.Guardian do
2
  @moduledoc """
3
  Guardian implementation module
4
  """
5
  use Guardian, otp_app: :cadet
6

7
  alias Cadet.Accounts
8
  alias Guardian.DB
9

10
  def subject_for_token(user, _claims) do
6✔
11
    {:ok,
12
     URI.encode_query(%{
13
       id: user.id,
6✔
14
       username: user.username,
6✔
15
       provider: user.provider
6✔
16
     })}
17
  end
18

19
  def resource_from_claims(claims) do
20
    case claims["sub"] |> URI.decode_query() |> Map.fetch("id") do
2✔
UNCOV
21
      :error ->
×
22
        {:error, :bad_request}
23

24
      {:ok, id} ->
25
        case user = Accounts.get_user(id) do
2✔
UNCOV
26
          nil -> {:error, :not_found}
×
27
          _ -> {:ok, user}
2✔
28
        end
29
    end
30
  end
31

32
  def after_encode_and_sign(resource, claims, token, _options) do
33
    with {:ok, _} <- DB.after_encode_and_sign(resource, claims["typ"], claims, token) do
6✔
34
      {:ok, token}
35
    end
36
  end
37

38
  def on_verify(claims, token, _options) do
UNCOV
39
    with {:ok, _} <- DB.on_verify(claims, token) do
×
40
      {:ok, claims}
41
    end
42
  end
43

44
  # TODO: Uncomment when there is an update to guardian_db > v1.1.0
45
  # (when git commit ef024b6 is merged)
46
  # def on_refresh({old_token, old_claims}, {new_token, new_claims}, _options) do
47
  #   with {:ok, _} <- DB.on_refresh({old_token, old_claims}, {new_token, new_claims}) do
48
  #     {:ok, {old_token, old_claims}, {new_token, new_claims}}
49
  #   end
50
  # end
51

52
  def on_revoke(claims, token, _options) do
UNCOV
53
    with {:ok, _} <- DB.on_revoke(claims, token) do
×
54
      {:ok, claims}
55
    end
56
  end
57
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc