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
89b3729a
Commit
89b3729a
authored
Dec 11, 2018
by
Maksim
Browse files
fix warnings
parent
2999a08e
Changes
32
Hide whitespace changes
Inline
Side-by-side
lib/pleroma/user.ex
View file @
89b3729a
...
...
@@ -212,7 +212,7 @@ def maybe_direct_follow(%User{} = follower, %User{local: true} = followed) do
end
def
maybe_direct_follow
(%
User
{}
=
follower
,
%
User
{}
=
followed
)
do
if
!
User
.
ap_enabled?
(
followed
)
do
if
not
User
.
ap_enabled?
(
followed
)
do
follow
(
follower
,
followed
)
else
{
:ok
,
follower
}
...
...
@@ -736,7 +736,8 @@ def public_key_from_info(%{
source_data:
%{
"publicKey"
=>
%{
"publicKeyPem"
=>
public_key_pem
}}
})
do
key
=
:public_key
.
pem_decode
(
public_key_pem
)
public_key_pem
|>
:public_key
.
pem_decode
()
|>
hd
()
|>
:public_key
.
pem_entry_decode
()
...
...
@@ -774,13 +775,10 @@ def ap_enabled?(%User{local: true}), do: true
def
ap_enabled?
(%
User
{
info:
info
}),
do
:
info
.
ap_enabled
def
ap_enabled?
(
_
),
do
:
false
def
get_or_fetch
(
uri_or_nickname
)
do
if
String
.
starts_with?
(
uri_or_nickname
,
"http"
)
do
get_or_fetch_by_ap_id
(
uri_or_nickname
)
else
get_or_fetch_by_nickname
(
uri_or_nickname
)
end
end
@doc
"Gets or fetch a user by uri or nickname."
@spec
get_or_fetch
(
String
.
t
())
::
User
.
t
()
def
get_or_fetch
(
"http"
<>
_host
=
uri
),
do
:
get_or_fetch_by_ap_id
(
uri
)
def
get_or_fetch
(
nickname
),
do
:
get_or_fetch_by_nickname
(
nickname
)
# wait a period of time and return newest version of the User structs
# this is because we have synchronous follow APIs and need to simulate them
...
...
@@ -821,7 +819,9 @@ def parse_bio(bio, user) do
{
String
.
trim
(
name
,
":"
),
url
}
end
)
CommonUtils
.
format_input
(
bio
,
mentions
,
tags
,
"text/plain"
)
|>
Formatter
.
emojify
(
emoji
)
bio
|>
CommonUtils
.
format_input
(
mentions
,
tags
,
"text/plain"
)
|>
Formatter
.
emojify
(
emoji
)
end
def
tag
(
user_identifiers
,
tags
)
when
is_list
(
user_identifiers
)
do
...
...
lib/pleroma/web/common_api/utils.ex
View file @
89b3729a
defmodule
Pleroma
.
Web
.
CommonAPI
.
Utils
do
alias
Pleroma
.
{
Repo
,
Object
,
Formatter
,
Activity
}
alias
Calendar
.
Strftime
alias
Comeonin
.
Pbkdf2
alias
Pleroma
.
{
Activity
,
Formatter
,
Object
,
Repo
}
alias
Pleroma
.
User
alias
Pleroma
.
Web
alias
Pleroma
.
Web
.
ActivityPub
.
Utils
alias
Pleroma
.
Web
.
Endpoint
alias
Pleroma
.
Web
.
MediaProxy
alias
Pleroma
.
User
alias
Calendar
.
Strftime
alias
Comeonin
.
Pbkdf2
# This is a hack for twidere.
def
get_by_id_or_ap_id
(
id
)
do
...
...
@@ -148,7 +149,7 @@ def add_tag_links(text, tags) do
|>
Enum
.
sort_by
(
fn
{
tag
,
_
}
->
-
String
.
length
(
tag
)
end
)
Enum
.
reduce
(
tags
,
text
,
fn
{
full
,
tag
},
text
->
url
=
"<a href='
#{
Pleroma
.
Web
.
base_url
()
}
/tag/
#{
tag
}
' rel='tag'>#
#{
tag
}
</a>"
url
=
"<a href='
#{
Web
.
base_url
()
}
/tag/
#{
tag
}
' rel='tag'>#
#{
tag
}
</a>"
String
.
replace
(
text
,
full
,
url
)
end
)
end
...
...
lib/pleroma/web/salmon/salmon.ex
View file @
89b3729a
...
...
@@ -180,7 +180,7 @@ defp send_to_user(_, _, _), do: nil
"Undo"
,
"Delete"
]
def
publish
(
user
,
activity
,
poster
\\
&
@httpoison
.
post
/
4
)
def
publish
(
user
,
activity
,
poster
\\
&
@httpoison
.
post
/
3
)
def
publish
(%{
info:
%{
keys:
keys
}}
=
user
,
%{
data:
%{
"type"
=>
type
}}
=
activity
,
poster
)
when
type
in
@supported_activities
do
...
...
lib/pleroma/web/web_finger/web_finger.ex
View file @
89b3729a
...
...
@@ -256,8 +256,7 @@ def finger(account) do
with
response
<-
@httpoison
.
get
(
address
,
[
Accept:
"application/xrd+xml,application/jrd+json"
],
follow_redirect:
true
Accept:
"application/xrd+xml,application/jrd+json"
),
{
:ok
,
%{
status:
status
,
body:
body
}}
when
status
in
200
..
299
<-
response
do
doc
=
XML
.
parse_document
(
body
)
...
...
lib/pleroma/web/xml/xml.ex
View file @
89b3729a
...
...
@@ -25,7 +25,7 @@ def parse_document(text) do
{
doc
,
_rest
}
=
text
|>
:binary
.
bin_to_list
()
|>
:xmerl_scan
.
string
()
|>
:xmerl_scan
.
string
(
quiet:
true
)
doc
rescue
...
...
test/filter_test.exs
View file @
89b3729a
defmodule
Pleroma
.
FilterTest
do
alias
Pleroma
.
{
User
,
Repo
}
alias
Pleroma
.
Repo
use
Pleroma
.
DataCase
import
Pleroma
.
Factory
import
Ecto
.
Query
describe
"creating filters"
do
test
"creating one filter"
do
...
...
@@ -99,7 +98,7 @@ test "deleting a filter" do
context:
[
"home"
]
}
{
:ok
,
filter
}
=
Pleroma
.
Filter
.
create
(
query
)
{
:ok
,
_
filter
}
=
Pleroma
.
Filter
.
create
(
query
)
{
:ok
,
filter
}
=
Pleroma
.
Filter
.
delete
(
query
)
assert
is_nil
(
Repo
.
get
(
Pleroma
.
Filter
,
filter
.
filter_id
))
end
...
...
test/list_test.exs
View file @
89b3729a
defmodule
Pleroma
.
ListTest
do
alias
Pleroma
.
{
User
,
Repo
}
alias
Pleroma
.
Repo
use
Pleroma
.
DataCase
import
Pleroma
.
Factory
import
Ecto
.
Query
test
"creating a list"
do
user
=
insert
(
:user
)
...
...
@@ -32,7 +31,7 @@ test "removing an user from a list" do
user
=
insert
(
:user
)
other_user
=
insert
(
:user
)
{
:ok
,
list
}
=
Pleroma
.
List
.
create
(
"title"
,
user
)
{
:ok
,
%{
following:
following
}}
=
Pleroma
.
List
.
follow
(
list
,
other_user
)
{
:ok
,
%{
following:
_
following
}}
=
Pleroma
.
List
.
follow
(
list
,
other_user
)
{
:ok
,
%{
following:
following
}}
=
Pleroma
.
List
.
unfollow
(
list
,
other_user
)
assert
[]
==
following
end
...
...
test/notification_test.exs
View file @
89b3729a
...
...
@@ -127,12 +127,12 @@ test "it sets all notifications as read up to a specified notification ID" do
user
=
insert
(
:user
)
other_user
=
insert
(
:user
)
{
:ok
,
activity
}
=
{
:ok
,
_
activity
}
=
TwitterAPI
.
create_status
(
user
,
%{
"status"
=>
"hey @
#{
other_user
.
nickname
}
!"
})
{
:ok
,
activity
}
=
{
:ok
,
_
activity
}
=
TwitterAPI
.
create_status
(
user
,
%{
"status"
=>
"hey again @
#{
other_user
.
nickname
}
!"
})
...
...
@@ -142,14 +142,14 @@ test "it sets all notifications as read up to a specified notification ID" do
assert
n2
.
id
>
n1
.
id
{
:ok
,
activity
}
=
{
:ok
,
_
activity
}
=
TwitterAPI
.
create_status
(
user
,
%{
"status"
=>
"hey yet again @
#{
other_user
.
nickname
}
!"
})
Notification
.
set_read_up_to
(
other_user
,
n2
.
id
)
[
n3
,
n2
,
n1
]
=
notifs
=
Notification
.
for_user
(
other_user
)
[
n3
,
n2
,
n1
]
=
Notification
.
for_user
(
other_user
)
assert
n1
.
seen
==
true
assert
n2
.
seen
==
true
...
...
test/plugs/user_is_admin_plug_test.exs
View file @
89b3729a
...
...
@@ -4,7 +4,7 @@ defmodule Pleroma.Plugs.UserIsAdminPlugTest do
alias
Pleroma
.
Plugs
.
UserIsAdminPlug
import
Pleroma
.
Factory
test
"accepts a user that is admin"
,
%{
conn:
conn
}
do
test
"accepts a user that is admin"
do
user
=
insert
(
:user
,
info:
%{
is_admin:
true
})
conn
=
...
...
@@ -18,7 +18,7 @@ test "accepts a user that is admin", %{conn: conn} do
assert
conn
==
ret_conn
end
test
"denies a user that isn't admin"
,
%{
conn:
conn
}
do
test
"denies a user that isn't admin"
do
user
=
insert
(
:user
)
conn
=
...
...
@@ -29,7 +29,7 @@ test "denies a user that isn't admin", %{conn: conn} do
assert
conn
.
status
==
403
end
test
"denies when a user isn't set"
,
%{
conn:
conn
}
do
test
"denies when a user isn't set"
do
conn
=
build_conn
()
|>
UserIsAdminPlug
.
call
(%{})
...
...
test/support/conn_case.ex
View file @
89b3729a
...
...
@@ -19,6 +19,7 @@ defmodule Pleroma.Web.ConnCase do
quote
do
# Import conveniences for testing with connections
use
Phoenix
.
ConnTest
use
Pleroma
.
Tests
.
Helpers
import
Pleroma
.
Web
.
Router
.
Helpers
# The default endpoint for testing
...
...
test/support/data_case.ex
View file @
89b3729a
...
...
@@ -22,6 +22,7 @@ defmodule Pleroma.DataCase do
import
Ecto
.
Changeset
import
Ecto
.
Query
import
Pleroma
.
DataCase
use
Pleroma
.
Tests
.
Helpers
end
end
...
...
test/support/helpers.ex
0 → 100644
View file @
89b3729a
defmodule
Pleroma
.
Tests
.
Helpers
do
@moduledoc
"""
Helpers for use in tests.
"""
defmacro
__using__
(
_opts
)
do
quote
do
def
refresh_record
(%{
id:
id
,
__struct__:
model
}
=
_
),
do
:
refresh_record
(
model
,
%{
id:
id
})
def
refresh_record
(
model
,
%{
id:
id
}
=
_
)
do
Pleroma
.
Repo
.
get_by
(
model
,
id:
id
)
end
# Used for comparing json rendering during tests.
def
render_json
(
view
,
template
,
assigns
)
do
assigns
=
Map
.
new
(
assigns
)
view
.
render
(
template
,
assigns
)
|>
Poison
.
encode!
()
|>
Poison
.
decode!
()
end
end
end
end
test/user_test.exs
View file @
89b3729a
defmodule
Pleroma
.
UserTest
do
alias
Pleroma
.
Builders
.
UserBuilder
alias
Pleroma
.
{
User
,
Repo
,
Activity
}
alias
Pleroma
.
Web
.
OStatus
alias
Pleroma
.
Web
.
Websub
.
WebsubClientSubscription
alias
Pleroma
.
Web
.
CommonAPI
use
Pleroma
.
DataCase
import
Pleroma
.
Factory
import
Ecto
.
Query
setup_all
do
Tesla
.
Mock
.
mock_global
(
fn
env
->
apply
(
HttpRequestMock
,
:request
,
[
env
])
end
)
...
...
@@ -163,6 +160,32 @@ test "it ensures info is not nil" do
end
end
describe
"get_or_fetch/1"
do
test
"gets an existing user by nickname"
do
user
=
insert
(
:user
)
fetched_user
=
User
.
get_or_fetch
(
user
.
nickname
)
assert
user
==
fetched_user
end
test
"gets an existing user by ap_id"
do
ap_id
=
"http://mastodon.example.org/users/admin"
user
=
insert
(
:user
,
local:
false
,
nickname:
"admin@mastodon.example.org"
,
ap_id:
ap_id
,
info:
%{}
)
fetched_user
=
User
.
get_or_fetch
(
ap_id
)
freshed_user
=
refresh_record
(
user
)
assert
freshed_user
==
fetched_user
end
end
describe
"fetching a user from nickname or trying to build one"
do
test
"gets an existing user"
do
user
=
insert
(
:user
)
...
...
@@ -574,7 +597,7 @@ test "html_filter_policy returns TwitterText scrubber when rich-text is disabled
describe
"caching"
do
test
"invalidate_cache works"
do
user
=
insert
(
:user
)
user_info
=
User
.
get_cached_user_info
(
user
)
_
user_info
=
User
.
get_cached_user_info
(
user
)
User
.
invalidate_cache
(
user
)
...
...
@@ -600,9 +623,9 @@ test "User.delete() plugs any possible zombie objects" do
describe
"User.search"
do
test
"finds a user, ranking by similarity"
do
user
=
insert
(
:user
,
%{
name:
"lain"
})
user_two
=
insert
(
:user
,
%{
name:
"ean"
})
user_three
=
insert
(
:user
,
%{
name:
"ebn"
,
nickname:
"lain@mastodon.social"
})
_
user
=
insert
(
:user
,
%{
name:
"lain"
})
_
user_two
=
insert
(
:user
,
%{
name:
"ean"
})
_
user_three
=
insert
(
:user
,
%{
name:
"ebn"
,
nickname:
"lain@mastodon.social"
})
user_four
=
insert
(
:user
,
%{
nickname:
"lain@pleroma.soykaf.com"
})
assert
user_four
==
...
...
test/web/activity_pub/activity_pub_controller_test.exs
View file @
89b3729a
...
...
@@ -23,10 +23,10 @@ test "with the relay active, it returns the relay user", %{conn: conn} do
test
"with the relay disabled, it returns 404"
,
%{
conn:
conn
}
do
Pleroma
.
Config
.
put
([
:instance
,
:allow_relay
],
false
)
res
=
conn
|>
get
(
activity_pub_path
(
conn
,
:relay
)
)
|>
json_response
(
404
)
conn
|>
get
(
activity_pub_path
(
conn
,
:relay
))
|>
json_response
(
404
)
|>
assert
Pleroma
.
Config
.
put
([
:instance
,
:allow_relay
],
true
)
end
...
...
test/web/activity_pub/activity_pub_test.exs
View file @
89b3729a
...
...
@@ -180,7 +180,7 @@ test "doesn't return blocked activities" do
test
"doesn't retrieve unlisted activities"
do
user
=
insert
(
:user
)
{
:ok
,
unlisted_activity
}
=
{
:ok
,
_
unlisted_activity
}
=
CommonAPI
.
post
(
user
,
%{
"status"
=>
"yeah"
,
"visibility"
=>
"unlisted"
})
{
:ok
,
listed_activity
}
=
CommonAPI
.
post
(
user
,
%{
"status"
=>
"yeah"
})
...
...
test/web/activity_pub/transmogrifier_test.exs
View file @
89b3729a
...
...
@@ -982,13 +982,12 @@ test "contain_origin_from_id() allows matching IDs" do
end
test
"users cannot be collided through fake direction spoofing attempts"
do
user
=
insert
(
:user
,
%{
nickname:
"rye@niu.moe"
,
local:
false
,
ap_id:
"https://niu.moe/users/rye"
,
follower_address:
User
.
ap_followers
(%
User
{
nickname:
"rye@niu.moe"
})
})
insert
(
:user
,
%{
nickname:
"rye@niu.moe"
,
local:
false
,
ap_id:
"https://niu.moe/users/rye"
,
follower_address:
User
.
ap_followers
(%
User
{
nickname:
"rye@niu.moe"
})
})
{
:error
,
_
}
=
User
.
get_or_fetch_by_ap_id
(
"https://n1u.moe/users/rye"
)
end
...
...
test/web/admin_api/admin_api_controller_test.exs
View file @
89b3729a
...
...
@@ -2,9 +2,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
use
Pleroma
.
Web
.
ConnCase
alias
Pleroma
.
{
Repo
,
User
}
import
Pleroma
.
Factory
import
ExUnit
.
CaptureLog
describe
"/api/pleroma/admin/user"
do
test
"Delete"
do
...
...
test/web/http_sigs/http_sig_test.exs
View file @
89b3729a
...
...
@@ -11,9 +11,6 @@ defmodule Pleroma.Web.HTTPSignaturesTest do
:ok
end
@private_key
hd
(
:public_key
.
pem_decode
(
File
.
read!
(
"test/web/http_sigs/priv.key"
)))
|>
:public_key
.
pem_entry_decode
()
@public_key
hd
(
:public_key
.
pem_decode
(
File
.
read!
(
"test/web/http_sigs/pub.key"
)))
|>
:public_key
.
pem_entry_decode
()
...
...
@@ -26,8 +23,6 @@ defmodule Pleroma.Web.HTTPSignaturesTest do
"content-length"
=>
"18"
}
@body
"{
\"
hello
\"
:
\"
world
\"
}"
@default_signature
"""
keyId="Test",algorithm="rsa-sha256",signature="jKyvPcxB4JbmYY4mByyBY7cZfNl4OW9HpFQlG7N4YcJPteKTu4MWCLyk+gIr0wDgqtLWf9NLpMAMimdfsH7FSWGfbMFSrsVTHNTk0rK3usrfFnti1dxsM4jl0kYJCKTGI/UWkqiaxwNiKqGcdlEDrTcUhhsFsOIo8VhddmZTZ8w="
"""
...
...
test/web/mastodon_api/list_view_test.exs
View file @
89b3729a
...
...
@@ -2,7 +2,6 @@ defmodule Pleroma.Web.MastodonAPI.ListViewTest do
use
Pleroma
.
DataCase
import
Pleroma
.
Factory
alias
Pleroma
.
Web
.
MastodonAPI
.
ListView
alias
Pleroma
.
List
test
"Represent a list"
do
user
=
insert
(
:user
)
...
...
test/web/mastodon_api/mastodon_api_controller_test.exs
View file @
89b3729a
...
...
@@ -5,7 +5,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
alias
Pleroma
.
{
Repo
,
User
,
Object
,
Activity
,
Notification
}
alias
Pleroma
.
Web
.
{
OStatus
,
CommonAPI
}
alias
Pleroma
.
Web
.
ActivityPub
.
ActivityPub
alias
Pleroma
.
Web
.
MastodonAPI
.
FilterView
import
Pleroma
.
Factory
import
ExUnit
.
CaptureLog
import
Tesla
.
Mock
...
...
@@ -351,12 +351,18 @@ test "fetching a list of filters", %{conn: conn} do
{
:ok
,
filter_one
}
=
Pleroma
.
Filter
.
create
(
query_one
)
{
:ok
,
filter_two
}
=
Pleroma
.
Filter
.
create
(
query_two
)
conn
=
response
=
conn
|>
assign
(
:user
,
user
)
|>
get
(
"/api/v1/filters"
)
assert
response
=
json_response
(
conn
,
200
)
|>
json_response
(
200
)
assert
response
==
render_json
(
FilterView
,
"filters.json"
,
filters:
[
filter_two
,
filter_one
]
)
end
test
"get a filter"
,
%{
conn:
conn
}
do
...
...
@@ -389,7 +395,7 @@ test "update a filter", %{conn: conn} do
context:
[
"home"
]
}
{
:ok
,
filter
}
=
Pleroma
.
Filter
.
create
(
query
)
{
:ok
,
_
filter
}
=
Pleroma
.
Filter
.
create
(
query
)
new
=
%
Pleroma
.
Filter
{
phrase:
"nii"
,
...
...
@@ -554,7 +560,7 @@ test "list timeline does not leak non-public statuses for unfollowed users", %{c
other_user
=
insert
(
:user
)
{
:ok
,
activity_one
}
=
TwitterAPI
.
create_status
(
other_user
,
%{
"status"
=>
"Marisa is cute."
})
{
:ok
,
activity_two
}
=
{
:ok
,
_
activity_two
}
=
TwitterAPI
.
create_status
(
other_user
,
%{
"status"
=>
"Marisa is cute."
,
"visibility"
=>
"private"
...
...
@@ -854,7 +860,7 @@ test "/api/v1/follow_requests works" do
user
=
insert
(
:user
,
%{
info:
%
Pleroma
.
User
.
Info
{
locked:
true
}})
other_user
=
insert
(
:user
)
{
:ok
,
activity
}
=
ActivityPub
.
follow
(
other_user
,
user
)
{
:ok
,
_
activity
}
=
ActivityPub
.
follow
(
other_user
,
user
)
user
=
Repo
.
get
(
User
,
user
.
id
)
other_user
=
Repo
.
get
(
User
,
other_user
.
id
)
...
...
@@ -874,7 +880,7 @@ test "/api/v1/follow_requests/:id/authorize works" do
user
=
insert
(
:user
,
%{
info:
%
Pleroma
.
User
.
Info
{
locked:
true
}})
other_user
=
insert
(
:user
)
{
:ok
,
activity
}
=
ActivityPub
.
follow
(
other_user
,
user
)
{
:ok
,
_
activity
}
=
ActivityPub
.
follow
(
other_user
,
user
)
user
=
Repo
.
get
(
User
,
user
.
id
)
other_user
=
Repo
.
get
(
User
,
other_user
.
id
)
...
...
@@ -911,7 +917,7 @@ test "/api/v1/follow_requests/:id/reject works" do
user
=
insert
(
:user
,
%{
info:
%
Pleroma
.
User
.
Info
{
locked:
true
}})
other_user
=
insert
(
:user
)
{
:ok
,
activity
}
=
ActivityPub
.
follow
(
other_user
,
user
)
{
:ok
,
_
activity
}
=
ActivityPub
.
follow
(
other_user
,
user
)
conn
=
build_conn
()
...
...
@@ -1015,7 +1021,7 @@ test "getting followers", %{conn: conn} do
test
"getting followers, hide_network"
,
%{
conn:
conn
}
do
user
=
insert
(
:user
)
other_user
=
insert
(
:user
,
%{
info:
%{
hide_network:
true
}})
{
:ok
,
user
}
=
User
.
follow
(
user
,
other_user
)
{
:ok
,
_
user
}
=
User
.
follow
(
user
,
other_user
)
conn
=
conn
...
...
@@ -1027,7 +1033,7 @@ test "getting followers, hide_network", %{conn: conn} do
test
"getting followers, hide_network, same user requesting"
,
%{
conn:
conn
}
do
user
=
insert
(
:user
)
other_user
=
insert
(
:user
,
%{
info:
%{
hide_network:
true
}})
{
:ok
,
user
}
=
User
.
follow
(
user
,
other_user
)
{
:ok
,
_
user
}
=
User
.
follow
(
user
,
other_user
)
conn
=
conn
...
...
Prev
1
2
Next
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