Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow secret to be an empty string #38

Merged
merged 2 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
PG_CFLAGS = -std=c99 -Werror -Wno-declaration-after-statement
EXTENSION = supabase_vault
EXTVERSION = 0.3.0
EXTVERSION = 0.3.1

DATA = $(wildcard sql/*--*.sql)

Expand Down
1 change: 1 addition & 0 deletions sql/supabase_vault--0.3.0--0.3.1.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-- no SQL changes in 0.3.1
2 changes: 1 addition & 1 deletion src/pgsodium.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ pgsodium_crypto_aead_det_decrypt_by_id (PG_FUNCTION_ARGS)
{
nonce = NULL;
}
ERRORIF (VARSIZE_ANY_EXHDR (ciphertext) <=
ERRORIF (VARSIZE_ANY_EXHDR (ciphertext) <
crypto_aead_det_xchacha20_ABYTES, "%s: invalid message");
result_len =
VARSIZE_ANY_EXHDR (ciphertext) - crypto_aead_det_xchacha20_ABYTES;
Expand Down
26 changes: 25 additions & 1 deletion test/expected/test.out
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,33 @@ select results_eq(
ok 5 - bob can query an updated secret
(1 row)

reset role;
truncate vault.secrets;
do $$
begin
perform vault.create_secret(
new_secret := '',
new_name := 'empty_secret'
);
end
$$;
select results_eq(
$test$
select decrypted_secret collate "default"
from vault.decrypted_secrets
where name = 'empty_secret'
$test$,
$results$values ('')$results$,
'secret can be an empty string'
);
results_eq
--------------------------------------
ok 6 - secret can be an empty string
(1 row)

select * from finish();
finish
--------
1..5
1..6
(1 row)

22 changes: 22 additions & 0 deletions test/sql/test.sql
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,26 @@ select results_eq(
$results$values ('fooz', 'barz', 'bazz')$results$,
'bob can query an updated secret');

reset role;
truncate vault.secrets;

do $$
begin
perform vault.create_secret(
new_secret := '',
new_name := 'empty_secret'
);
end
$$;

select results_eq(
$test$
select decrypted_secret collate "default"
from vault.decrypted_secrets
where name = 'empty_secret'
$test$,
$results$values ('')$results$,
'secret can be an empty string'
);

select * from finish();
Loading