Unify HTTP metadata handling
This commit is contained in:
@@ -4,6 +4,9 @@ defmodule Parrhesia.ConfigTest do
|
||||
alias Parrhesia.Web.Listener
|
||||
|
||||
test "returns configured relay limits/policies/features" do
|
||||
assert Parrhesia.Config.get([:metadata, :name]) == "Parrhesia"
|
||||
assert Parrhesia.Config.get([:metadata, :version]) == "0.5.0"
|
||||
assert Parrhesia.Config.get([:metadata, :hide_version?]) == true
|
||||
assert Parrhesia.Config.get([:limits, :max_frame_bytes]) == 1_048_576
|
||||
assert Parrhesia.Config.get([:limits, :max_event_bytes]) == 262_144
|
||||
assert Parrhesia.Config.get([:limits, :max_event_future_skew_seconds]) == 900
|
||||
|
||||
32
test/parrhesia/http_test.exs
Normal file
32
test/parrhesia/http_test.exs
Normal file
@@ -0,0 +1,32 @@
|
||||
defmodule Parrhesia.HTTPTest do
|
||||
use ExUnit.Case, async: true
|
||||
|
||||
alias Parrhesia.HTTP
|
||||
alias Parrhesia.Metadata
|
||||
|
||||
test "default headers advertise the configured user agent" do
|
||||
assert Metadata.hide_version?() == true
|
||||
assert HTTP.default_headers() == [{"user-agent", Metadata.user_agent()}]
|
||||
end
|
||||
|
||||
test "default headers are added without overriding request-specific headers" do
|
||||
options =
|
||||
HTTP.put_default_headers(
|
||||
headers: [{"accept", "application/nostr+json"}],
|
||||
decode_body: false
|
||||
)
|
||||
|
||||
assert Keyword.get(options, :headers) == [
|
||||
{"accept", "application/nostr+json"},
|
||||
{"user-agent", Metadata.user_agent()}
|
||||
]
|
||||
|
||||
assert Keyword.get(options, :decode_body) == false
|
||||
end
|
||||
|
||||
test "explicit user-agent overrides suppress the default case-insensitively" do
|
||||
options = HTTP.put_default_headers(headers: [{"User-Agent", "custom-agent"}])
|
||||
|
||||
assert Keyword.get(options, :headers) == [{"User-Agent", "custom-agent"}]
|
||||
end
|
||||
end
|
||||
17
test/parrhesia/web/relay_info_test.exs
Normal file
17
test/parrhesia/web/relay_info_test.exs
Normal file
@@ -0,0 +1,17 @@
|
||||
defmodule Parrhesia.Web.RelayInfoTest do
|
||||
use ExUnit.Case, async: true
|
||||
|
||||
alias Parrhesia.Web.Listener
|
||||
alias Parrhesia.Web.RelayInfo
|
||||
|
||||
test "nip-11 omits version when metadata hides it" do
|
||||
document =
|
||||
:parrhesia
|
||||
|> Application.get_env(:listeners, %{})
|
||||
|> Keyword.fetch!(:public)
|
||||
|> then(&Listener.from_opts(listener: &1))
|
||||
|> RelayInfo.document()
|
||||
|
||||
refute Map.has_key?(document, "version")
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user