1
0
Fork 1
mirror of https://akkoma.dev/AkkomaGang/akkoma.git synced 2024-12-25 04:53:06 +00:00

Merge remote-tracking branch 'remotes/origin/develop' into auth-improvements

This commit is contained in:
Ivan Tashkinov 2020-11-28 21:51:27 +03:00
commit 50e47a215f
6 changed files with 68 additions and 21 deletions

View file

@ -228,7 +228,7 @@ arm:
artifacts: *release-artifacts
only: *release-only
tags:
- arm32
- arm32-specified
image: arm32v7/elixir:1.10.3
cache: *release-cache
variables: *release-variables
@ -240,7 +240,7 @@ arm-musl:
artifacts: *release-artifacts
only: *release-only
tags:
- arm32
- arm32-specified
image: arm32v7/elixir:1.10.3-alpine
cache: *release-cache
variables: *release-variables

View file

@ -147,16 +147,6 @@
"SameSite=Lax"
]
config :pleroma, :fed_sockets,
enabled: false,
connection_duration: :timer.hours(8),
rejection_duration: :timer.minutes(15),
fed_socket_fetches: [
default: 12_000,
interval: 3_000,
lazy: false
]
# Configures Elixir's Logger
config :logger, :console,
level: :debug,

View file

@ -19,11 +19,6 @@
level: :warn,
format: "\n[$level] $message\n"
config :pleroma, :fed_sockets,
enabled: false,
connection_duration: 5,
rejection_duration: 5
config :pleroma, :auth, oauth_consumer_strategies: []
config :pleroma, Pleroma.Upload,

View file

@ -22,8 +22,8 @@ def start_pleroma do
Pleroma.Application.limiters_setup()
Application.put_env(:phoenix, :serve_endpoints, false, persistent: true)
if Pleroma.Config.get(:env) != :test do
Application.put_env(:logger, :console, level: :debug)
unless System.get_env("DEBUG") do
Logger.remove_backend(:console)
end
adapter = Application.get_env(:tesla, :adapter)

View file

@ -7,8 +7,22 @@ defmodule Pleroma.Web.Plugs.DigestPlug do
require Logger
def read_body(conn, opts) do
digest_algorithm =
with [digest_header] <- Conn.get_req_header(conn, "digest") do
digest_header
|> String.split("=", parts: 2)
|> List.first()
else
_ -> "SHA-256"
end
unless String.downcase(digest_algorithm) == "sha-256" do
raise ArgumentError,
message: "invalid value for digest algorithm, got: #{digest_algorithm}"
end
{:ok, body, conn} = Conn.read_body(conn, opts)
digest = "SHA-256=" <> (:crypto.hash(:sha256, body) |> Base.encode64())
{:ok, body, Conn.assign(conn, :digest, digest)}
encoded_digest = :crypto.hash(:sha256, body) |> Base.encode64()
{:ok, body, Conn.assign(conn, :digest, "#{digest_algorithm}=#{encoded_digest}")}
end
end

View file

@ -0,0 +1,48 @@
defmodule Pleroma.Web.Plugs.DigestPlugTest do
use ExUnit.Case, async: true
use Plug.Test
test "digest algorithm is taken from digest header" do
body = "{\"hello\": \"world\"}"
digest = "X48E9qOokqqrvdts8nOJRJN3OWDUoyWxBf7kbu9DBPE="
{:ok, ^body, conn} =
:get
|> conn("/", body)
|> put_req_header("content-type", "application/json")
|> put_req_header("digest", "sha-256=" <> digest)
|> Pleroma.Web.Plugs.DigestPlug.read_body([])
assert conn.assigns[:digest] == "sha-256=" <> digest
{:ok, ^body, conn} =
:get
|> conn("/", body)
|> put_req_header("content-type", "application/json")
|> put_req_header("digest", "SHA-256=" <> digest)
|> Pleroma.Web.Plugs.DigestPlug.read_body([])
assert conn.assigns[:digest] == "SHA-256=" <> digest
end
test "error if digest algorithm is invalid" do
body = "{\"hello\": \"world\"}"
digest = "X48E9qOokqqrvdts8nOJRJN3OWDUoyWxBf7kbu9DBPE="
assert_raise ArgumentError, "invalid value for digest algorithm, got: MD5", fn ->
:get
|> conn("/", body)
|> put_req_header("content-type", "application/json")
|> put_req_header("digest", "MD5=" <> digest)
|> Pleroma.Web.Plugs.DigestPlug.read_body([])
end
assert_raise ArgumentError, "invalid value for digest algorithm, got: md5", fn ->
:get
|> conn("/", body)
|> put_req_header("content-type", "application/json")
|> put_req_header("digest", "md5=" <> digest)
|> Pleroma.Web.Plugs.DigestPlug.read_body([])
end
end
end