Add URI matchers
This commit is contained in:
parent
368b22fd2f
commit
9723264fe5
3 changed files with 46 additions and 4 deletions
|
@ -34,7 +34,9 @@ defmodule Pleroma.Web.Plugs.OAuthScopesPlug do
|
|||
permissions = Enum.join(missing_scopes, " #{op} ")
|
||||
|
||||
error_message =
|
||||
dgettext("errors", "Insufficient permissions: %{permissions}.", permissions: permissions)
|
||||
dgettext("errors", "Insufficient permissions: %{permissions}.",
|
||||
permissions: permissions
|
||||
)
|
||||
|
||||
conn
|
||||
|> put_resp_content_type("application/json")
|
||||
|
|
|
@ -6,16 +6,19 @@ defmodule Pleroma.MFA.TOTPTest do
|
|||
use Pleroma.DataCase, async: true
|
||||
|
||||
alias Pleroma.MFA.TOTP
|
||||
import Pleroma.Test.URIHelpers
|
||||
|
||||
test "create provisioning_uri to generate qrcode" do
|
||||
uri =
|
||||
TOTP.provisioning_uri("test-secrcet", "test@example.com",
|
||||
TOTP.provisioning_uri("test-secret", "test@example.com",
|
||||
issuer: "Plerome-42",
|
||||
digits: 8,
|
||||
period: 60
|
||||
)
|
||||
|
||||
assert uri ==
|
||||
"otpauth://totp/test@example.com?digits=8&issuer=Plerome-42&period=60&secret=test-secrcet"
|
||||
assert_uri_equals(
|
||||
uri,
|
||||
"otpauth://totp/test@example.com?digits=8&issuer=Plerome-42&period=60&secret=test-secret"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
|
37
test/support/uri_helpers.ex
Normal file
37
test/support/uri_helpers.ex
Normal file
|
@ -0,0 +1,37 @@
|
|||
defmodule Pleroma.Test.URIHelpers do
|
||||
import ExUnit.Assertions
|
||||
|
||||
def assert_uri_equals(%URI{} = uri_a, %URI{} = uri_b) do
|
||||
[:scheme, :authority, :userinfo, :host, :port, :path, :fragment]
|
||||
|> Enum.each(fn attribute ->
|
||||
if Map.get(uri_a, attribute) == Map.get(uri_b, attribute) do
|
||||
:ok
|
||||
else
|
||||
flunk("Expected #{uri_a} to match #{uri_b} - #{attribute} does not match")
|
||||
end
|
||||
end)
|
||||
|
||||
# And the query string
|
||||
query_a = URI.decode_query(uri_a.query)
|
||||
query_b = URI.decode_query(uri_b.query)
|
||||
|
||||
if query_a == query_b do
|
||||
:ok
|
||||
else
|
||||
flunk(
|
||||
"Expected #{uri_a} to match #{uri_b} - query parameters #{inspect(query_a)} do not match #{inspect(query_b)}"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
def assert_uri_equals(uri_a, uri_b) when is_binary(uri_a) do
|
||||
uri_a
|
||||
|> URI.parse()
|
||||
|> assert_uri_equals(uri_b)
|
||||
end
|
||||
|
||||
def assert_uri_equals(%URI{} = uri_a, uri_b) when is_binary(uri_b) do
|
||||
uri_b = URI.parse(uri_b)
|
||||
assert_uri_equals(uri_a, uri_b)
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue