From 9ecfdc722adf5d21e9423a0ade0682c004770b94 Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Thu, 7 Mar 2024 14:42:25 +0100 Subject: [PATCH] fix currentContext resp. define Context and fix related fixme --- .../rbac/rbacdef/InsertTriggerGenerator.java | 2 +- src/main/resources/db/changelog/010-context.sql | 15 ++++++++------- .../db/changelog/113-test-customer-rbac.sql | 2 +- .../db/changelog/123-test-package-rbac.sql | 4 ++-- src/test/resources/application.yml | 4 ++-- 5 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/main/java/net/hostsharing/hsadminng/rbac/rbacdef/InsertTriggerGenerator.java b/src/main/java/net/hostsharing/hsadminng/rbac/rbacdef/InsertTriggerGenerator.java index d5266ae9..1f48d045 100644 --- a/src/main/java/net/hostsharing/hsadminng/rbac/rbacdef/InsertTriggerGenerator.java +++ b/src/main/java/net/hostsharing/hsadminng/rbac/rbacdef/InsertTriggerGenerator.java @@ -48,7 +48,7 @@ public class InsertTriggerGenerator { permissionUuid uuid; roleUuid uuid; begin - call defineContext('generated Liquibase: create INSERT INTO ${rawSubTableName} permissions for the related ${rawSuperTableName} rows'); + call defineContext('create INSERT INTO ${rawSubTableName} permissions for the related ${rawSuperTableName} rows'); FOR row IN SELECT * FROM ${rawSuperTableName} LOOP diff --git a/src/main/resources/db/changelog/010-context.sql b/src/main/resources/db/changelog/010-context.sql index 521e4812..d1129184 100644 --- a/src/main/resources/db/changelog/010-context.sql +++ b/src/main/resources/db/changelog/010-context.sql @@ -23,13 +23,15 @@ end; $$; Defines the transaction context. */ create or replace procedure defineContext( - currentTask varchar, - currentRequest varchar = null, + currentTask varchar(96), + currentRequest varchar(512) = null, currentUser varchar = null, assumedRoles varchar = null ) language plpgsql as $$ begin + assert length(currentTask) <= 96, 'currentTask must not be longer than 96 characters'; + assert length(currentTask) > 8, 'currentTask must be at least 8 characters long'; execute format('set local hsadminng.currentTask to %L', currentTask); currentRequest := coalesce(currentRequest, ''); @@ -66,11 +68,10 @@ begin when others then currentTask := null; end; --- FIXME: uncomment --- if (currentTask is null or currentTask = '') then --- raise exception '[401] currentTask must be defined, please call `defineContext(...)`'; --- end if; - return 'unknown'; -- FIXME: currentTask; + if (currentTask is null or currentTask = '') then + raise exception '[401] currentTask must be defined, please call `defineContext(...)`'; + end if; + return currentTask; end; $$; --// diff --git a/src/main/resources/db/changelog/113-test-customer-rbac.sql b/src/main/resources/db/changelog/113-test-customer-rbac.sql index 3149ccc9..f62be84b 100644 --- a/src/main/resources/db/changelog/113-test-customer-rbac.sql +++ b/src/main/resources/db/changelog/113-test-customer-rbac.sql @@ -1,5 +1,5 @@ --liquibase formatted sql --- This code generated was by RbacViewPostgresGenerator at 2024-03-07T12:25:36.376742633. +-- This code generated was by RbacViewPostgresGenerator at 2024-03-07T14:39:25.446629076. -- ============================================================================ diff --git a/src/main/resources/db/changelog/123-test-package-rbac.sql b/src/main/resources/db/changelog/123-test-package-rbac.sql index b32a98dc..2d4ac417 100644 --- a/src/main/resources/db/changelog/123-test-package-rbac.sql +++ b/src/main/resources/db/changelog/123-test-package-rbac.sql @@ -1,5 +1,5 @@ --liquibase formatted sql --- This code generated was by RbacViewPostgresGenerator at 2024-03-07T12:25:36.422351715. +-- This code generated was by RbacViewPostgresGenerator at 2024-03-07T14:39:25.488573238. -- ============================================================================ @@ -157,7 +157,7 @@ do language plpgsql $$ permissionUuid uuid; roleUuid uuid; begin - call defineContext('generated Liquibase: create INSERT INTO test_package permissions for the related test_customer rows'); + call defineContext('create INSERT INTO test_package permissions for the related test_customer rows'); FOR row IN SELECT * FROM test_customer LOOP diff --git a/src/test/resources/application.yml b/src/test/resources/application.yml index 01e283b9..a4f570f9 100644 --- a/src/test/resources/application.yml +++ b/src/test/resources/application.yml @@ -4,8 +4,8 @@ spring: platform: postgres datasource: - url-tc: jdbc:tc:postgresql:15.5-bookworm:///spring_boot_testcontainers - url: jdbc:postgresql://localhost:5432/postgres + url: jdbc:tc:postgresql:15.5-bookworm:///spring_boot_testcontainers + url-local: jdbc:postgresql://localhost:5432/postgres username: postgres password: password