39 lines
984 B
Elixir
39 lines
984 B
Elixir
defmodule ActivityPub.HeadersTest do
|
|
use Postland.DataCase, async: true
|
|
|
|
use ExUnitProperties
|
|
|
|
import ActivityPub.Headers
|
|
|
|
property "can verify what it signs" do
|
|
private =
|
|
Postland.KeyFixtures.private()
|
|
|> :public_key.pem_decode()
|
|
|> hd()
|
|
|> :public_key.pem_entry_decode()
|
|
|
|
actor_fetcher = fn _ ->
|
|
pub_key =
|
|
Postland.KeyFixtures.public()
|
|
|> :public_key.pem_decode()
|
|
|> hd()
|
|
|> :public_key.pem_entry_decode()
|
|
|
|
{:ok, pub_key}
|
|
end
|
|
|
|
check all(
|
|
method <- member_of([:get, :post]),
|
|
body <- StreamData.binary(),
|
|
host1 <- StreamData.string([?a..?z, ?0..?9, ?-]),
|
|
host2 <- StreamData.string([?a..?z, ?0..?9, ?-])
|
|
) do
|
|
url = URI.parse("#{host1}.com/inbox")
|
|
actor_url = "#{host2}/actor"
|
|
|
|
headers = signing_headers(method, url, body, actor_url, private)
|
|
|
|
verify(method, "/inbox", headers, actor_fetcher)
|
|
end
|
|
end
|
|
end
|