Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
pleroma
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
normandy
pleroma
Commits
3cf17dc4
Commit
3cf17dc4
authored
6 years ago
by
lain
Browse files
Options
Downloads
Patches
Plain Diff
Add EnsureAuthenticatedPlug
parent
faf53477
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/pleroma/plugs/ensure_authenticated_plug.ex
+19
-0
19 additions, 0 deletions
lib/pleroma/plugs/ensure_authenticated_plug.ex
test/plugs/ensure_authenticated_plug_test.exs
+27
-0
27 additions, 0 deletions
test/plugs/ensure_authenticated_plug_test.exs
with
46 additions
and
0 deletions
lib/pleroma/plugs/ensure_authenticated_plug.ex
0 → 100644
+
19
−
0
View file @
3cf17dc4
defmodule
Pleroma
.
Plugs
.
EnsureAuthenticatedPlug
do
import
Plug
.
Conn
alias
Pleroma
.
User
def
init
(
options
)
do
options
end
def
call
(%{
assigns:
%{
user:
%
User
{}}}
=
conn
,
_
)
do
conn
end
def
call
(
conn
,
_
)
do
conn
|>
put_resp_content_type
(
"application/json"
)
|>
send_resp
(
403
,
Jason
.
encode!
(%{
error:
"Invalid credentials."
}))
|>
halt
end
end
This diff is collapsed.
Click to expand it.
test/plugs/ensure_authenticated_plug_test.exs
0 → 100644
+
27
−
0
View file @
3cf17dc4
defmodule
Pleroma
.
Plugs
.
EnsureAuthenticatedPlugTest
do
use
Pleroma
.
Web
.
ConnCase
,
async:
true
alias
Pleroma
.
Plugs
.
EnsureAuthenticatedPlug
alias
Pleroma
.
User
test
"it halts if no user is assigned"
,
%{
conn:
conn
}
do
conn
=
conn
|>
EnsureAuthenticatedPlug
.
call
(%{})
assert
conn
.
status
==
403
assert
conn
.
halted
==
true
end
test
"it continues if a user is assigned"
,
%{
conn:
conn
}
do
conn
=
conn
|>
assign
(
:user
,
%
User
{})
ret_conn
=
conn
|>
EnsureAuthenticatedPlug
.
call
(%{})
assert
ret_conn
==
conn
end
end
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment