Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-- migrate:up
ALTER ROLE authenticated SET session_preload_libraries = 'safeupdate';
ALTER ROLE anon SET session_preload_libraries = 'safeupdate';
load 'safeupdate';

SET safeupdate.enabled=0;

-- migrate:down

6 changes: 6 additions & 0 deletions nix/ext/tests/pg_safeupdate.nix
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ self.inputs.nixpkgs.lib.nixos.runTest {
enable = true;
package = (postgresqlWithExtension psql_15);
settings = (installedExtension "15").defaultSettings or { };
initialScript = pkgs.writeText "init-postgres" ''
CREATE ROLE authenticated NOLOGIN NOINHERIT;
GRANT USAGE ON SCHEMA public TO authenticated;
CREATE ROLE anon NOLOGIN NOINHERIT;
GRANT USAGE ON SCHEMA public TO anon;
'';
};

specialisation.postgresql17.configuration = {
Expand Down
5 changes: 5 additions & 0 deletions nix/tests/expected/pg-safeupdate.out
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,10 @@ create table v.foo(
update v.foo
set val = 'bar';
ERROR: UPDATE requires a WHERE clause
grant all on schema v to authenticated;
set role authenticated;
delete from v.foo;
ERROR: DELETE requires a WHERE clause
reset role;
drop schema v cascade;
NOTICE: drop cascades to table v.foo
4 changes: 2 additions & 2 deletions nix/tests/expected/roles.out
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ where rolname not in ('pg_create_subscription', 'pg_maintain', 'pg_use_reserved_
order by rolname;
rolname | rolconfig
----------------------------+---------------------------------------------------------------------------------
anon | {statement_timeout=3s}
authenticated | {statement_timeout=8s}
anon | {statement_timeout=3s,session_preload_libraries=safeupdate}
authenticated | {statement_timeout=8s,session_preload_libraries=safeupdate}
authenticator | {session_preload_libraries=safeupdate,statement_timeout=8s,lock_timeout=8s}
dashboard_user |
pg_checkpoint |
Expand Down
8 changes: 8 additions & 0 deletions nix/tests/sql/pg-safeupdate.sql
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,12 @@ create table v.foo(
update v.foo
set val = 'bar';

grant all on schema v to authenticated;
set role authenticated;

delete from v.foo;
reset role;
drop schema v cascade;



Loading