diff --git a/VERSION b/VERSION index da44c7f3..3baec790 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.1.50 +1.1.51 diff --git a/lib/supavisor/helpers.ex b/lib/supavisor/helpers.ex index bdb615c8..26b97ef4 100644 --- a/lib/supavisor/helpers.ex +++ b/lib/supavisor/helpers.ex @@ -134,6 +134,10 @@ defmodule Supavisor.Helpers do {:ok, %{digest: :md5, secret: secret, user: user}} end + def parse_secret(_secret, _user) do + {:error, "Unsupported or invalid secret format"} + end + def parse_postgres_secret(_), do: {:error, "Digest not supported"} ## Internal functions diff --git a/test/supavisor/helpers_test.exs b/test/supavisor/helpers_test.exs index a8b38147..3966d1ad 100644 --- a/test/supavisor/helpers_test.exs +++ b/test/supavisor/helpers_test.exs @@ -1,4 +1,38 @@ defmodule Supavisor.HelpersTest do - use ExUnit.Case - doctest Supavisor.Helpers + use ExUnit.Case, async: true + alias Supavisor.Helpers + + describe "parse_secret/2" do + test "parses SCRAM-SHA-256 secrets correctly" do + encoded_stored_key = Base.encode64("storedKey") + encoded_server_key = Base.encode64("serverKey") + secret = "SCRAM-SHA-256$4000:salt$#{encoded_stored_key}:#{encoded_server_key}" + user = "user@example.com" + + expected = + {:ok, + %{ + digest: "SCRAM-SHA-256", + iterations: 4000, + salt: "salt", + stored_key: "storedKey", + server_key: "serverKey", + user: user + }} + + assert Helpers.parse_secret(secret, user) == expected + end + + test "parses md5 secrets correctly" do + secret = "supersecret" + user = "user@example.com" + expected = {:ok, %{digest: :md5, secret: secret, user: user}} + assert Helpers.parse_secret("md5supersecret", user) == expected + end + + test "returns error for unsupported or invalid secret formats" do + assert Helpers.parse_secret("unsupported_secret", "user@example.com") == + {:error, "Unsupported or invalid secret format"} + end + end end