Compare commits
6 commits
0c38e16970
...
1b4034dac6
Author | SHA1 | Date | |
---|---|---|---|
1b4034dac6 | |||
158e500fe6 | |||
63ce21475e | |||
2d98fee0c3 | |||
95df5ed0e0 | |||
32bb4c7ca2 |
5 changed files with 172 additions and 43 deletions
|
@ -122,10 +122,10 @@ defmodule Nulla.ActivityPub do
|
||||||
def following(actor, total) do
|
def following(actor, total) do
|
||||||
Jason.OrderedObject.new(
|
Jason.OrderedObject.new(
|
||||||
"@context": "https://www.w3.org/ns/activitystreams",
|
"@context": "https://www.w3.org/ns/activitystreams",
|
||||||
id: "https://#{actor.domain}/users/#{actor.preferredUsername}/following",
|
id: "#{actor.ap_id}/following",
|
||||||
type: "OrderedCollection",
|
type: "OrderedCollection",
|
||||||
totalItems: total,
|
totalItems: total,
|
||||||
first: "https://#{actor.domain}/users/#{actor.preferredUsername}/following?page=1"
|
first: "#{actor.ap_id}/following?page=1"
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -134,12 +134,12 @@ defmodule Nulla.ActivityPub do
|
||||||
def following(actor, total, following_list, page, limit) when is_integer(page) and page > 0 do
|
def following(actor, total, following_list, page, limit) when is_integer(page) and page > 0 do
|
||||||
data = [
|
data = [
|
||||||
"@context": "https://www.w3.org/ns/activitystreams",
|
"@context": "https://www.w3.org/ns/activitystreams",
|
||||||
id: "https://#{actor.domain}/@#{actor.preferredUsername}/following?page=#{page}",
|
id: "#{actor.ap_id}/following?page=#{page}",
|
||||||
type: "OrderedCollectionPage",
|
type: "OrderedCollectionPage",
|
||||||
totalItems: total,
|
totalItems: total,
|
||||||
next: "https://#{actor.domain}/users/#{actor.preferredUsername}/following?page=#{page + 1}",
|
next: "#{actor.ap_id}/following?page=#{page + 1}",
|
||||||
prev: "https://#{actor.domain}/users/#{actor.preferredUsername}/following?page=#{page - 1}",
|
prev: "#{actor.ap_id}/following?page=#{page - 1}",
|
||||||
partOf: "https://#{actor.domain}/users/#{actor.preferredUsername}/following",
|
partOf: "#{actor.ap_id}/following",
|
||||||
orderedItems: following_list
|
orderedItems: following_list
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -166,10 +166,10 @@ defmodule Nulla.ActivityPub do
|
||||||
def followers(actor, total) do
|
def followers(actor, total) do
|
||||||
Jason.OrderedObject.new(
|
Jason.OrderedObject.new(
|
||||||
"@context": "https://www.w3.org/ns/activitystreams",
|
"@context": "https://www.w3.org/ns/activitystreams",
|
||||||
id: "https://#{actor.domain}/users/#{actor.preferredUsername}/followers",
|
id: "#{actor.ap_id}/followers",
|
||||||
type: "OrderedCollection",
|
type: "OrderedCollection",
|
||||||
totalItems: total,
|
totalItems: total,
|
||||||
first: "https://#{actor.domain}/users/#{actor.preferredUsername}/followers?page=1"
|
first: "#{actor.ap_id}/followers?page=1"
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -179,12 +179,12 @@ defmodule Nulla.ActivityPub do
|
||||||
when is_integer(page) and page > 0 do
|
when is_integer(page) and page > 0 do
|
||||||
data = [
|
data = [
|
||||||
"@context": "https://www.w3.org/ns/activitystreams",
|
"@context": "https://www.w3.org/ns/activitystreams",
|
||||||
id: "https://#{actor.domain}/users#{actor.preferredUsername}/followers?page=#{page}",
|
id: "#{actor.ap_id}/followers?page=#{page}",
|
||||||
type: "OrderedCollectionPage",
|
type: "OrderedCollectionPage",
|
||||||
totalItems: total,
|
totalItems: total,
|
||||||
next: "https://#{actor.domain}/users/#{actor.preferredUsername}/followers?page=#{page + 1}",
|
next: "#{actor.ap_id}/followers?page=#{page + 1}",
|
||||||
prev: "https://#{actor.domain}/users/#{actor.preferredUsername}/followers?page=#{page - 1}",
|
prev: "#{actor.ap_id}/followers?page=#{page - 1}",
|
||||||
partOf: "https://#{actor.domain}/users/#{actor.preferredUsername}/followers",
|
partOf: "#{actor.ap_id}/followers",
|
||||||
orderedItems: followers_list
|
orderedItems: followers_list
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ defmodule NullaWeb.FollowController do
|
||||||
def following(conn, %{"username" => username, "page" => page_param}) do
|
def following(conn, %{"username" => username, "page" => page_param}) do
|
||||||
instance_settings = InstanceSettings.get_instance_settings!()
|
instance_settings = InstanceSettings.get_instance_settings!()
|
||||||
domain = instance_settings.domain
|
domain = instance_settings.domain
|
||||||
limit = instance_settings.limit
|
limit = instance_settings.api_limit
|
||||||
actor = Actor.get_actor(username, domain)
|
actor = Actor.get_actor(username, domain)
|
||||||
total = Relation.count_following(actor.id)
|
total = Relation.count_following(actor.id)
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ defmodule NullaWeb.FollowController do
|
||||||
def followers(conn, %{"username" => username, "page" => page_param}) do
|
def followers(conn, %{"username" => username, "page" => page_param}) do
|
||||||
instance_settings = InstanceSettings.get_instance_settings!()
|
instance_settings = InstanceSettings.get_instance_settings!()
|
||||||
domain = instance_settings.domain
|
domain = instance_settings.domain
|
||||||
limit = instance_settings.limit
|
limit = instance_settings.api_limit
|
||||||
actor = Actor.get_actor(username, domain)
|
actor = Actor.get_actor(username, domain)
|
||||||
total = Relation.count_followers(actor.id)
|
total = Relation.count_followers(actor.id)
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ defmodule Nulla.Repo.Migrations.CreateUsers do
|
||||||
add :id, :bigint, primary_key: true
|
add :id, :bigint, primary_key: true
|
||||||
add :email, :string
|
add :email, :string
|
||||||
add :password, :string
|
add :password, :string
|
||||||
add :privateKeyPem, :string
|
add :privateKeyPem, :text
|
||||||
add :last_active_at, :utc_datetime
|
add :last_active_at, :utc_datetime
|
||||||
|
|
||||||
timestamps(type: :utc_datetime)
|
timestamps(type: :utc_datetime)
|
||||||
|
|
123
test/nulla_web/controllers/follow_controller_test.exs
Normal file
123
test/nulla_web/controllers/follow_controller_test.exs
Normal file
|
@ -0,0 +1,123 @@
|
||||||
|
defmodule NullaWeb.FollowControllerTest do
|
||||||
|
use NullaWeb.ConnCase
|
||||||
|
alias Nulla.KeyGen
|
||||||
|
alias Nulla.Models.User
|
||||||
|
alias Nulla.Models.Actor
|
||||||
|
|
||||||
|
setup do
|
||||||
|
{publicKeyPem, privateKeyPem} = KeyGen.gen()
|
||||||
|
|
||||||
|
{:ok, actor} =
|
||||||
|
Actor.create_actor(%{
|
||||||
|
domain: "localhost",
|
||||||
|
ap_id: "http://localhost/users/test",
|
||||||
|
type: "Person",
|
||||||
|
following: "http://localhost/users/test/following",
|
||||||
|
followers: "http://localhost/users/test/followers",
|
||||||
|
inbox: "http://localhost/users/test/inbox",
|
||||||
|
outbox: "http://localhost/users/test/outbox",
|
||||||
|
featured: "http://localhost/users/test/collections/featured",
|
||||||
|
featuredTags: "http://localhost/users/test/collections/tags",
|
||||||
|
preferredUsername: "test",
|
||||||
|
name: "Test",
|
||||||
|
summary: "Test User",
|
||||||
|
url: "http://localhost/@test",
|
||||||
|
manuallyApprovesFollowers: false,
|
||||||
|
discoverable: true,
|
||||||
|
indexable: true,
|
||||||
|
published: DateTime.utc_now(),
|
||||||
|
memorial: false,
|
||||||
|
publicKey:
|
||||||
|
Jason.OrderedObject.new(
|
||||||
|
id: "http://localhost/users/test#main-key",
|
||||||
|
owner: "http://localhost/users/test",
|
||||||
|
publicKeyPem: publicKeyPem
|
||||||
|
),
|
||||||
|
endpoints: Jason.OrderedObject.new(sharedInbox: "http://localhost/inbox")
|
||||||
|
})
|
||||||
|
|
||||||
|
User.create_user(%{
|
||||||
|
id: actor.id,
|
||||||
|
email: "test@localhost",
|
||||||
|
password: "password",
|
||||||
|
privateKeyPem: privateKeyPem,
|
||||||
|
last_active_at: DateTime.utc_now()
|
||||||
|
})
|
||||||
|
|
||||||
|
:ok
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "GET /users/username/following" do
|
||||||
|
test "returns ActivityPub JSON of following", %{conn: conn} do
|
||||||
|
conn =
|
||||||
|
conn
|
||||||
|
|> get(~p"/users/test/following")
|
||||||
|
|
||||||
|
assert response = json_response(conn, 200)
|
||||||
|
|
||||||
|
assert response["id"] == "http://localhost/users/test/following"
|
||||||
|
assert response["type"] == "OrderedCollection"
|
||||||
|
assert response["totalItems"] == 0
|
||||||
|
assert response["first"] == "http://localhost/users/test/following?page=1"
|
||||||
|
end
|
||||||
|
|
||||||
|
test "returns ActivityPub JSON of following with page", %{conn: conn} do
|
||||||
|
conn =
|
||||||
|
conn
|
||||||
|
|> get(~p"/users/test/following?page=1")
|
||||||
|
|
||||||
|
assert response = json_response(conn, 200)
|
||||||
|
|
||||||
|
assert response["id"] == "http://localhost/users/test/following?page=1"
|
||||||
|
assert response["type"] == "OrderedCollectionPage"
|
||||||
|
assert response["totalItems"] == 0
|
||||||
|
assert response["partOf"] == "http://localhost/users/test/following"
|
||||||
|
assert is_list(response["orderedItems"])
|
||||||
|
end
|
||||||
|
|
||||||
|
test "returns first page with invalid value", %{conn: conn} do
|
||||||
|
conn =
|
||||||
|
conn
|
||||||
|
|> get(~p"/users/test/following?page=abc")
|
||||||
|
|
||||||
|
assert conn.status == 200
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "GET /users/username/followers" do
|
||||||
|
test "returns ActivityPub JSON of followers", %{conn: conn} do
|
||||||
|
conn =
|
||||||
|
conn
|
||||||
|
|> get(~p"/users/test/followers")
|
||||||
|
|
||||||
|
assert response = json_response(conn, 200)
|
||||||
|
|
||||||
|
assert response["id"] == "http://localhost/users/test/followers"
|
||||||
|
assert response["type"] == "OrderedCollection"
|
||||||
|
assert response["totalItems"] == 0
|
||||||
|
assert response["first"] == "http://localhost/users/test/followers?page=1"
|
||||||
|
end
|
||||||
|
|
||||||
|
test "returns ActivityPub JSON of followers with page", %{conn: conn} do
|
||||||
|
conn =
|
||||||
|
conn
|
||||||
|
|> get(~p"/users/test/followers?page=1")
|
||||||
|
|
||||||
|
assert response = json_response(conn, 200)
|
||||||
|
|
||||||
|
assert response["id"] == "http://localhost/users/test/followers?page=1"
|
||||||
|
assert response["type"] == "OrderedCollectionPage"
|
||||||
|
assert response["totalItems"] == 0
|
||||||
|
assert response["partOf"] == "http://localhost/users/test/followers"
|
||||||
|
assert is_list(response["orderedItems"])
|
||||||
|
end
|
||||||
|
|
||||||
|
test "returns first page with invalid value", %{conn: conn} do
|
||||||
|
conn =
|
||||||
|
conn
|
||||||
|
|> get(~p"/users/test/followers?page=abc")
|
||||||
|
|
||||||
|
assert conn.status == 200
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,42 +1,46 @@
|
||||||
defmodule NullaWeb.NodeinfoControllerTest do
|
defmodule NullaWeb.NodeinfoControllerTest do
|
||||||
use NullaWeb.ConnCase
|
use NullaWeb.ConnCase
|
||||||
|
alias Nulla.KeyGen
|
||||||
alias Nulla.Models.User
|
alias Nulla.Models.User
|
||||||
alias Nulla.Models.Actor
|
alias Nulla.Models.Actor
|
||||||
|
|
||||||
setup do
|
setup do
|
||||||
{:ok, actor} = Actor.create_actor(%{
|
{publicKeyPem, privateKeyPem} = KeyGen.gen()
|
||||||
domain: "localhost",
|
|
||||||
ap_id: "http://localhost/users/test",
|
{:ok, actor} =
|
||||||
type: "Person",
|
Actor.create_actor(%{
|
||||||
following: "http://localhost/users/test/following",
|
domain: "localhost",
|
||||||
followers: "http://localhost/users/test/followers",
|
ap_id: "http://localhost/users/test",
|
||||||
inbox: "http://localhost/users/test/inbox",
|
type: "Person",
|
||||||
outbox: "http://localhost/users/test/outbox",
|
following: "http://localhost/users/test/following",
|
||||||
featured: "http://localhost/users/test/collections/featured",
|
followers: "http://localhost/users/test/followers",
|
||||||
featuredTags: "http://localhost/users/test/collections/tags",
|
inbox: "http://localhost/users/test/inbox",
|
||||||
preferredUsername: "test",
|
outbox: "http://localhost/users/test/outbox",
|
||||||
name: "Test",
|
featured: "http://localhost/users/test/collections/featured",
|
||||||
summary: "Test User",
|
featuredTags: "http://localhost/users/test/collections/tags",
|
||||||
url: "http://localhost/@test",
|
preferredUsername: "test",
|
||||||
manuallyApprovesFollowers: false,
|
name: "Test",
|
||||||
discoverable: true,
|
summary: "Test User",
|
||||||
indexable: true,
|
url: "http://localhost/@test",
|
||||||
published: DateTime.utc_now(),
|
manuallyApprovesFollowers: false,
|
||||||
memorial: false,
|
discoverable: true,
|
||||||
publicKey:
|
indexable: true,
|
||||||
Jason.OrderedObject.new(
|
published: DateTime.utc_now(),
|
||||||
id: "http://localhost/users/test#main-key",
|
memorial: false,
|
||||||
owner: "http://localhost/users/test",
|
publicKey:
|
||||||
publicKeyPem: "PUBLIC KEY"
|
Jason.OrderedObject.new(
|
||||||
),
|
id: "http://localhost/users/test#main-key",
|
||||||
endpoints: Jason.OrderedObject.new(sharedInbox: "http://localhost/inbox")
|
owner: "http://localhost/users/test",
|
||||||
})
|
publicKeyPem: publicKeyPem
|
||||||
|
),
|
||||||
|
endpoints: Jason.OrderedObject.new(sharedInbox: "http://localhost/inbox")
|
||||||
|
})
|
||||||
|
|
||||||
User.create_user(%{
|
User.create_user(%{
|
||||||
id: actor.id,
|
id: actor.id,
|
||||||
email: "test@localhost",
|
email: "test@localhost",
|
||||||
password: "password",
|
password: "password",
|
||||||
privateKeyPem: "PRIVATE KEY",
|
privateKeyPem: privateKeyPem,
|
||||||
last_active_at: DateTime.utc_now()
|
last_active_at: DateTime.utc_now()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -59,7 +63,9 @@ defmodule NullaWeb.NodeinfoControllerTest do
|
||||||
assert is_binary(link["href"])
|
assert is_binary(link["href"])
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "GET /nodeinfo/2.0" do
|
||||||
test "returns Nodeinfo JSON show", %{conn: conn} do
|
test "returns Nodeinfo JSON show", %{conn: conn} do
|
||||||
conn =
|
conn =
|
||||||
conn
|
conn
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue