Browse Source

fix(app): Wide-spread tweaks.

jackyalcine 8 months ago
parent
commit
5a9a5ee509
Signed by: Jacky Alciné <yo@jacky.wtf> GPG Key ID: 537A4F904B15268D

+ 161
- 0
.credo.exs View File

@@ -0,0 +1,161 @@
1
+# This file contains the configuration for Credo and you are probably reading
2
+# this after creating it with `mix credo.gen.config`.
3
+#
4
+# If you find anything wrong or unclear in this file, please report an
5
+# issue on GitHub: https://github.com/rrrene/credo/issues
6
+#
7
+%{
8
+  #
9
+  # You can have as many configs as you like in the `configs:` field.
10
+  configs: [
11
+    %{
12
+      #
13
+      # Run any exec using `mix credo -C <name>`. If no exec name is given
14
+      # "default" is used.
15
+      #
16
+      name: "default",
17
+      #
18
+      # These are the files included in the analysis:
19
+      files: %{
20
+        #
21
+        # You can give explicit globs or simply directories.
22
+        # In the latter case `**/*.{ex,exs}` will be used.
23
+        #
24
+        included: ["lib/", "src/", "test/", "web/", "apps/"],
25
+        excluded: [~r"/_build/", ~r"/deps/", ~r"/node_modules/"]
26
+      },
27
+      #
28
+      # If you create your own checks, you must specify the source files for
29
+      # them here, so they can be loaded by Credo before running the analysis.
30
+      #
31
+      requires: [],
32
+      #
33
+      # If you want to enforce a style guide and need a more traditional linting
34
+      # experience, you can change `strict` to `true` below:
35
+      #
36
+      strict: false,
37
+      #
38
+      # If you want to use uncolored output by default, you can change `color`
39
+      # to `false` below:
40
+      #
41
+      color: true,
42
+      #
43
+      # You can customize the parameters of any check by adding a second element
44
+      # to the tuple.
45
+      #
46
+      # To disable a check put `false` as second element:
47
+      #
48
+      #     {Credo.Check.Design.DuplicatedCode, false}
49
+      #
50
+      checks: [
51
+        #
52
+        ## Consistency Checks
53
+        #
54
+        {Credo.Check.Consistency.ExceptionNames, []},
55
+        {Credo.Check.Consistency.LineEndings, []},
56
+        {Credo.Check.Consistency.ParameterPatternMatching, []},
57
+        {Credo.Check.Consistency.SpaceAroundOperators, []},
58
+        {Credo.Check.Consistency.SpaceInParentheses, []},
59
+        {Credo.Check.Consistency.TabsOrSpaces, []},
60
+
61
+        #
62
+        ## Design Checks
63
+        #
64
+        # You can customize the priority of any check
65
+        # Priority values are: `low, normal, high, higher`
66
+        #
67
+        {Credo.Check.Design.AliasUsage, [priority: :low]},
68
+        # For some checks, you can also set other parameters
69
+        #
70
+        # If you don't want the `setup` and `test` macro calls in ExUnit tests
71
+        # or the `schema` macro in Ecto schemas to trigger DuplicatedCode, just
72
+        # set the `excluded_macros` parameter to `[:schema, :setup, :test]`.
73
+        #
74
+        {Credo.Check.Design.DuplicatedCode, [excluded_macros: []]},
75
+        # You can also customize the exit_status of each check.
76
+        # If you don't want TODO comments to cause `mix credo` to fail, just
77
+        # set this value to 0 (zero).
78
+        #
79
+        {Credo.Check.Design.TagTODO, [exit_status: 2]},
80
+        {Credo.Check.Design.TagFIXME, []},
81
+
82
+        #
83
+        ## Readability Checks
84
+        #
85
+        {Credo.Check.Readability.AliasOrder, []},
86
+        {Credo.Check.Readability.FunctionNames, []},
87
+        {Credo.Check.Readability.LargeNumbers, []},
88
+        {Credo.Check.Readability.MaxLineLength, [priority: :low, max_length: 120]},
89
+        {Credo.Check.Readability.ModuleAttributeNames, []},
90
+        {Credo.Check.Readability.ModuleDoc, []},
91
+        {Credo.Check.Readability.ModuleNames, []},
92
+        {Credo.Check.Readability.ParenthesesOnZeroArityDefs, []},
93
+        {Credo.Check.Readability.ParenthesesInCondition, []},
94
+        {Credo.Check.Readability.PredicateFunctionNames, []},
95
+        {Credo.Check.Readability.PreferImplicitTry, []},
96
+        {Credo.Check.Readability.RedundantBlankLines, []},
97
+        {Credo.Check.Readability.StringSigils, []},
98
+        {Credo.Check.Readability.TrailingBlankLine, []},
99
+        {Credo.Check.Readability.TrailingWhiteSpace, []},
100
+        {Credo.Check.Readability.VariableNames, []},
101
+        {Credo.Check.Readability.Semicolons, []},
102
+        {Credo.Check.Readability.SpaceAfterCommas, []},
103
+
104
+        #
105
+        ## Refactoring Opportunities
106
+        #
107
+        {Credo.Check.Refactor.DoubleBooleanNegation, []},
108
+        {Credo.Check.Refactor.CondStatements, []},
109
+        {Credo.Check.Refactor.CyclomaticComplexity, []},
110
+        {Credo.Check.Refactor.FunctionArity, []},
111
+        {Credo.Check.Refactor.LongQuoteBlocks, []},
112
+        {Credo.Check.Refactor.MapInto, []},
113
+        {Credo.Check.Refactor.MatchInCondition, []},
114
+        {Credo.Check.Refactor.NegatedConditionsInUnless, []},
115
+        {Credo.Check.Refactor.NegatedConditionsWithElse, []},
116
+        {Credo.Check.Refactor.Nesting, []},
117
+        {Credo.Check.Refactor.PipeChainStart,
118
+         [excluded_argument_types: [:atom, :binary, :fn, :keyword], excluded_functions: []]},
119
+        {Credo.Check.Refactor.UnlessWithElse, []},
120
+
121
+        #
122
+        ## Warnings
123
+        #
124
+        {Credo.Check.Warning.BoolOperationOnSameValues, []},
125
+        {Credo.Check.Warning.ExpensiveEmptyEnumCheck, []},
126
+        {Credo.Check.Warning.IExPry, []},
127
+        {Credo.Check.Warning.IoInspect, []},
128
+        {Credo.Check.Warning.LazyLogging, []},
129
+        {Credo.Check.Warning.OperationOnSameValues, []},
130
+        {Credo.Check.Warning.OperationWithConstantResult, []},
131
+        {Credo.Check.Warning.UnusedEnumOperation, []},
132
+        {Credo.Check.Warning.UnusedFileOperation, []},
133
+        {Credo.Check.Warning.UnusedKeywordOperation, []},
134
+        {Credo.Check.Warning.UnusedListOperation, []},
135
+        {Credo.Check.Warning.UnusedPathOperation, []},
136
+        {Credo.Check.Warning.UnusedRegexOperation, []},
137
+        {Credo.Check.Warning.UnusedStringOperation, []},
138
+        {Credo.Check.Warning.UnusedTupleOperation, []},
139
+        {Credo.Check.Warning.RaiseInsideRescue, []},
140
+
141
+        #
142
+        # Controversial and experimental checks (opt-in, just remove `, false`)
143
+        #
144
+        {Credo.Check.Refactor.ABCSize, false},
145
+        {Credo.Check.Refactor.AppendSingleItem, false},
146
+        {Credo.Check.Refactor.VariableRebinding, false},
147
+        {Credo.Check.Warning.MapGetUnsafePass, false},
148
+        {Credo.Check.Consistency.MultiAliasImportRequireUse, false},
149
+
150
+        #
151
+        # Deprecated checks (these will be deleted after a grace period)
152
+        #
153
+        {Credo.Check.Readability.Specs, false}
154
+
155
+        #
156
+        # Custom checks can be created using `mix credo.gen.check`.
157
+        #
158
+      ]
159
+    }
160
+  ]
161
+}

+ 0
- 3
app.json View File

@@ -9,9 +9,6 @@
9 9
   "description": "A self-hosted, single-tenant social website.",
10 10
   "repository": "https://git.jacky.wtf/indieweb/koype",
11 11
   "keywords": ["indieweb", "social", "koype", "single-tenant", "federated", "website", "web site"],
12
-  "addons": [
13
-    "heroku-redis:hobby-dev"
14
-  ],
15 12
   "env": {
16 13
     "SECRET_KEY_BASE": {
17 14
       "generator": "secret"

+ 1
- 1
cssnano.config.js View File

@@ -2,7 +2,7 @@ module.exports = {
2 2
   preset: [
3 3
     'default',
4 4
     {
5
-      calc: false,
5
+      calc: true,
6 6
       discardComments: {
7 7
         removeAll: true
8 8
       }

lib/indieweb/auth.ex → lib/auth.ex View File

@@ -16,7 +16,7 @@
16 16
 # 
17 17
 # You should have received a copy of the GNU Affero General Public License
18 18
 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
19
-defmodule IndieWeb.Auth do
19
+defmodule Koype.Auth do
20 20
   @spec inbuilt_auth_endpoint() :: binary()
21 21
   def inbuilt_auth_endpoint() do
22 22
     Koype.host() <> Koype.Web.Router.Helpers.indie_auth_path(Koype.Web.Endpoint, :authorize)

lib/indieweb/auth/scope.ex → lib/auth/scope.ex View File

@@ -16,14 +16,9 @@
16 16
 # 
17 17
 # You should have received a copy of the GNU Affero General Public License
18 18
 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
19
-defmodule IndieWeb.Auth.Scope do
20
-  @moduledoc "Scope logic for IndieAuth."
21
-  alias Koype.Cache
19
+defmodule Koype.Auth.Scope do
20
+  @moduledoc false
22 21
 
23
-  @scope_age 1000 * 60 * 60 * 24 * 7
24
-  @separator " "
25
-
26
-  # TODO: Move this to be on disk.
27 22
   def unknown do
28 23
     %{
29 24
       description: "This scope is unknown to this site and will be rejected.",
@@ -31,7 +26,6 @@ defmodule IndieWeb.Auth.Scope do
31 26
     }
32 27
   end
33 28
 
34
-  # TODO: Move each of these entries to be on disk.
35 29
   def known do
36 30
     %{
37 31
       read: %{
@@ -82,14 +76,6 @@ defmodule IndieWeb.Auth.Scope do
82 76
     }
83 77
   end
84 78
 
85
-  defp do_make_key(code) do
86
-    [
87
-      "scope",
88
-      :crypto.hash(:sha256, code) |> Base.hex_encode32(padding: false)
89
-    ]
90
-    |> Enum.join("_")
91
-  end
92
-
93 79
   def info(scope_name) when is_binary(scope_name),
94 80
     do: info(scope_name |> String.to_atom())
95 81
 
@@ -107,38 +93,4 @@ defmodule IndieWeb.Auth.Scope do
107 93
       }
108 94
     )
109 95
   end
110
-
111
-  def fetch(code)
112
-  def fetch(nil), do: {:error, :missing_code}
113
-
114
-  def fetch(code) when is_binary(code) do
115
-    case Cache.get(do_make_key(code)) do
116
-      {:ok, nil} -> {:error, :scope_for_code_not_found}
117
-      {:ok, []} -> {:ok, []}
118
-      {:ok, scope_string} -> {:ok, from_string(scope_string)}
119
-      {:error, cache_error} -> {:error, cache_error}
120
-    end
121
-  end
122
-
123
-  def from_string(scope_string) when is_binary(scope_string),
124
-    do: String.split(scope_string, @separator)
125
-
126
-  def to_string(scopes) when is_list(scopes),
127
-    do: Enum.join(scopes, @separator)
128
-
129
-  def to_public_string(scopes) when is_list(scopes),
130
-    do: Enum.join(scopes, " ")
131
-
132
-  def persist!(code, scope)
133
-
134
-  def persist!(code, nil), do: persist!(code, ~w(read))
135
-
136
-  def persist!(code, scope) when is_binary(scope),
137
-    do: persist!(code, from_string(scope))
138
-
139
-  def persist!(code, scope) when is_list(scope) do
140
-    Cache.set(do_make_key(code), __MODULE__.to_string(scope), expire: @scope_age)
141
-  end
142
-
143
-  def can_upload?(scope) when is_list(scope), do: Enum.member?(scope, "media")
144 96
 end

+ 0
- 86
lib/indieweb/auth/code.ex View File

@@ -1,86 +0,0 @@
1
-# Koype: a IndieWeb-focused, single-tenant website engine for people.
2
-# 
3
-# Copyright © 2019 Jacky Alciné <jacky.is@black.af>
4
-# 
5
-# This file belongs to the Koype project.
6
-# 
7
-# This program is free software: you can redistribute it and/or modify
8
-# it under the terms of the GNU Affero General Public License as published by
9
-# the Free Software Foundation, either version 3 of the License, or
10
-# (at your option) any later version.
11
-# 
12
-# This program is distributed in the hope that it will be useful,
13
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
-# GNU Affero General Public License for more details.
16
-# 
17
-# You should have received a copy of the GNU Affero General Public License
18
-# along with this program.  If not, see <https://www.gnu.org/licenses/>.
19
-defmodule IndieWeb.Auth.Code do
20
-  alias Koype.Cache
21
-  @code_age 1000 * 5
22
-  @code_separator "/"
23
-
24
-  defp do_make_key_for_client(client_id, redirect_uri) do
25
-    [
26
-      URI.parse(client_id).host,
27
-      redirect_uri
28
-    ]
29
-    |> Enum.join("_")
30
-  end
31
-
32
-  def generate(nil, _redirect_uri), do: {:error, :missing_client_id}
33
-  def generate(_client_id, nil), do: {:error, :missing_redirect_uri}
34
-
35
-  def generate(client_id, redirect_uri) do
36
-    [
37
-      :crypto.strong_rand_bytes(16),
38
-      client_id,
39
-      redirect_uri
40
-    ]
41
-    |> Enum.map(&Base.url_encode64/1)
42
-    |> Enum.join(@code_separator)
43
-  end
44
-
45
-  def persist!(code, client_id, redirect_uri) do
46
-    :ok = Cache.set(do_make_key_for_client(client_id, redirect_uri), code, expire: @code_age)
47
-  end
48
-
49
-  def valid?(code, client_id, redirect_uri) do
50
-    case Cache.get(do_make_key_for_client(client_id, redirect_uri)) do
51
-      {:ok, nil} ->
52
-        {:error, :code_not_found}
53
-
54
-      {:ok, fetched_code} when is_binary(fetched_code) ->
55
-        [_token, fetched_client_id, fetched_redirect_uri] =
56
-          String.split(fetched_code, @code_separator)
57
-          |> Enum.map(fn value -> Base.url_decode64(value) end)
58
-          |> Enum.map(fn {:ok, value} -> value end)
59
-
60
-        cond do
61
-          code != fetched_code ->
62
-            {:error, :invalid_code}
63
-
64
-          URI.parse(fetched_client_id).host != URI.parse(client_id).host ->
65
-            {:error, :mismatched_client_id_for_code}
66
-
67
-          fetched_redirect_uri != redirect_uri ->
68
-            {:error, :mismatched_redirect_uri_for_code}
69
-
70
-          true ->
71
-            :ok
72
-        end
73
-    end
74
-  end
75
-
76
-  def delete!(code) do
77
-    code_components =
78
-      code
79
-      |> String.split(@code_separator)
80
-      |> Enum.map(&Base.url_decode64!/1)
81
-
82
-    [_bytes, client_id, redirect_uri] = code_components
83
-
84
-    Cache.delete(do_make_key_for_client(client_id, redirect_uri))
85
-  end
86
-end

+ 2
- 2
lib/koype.ex View File

@@ -40,13 +40,13 @@ defmodule Koype do
40 40
   @spec links() :: map()
41 41
   def links() do
42 42
     %{
43
-      authorization_endpoint: IndieWeb.Auth.auth_endpoint(),
43
+      authorization_endpoint: Koype.Auth.auth_endpoint(),
44 44
       me: IndieWeb.RelMe.all() |> Enum.map(& &1.uri),
45 45
       media_endpoint: IndieWeb.Micropub.media_endpoint(),
46 46
       micropub: IndieWeb.Micropub.endpoint(),
47 47
       microsub: IndieWeb.Microsub.endpoint(),
48 48
       self: Koype.host(),
49
-      token_endpoint: IndieWeb.Auth.token_endpoint(),
49
+      token_endpoint: Koype.Auth.token_endpoint(),
50 50
       subscribe: IndieWeb.Microsub.subscription_endpoint()
51 51
     }
52 52
     |> Enum.reject(fn

+ 0
- 31
lib/post.ex View File

@@ -85,37 +85,6 @@ defmodule Koype.Post do
85 85
 
86 86
   def extract_uris(_, _), do: []
87 87
 
88
-  def known_types do
89
-    [
90
-      %{type: "article", name: "Article", names: "Articles"},
91
-      %{type: "audio", name: "Audio", names: "Audio"},
92
-      %{type: "bookmark", name: "Bookmark", names: "Bookmarks"},
93
-      %{type: "checkin", name: "Check In", names: "Check Ins"},
94
-      %{type: "like", name: "Like", names: "Likes"},
95
-      %{type: "listen", name: "Listen", names: "Listens"},
96
-      %{type: "note", name: "Note", names: "Notes"},
97
-      %{type: "reply", name: "Reply", names: "Replies"},
98
-      %{type: "repost", name: "Repost", names: "Reposts"},
99
-      %{type: "donation", name: "Donation", names: "Donations"},
100
-      %{type: "payment", name: "Payment", names: "Payments"},
101
-      %{type: "event", name: "Event", names: "Events"},
102
-      %{type: "exercise", name: "Workout", names: "Workouts"},
103
-      %{type: "follow", name: "Follow", names: "Follows"},
104
-      %{type: "food", name: "Food", names: "Meals"},
105
-      %{type: "gameplay", name: "Game Play", names: "Game Plays"},
106
-      %{type: "issue", name: "Issue", names: "Issues"},
107
-      %{type: "photo", name: "Photo", names: "Photos"},
108
-      %{type: "presentation", name: "Presentation", names: "Presentations"},
109
-      %{type: "quotation", name: "Quotation", names: "Quotations"},
110
-      %{type: "read", name: "Read", names: "Reads"},
111
-      %{type: "sleep", name: "Sleep", names: "Sleeps"},
112
-      %{type: "venue", name: "Venue", names: "Venues"},
113
-      %{type: "watch", name: "Watch", names: "Watches"},
114
-      %{type: "video", name: "Video", names: "Videos"},
115
-      %{type: "rsvp", name: "RSVP", names: "RSVPs"}
116
-    ]
117
-  end
118
-
119 88
   @spec determine_title(type :: atom(), properties :: map()) :: binary()
120 89
   def determine_title(type, data)
121 90
 

+ 6
- 6
lib/timeline.ex View File

@@ -70,10 +70,10 @@ defmodule Koype.Timeline do
70 70
 
71 71
   defp do_filter_for_types(query, _), do: query
72 72
 
73
-  def chronological(
74
-        filter \\ [],
75
-        models \\ Koype.Repo.Entry.published() |> preload(:categories) |> order_by(desc: :published_at)
76
-      ) do
77
-    config = [page: Keyword.get(filter, :page, 1), page_size: Keyword.get(filter, :size, 10)]
78
-  end
73
+#   def chronological(
74
+#         filter \\ [],
75
+#         models \\ Koype.Repo.Entry.published() |> preload(:categories) |> order_by(desc: :published_at)
76
+#       ) do
77
+#     config = [page: Keyword.get(filter, :page, 1), page_size: Keyword.get(filter, :size, 10)]
78
+#   end
79 79
 end

+ 6
- 2
lib/webmention.ex View File

@@ -84,7 +84,9 @@ defmodule Koype.Webmention do
84 84
     Koype.Job.create(Koype.Job.Webmention.Send, args)
85 85
   end
86 86
 
87
-  def send!(source: source, target: target) do
87
+  def send!(args) do
88
+    [source: source, target: target] = args
89
+
88 90
     case IndieWeb.Webmention.send(target, source) do
89 91
       {:ok, resp} ->
90 92
         Logger.debug("Webmention for #{inspect(source)} to #{target}!")
@@ -145,7 +147,9 @@ defmodule Koype.Webmention do
145 147
     {:ok, :gone}
146 148
   end
147 149
 
148
-  defp do_upsertion_of_webmention(target_url: target_url, source: source, target: _) do
150
+  defp do_upsertion_of_webmention(args) do
151
+    [target_url: target_url, source: source, target: _] = args
152
+
149 153
     with(
150 154
       {:ok, mf2} when is_map(mf2) <- IndieWeb.MF2.Remote.fetch(source),
151 155
       entry_mf2 when is_map(entry_mf2) <- IndieWeb.MF2.get_format(mf2, "entry")

+ 1
- 1
mix.exs View File

@@ -166,7 +166,7 @@ defmodule Koype.Mixfile do
166 166
       lint: ["credo", "sobelow", "dialyzer --plt"],
167 167
       start: ["phx.server"],
168 168
       coverage: ["coveralls"],
169
-      ci: ["lint", "coverage.detail", "test.features"],
169
+      ci: ["coverage.detail", "test.features", "lint"],
170 170
       "coverage.html": ["coveralls.html"]
171 171
     ]
172 172
   end

+ 1
- 1
mix.lock View File

@@ -64,7 +64,7 @@
64 64
   "ibrowse": {:hex, :ibrowse, "4.4.0", "2d923325efe0d2cb09b9c6a047b2835a5eda69d8a47ed6ff8bc03628b764e991", [:rebar3], [], "hexpm"},
65 65
   "idna": {:hex, :idna, "6.0.0", "689c46cbcdf3524c44d5f3dde8001f364cd7608a99556d8fbd8239a5798d4c10", [:rebar3], [{:unicode_util_compat, "0.4.1", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm"},
66 66
   "inch_ex": {:git, "https://github.com/rrrene/inch_ex.git", "45ecbc4b57fa8b943b9e4cd0d4da72da95c9dd4a", []},
67
-  "indieweb": {:hex, :indieweb, "0.0.19", "f0861ecfc6aea59a51a256edfb16c1373cd1d3cc1525ea76f9250041cd0a6b9e", [:mix], [{:cachex, "~> 3.1", [hex: :cachex, repo: "hexpm", optional: false]}, {:microformats2, "~> 0.2.0", [hex: :microformats2, repo: "hexpm", optional: false]}], "hexpm"},
67
+  "indieweb": {:hex, :indieweb, "0.0.24", "4c46e4931c3114e3b0f5c9aaf12b0e48a28ce7046b8d3e8d7a02c1d18812cb72", [:mix], [{:cachex, "~> 3.1", [hex: :cachex, repo: "hexpm", optional: false]}, {:microformats2, "~> 0.2.0", [hex: :microformats2, repo: "hexpm", optional: false]}], "hexpm"},
68 68
   "inflex": {:hex, :inflex, "1.10.0", "8366a7696e70e1813aca102e61274addf85d99f4a072b2f9c7984054ea1b9d29", [:mix], [], "hexpm"},
69 69
   "jason": {:hex, :jason, "1.1.2", "b03dedea67a99223a2eaf9f1264ce37154564de899fd3d8b9a21b1a6fd64afe7", [:mix], [{:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm"},
70 70
   "jose": {:hex, :jose, "1.9.0", "4167c5f6d06ffaebffd15cdb8da61a108445ef5e85ab8f5a7ad926fdf3ada154", [:mix, :rebar3], [{:base64url, "~> 0.0.1", [hex: :base64url, repo: "hexpm", optional: false]}], "hexpm"},

+ 0
- 53
test/unit/indieweb/auth/scope_test.exs View File

@@ -1,17 +1,11 @@
1 1
 defmodule IndieWeb.Auth.ScopeTest do
2 2
   use Koype.Test.BaseCase
3
-  import Mock
4 3
   alias IndieWeb.Auth.Scope
5
-  alias Koype.Cache
6
-
7
-  @code "this_is_very_important"
8 4
 
9 5
   describe ".info/1" do
10 6
     test "defaults out unknown scopes" do
11 7
       scope_info = Scope.info(:foobar)
12
-
13 8
       assert scope_info[:name] == "foobar"
14
-
15 9
       assert scope_info[:description] == "This scope is unknown to this site and will be rejected."
16 10
     end
17 11
 
@@ -27,51 +21,4 @@ defmodule IndieWeb.Auth.ScopeTest do
27 21
       assert %{name: _, description: _} = Scope.info("read")
28 22
     end
29 23
   end
30
-
31
-  describe ".fetch/1" do
32
-    test "finds stored scope info" do
33
-      with_mock Cache, get: fn _key -> {:ok, "eat pray love"} end do
34
-        assert {:ok, ~w(eat pray love)} = Scope.fetch(@code)
35
-      end
36
-    end
37
-
38
-    test "returns empty for code with no scope" do
39
-      with_mock Cache, get: fn _key -> {:ok, ""} end do
40
-        assert {:ok, [""]} = Scope.fetch(@code)
41
-      end
42
-    end
43
-
44
-    test "returns nil for non-existent code-to-scope" do
45
-      with_mock Cache, get: fn _key -> {:ok, nil} end do
46
-        assert {:error, :scope_for_code_not_found} = Scope.fetch(@code)
47
-      end
48
-    end
49
-  end
50
-
51
-  describe ".persist!/2" do
52
-    test "saves provided scope when it's a string" do
53
-      with_mock Cache, set: fn _key, _value, _options -> :ok end do
54
-        scope_str = "read pray"
55
-        assert :ok = Scope.persist!(@code, scope_str)
56
-        assert_called(Cache.set(:_, scope_str, :_))
57
-      end
58
-    end
59
-
60
-    test "saves default code of read" do
61
-      with_mock Cache, set: fn _key, _value, _options -> :ok end do
62
-        assert :ok = Scope.persist!(@code, nil)
63
-        assert_called(Cache.set(:_, "read", :_))
64
-      end
65
-    end
66
-  end
67
-
68
-  describe ".can_upload?/1" do
69
-    test "confirms provided list of scopes has a scope for uploading" do
70
-      assert Scope.can_upload?(~w(media read))
71
-    end
72
-
73
-    test "denies provided list of scopes for uploading" do
74
-      refute Scope.can_upload?(~w(read))
75
-    end
76
-  end
77 24
 end

+ 0
- 1
web/authentication_helpers.ex View File

@@ -53,7 +53,6 @@ defmodule Koype.Web.AuthenticationHelpers do
53 53
       Koype.Guardian.encode_and_sign(
54 54
         client_id,
55 55
         claims,
56
-        ttl: {48, :hour},
57 56
         key: :indie,
58 57
         token_type: "access"
59 58
       )

+ 2
- 2
web/controllers/indie/auth_controller.ex View File

@@ -26,7 +26,7 @@ defmodule Koype.Web.Indie.AuthController do
26 26
         "client_id" => client_id,
27 27
         "redirect_uri" => redirect_uri
28 28
       }) do
29
-    case IndieWeb.Auth.Code.valid?(code, client_id, redirect_uri) do
29
+    case IndieWeb.Auth.Code.verify(code, client_id, redirect_uri) do
30 30
       {:error, error} ->
31 31
         conn
32 32
         |> put_status(:unauthorized)
@@ -117,7 +117,7 @@ defmodule Koype.Web.Indie.AuthController do
117 117
     end
118 118
 
119 119
     with :ok = Scope.persist!(code, scope),
120
-         :ok = Code.persist!(code, client_id, redirect_uri) do
120
+         :ok = Code.persist(code, client_id, redirect_uri) do
121 121
       signed_uri =
122 122
         URI.merge(
123 123
           URI.parse(redirect_uri),

+ 6
- 6
web/controllers/indie/token_api_controller.ex View File

@@ -47,8 +47,8 @@ defmodule Koype.Web.Indie.TokenApiController do
47 47
       ) do
48 48
     with(
49 49
       :ok <- assert_me(params),
50
-      :ok <- Code.valid?(code, client_id, redirect_uri),
51
-      {:ok, scope} <- Scope.fetch(code)
50
+      {:ok, scope} <- Scope.get(code),
51
+      :ok <- Code.verify(code, client_id, redirect_uri, %{"scope" => scope})
52 52
     ) do
53 53
       token = indie_sign_in(client_id, scope)
54 54
 
@@ -58,19 +58,19 @@ defmodule Koype.Web.Indie.TokenApiController do
58 58
       |> put_resp_header("authorization", "Bearer #{token}")
59 59
       |> json(%{
60 60
         me: Koype.host(),
61
-        scope: Scope.to_public_string(scope),
61
+        scope: Scope.to_string(scope),
62 62
         token_type: :bearer,
63 63
         access_token: token
64 64
       })
65 65
     else
66 66
       {:error, :me_not_valid} ->
67
-        Code.delete!(code)
67
+        Code.destroy(code, client_id, redirect_uri)
68 68
 
69 69
         conn
70 70
         |> Explode.bad_request("The 'me' provided is incorrect for this server.")
71 71
 
72 72
       {:error, :invalid_code} ->
73
-        Code.delete!(code)
73
+        Code.destroy(code, client_id, redirect_uri)
74 74
 
75 75
         conn
76 76
         |> Explode.forbidden("The provided code was not valid.")
@@ -116,7 +116,7 @@ defmodule Koype.Web.Indie.TokenApiController do
116 116
       |> json(%{
117 117
         client_id: client_id,
118 118
         me: Koype.host(),
119
-        scope: scope |> Scope.from_string() |> Scope.to_public_string()
119
+        scope: scope |> Scope.from_string() |> Scope.to_string()
120 120
       })
121 121
     else
122 122
       {:error, error} ->

+ 2
- 2
web/controllers/settings_controller.ex View File

@@ -25,8 +25,8 @@ defmodule Koype.Web.SettingsController do
25 25
   @endpoints ~w(endpoint.microsub endpoint.indieauth.auth endpoint.indieauth.token endpoint.microsub.subscription)
26 26
 
27 27
   def default_endpoint_for(name)
28
-  def default_endpoint_for("indieauth.auth"), do: IndieWeb.Auth.inbuilt_auth_endpoint()
29
-  def default_endpoint_for("indieauth.token"), do: IndieWeb.Auth.inbuilt_token_endpoint()
28
+  def default_endpoint_for("indieauth.auth"), do: Koype.Auth.inbuilt_auth_endpoint()
29
+  def default_endpoint_for("indieauth.token"), do: Koype.Auth.inbuilt_token_endpoint()
30 30
   def default_endpoint_for("indieauth.microsub.subscription"), do: IndieWeb.Microsub.inbuilt_subscription_endpoint()
31 31
 
32 32
   def view(conn, %{"component" => component}) do

+ 4
- 4
web/templates/settings/_view-endpoints.html.eex View File

@@ -59,14 +59,14 @@
59 59
         <input class="v-mid"
60 60
                type="checkbox"
61 61
                name="inbuilt[indieauth.auth]"
62
-               <%= if IndieWeb.Auth.auth_endpoint == IndieWeb.Auth.inbuilt_auth_endpoint, do: "checked" %>>
62
+               <%= if Koype.Auth.auth_endpoint == Koype.Auth.inbuilt_auth_endpoint, do: "checked" %>>
63 63
         <span class="v-mid">Use Koype's inbuilt system</span>
64 64
         <a href="#" class="link underline-hover v-mid gray">(why?)</a>
65 65
       </label>
66 66
     </small>
67 67
   </label>
68 68
   <input name="endpoint.indieauth.auth"
69
-         value="<%= if IndieWeb.Auth.auth_endpoint == IndieWeb.Auth.inbuilt_auth_endpoint, do: "", else: IndieWeb.Auth.auth_endpoint %>"
69
+         value="<%= if Koype.Auth.auth_endpoint == Koype.Auth.inbuilt_auth_endpoint, do: "", else: Koype.Auth.auth_endpoint %>"
70 70
          type="url"
71 71
          placeholder="https://auth.indieauth.endpoint/"
72 72
          id="endpoint-indieauth-auth"
@@ -87,14 +87,14 @@
87 87
         <input class="v-mid"
88 88
                type="checkbox"
89 89
                name="inbuilt[indieauth.token]"
90
-               <%= if IndieWeb.Auth.token_endpoint == IndieWeb.Auth.inbuilt_token_endpoint, do: "checked" %>>
90
+               <%= if Koype.Auth.token_endpoint == Koype.Auth.inbuilt_token_endpoint, do: "checked" %>>
91 91
         <span class="v-mid">Use Koype's inbuilt system</span>
92 92
         <a href="#" class="link underline-hover v-mid gray">(why?)</a>
93 93
       </label>
94 94
     </small>
95 95
   </label>
96 96
   <input name="endpoint.indieauth.token"
97
-         value="<%= if IndieWeb.Auth.token_endpoint == IndieWeb.Auth.inbuilt_token_endpoint, do: "", else: IndieWeb.Auth.token_endpoint %>"
97
+         value="<%= if Koype.Auth.token_endpoint == Koype.Auth.inbuilt_token_endpoint, do: "", else: Koype.Auth.token_endpoint %>"
98 98
          type="url"
99 99
          id="endpoint-indieauth-token"
100 100
          placeholder="https://token.indieauth.endpoint/"

+ 3
- 1
web/views/indie/auth_view.ex View File

@@ -18,7 +18,7 @@
18 18
 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
19 19
 defmodule Koype.Web.Indie.AuthView do
20 20
   use Koype.Web, :view
21
-  alias IndieWeb.Auth.Scope
21
+  alias Koype.Auth.Scope
22 22
 
23 23
   @doc false
24 24
   def title("authorize.html", assigns) do
@@ -27,8 +27,10 @@ defmodule Koype.Web.Indie.AuthView do
27 27
 
28 28
   @doc false
29 29
   def title("error.html", _assigns), do: "Error Authorizing Client"
30
+
30 31
   @doc false
31 32
   def tags(_, _, _), do: []
33
+
32 34
   @doc false
33 35
   def tag(_, _, _), do: []
34 36
 

Loading…
Cancel
Save