Skip to content

Commit

Permalink
fix: add catch all clause
Browse files Browse the repository at this point in the history
  • Loading branch information
J0 committed May 2, 2024
1 parent dbb48ff commit 50f9206
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
4 changes: 4 additions & 0 deletions lib/supavisor/helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 31 additions & 2 deletions test/supavisor/helpers_test.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,33 @@
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
secret = "SCRAM-SHA-256$4000:salt$storedKey:serverKey"
user = "user@example.com"
expected = {:ok,
%{
digest: "SCRAM-SHA-256",
iterations: 4000,
salt: "salt",
stored_key: Base.decode64!("storedKey"),
server_key: Base.decode64!("serverKey"),
user: user
}}
assert Helpers.parse_secret(secret, user) == expected
end

test "parses md5 secrets correctly" do
secret = "md5supersecret"
user = "user@example.com"
expected = {:ok, %{digest: :md5, secret: "supersecret", user: user}}
assert Helpers.parse_secret("md5" <> secret, 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

0 comments on commit 50f9206

Please sign in to comment.