Merge remote-tracking branch 'remotes/origin/develop' into follow-request-notifications
This commit is contained in:
commit
cf5ca7e45b
65 changed files with 1289 additions and 738 deletions
|
|
@ -61,7 +61,7 @@ defmodule Pleroma.CaptchaTest do
|
|||
|
||||
assert is_binary(answer)
|
||||
assert :ok = Native.validate(token, answer, answer)
|
||||
assert {:error, "Invalid CAPTCHA"} == Native.validate(token, answer, answer <> "foobar")
|
||||
assert {:error, :invalid} == Native.validate(token, answer, answer <> "foobar")
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -78,6 +78,7 @@ defmodule Pleroma.CaptchaTest do
|
|||
|
||||
assert is_binary(answer)
|
||||
assert :ok = Captcha.validate(token, "63615261b77f5354fb8c4e4986477555", answer)
|
||||
Cachex.del(:used_captcha_cache, token)
|
||||
end
|
||||
|
||||
test "doesn't validate invalid answer" do
|
||||
|
|
@ -92,7 +93,7 @@ defmodule Pleroma.CaptchaTest do
|
|||
|
||||
assert is_binary(answer)
|
||||
|
||||
assert {:error, "Invalid answer data"} =
|
||||
assert {:error, :invalid_answer_data} =
|
||||
Captcha.validate(token, "63615261b77f5354fb8c4e4986477555", answer <> "foobar")
|
||||
end
|
||||
|
||||
|
|
@ -108,7 +109,7 @@ defmodule Pleroma.CaptchaTest do
|
|||
|
||||
assert is_binary(answer)
|
||||
|
||||
assert {:error, "Invalid answer data"} =
|
||||
assert {:error, :invalid_answer_data} =
|
||||
Captcha.validate(token, "63615261b77f5354fb8c4e4986477555", nil)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
112
test/fixtures/tesla_mock/craigmaloney.json
vendored
Normal file
112
test/fixtures/tesla_mock/craigmaloney.json
vendored
Normal file
|
|
@ -0,0 +1,112 @@
|
|||
{
|
||||
"@context": [
|
||||
"https://www.w3.org/ns/activitystreams",
|
||||
"https://w3id.org/security/v1",
|
||||
{
|
||||
"CacheFile": "pt:CacheFile",
|
||||
"Hashtag": "as:Hashtag",
|
||||
"Infohash": "pt:Infohash",
|
||||
"RsaSignature2017": "https://w3id.org/security#RsaSignature2017",
|
||||
"category": "sc:category",
|
||||
"commentsEnabled": {
|
||||
"@id": "pt:commentsEnabled",
|
||||
"@type": "sc:Boolean"
|
||||
},
|
||||
"downloadEnabled": {
|
||||
"@id": "pt:downloadEnabled",
|
||||
"@type": "sc:Boolean"
|
||||
},
|
||||
"expires": "sc:expires",
|
||||
"fps": {
|
||||
"@id": "pt:fps",
|
||||
"@type": "sc:Number"
|
||||
},
|
||||
"language": "sc:inLanguage",
|
||||
"licence": "sc:license",
|
||||
"originallyPublishedAt": "sc:datePublished",
|
||||
"position": {
|
||||
"@id": "pt:position",
|
||||
"@type": "sc:Number"
|
||||
},
|
||||
"pt": "https://joinpeertube.org/ns#",
|
||||
"sc": "http://schema.org#",
|
||||
"sensitive": "as:sensitive",
|
||||
"size": {
|
||||
"@id": "pt:size",
|
||||
"@type": "sc:Number"
|
||||
},
|
||||
"startTimestamp": {
|
||||
"@id": "pt:startTimestamp",
|
||||
"@type": "sc:Number"
|
||||
},
|
||||
"state": {
|
||||
"@id": "pt:state",
|
||||
"@type": "sc:Number"
|
||||
},
|
||||
"stopTimestamp": {
|
||||
"@id": "pt:stopTimestamp",
|
||||
"@type": "sc:Number"
|
||||
},
|
||||
"subtitleLanguage": "sc:subtitleLanguage",
|
||||
"support": {
|
||||
"@id": "pt:support",
|
||||
"@type": "sc:Text"
|
||||
},
|
||||
"uuid": "sc:identifier",
|
||||
"views": {
|
||||
"@id": "pt:views",
|
||||
"@type": "sc:Number"
|
||||
},
|
||||
"waitTranscoding": {
|
||||
"@id": "pt:waitTranscoding",
|
||||
"@type": "sc:Boolean"
|
||||
}
|
||||
},
|
||||
{
|
||||
"comments": {
|
||||
"@id": "as:comments",
|
||||
"@type": "@id"
|
||||
},
|
||||
"dislikes": {
|
||||
"@id": "as:dislikes",
|
||||
"@type": "@id"
|
||||
},
|
||||
"likes": {
|
||||
"@id": "as:likes",
|
||||
"@type": "@id"
|
||||
},
|
||||
"playlists": {
|
||||
"@id": "pt:playlists",
|
||||
"@type": "@id"
|
||||
},
|
||||
"shares": {
|
||||
"@id": "as:shares",
|
||||
"@type": "@id"
|
||||
}
|
||||
}
|
||||
],
|
||||
"endpoints": {
|
||||
"sharedInbox": "https://peertube.social/inbox"
|
||||
},
|
||||
"followers": "https://peertube.social/accounts/craigmaloney/followers",
|
||||
"following": "https://peertube.social/accounts/craigmaloney/following",
|
||||
"icon": {
|
||||
"mediaType": "image/png",
|
||||
"type": "Image",
|
||||
"url": "https://peertube.social/lazy-static/avatars/87bd694b-95bc-4066-83f4-bddfcd2b9caa.png"
|
||||
},
|
||||
"id": "https://peertube.social/accounts/craigmaloney",
|
||||
"inbox": "https://peertube.social/accounts/craigmaloney/inbox",
|
||||
"name": "Craig Maloney",
|
||||
"outbox": "https://peertube.social/accounts/craigmaloney/outbox",
|
||||
"playlists": "https://peertube.social/accounts/craigmaloney/playlists",
|
||||
"preferredUsername": "craigmaloney",
|
||||
"publicKey": {
|
||||
"id": "https://peertube.social/accounts/craigmaloney#main-key",
|
||||
"owner": "https://peertube.social/accounts/craigmaloney",
|
||||
"publicKeyPem": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA9qvGIYUW01yc8CCsrwxK\n5OXlV5s7EbNWY8tJr/p1oGuELZwAnG2XKxtdbvgcCT+YxL5uRXIdCFIIIKrzRFr/\nHfS0mOgNT9u3gu+SstCNgtatciT0RVP77yiC3b2NHq1NRRvvVhzQb4cpIWObIxqh\nb2ypDClTc7XaKtgmQCbwZlGyZMT+EKz/vustD6BlpGsglRkm7iES6s1PPGb1BU+n\nS94KhbS2DOFiLcXCVWt0QarokIIuKznp4+xP1axKyP+SkT5AHx08Nd5TYFb2C1Jl\nz0WD/1q0mAN62m7QrA3SQPUgB+wWD+S3Nzf7FwNPiP4srbBgxVEUnji/r9mQ6BXC\nrQIDAQAB\n-----END PUBLIC KEY-----"
|
||||
},
|
||||
"summary": null,
|
||||
"type": "Person",
|
||||
"url": "https://peertube.social/accounts/craigmaloney"
|
||||
}
|
||||
234
test/fixtures/tesla_mock/peertube-social.json
vendored
Normal file
234
test/fixtures/tesla_mock/peertube-social.json
vendored
Normal file
|
|
@ -0,0 +1,234 @@
|
|||
{
|
||||
"@context": [
|
||||
"https://www.w3.org/ns/activitystreams",
|
||||
"https://w3id.org/security/v1",
|
||||
{
|
||||
"CacheFile": "pt:CacheFile",
|
||||
"Hashtag": "as:Hashtag",
|
||||
"Infohash": "pt:Infohash",
|
||||
"RsaSignature2017": "https://w3id.org/security#RsaSignature2017",
|
||||
"category": "sc:category",
|
||||
"commentsEnabled": {
|
||||
"@id": "pt:commentsEnabled",
|
||||
"@type": "sc:Boolean"
|
||||
},
|
||||
"downloadEnabled": {
|
||||
"@id": "pt:downloadEnabled",
|
||||
"@type": "sc:Boolean"
|
||||
},
|
||||
"expires": "sc:expires",
|
||||
"fps": {
|
||||
"@id": "pt:fps",
|
||||
"@type": "sc:Number"
|
||||
},
|
||||
"language": "sc:inLanguage",
|
||||
"licence": "sc:license",
|
||||
"originallyPublishedAt": "sc:datePublished",
|
||||
"position": {
|
||||
"@id": "pt:position",
|
||||
"@type": "sc:Number"
|
||||
},
|
||||
"pt": "https://joinpeertube.org/ns#",
|
||||
"sc": "http://schema.org#",
|
||||
"sensitive": "as:sensitive",
|
||||
"size": {
|
||||
"@id": "pt:size",
|
||||
"@type": "sc:Number"
|
||||
},
|
||||
"startTimestamp": {
|
||||
"@id": "pt:startTimestamp",
|
||||
"@type": "sc:Number"
|
||||
},
|
||||
"state": {
|
||||
"@id": "pt:state",
|
||||
"@type": "sc:Number"
|
||||
},
|
||||
"stopTimestamp": {
|
||||
"@id": "pt:stopTimestamp",
|
||||
"@type": "sc:Number"
|
||||
},
|
||||
"subtitleLanguage": "sc:subtitleLanguage",
|
||||
"support": {
|
||||
"@id": "pt:support",
|
||||
"@type": "sc:Text"
|
||||
},
|
||||
"uuid": "sc:identifier",
|
||||
"views": {
|
||||
"@id": "pt:views",
|
||||
"@type": "sc:Number"
|
||||
},
|
||||
"waitTranscoding": {
|
||||
"@id": "pt:waitTranscoding",
|
||||
"@type": "sc:Boolean"
|
||||
}
|
||||
},
|
||||
{
|
||||
"comments": {
|
||||
"@id": "as:comments",
|
||||
"@type": "@id"
|
||||
},
|
||||
"dislikes": {
|
||||
"@id": "as:dislikes",
|
||||
"@type": "@id"
|
||||
},
|
||||
"likes": {
|
||||
"@id": "as:likes",
|
||||
"@type": "@id"
|
||||
},
|
||||
"playlists": {
|
||||
"@id": "pt:playlists",
|
||||
"@type": "@id"
|
||||
},
|
||||
"shares": {
|
||||
"@id": "as:shares",
|
||||
"@type": "@id"
|
||||
}
|
||||
}
|
||||
],
|
||||
"attributedTo": [
|
||||
{
|
||||
"id": "https://peertube.social/accounts/craigmaloney",
|
||||
"type": "Person"
|
||||
},
|
||||
{
|
||||
"id": "https://peertube.social/video-channels/9909c7d9-6b5b-4aae-9164-c1af7229c91c",
|
||||
"type": "Group"
|
||||
}
|
||||
],
|
||||
"category": {
|
||||
"identifier": "15",
|
||||
"name": "Science & Technology"
|
||||
},
|
||||
"cc": [
|
||||
"https://peertube.social/accounts/craigmaloney/followers"
|
||||
],
|
||||
"comments": "https://peertube.social/videos/watch/278d2b7c-0f38-4aaa-afe6-9ecc0c4a34fe/comments",
|
||||
"commentsEnabled": true,
|
||||
"content": "Support this and our other Michigan!/usr/group videos and meetings. Learn more at http://mug.org/membership\n\nTwenty Years in Jail: FreeBSD's Jails, Then and Now\n\nJails started as a limited virtualization system, but over the last two years they've...",
|
||||
"dislikes": "https://peertube.social/videos/watch/278d2b7c-0f38-4aaa-afe6-9ecc0c4a34fe/dislikes",
|
||||
"downloadEnabled": true,
|
||||
"duration": "PT5151S",
|
||||
"icon": {
|
||||
"height": 122,
|
||||
"mediaType": "image/jpeg",
|
||||
"type": "Image",
|
||||
"url": "https://peertube.social/static/thumbnails/278d2b7c-0f38-4aaa-afe6-9ecc0c4a34fe.jpg",
|
||||
"width": 223
|
||||
},
|
||||
"id": "https://peertube.social/videos/watch/278d2b7c-0f38-4aaa-afe6-9ecc0c4a34fe",
|
||||
"language": {
|
||||
"identifier": "en",
|
||||
"name": "English"
|
||||
},
|
||||
"licence": {
|
||||
"identifier": "1",
|
||||
"name": "Attribution"
|
||||
},
|
||||
"likes": "https://peertube.social/videos/watch/278d2b7c-0f38-4aaa-afe6-9ecc0c4a34fe/likes",
|
||||
"mediaType": "text/markdown",
|
||||
"name": "Twenty Years in Jail: FreeBSD's Jails, Then and Now",
|
||||
"originallyPublishedAt": "2019-08-13T00:00:00.000Z",
|
||||
"published": "2020-02-12T01:06:08.054Z",
|
||||
"sensitive": false,
|
||||
"shares": "https://peertube.social/videos/watch/278d2b7c-0f38-4aaa-afe6-9ecc0c4a34fe/announces",
|
||||
"state": 1,
|
||||
"subtitleLanguage": [],
|
||||
"support": "Learn more at http://mug.org",
|
||||
"tag": [
|
||||
{
|
||||
"name": "linux",
|
||||
"type": "Hashtag"
|
||||
},
|
||||
{
|
||||
"name": "mug.org",
|
||||
"type": "Hashtag"
|
||||
},
|
||||
{
|
||||
"name": "open",
|
||||
"type": "Hashtag"
|
||||
},
|
||||
{
|
||||
"name": "oss",
|
||||
"type": "Hashtag"
|
||||
},
|
||||
{
|
||||
"name": "source",
|
||||
"type": "Hashtag"
|
||||
}
|
||||
],
|
||||
"to": [
|
||||
"https://www.w3.org/ns/activitystreams#Public"
|
||||
],
|
||||
"type": "Video",
|
||||
"updated": "2020-02-15T15:01:09.474Z",
|
||||
"url": [
|
||||
{
|
||||
"href": "https://peertube.social/videos/watch/278d2b7c-0f38-4aaa-afe6-9ecc0c4a34fe",
|
||||
"mediaType": "text/html",
|
||||
"type": "Link"
|
||||
},
|
||||
{
|
||||
"fps": 30,
|
||||
"height": 240,
|
||||
"href": "https://peertube.social/static/webseed/278d2b7c-0f38-4aaa-afe6-9ecc0c4a34fe-240.mp4",
|
||||
"mediaType": "video/mp4",
|
||||
"size": 119465800,
|
||||
"type": "Link"
|
||||
},
|
||||
{
|
||||
"height": 240,
|
||||
"href": "https://peertube.social/static/torrents/278d2b7c-0f38-4aaa-afe6-9ecc0c4a34fe-240.torrent",
|
||||
"mediaType": "application/x-bittorrent",
|
||||
"type": "Link"
|
||||
},
|
||||
{
|
||||
"height": 240,
|
||||
"href": "magnet:?xs=https%3A%2F%2Fpeertube.social%2Fstatic%2Ftorrents%2F278d2b7c-0f38-4aaa-afe6-9ecc0c4a34fe-240.torrent&xt=urn:btih:b3365331a8543bf48d09add56d7fe4b1cbbb5659&dn=Twenty+Years+in+Jail%3A+FreeBSD's+Jails%2C+Then+and+Now&tr=wss%3A%2F%2Fpeertube.social%3A443%2Ftracker%2Fsocket&tr=https%3A%2F%2Fpeertube.social%2Ftracker%2Fannounce&ws=https%3A%2F%2Fpeertube.social%2Fstatic%2Fwebseed%2F278d2b7c-0f38-4aaa-afe6-9ecc0c4a34fe-240.mp4",
|
||||
"mediaType": "application/x-bittorrent;x-scheme-handler/magnet",
|
||||
"type": "Link"
|
||||
},
|
||||
{
|
||||
"fps": 30,
|
||||
"height": 360,
|
||||
"href": "https://peertube.social/static/webseed/278d2b7c-0f38-4aaa-afe6-9ecc0c4a34fe-360.mp4",
|
||||
"mediaType": "video/mp4",
|
||||
"size": 143930318,
|
||||
"type": "Link"
|
||||
},
|
||||
{
|
||||
"height": 360,
|
||||
"href": "https://peertube.social/static/torrents/278d2b7c-0f38-4aaa-afe6-9ecc0c4a34fe-360.torrent",
|
||||
"mediaType": "application/x-bittorrent",
|
||||
"type": "Link"
|
||||
},
|
||||
{
|
||||
"height": 360,
|
||||
"href": "magnet:?xs=https%3A%2F%2Fpeertube.social%2Fstatic%2Ftorrents%2F278d2b7c-0f38-4aaa-afe6-9ecc0c4a34fe-360.torrent&xt=urn:btih:0d37b23c98cb0d89e28b5dc8f49b3c97a041e569&dn=Twenty+Years+in+Jail%3A+FreeBSD's+Jails%2C+Then+and+Now&tr=wss%3A%2F%2Fpeertube.social%3A443%2Ftracker%2Fsocket&tr=https%3A%2F%2Fpeertube.social%2Ftracker%2Fannounce&ws=https%3A%2F%2Fpeertube.social%2Fstatic%2Fwebseed%2F278d2b7c-0f38-4aaa-afe6-9ecc0c4a34fe-360.mp4",
|
||||
"mediaType": "application/x-bittorrent;x-scheme-handler/magnet",
|
||||
"type": "Link"
|
||||
},
|
||||
{
|
||||
"fps": 30,
|
||||
"height": 480,
|
||||
"href": "https://peertube.social/static/webseed/278d2b7c-0f38-4aaa-afe6-9ecc0c4a34fe-480.mp4",
|
||||
"mediaType": "video/mp4",
|
||||
"size": 130530754,
|
||||
"type": "Link"
|
||||
},
|
||||
{
|
||||
"height": 480,
|
||||
"href": "https://peertube.social/static/torrents/278d2b7c-0f38-4aaa-afe6-9ecc0c4a34fe-480.torrent",
|
||||
"mediaType": "application/x-bittorrent",
|
||||
"type": "Link"
|
||||
},
|
||||
{
|
||||
"height": 480,
|
||||
"href": "magnet:?xs=https%3A%2F%2Fpeertube.social%2Fstatic%2Ftorrents%2F278d2b7c-0f38-4aaa-afe6-9ecc0c4a34fe-480.torrent&xt=urn:btih:3a13ff822ad9494165eff6167183ddaaabc1372a&dn=Twenty+Years+in+Jail%3A+FreeBSD's+Jails%2C+Then+and+Now&tr=wss%3A%2F%2Fpeertube.social%3A443%2Ftracker%2Fsocket&tr=https%3A%2F%2Fpeertube.social%2Ftracker%2Fannounce&ws=https%3A%2F%2Fpeertube.social%2Fstatic%2Fwebseed%2F278d2b7c-0f38-4aaa-afe6-9ecc0c4a34fe-480.mp4",
|
||||
"mediaType": "application/x-bittorrent;x-scheme-handler/magnet",
|
||||
"type": "Link"
|
||||
}
|
||||
],
|
||||
"uuid": "278d2b7c-0f38-4aaa-afe6-9ecc0c4a34fe",
|
||||
"views": 2,
|
||||
"waitTranscoding": false
|
||||
}
|
||||
|
|
@ -44,7 +44,8 @@ defmodule Pleroma.SignatureTest do
|
|||
|
||||
test "it returns error when not found user" do
|
||||
assert capture_log(fn ->
|
||||
assert Signature.fetch_public_key(make_fake_conn("test-ap_id")) == {:error, :error}
|
||||
assert Signature.fetch_public_key(make_fake_conn("https://test-ap-id")) ==
|
||||
{:error, :error}
|
||||
end) =~ "[error] Could not decode user"
|
||||
end
|
||||
|
||||
|
|
@ -64,7 +65,7 @@ defmodule Pleroma.SignatureTest do
|
|||
|
||||
test "it returns error when not found user" do
|
||||
assert capture_log(fn ->
|
||||
{:error, _} = Signature.refetch_public_key(make_fake_conn("test-ap_id"))
|
||||
{:error, _} = Signature.refetch_public_key(make_fake_conn("https://test-ap_id"))
|
||||
end) =~ "[error] Could not decode user"
|
||||
end
|
||||
end
|
||||
|
|
@ -100,12 +101,21 @@ defmodule Pleroma.SignatureTest do
|
|||
describe "key_id_to_actor_id/1" do
|
||||
test "it properly deduces the actor id for misskey" do
|
||||
assert Signature.key_id_to_actor_id("https://example.com/users/1234/publickey") ==
|
||||
"https://example.com/users/1234"
|
||||
{:ok, "https://example.com/users/1234"}
|
||||
end
|
||||
|
||||
test "it properly deduces the actor id for mastodon and pleroma" do
|
||||
assert Signature.key_id_to_actor_id("https://example.com/users/1234#main-key") ==
|
||||
"https://example.com/users/1234"
|
||||
{:ok, "https://example.com/users/1234"}
|
||||
end
|
||||
|
||||
test "it calls webfinger for 'acct:' accounts" do
|
||||
with_mock(Pleroma.Web.WebFinger,
|
||||
finger: fn _ -> %{"ap_id" => "https://gensokyo.2hu/users/raymoo"} end
|
||||
) do
|
||||
assert Signature.key_id_to_actor_id("acct:raymoo@gensokyo.2hu") ==
|
||||
{:ok, "https://gensokyo.2hu/users/raymoo"}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -6,12 +6,16 @@ defmodule Pleroma.Captcha.Mock do
|
|||
alias Pleroma.Captcha.Service
|
||||
@behaviour Service
|
||||
|
||||
@solution "63615261b77f5354fb8c4e4986477555"
|
||||
|
||||
def solution, do: @solution
|
||||
|
||||
@impl Service
|
||||
def new,
|
||||
do: %{
|
||||
type: :mock,
|
||||
token: "afa1815e14e29355e6c8f6b143a39fa2",
|
||||
answer_data: "63615261b77f5354fb8c4e4986477555",
|
||||
answer_data: @solution,
|
||||
url: "https://example.org/captcha.png"
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -308,6 +308,22 @@ defmodule HttpRequestMock do
|
|||
}}
|
||||
end
|
||||
|
||||
def get("https://peertube.social/accounts/craigmaloney", _, _, _) do
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/tesla_mock/craigmaloney.json")
|
||||
}}
|
||||
end
|
||||
|
||||
def get("https://peertube.social/videos/watch/278d2b7c-0f38-4aaa-afe6-9ecc0c4a34fe", _, _, _) do
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/tesla_mock/peertube-social.json")
|
||||
}}
|
||||
end
|
||||
|
||||
def get("https://mobilizon.org/events/252d5816-00a3-4a89-a66f-15bf65c33e39", _, _, [
|
||||
{"accept", "application/activity+json"}
|
||||
]) do
|
||||
|
|
|
|||
|
|
@ -1221,6 +1221,35 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
:error = Transmogrifier.handle_incoming(data)
|
||||
end
|
||||
|
||||
test "skip converting the content when it is nil" do
|
||||
object_id = "https://peertube.social/videos/watch/278d2b7c-0f38-4aaa-afe6-9ecc0c4a34fe"
|
||||
|
||||
{:ok, object} = Fetcher.fetch_and_contain_remote_object_from_id(object_id)
|
||||
|
||||
result =
|
||||
Pleroma.Web.ActivityPub.Transmogrifier.fix_object(Map.merge(object, %{"content" => nil}))
|
||||
|
||||
assert result["content"] == nil
|
||||
end
|
||||
|
||||
test "it converts content of object to html" do
|
||||
object_id = "https://peertube.social/videos/watch/278d2b7c-0f38-4aaa-afe6-9ecc0c4a34fe"
|
||||
|
||||
{:ok, %{"content" => content_markdown}} =
|
||||
Fetcher.fetch_and_contain_remote_object_from_id(object_id)
|
||||
|
||||
{:ok, %Pleroma.Object{data: %{"content" => content}} = object} =
|
||||
Fetcher.fetch_object_from_id(object_id)
|
||||
|
||||
assert content_markdown ==
|
||||
"Support this and our other Michigan!/usr/group videos and meetings. Learn more at http://mug.org/membership\n\nTwenty Years in Jail: FreeBSD's Jails, Then and Now\n\nJails started as a limited virtualization system, but over the last two years they've..."
|
||||
|
||||
assert content ==
|
||||
"<p>Support this and our other Michigan!/usr/group videos and meetings. Learn more at <a href=\"http://mug.org/membership\">http://mug.org/membership</a></p><p>Twenty Years in Jail: FreeBSD’s Jails, Then and Now</p><p>Jails started as a limited virtualization system, but over the last two years they’ve…</p>"
|
||||
|
||||
assert object.data["mediaType"] == "text/html"
|
||||
end
|
||||
|
||||
test "it remaps video URLs as attachments if necessary" do
|
||||
{:ok, object} =
|
||||
Fetcher.fetch_object_from_id(
|
||||
|
|
|
|||
|
|
@ -1347,9 +1347,9 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
|
||||
{:ok, %{id: report_id}} =
|
||||
CommonAPI.report(reporter, %{
|
||||
"account_id" => target_user.id,
|
||||
"comment" => "I feel offended",
|
||||
"status_ids" => [activity.id]
|
||||
account_id: target_user.id,
|
||||
comment: "I feel offended",
|
||||
status_ids: [activity.id]
|
||||
})
|
||||
|
||||
response =
|
||||
|
|
@ -1374,16 +1374,16 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
|
||||
{:ok, %{id: report_id}} =
|
||||
CommonAPI.report(reporter, %{
|
||||
"account_id" => target_user.id,
|
||||
"comment" => "I feel offended",
|
||||
"status_ids" => [activity.id]
|
||||
account_id: target_user.id,
|
||||
comment: "I feel offended",
|
||||
status_ids: [activity.id]
|
||||
})
|
||||
|
||||
{:ok, %{id: second_report_id}} =
|
||||
CommonAPI.report(reporter, %{
|
||||
"account_id" => target_user.id,
|
||||
"comment" => "I feel very offended",
|
||||
"status_ids" => [activity.id]
|
||||
account_id: target_user.id,
|
||||
comment: "I feel very offended",
|
||||
status_ids: [activity.id]
|
||||
})
|
||||
|
||||
%{
|
||||
|
|
@ -1523,9 +1523,9 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
|
||||
{:ok, %{id: report_id}} =
|
||||
CommonAPI.report(reporter, %{
|
||||
"account_id" => target_user.id,
|
||||
"comment" => "I feel offended",
|
||||
"status_ids" => [activity.id]
|
||||
account_id: target_user.id,
|
||||
comment: "I feel offended",
|
||||
status_ids: [activity.id]
|
||||
})
|
||||
|
||||
response =
|
||||
|
|
@ -1547,15 +1547,15 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
|
||||
{:ok, %{id: first_report_id}} =
|
||||
CommonAPI.report(reporter, %{
|
||||
"account_id" => target_user.id,
|
||||
"comment" => "I feel offended",
|
||||
"status_ids" => [activity.id]
|
||||
account_id: target_user.id,
|
||||
comment: "I feel offended",
|
||||
status_ids: [activity.id]
|
||||
})
|
||||
|
||||
{:ok, %{id: second_report_id}} =
|
||||
CommonAPI.report(reporter, %{
|
||||
"account_id" => target_user.id,
|
||||
"comment" => "I don't like this user"
|
||||
account_id: target_user.id,
|
||||
comment: "I don't like this user"
|
||||
})
|
||||
|
||||
CommonAPI.update_report_state(second_report_id, "closed")
|
||||
|
|
@ -3431,9 +3431,9 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
|
||||
{:ok, %{id: report_id}} =
|
||||
CommonAPI.report(reporter, %{
|
||||
"account_id" => target_user.id,
|
||||
"comment" => "I feel offended",
|
||||
"status_ids" => [activity.id]
|
||||
account_id: target_user.id,
|
||||
comment: "I feel offended",
|
||||
status_ids: [activity.id]
|
||||
})
|
||||
|
||||
post(conn, "/api/pleroma/admin/reports/#{report_id}/notes", %{
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ defmodule Pleroma.Web.AdminAPI.ReportViewTest do
|
|||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, activity} = CommonAPI.report(user, %{"account_id" => other_user.id})
|
||||
{:ok, activity} = CommonAPI.report(user, %{account_id: other_user.id})
|
||||
|
||||
expected = %{
|
||||
content: nil,
|
||||
|
|
@ -48,7 +48,7 @@ defmodule Pleroma.Web.AdminAPI.ReportViewTest do
|
|||
{:ok, activity} = CommonAPI.post(other_user, %{"status" => "toot"})
|
||||
|
||||
{:ok, report_activity} =
|
||||
CommonAPI.report(user, %{"account_id" => other_user.id, "status_ids" => [activity.id]})
|
||||
CommonAPI.report(user, %{account_id: other_user.id, status_ids: [activity.id]})
|
||||
|
||||
other_user = Pleroma.User.get_by_id(other_user.id)
|
||||
|
||||
|
|
@ -81,7 +81,7 @@ defmodule Pleroma.Web.AdminAPI.ReportViewTest do
|
|||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, activity} = CommonAPI.report(user, %{"account_id" => other_user.id})
|
||||
{:ok, activity} = CommonAPI.report(user, %{account_id: other_user.id})
|
||||
{:ok, activity} = CommonAPI.update_report_state(activity.id, "closed")
|
||||
|
||||
assert %{state: "closed"} =
|
||||
|
|
@ -94,8 +94,8 @@ defmodule Pleroma.Web.AdminAPI.ReportViewTest do
|
|||
|
||||
{:ok, activity} =
|
||||
CommonAPI.report(user, %{
|
||||
"account_id" => other_user.id,
|
||||
"comment" => "posts are too good for this instance"
|
||||
account_id: other_user.id,
|
||||
comment: "posts are too good for this instance"
|
||||
})
|
||||
|
||||
assert %{content: "posts are too good for this instance"} =
|
||||
|
|
@ -108,8 +108,8 @@ defmodule Pleroma.Web.AdminAPI.ReportViewTest do
|
|||
|
||||
{:ok, activity} =
|
||||
CommonAPI.report(user, %{
|
||||
"account_id" => other_user.id,
|
||||
"comment" => ""
|
||||
account_id: other_user.id,
|
||||
comment: ""
|
||||
})
|
||||
|
||||
data = Map.put(activity.data, "content", "<script> alert('hecked :D:D:D:D:D:D:D') </script>")
|
||||
|
|
@ -125,8 +125,8 @@ defmodule Pleroma.Web.AdminAPI.ReportViewTest do
|
|||
|
||||
{:ok, activity} =
|
||||
CommonAPI.report(user, %{
|
||||
"account_id" => other_user.id,
|
||||
"comment" => ""
|
||||
account_id: other_user.id,
|
||||
comment: ""
|
||||
})
|
||||
|
||||
Pleroma.User.delete(other_user)
|
||||
|
|
|
|||
|
|
@ -485,9 +485,9 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
comment = "foobar"
|
||||
|
||||
report_data = %{
|
||||
"account_id" => target_user.id,
|
||||
"comment" => comment,
|
||||
"status_ids" => [activity.id]
|
||||
account_id: target_user.id,
|
||||
comment: comment,
|
||||
status_ids: [activity.id]
|
||||
}
|
||||
|
||||
note_obj = %{
|
||||
|
|
@ -517,9 +517,9 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
|
||||
{:ok, %Activity{id: report_id}} =
|
||||
CommonAPI.report(reporter, %{
|
||||
"account_id" => target_user.id,
|
||||
"comment" => "I feel offended",
|
||||
"status_ids" => [activity.id]
|
||||
account_id: target_user.id,
|
||||
comment: "I feel offended",
|
||||
status_ids: [activity.id]
|
||||
})
|
||||
|
||||
{:ok, report} = CommonAPI.update_report_state(report_id, "resolved")
|
||||
|
|
@ -538,9 +538,9 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
|
||||
{:ok, %Activity{id: report_id}} =
|
||||
CommonAPI.report(reporter, %{
|
||||
"account_id" => target_user.id,
|
||||
"comment" => "I feel offended",
|
||||
"status_ids" => [activity.id]
|
||||
account_id: target_user.id,
|
||||
comment: "I feel offended",
|
||||
status_ids: [activity.id]
|
||||
})
|
||||
|
||||
assert CommonAPI.update_report_state(report_id, "test") == {:error, "Unsupported state"}
|
||||
|
|
@ -552,16 +552,16 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
|
||||
{:ok, %Activity{id: first_report_id}} =
|
||||
CommonAPI.report(reporter, %{
|
||||
"account_id" => target_user.id,
|
||||
"comment" => "I feel offended",
|
||||
"status_ids" => [activity.id]
|
||||
account_id: target_user.id,
|
||||
comment: "I feel offended",
|
||||
status_ids: [activity.id]
|
||||
})
|
||||
|
||||
{:ok, %Activity{id: second_report_id}} =
|
||||
CommonAPI.report(reporter, %{
|
||||
"account_id" => target_user.id,
|
||||
"comment" => "I feel very offended!",
|
||||
"status_ids" => [activity.id]
|
||||
account_id: target_user.id,
|
||||
comment: "I feel very offended!",
|
||||
status_ids: [activity.id]
|
||||
})
|
||||
|
||||
{:ok, report_ids} =
|
||||
|
|
|
|||
|
|
@ -925,7 +925,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
|> Map.put(:remote_ip, {127, 0, 0, 5})
|
||||
|> post("/api/v1/accounts", Map.delete(valid_params, :email))
|
||||
|
||||
assert json_response_and_validate_schema(res, 400) == %{"error" => "Missing parameters"}
|
||||
assert json_response_and_validate_schema(res, 400) ==
|
||||
%{"error" => "Missing parameter: email"}
|
||||
|
||||
res =
|
||||
conn
|
||||
|
|
@ -1093,6 +1094,91 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
end
|
||||
end
|
||||
|
||||
describe "create account with enabled captcha" do
|
||||
setup %{conn: conn} do
|
||||
app_token = insert(:oauth_token, user: nil)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> put_req_header("authorization", "Bearer " <> app_token.token)
|
||||
|> put_req_header("content-type", "multipart/form-data")
|
||||
|
||||
[conn: conn]
|
||||
end
|
||||
|
||||
setup do: clear_config([Pleroma.Captcha, :enabled], true)
|
||||
|
||||
test "creates an account and returns 200 if captcha is valid", %{conn: conn} do
|
||||
%{token: token, answer_data: answer_data} = Pleroma.Captcha.new()
|
||||
|
||||
params = %{
|
||||
username: "lain",
|
||||
email: "lain@example.org",
|
||||
password: "PlzDontHackLain",
|
||||
agreement: true,
|
||||
captcha_solution: Pleroma.Captcha.Mock.solution(),
|
||||
captcha_token: token,
|
||||
captcha_answer_data: answer_data
|
||||
}
|
||||
|
||||
assert %{
|
||||
"access_token" => access_token,
|
||||
"created_at" => _,
|
||||
"scope" => ["read"],
|
||||
"token_type" => "Bearer"
|
||||
} =
|
||||
conn
|
||||
|> post("/api/v1/accounts", params)
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|
||||
assert Token |> Repo.get_by(token: access_token) |> Repo.preload(:user) |> Map.get(:user)
|
||||
|
||||
Cachex.del(:used_captcha_cache, token)
|
||||
end
|
||||
|
||||
test "returns 400 if any captcha field is not provided", %{conn: conn} do
|
||||
captcha_fields = [:captcha_solution, :captcha_token, :captcha_answer_data]
|
||||
|
||||
valid_params = %{
|
||||
username: "lain",
|
||||
email: "lain@example.org",
|
||||
password: "PlzDontHackLain",
|
||||
agreement: true,
|
||||
captcha_solution: "xx",
|
||||
captcha_token: "xx",
|
||||
captcha_answer_data: "xx"
|
||||
}
|
||||
|
||||
for field <- captcha_fields do
|
||||
expected = %{
|
||||
"error" => "{\"captcha\":[\"Invalid CAPTCHA (Missing parameter: #{field})\"]}"
|
||||
}
|
||||
|
||||
assert expected ==
|
||||
conn
|
||||
|> post("/api/v1/accounts", Map.delete(valid_params, field))
|
||||
|> json_response_and_validate_schema(:bad_request)
|
||||
end
|
||||
end
|
||||
|
||||
test "returns an error if captcha is invalid", %{conn: conn} do
|
||||
params = %{
|
||||
username: "lain",
|
||||
email: "lain@example.org",
|
||||
password: "PlzDontHackLain",
|
||||
agreement: true,
|
||||
captcha_solution: "cofe",
|
||||
captcha_token: "cofe",
|
||||
captcha_answer_data: "cofe"
|
||||
}
|
||||
|
||||
assert %{"error" => "{\"captcha\":[\"Invalid answer data\"]}"} ==
|
||||
conn
|
||||
|> post("/api/v1/accounts", params)
|
||||
|> json_response_and_validate_schema(:bad_request)
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET /api/v1/accounts/:id/lists - account_lists" do
|
||||
test "returns lists to which the account belongs" do
|
||||
%{user: user, conn: conn} = oauth_access(["read:lists"])
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
|
|||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/v1/notifications")
|
||||
|> json_response(200)
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert Enum.all?(response, fn n ->
|
||||
get_in(n, ["account", "pleroma", "relationship"]) == %{}
|
||||
|
|
@ -50,7 +50,9 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
|
|||
user.ap_id
|
||||
}\" rel=\"ugc\">@<span>#{user.nickname}</span></a></span>"
|
||||
|
||||
assert [%{"status" => %{"content" => response}} | _rest] = json_response(conn, 200)
|
||||
assert [%{"status" => %{"content" => response}} | _rest] =
|
||||
json_response_and_validate_schema(conn, 200)
|
||||
|
||||
assert response == expected_response
|
||||
end
|
||||
|
||||
|
|
@ -69,7 +71,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
|
|||
user.ap_id
|
||||
}\" rel=\"ugc\">@<span>#{user.nickname}</span></a></span>"
|
||||
|
||||
assert %{"status" => %{"content" => response}} = json_response(conn, 200)
|
||||
assert %{"status" => %{"content" => response}} = json_response_and_validate_schema(conn, 200)
|
||||
assert response == expected_response
|
||||
end
|
||||
|
||||
|
|
@ -84,9 +86,10 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
|
|||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> post("/api/v1/notifications/dismiss", %{"id" => notification.id})
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/v1/notifications/dismiss", %{"id" => to_string(notification.id)})
|
||||
|
||||
assert %{} = json_response(conn, 200)
|
||||
assert %{} = json_response_and_validate_schema(conn, 200)
|
||||
end
|
||||
|
||||
test "dismissing a single notification" do
|
||||
|
|
@ -102,7 +105,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
|
|||
|> assign(:user, user)
|
||||
|> post("/api/v1/notifications/#{notification.id}/dismiss")
|
||||
|
||||
assert %{} = json_response(conn, 200)
|
||||
assert %{} = json_response_and_validate_schema(conn, 200)
|
||||
end
|
||||
|
||||
test "clearing all notifications" do
|
||||
|
|
@ -115,11 +118,11 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
|
|||
|
||||
ret_conn = post(conn, "/api/v1/notifications/clear")
|
||||
|
||||
assert %{} = json_response(ret_conn, 200)
|
||||
assert %{} = json_response_and_validate_schema(ret_conn, 200)
|
||||
|
||||
ret_conn = get(conn, "/api/v1/notifications")
|
||||
|
||||
assert all = json_response(ret_conn, 200)
|
||||
assert all = json_response_and_validate_schema(ret_conn, 200)
|
||||
assert all == []
|
||||
end
|
||||
|
||||
|
|
@ -143,7 +146,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
|
|||
result =
|
||||
conn
|
||||
|> get("/api/v1/notifications?limit=2&min_id=#{notification1_id}")
|
||||
|> json_response(:ok)
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|
||||
assert [%{"id" => ^notification3_id}, %{"id" => ^notification2_id}] = result
|
||||
|
||||
|
|
@ -151,7 +154,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
|
|||
result =
|
||||
conn
|
||||
|> get("/api/v1/notifications?limit=2&since_id=#{notification1_id}")
|
||||
|> json_response(:ok)
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|
||||
assert [%{"id" => ^notification4_id}, %{"id" => ^notification3_id}] = result
|
||||
|
||||
|
|
@ -159,7 +162,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
|
|||
result =
|
||||
conn
|
||||
|> get("/api/v1/notifications?limit=2&max_id=#{notification4_id}")
|
||||
|> json_response(:ok)
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|
||||
assert [%{"id" => ^notification3_id}, %{"id" => ^notification2_id}] = result
|
||||
end
|
||||
|
|
@ -181,36 +184,28 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
|
|||
{:ok, private_activity} =
|
||||
CommonAPI.post(other_user, %{"status" => "@#{user.nickname}", "visibility" => "private"})
|
||||
|
||||
conn_res =
|
||||
get(conn, "/api/v1/notifications", %{
|
||||
exclude_visibilities: ["public", "unlisted", "private"]
|
||||
})
|
||||
query = params_to_query(%{exclude_visibilities: ["public", "unlisted", "private"]})
|
||||
conn_res = get(conn, "/api/v1/notifications?" <> query)
|
||||
|
||||
assert [%{"status" => %{"id" => id}}] = json_response(conn_res, 200)
|
||||
assert [%{"status" => %{"id" => id}}] = json_response_and_validate_schema(conn_res, 200)
|
||||
assert id == direct_activity.id
|
||||
|
||||
conn_res =
|
||||
get(conn, "/api/v1/notifications", %{
|
||||
exclude_visibilities: ["public", "unlisted", "direct"]
|
||||
})
|
||||
query = params_to_query(%{exclude_visibilities: ["public", "unlisted", "direct"]})
|
||||
conn_res = get(conn, "/api/v1/notifications?" <> query)
|
||||
|
||||
assert [%{"status" => %{"id" => id}}] = json_response(conn_res, 200)
|
||||
assert [%{"status" => %{"id" => id}}] = json_response_and_validate_schema(conn_res, 200)
|
||||
assert id == private_activity.id
|
||||
|
||||
conn_res =
|
||||
get(conn, "/api/v1/notifications", %{
|
||||
exclude_visibilities: ["public", "private", "direct"]
|
||||
})
|
||||
query = params_to_query(%{exclude_visibilities: ["public", "private", "direct"]})
|
||||
conn_res = get(conn, "/api/v1/notifications?" <> query)
|
||||
|
||||
assert [%{"status" => %{"id" => id}}] = json_response(conn_res, 200)
|
||||
assert [%{"status" => %{"id" => id}}] = json_response_and_validate_schema(conn_res, 200)
|
||||
assert id == unlisted_activity.id
|
||||
|
||||
conn_res =
|
||||
get(conn, "/api/v1/notifications", %{
|
||||
exclude_visibilities: ["unlisted", "private", "direct"]
|
||||
})
|
||||
query = params_to_query(%{exclude_visibilities: ["unlisted", "private", "direct"]})
|
||||
conn_res = get(conn, "/api/v1/notifications?" <> query)
|
||||
|
||||
assert [%{"status" => %{"id" => id}}] = json_response(conn_res, 200)
|
||||
assert [%{"status" => %{"id" => id}}] = json_response_and_validate_schema(conn_res, 200)
|
||||
assert id == public_activity.id
|
||||
end
|
||||
|
||||
|
|
@ -237,8 +232,8 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
|
|||
|
||||
activity_ids =
|
||||
conn
|
||||
|> get("/api/v1/notifications", %{exclude_visibilities: ["direct"]})
|
||||
|> json_response(200)
|
||||
|> get("/api/v1/notifications?exclude_visibilities[]=direct")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|> Enum.map(& &1["status"]["id"])
|
||||
|
||||
assert public_activity.id in activity_ids
|
||||
|
|
@ -248,8 +243,8 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
|
|||
|
||||
activity_ids =
|
||||
conn
|
||||
|> get("/api/v1/notifications", %{exclude_visibilities: ["unlisted"]})
|
||||
|> json_response(200)
|
||||
|> get("/api/v1/notifications?exclude_visibilities[]=unlisted")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|> Enum.map(& &1["status"]["id"])
|
||||
|
||||
assert public_activity.id in activity_ids
|
||||
|
|
@ -259,8 +254,8 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
|
|||
|
||||
activity_ids =
|
||||
conn
|
||||
|> get("/api/v1/notifications", %{exclude_visibilities: ["private"]})
|
||||
|> json_response(200)
|
||||
|> get("/api/v1/notifications?exclude_visibilities[]=private")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|> Enum.map(& &1["status"]["id"])
|
||||
|
||||
assert public_activity.id in activity_ids
|
||||
|
|
@ -270,8 +265,8 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
|
|||
|
||||
activity_ids =
|
||||
conn
|
||||
|> get("/api/v1/notifications", %{exclude_visibilities: ["public"]})
|
||||
|> json_response(200)
|
||||
|> get("/api/v1/notifications?exclude_visibilities[]=public")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|> Enum.map(& &1["status"]["id"])
|
||||
|
||||
refute public_activity.id in activity_ids
|
||||
|
|
@ -295,8 +290,8 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
|
|||
|
||||
activity_ids =
|
||||
conn
|
||||
|> get("/api/v1/notifications", %{exclude_visibilities: ["unlisted"]})
|
||||
|> json_response(200)
|
||||
|> get("/api/v1/notifications?exclude_visibilities[]=unlisted")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|> Enum.map(& &1["status"]["id"])
|
||||
|
||||
assert public_activity.id in activity_ids
|
||||
|
|
@ -319,25 +314,27 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
|
|||
reblog_notification_id = get_notification_id_by_activity(reblog_activity)
|
||||
follow_notification_id = get_notification_id_by_activity(follow_activity)
|
||||
|
||||
conn_res =
|
||||
get(conn, "/api/v1/notifications", %{exclude_types: ["mention", "favourite", "reblog"]})
|
||||
query = params_to_query(%{exclude_types: ["mention", "favourite", "reblog"]})
|
||||
conn_res = get(conn, "/api/v1/notifications?" <> query)
|
||||
|
||||
assert [%{"id" => ^follow_notification_id}] = json_response(conn_res, 200)
|
||||
assert [%{"id" => ^follow_notification_id}] = json_response_and_validate_schema(conn_res, 200)
|
||||
|
||||
conn_res =
|
||||
get(conn, "/api/v1/notifications", %{exclude_types: ["favourite", "reblog", "follow"]})
|
||||
query = params_to_query(%{exclude_types: ["favourite", "reblog", "follow"]})
|
||||
conn_res = get(conn, "/api/v1/notifications?" <> query)
|
||||
|
||||
assert [%{"id" => ^mention_notification_id}] = json_response(conn_res, 200)
|
||||
assert [%{"id" => ^mention_notification_id}] =
|
||||
json_response_and_validate_schema(conn_res, 200)
|
||||
|
||||
conn_res =
|
||||
get(conn, "/api/v1/notifications", %{exclude_types: ["reblog", "follow", "mention"]})
|
||||
query = params_to_query(%{exclude_types: ["reblog", "follow", "mention"]})
|
||||
conn_res = get(conn, "/api/v1/notifications?" <> query)
|
||||
|
||||
assert [%{"id" => ^favorite_notification_id}] = json_response(conn_res, 200)
|
||||
assert [%{"id" => ^favorite_notification_id}] =
|
||||
json_response_and_validate_schema(conn_res, 200)
|
||||
|
||||
conn_res =
|
||||
get(conn, "/api/v1/notifications", %{exclude_types: ["follow", "mention", "favourite"]})
|
||||
query = params_to_query(%{exclude_types: ["follow", "mention", "favourite"]})
|
||||
conn_res = get(conn, "/api/v1/notifications?" <> query)
|
||||
|
||||
assert [%{"id" => ^reblog_notification_id}] = json_response(conn_res, 200)
|
||||
assert [%{"id" => ^reblog_notification_id}] = json_response_and_validate_schema(conn_res, 200)
|
||||
end
|
||||
|
||||
test "filters notifications using include_types" do
|
||||
|
|
@ -355,32 +352,34 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
|
|||
reblog_notification_id = get_notification_id_by_activity(reblog_activity)
|
||||
follow_notification_id = get_notification_id_by_activity(follow_activity)
|
||||
|
||||
conn_res = get(conn, "/api/v1/notifications", %{include_types: ["follow"]})
|
||||
conn_res = get(conn, "/api/v1/notifications?include_types[]=follow")
|
||||
|
||||
assert [%{"id" => ^follow_notification_id}] = json_response(conn_res, 200)
|
||||
assert [%{"id" => ^follow_notification_id}] = json_response_and_validate_schema(conn_res, 200)
|
||||
|
||||
conn_res = get(conn, "/api/v1/notifications", %{include_types: ["mention"]})
|
||||
conn_res = get(conn, "/api/v1/notifications?include_types[]=mention")
|
||||
|
||||
assert [%{"id" => ^mention_notification_id}] = json_response(conn_res, 200)
|
||||
assert [%{"id" => ^mention_notification_id}] =
|
||||
json_response_and_validate_schema(conn_res, 200)
|
||||
|
||||
conn_res = get(conn, "/api/v1/notifications", %{include_types: ["favourite"]})
|
||||
conn_res = get(conn, "/api/v1/notifications?include_types[]=favourite")
|
||||
|
||||
assert [%{"id" => ^favorite_notification_id}] = json_response(conn_res, 200)
|
||||
assert [%{"id" => ^favorite_notification_id}] =
|
||||
json_response_and_validate_schema(conn_res, 200)
|
||||
|
||||
conn_res = get(conn, "/api/v1/notifications", %{include_types: ["reblog"]})
|
||||
conn_res = get(conn, "/api/v1/notifications?include_types[]=reblog")
|
||||
|
||||
assert [%{"id" => ^reblog_notification_id}] = json_response(conn_res, 200)
|
||||
assert [%{"id" => ^reblog_notification_id}] = json_response_and_validate_schema(conn_res, 200)
|
||||
|
||||
result = conn |> get("/api/v1/notifications") |> json_response(200)
|
||||
result = conn |> get("/api/v1/notifications") |> json_response_and_validate_schema(200)
|
||||
|
||||
assert length(result) == 4
|
||||
|
||||
query = params_to_query(%{include_types: ["follow", "mention", "favourite", "reblog"]})
|
||||
|
||||
result =
|
||||
conn
|
||||
|> get("/api/v1/notifications", %{
|
||||
include_types: ["follow", "mention", "favourite", "reblog"]
|
||||
})
|
||||
|> json_response(200)
|
||||
|> get("/api/v1/notifications?" <> query)
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert length(result) == 4
|
||||
end
|
||||
|
|
@ -402,7 +401,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
|
|||
result =
|
||||
conn
|
||||
|> get("/api/v1/notifications")
|
||||
|> json_response(:ok)
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|
||||
assert [%{"id" => ^notification2_id}, %{"id" => ^notification1_id}] = result
|
||||
|
||||
|
|
@ -414,22 +413,19 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
|
|||
result =
|
||||
conn2
|
||||
|> get("/api/v1/notifications")
|
||||
|> json_response(:ok)
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|
||||
assert [%{"id" => ^notification4_id}, %{"id" => ^notification3_id}] = result
|
||||
|
||||
conn_destroy =
|
||||
conn
|
||||
|> delete("/api/v1/notifications/destroy_multiple", %{
|
||||
"ids" => [notification1_id, notification2_id]
|
||||
})
|
||||
query = params_to_query(%{ids: [notification1_id, notification2_id]})
|
||||
conn_destroy = delete(conn, "/api/v1/notifications/destroy_multiple?" <> query)
|
||||
|
||||
assert json_response(conn_destroy, 200) == %{}
|
||||
assert json_response_and_validate_schema(conn_destroy, 200) == %{}
|
||||
|
||||
result =
|
||||
conn2
|
||||
|> get("/api/v1/notifications")
|
||||
|> json_response(:ok)
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|
||||
assert [%{"id" => ^notification4_id}, %{"id" => ^notification3_id}] = result
|
||||
end
|
||||
|
|
@ -443,13 +439,13 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
|
|||
|
||||
ret_conn = get(conn, "/api/v1/notifications")
|
||||
|
||||
assert length(json_response(ret_conn, 200)) == 1
|
||||
assert length(json_response_and_validate_schema(ret_conn, 200)) == 1
|
||||
|
||||
{:ok, _user_relationships} = User.mute(user, user2)
|
||||
|
||||
conn = get(conn, "/api/v1/notifications")
|
||||
|
||||
assert json_response(conn, 200) == []
|
||||
assert json_response_and_validate_schema(conn, 200) == []
|
||||
end
|
||||
|
||||
test "see notifications after muting user without notifications" do
|
||||
|
|
@ -461,13 +457,13 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
|
|||
|
||||
ret_conn = get(conn, "/api/v1/notifications")
|
||||
|
||||
assert length(json_response(ret_conn, 200)) == 1
|
||||
assert length(json_response_and_validate_schema(ret_conn, 200)) == 1
|
||||
|
||||
{:ok, _user_relationships} = User.mute(user, user2, false)
|
||||
|
||||
conn = get(conn, "/api/v1/notifications")
|
||||
|
||||
assert length(json_response(conn, 200)) == 1
|
||||
assert length(json_response_and_validate_schema(conn, 200)) == 1
|
||||
end
|
||||
|
||||
test "see notifications after muting user with notifications and with_muted parameter" do
|
||||
|
|
@ -479,13 +475,13 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
|
|||
|
||||
ret_conn = get(conn, "/api/v1/notifications")
|
||||
|
||||
assert length(json_response(ret_conn, 200)) == 1
|
||||
assert length(json_response_and_validate_schema(ret_conn, 200)) == 1
|
||||
|
||||
{:ok, _user_relationships} = User.mute(user, user2)
|
||||
|
||||
conn = get(conn, "/api/v1/notifications", %{"with_muted" => "true"})
|
||||
conn = get(conn, "/api/v1/notifications?with_muted=true")
|
||||
|
||||
assert length(json_response(conn, 200)) == 1
|
||||
assert length(json_response_and_validate_schema(conn, 200)) == 1
|
||||
end
|
||||
|
||||
@tag capture_log: true
|
||||
|
|
@ -512,7 +508,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
|
|||
|
||||
conn = get(conn, "/api/v1/notifications")
|
||||
|
||||
assert length(json_response(conn, 200)) == 1
|
||||
assert length(json_response_and_validate_schema(conn, 200)) == 1
|
||||
end
|
||||
|
||||
describe "link headers" do
|
||||
|
|
@ -538,10 +534,10 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
|
|||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/v1/notifications", %{media_only: true})
|
||||
|> get("/api/v1/notifications?limit=5")
|
||||
|
||||
assert [link_header] = get_resp_header(conn, "link")
|
||||
assert link_header =~ ~r/media_only=true/
|
||||
assert link_header =~ ~r/limit=5/
|
||||
assert link_header =~ ~r/min_id=#{notification2.id}/
|
||||
assert link_header =~ ~r/max_id=#{notification1.id}/
|
||||
end
|
||||
|
|
@ -560,14 +556,14 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
|
|||
assert [%{"account" => %{"id" => ^account_id}}] =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/v1/notifications", %{account_id: account_id})
|
||||
|> json_response(200)
|
||||
|> get("/api/v1/notifications?account_id=#{account_id}")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert %{"error" => "Account is not found"} =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/v1/notifications", %{account_id: "cofe"})
|
||||
|> json_response(404)
|
||||
|> get("/api/v1/notifications?account_id=cofe")
|
||||
|> json_response_and_validate_schema(404)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -577,4 +573,11 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
|
|||
|> Map.get(:id)
|
||||
|> to_string()
|
||||
end
|
||||
|
||||
defp params_to_query(%{} = params) do
|
||||
Enum.map_join(params, "&", fn
|
||||
{k, v} when is_list(v) -> Enum.map_join(v, "&", &"#{k}[]=#{&1}")
|
||||
{k, v} -> k <> "=" <> v
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -22,8 +22,9 @@ defmodule Pleroma.Web.MastodonAPI.ReportControllerTest do
|
|||
test "submit a basic report", %{conn: conn, target_user: target_user} do
|
||||
assert %{"action_taken" => false, "id" => _} =
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/v1/reports", %{"account_id" => target_user.id})
|
||||
|> json_response(200)
|
||||
|> json_response_and_validate_schema(200)
|
||||
end
|
||||
|
||||
test "submit a report with statuses and comment", %{
|
||||
|
|
@ -33,23 +34,25 @@ defmodule Pleroma.Web.MastodonAPI.ReportControllerTest do
|
|||
} do
|
||||
assert %{"action_taken" => false, "id" => _} =
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/v1/reports", %{
|
||||
"account_id" => target_user.id,
|
||||
"status_ids" => [activity.id],
|
||||
"comment" => "bad status!",
|
||||
"forward" => "false"
|
||||
})
|
||||
|> json_response(200)
|
||||
|> json_response_and_validate_schema(200)
|
||||
end
|
||||
|
||||
test "account_id is required", %{
|
||||
conn: conn,
|
||||
activity: activity
|
||||
} do
|
||||
assert %{"error" => "Valid `account_id` required"} =
|
||||
assert %{"error" => "Missing field: account_id."} =
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/v1/reports", %{"status_ids" => [activity.id]})
|
||||
|> json_response(400)
|
||||
|> json_response_and_validate_schema(400)
|
||||
end
|
||||
|
||||
test "comment must be up to the size specified in the config", %{
|
||||
|
|
@ -63,17 +66,21 @@ defmodule Pleroma.Web.MastodonAPI.ReportControllerTest do
|
|||
|
||||
assert ^error =
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/v1/reports", %{"account_id" => target_user.id, "comment" => comment})
|
||||
|> json_response(400)
|
||||
|> json_response_and_validate_schema(400)
|
||||
end
|
||||
|
||||
test "returns error when account is not exist", %{
|
||||
conn: conn,
|
||||
activity: activity
|
||||
} do
|
||||
conn = post(conn, "/api/v1/reports", %{"status_ids" => [activity.id], "account_id" => "foo"})
|
||||
conn =
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/v1/reports", %{"status_ids" => [activity.id], "account_id" => "foo"})
|
||||
|
||||
assert json_response(conn, 400) == %{"error" => "Account not found"}
|
||||
assert json_response_and_validate_schema(conn, 400) == %{"error" => "Account not found"}
|
||||
end
|
||||
|
||||
test "doesn't fail if an admin has no email", %{conn: conn, target_user: target_user} do
|
||||
|
|
@ -81,7 +88,8 @@ defmodule Pleroma.Web.MastodonAPI.ReportControllerTest do
|
|||
|
||||
assert %{"action_taken" => false, "id" => _} =
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/v1/reports", %{"account_id" => target_user.id})
|
||||
|> json_response(200)
|
||||
|> json_response_and_validate_schema(200)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -5,8 +5,6 @@
|
|||
defmodule Pleroma.Web.MastodonAPI.SuggestionControllerTest do
|
||||
use Pleroma.Web.ConnCase
|
||||
|
||||
alias Pleroma.Config
|
||||
|
||||
setup do: oauth_access(["read"])
|
||||
|
||||
test "returns empty result", %{conn: conn} do
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
|
||||
test "it registers a new user and returns the user." do
|
||||
data = %{
|
||||
:nickname => "lain",
|
||||
:username => "lain",
|
||||
:email => "lain@wired.jp",
|
||||
:fullname => "lain iwakura",
|
||||
:password => "bear",
|
||||
|
|
@ -35,7 +35,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
|
||||
test "it registers a new user with empty string in bio and returns the user." do
|
||||
data = %{
|
||||
:nickname => "lain",
|
||||
:username => "lain",
|
||||
:email => "lain@wired.jp",
|
||||
:fullname => "lain iwakura",
|
||||
:bio => "",
|
||||
|
|
@ -60,7 +60,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
end
|
||||
|
||||
data = %{
|
||||
:nickname => "lain",
|
||||
:username => "lain",
|
||||
:email => "lain@wired.jp",
|
||||
:fullname => "lain iwakura",
|
||||
:bio => "",
|
||||
|
|
@ -87,7 +87,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
|
||||
test "it registers a new user and parses mentions in the bio" do
|
||||
data1 = %{
|
||||
:nickname => "john",
|
||||
:username => "john",
|
||||
:email => "john@gmail.com",
|
||||
:fullname => "John Doe",
|
||||
:bio => "test",
|
||||
|
|
@ -98,7 +98,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
{:ok, user1} = TwitterAPI.register_user(data1)
|
||||
|
||||
data2 = %{
|
||||
:nickname => "lain",
|
||||
:username => "lain",
|
||||
:email => "lain@wired.jp",
|
||||
:fullname => "lain iwakura",
|
||||
:bio => "@john test",
|
||||
|
|
@ -123,7 +123,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
{:ok, invite} = UserInviteToken.create_invite()
|
||||
|
||||
data = %{
|
||||
:nickname => "vinny",
|
||||
:username => "vinny",
|
||||
:email => "pasta@pizza.vs",
|
||||
:fullname => "Vinny Vinesauce",
|
||||
:bio => "streamer",
|
||||
|
|
@ -145,7 +145,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
|
||||
test "returns error on invalid token" do
|
||||
data = %{
|
||||
:nickname => "GrimReaper",
|
||||
:username => "GrimReaper",
|
||||
:email => "death@reapers.afterlife",
|
||||
:fullname => "Reaper Grim",
|
||||
:bio => "Your time has come",
|
||||
|
|
@ -165,7 +165,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
UserInviteToken.update_invite!(invite, used: true)
|
||||
|
||||
data = %{
|
||||
:nickname => "GrimReaper",
|
||||
:username => "GrimReaper",
|
||||
:email => "death@reapers.afterlife",
|
||||
:fullname => "Reaper Grim",
|
||||
:bio => "Your time has come",
|
||||
|
|
@ -186,7 +186,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
|
||||
setup do
|
||||
data = %{
|
||||
:nickname => "vinny",
|
||||
:username => "vinny",
|
||||
:email => "pasta@pizza.vs",
|
||||
:fullname => "Vinny Vinesauce",
|
||||
:bio => "streamer",
|
||||
|
|
@ -250,7 +250,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
UserInviteToken.update_invite!(invite, uses: 99)
|
||||
|
||||
data = %{
|
||||
:nickname => "vinny",
|
||||
:username => "vinny",
|
||||
:email => "pasta@pizza.vs",
|
||||
:fullname => "Vinny Vinesauce",
|
||||
:bio => "streamer",
|
||||
|
|
@ -269,7 +269,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
AccountView.render("show.json", %{user: fetched_user})
|
||||
|
||||
data = %{
|
||||
:nickname => "GrimReaper",
|
||||
:username => "GrimReaper",
|
||||
:email => "death@reapers.afterlife",
|
||||
:fullname => "Reaper Grim",
|
||||
:bio => "Your time has come",
|
||||
|
|
@ -292,7 +292,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
{:ok, invite} = UserInviteToken.create_invite(%{expires_at: Date.utc_today(), max_use: 100})
|
||||
|
||||
data = %{
|
||||
:nickname => "vinny",
|
||||
:username => "vinny",
|
||||
:email => "pasta@pizza.vs",
|
||||
:fullname => "Vinny Vinesauce",
|
||||
:bio => "streamer",
|
||||
|
|
@ -317,7 +317,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
UserInviteToken.update_invite!(invite, uses: 99)
|
||||
|
||||
data = %{
|
||||
:nickname => "vinny",
|
||||
:username => "vinny",
|
||||
:email => "pasta@pizza.vs",
|
||||
:fullname => "Vinny Vinesauce",
|
||||
:bio => "streamer",
|
||||
|
|
@ -335,7 +335,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
AccountView.render("show.json", %{user: fetched_user})
|
||||
|
||||
data = %{
|
||||
:nickname => "GrimReaper",
|
||||
:username => "GrimReaper",
|
||||
:email => "death@reapers.afterlife",
|
||||
:fullname => "Reaper Grim",
|
||||
:bio => "Your time has come",
|
||||
|
|
@ -355,7 +355,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
UserInviteToken.create_invite(%{expires_at: Date.add(Date.utc_today(), -1), max_use: 100})
|
||||
|
||||
data = %{
|
||||
:nickname => "GrimReaper",
|
||||
:username => "GrimReaper",
|
||||
:email => "death@reapers.afterlife",
|
||||
:fullname => "Reaper Grim",
|
||||
:bio => "Your time has come",
|
||||
|
|
@ -377,7 +377,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
UserInviteToken.update_invite!(invite, uses: 100)
|
||||
|
||||
data = %{
|
||||
:nickname => "GrimReaper",
|
||||
:username => "GrimReaper",
|
||||
:email => "death@reapers.afterlife",
|
||||
:fullname => "Reaper Grim",
|
||||
:bio => "Your time has come",
|
||||
|
|
@ -395,16 +395,15 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
|
||||
test "it returns the error on registration problems" do
|
||||
data = %{
|
||||
:nickname => "lain",
|
||||
:username => "lain",
|
||||
:email => "lain@wired.jp",
|
||||
:fullname => "lain iwakura",
|
||||
:bio => "close the world.",
|
||||
:password => "bear"
|
||||
:bio => "close the world."
|
||||
}
|
||||
|
||||
{:error, error_object} = TwitterAPI.register_user(data)
|
||||
{:error, error} = TwitterAPI.register_user(data)
|
||||
|
||||
assert is_binary(error_object[:error])
|
||||
assert is_binary(error)
|
||||
refute User.get_cached_by_nickname("lain")
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue