-
-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: handle invalid secret formats in parse_secret (#326)
- Loading branch information
Showing
3 changed files
with
41 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
1.1.50 | ||
1.1.51 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 = "[email protected]" | ||
|
||
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 = "[email protected]" | ||
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", "[email protected]") == | ||
{:error, "Unsupported or invalid secret format"} | ||
end | ||
end | ||
end |