Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Pleroma
pleroma
Commits
497d34b8
Commit
497d34b8
authored
May 02, 2019
by
lain
Browse files
Merge branch 'iss-849' into 'develop'
Parse access_token from body parameters and URL parameters See merge request
!1103
parents
d107919b
a53a6c9d
Pipeline
#11353
passed with stages
in 5 minutes and 11 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
.gitlab-ci.yml
View file @
497d34b8
...
...
@@ -48,6 +48,7 @@ unit-testing:
-
name
:
postgres:9.6.2
command
:
[
"
postgres"
,
"
-c"
,
"
fsync=off"
,
"
-c"
,
"
synchronous_commit=off"
,
"
-c"
,
"
full_page_writes=off"
]
script
:
-
mix deps.get
-
mix ecto.create
-
mix ecto.migrate
-
mix test --trace --preload-modules
...
...
@@ -77,4 +78,4 @@ docs-deploy:
-
echo "${SSH_HOST_KEY}" > ~/.ssh/known_hosts
-
eval $(ssh-agent -s)
-
echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
-
rsync -hrvz --delete -e "ssh -p ${SSH_PORT}" priv/static/doc/ "${SSH_USER_HOST_LOCATION}/${CI_COMMIT_REF_NAME}"
-
rsync -hrvz --delete -e "ssh -p ${SSH_PORT}" priv/static/doc/ "${SSH_USER_HOST_LOCATION}/${CI_COMMIT_REF_NAME}"
lib/pleroma/plugs/oauth_plug.ex
View file @
497d34b8
...
...
@@ -16,6 +16,16 @@ def init(options), do: options
def
call
(%{
assigns:
%{
user:
%
User
{}}}
=
conn
,
_
),
do
:
conn
def
call
(%{
params:
%{
"access_token"
=>
access_token
}}
=
conn
,
_
)
do
with
{
:ok
,
user
,
token_record
}
<-
fetch_user_and_token
(
access_token
)
do
conn
|>
assign
(
:token
,
token_record
)
|>
assign
(
:user
,
user
)
else
_
->
conn
end
end
def
call
(
conn
,
_
)
do
with
{
:ok
,
token_str
}
<-
fetch_token_str
(
conn
),
{
:ok
,
user
,
token_record
}
<-
fetch_user_and_token
(
token_str
)
do
...
...
test/plugs/oauth_plug_test.exs
View file @
497d34b8
...
...
@@ -38,6 +38,26 @@ test "with valid token(downcase), it assigns the user", %{conn: conn} = opts do
assert
conn
.
assigns
[
:user
]
==
opts
[
:user
]
end
test
"with valid token(downcase) in url parameters, it assings the user"
,
opts
do
conn
=
:get
|>
build_conn
(
"/?access_token=
#{
opts
[
:token
]
}
"
)
|>
put_req_header
(
"content-type"
,
"application/json"
)
|>
fetch_query_params
()
|>
OAuthPlug
.
call
(%{})
assert
conn
.
assigns
[
:user
]
==
opts
[
:user
]
end
test
"with valid token(downcase) in body parameters, it assigns the user"
,
opts
do
conn
=
:post
|>
build_conn
(
"/api/v1/statuses"
,
access_token:
opts
[
:token
],
status:
"test"
)
|>
OAuthPlug
.
call
(%{})
assert
conn
.
assigns
[
:user
]
==
opts
[
:user
]
end
test
"with invalid token, it not assigns the user"
,
%{
conn:
conn
}
do
conn
=
conn
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment