Skip to content

Commit

Permalink
Run tests with different users.
Browse files Browse the repository at this point in the history
In the real world, people don't use superusers and DBAs will likely not
want just anyone adding system versioning and whatnot.  So run the tests
as realistic users in order to better simulate the real world.
  • Loading branch information
Vik Fearing committed Sep 21, 2020
1 parent dedb49a commit b3e7d54
Show file tree
Hide file tree
Showing 38 changed files with 91 additions and 0 deletions.
2 changes: 2 additions & 0 deletions expected/drop_protection.out
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ FROM pg_settings WHERE name = 'server_version_num';
f
(1 row)

/* Run tests as unprivileged user */
SET ROLE TO periods_unprivileged_user;
/* Make sure nobody drops the objects we keep track of in our catalogs. */
CREATE TYPE integerrange AS RANGE (SUBTYPE = integer);
CREATE TABLE dp (
Expand Down
2 changes: 2 additions & 0 deletions expected/drop_protection_1.out
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ FROM pg_settings WHERE name = 'server_version_num';
t
(1 row)

/* Run tests as unprivileged user */
SET ROLE TO periods_unprivileged_user;
/* Make sure nobody drops the objects we keep track of in our catalogs. */
CREATE TYPE integerrange AS RANGE (SUBTYPE = integer);
CREATE TABLE dp (
Expand Down
2 changes: 2 additions & 0 deletions expected/excluded_columns.out
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ FROM pg_settings WHERE name = 'server_version_num';
f
(1 row)

/* Run tests as unprivileged user */
SET ROLE TO periods_unprivileged_user;
CREATE TABLE excl (
value text NOT NULL,
null_value integer,
Expand Down
2 changes: 2 additions & 0 deletions expected/excluded_columns_1.out
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ FROM pg_settings WHERE name = 'server_version_num';
t
(1 row)

/* Run tests as unprivileged user */
SET ROLE TO periods_unprivileged_user;
CREATE TABLE excl (
value text NOT NULL,
null_value integer,
Expand Down
2 changes: 2 additions & 0 deletions expected/for_portion_of.out
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ FROM pg_settings WHERE name = 'server_version_num';
f | f
(1 row)

/* Run tests as unprivileged user */
SET ROLE TO periods_unprivileged_user;
/*
* Create a sequence to test non-serial primary keys. This actually tests
* things like uuid primary keys, but makes for reproducible test cases.
Expand Down
2 changes: 2 additions & 0 deletions expected/for_portion_of_1.out
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ FROM pg_settings WHERE name = 'server_version_num';
f | t
(1 row)

/* Run tests as unprivileged user */
SET ROLE TO periods_unprivileged_user;
/*
* Create a sequence to test non-serial primary keys. This actually tests
* things like uuid primary keys, but makes for reproducible test cases.
Expand Down
2 changes: 2 additions & 0 deletions expected/for_portion_of_2.out
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ FROM pg_settings WHERE name = 'server_version_num';
t | t
(1 row)

/* Run tests as unprivileged user */
SET ROLE TO periods_unprivileged_user;
/*
* Create a sequence to test non-serial primary keys. This actually tests
* things like uuid primary keys, but makes for reproducible test cases.
Expand Down
2 changes: 2 additions & 0 deletions expected/health_checks.out
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ FROM pg_settings WHERE name = 'server_version_num';
f
(1 row)

/* Run tests as unprivileged user */
SET ROLE TO periods_unprivileged_user;
/* Ensure tables with periods are persistent */
CREATE UNLOGGED TABLE log (id bigint, s date, e date);
SELECT periods.add_period('log', 'p', 's', 'e'); -- fails
Expand Down
2 changes: 2 additions & 0 deletions expected/health_checks_1.out
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ FROM pg_settings WHERE name = 'server_version_num';
t
(1 row)

/* Run tests as unprivileged user */
SET ROLE TO periods_unprivileged_user;
/* Ensure tables with periods are persistent */
CREATE UNLOGGED TABLE log (id bigint, s date, e date);
SELECT periods.add_period('log', 'p', 's', 'e'); -- fails
Expand Down
3 changes: 3 additions & 0 deletions expected/install.out
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ WHERE extname = 'periods';
1.2
(1 row)

DROP ROLE periods_unprivileged_user;
ERROR: role "periods_unprivileged_user" does not exist
CREATE ROLE periods_unprivileged_user;
2 changes: 2 additions & 0 deletions expected/issues.out
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ FROM pg_settings WHERE name = 'server_version_num';
f
(1 row)

/* Run tests as unprivileged user */
SET ROLE TO periods_unprivileged_user;
/* https://github.com/xocolatl/periods/issues/5 */
CREATE TABLE issue5 (
id integer GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
Expand Down
2 changes: 2 additions & 0 deletions expected/issues_1.out
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ FROM pg_settings WHERE name = 'server_version_num';
t
(1 row)

/* Run tests as unprivileged user */
SET ROLE TO periods_unprivileged_user;
/* https://github.com/xocolatl/periods/issues/5 */
CREATE TABLE issue5 (
id integer GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
Expand Down
2 changes: 2 additions & 0 deletions expected/periods.out
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ FROM pg_settings WHERE name = 'server_version_num';
f
(1 row)

/* Run tests as unprivileged user */
SET ROLE TO periods_unprivileged_user;
/* Basic period definitions with dates */
CREATE TABLE basic (val text, s date, e date);
TABLE periods.periods;
Expand Down
2 changes: 2 additions & 0 deletions expected/periods_1.out
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ FROM pg_settings WHERE name = 'server_version_num';
t
(1 row)

/* Run tests as unprivileged user */
SET ROLE TO periods_unprivileged_user;
/* Basic period definitions with dates */
CREATE TABLE basic (val text, s date, e date);
TABLE periods.periods;
Expand Down
2 changes: 2 additions & 0 deletions expected/predicates.out
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* Run tests as unprivileged user */
SET ROLE TO periods_unprivileged_user;
CREATE TABLE preds (s integer, e integer);
SELECT periods.add_period('preds', 'p', 's', 'e');
add_period
Expand Down
2 changes: 2 additions & 0 deletions expected/rename_following.out
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ FROM pg_settings WHERE name = 'server_version_num';
f
(1 row)

/* Run tests as unprivileged user */
SET ROLE TO periods_unprivileged_user;
/*
* If anything we store as "name" is renamed, we need to update our catalogs or
* throw an error.
Expand Down
2 changes: 2 additions & 0 deletions expected/rename_following_1.out
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ FROM pg_settings WHERE name = 'server_version_num';
t
(1 row)

/* Run tests as unprivileged user */
SET ROLE TO periods_unprivileged_user;
/*
* If anything we store as "name" is renamed, we need to update our catalogs or
* throw an error.
Expand Down
2 changes: 2 additions & 0 deletions expected/system_time_periods.out
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ FROM pg_settings WHERE name = 'server_version_num';
f
(1 row)

/* Run tests as unprivileged user */
SET ROLE TO periods_unprivileged_user;
/* SYSTEM_TIME with date */
BEGIN;
SELECT transaction_timestamp()::date AS xd,
Expand Down
2 changes: 2 additions & 0 deletions expected/system_time_periods_1.out
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ FROM pg_settings WHERE name = 'server_version_num';
t
(1 row)

/* Run tests as unprivileged user */
SET ROLE TO periods_unprivileged_user;
/* SYSTEM_TIME with date */
BEGIN;
SELECT transaction_timestamp()::date AS xd,
Expand Down
2 changes: 2 additions & 0 deletions expected/system_versioning.out
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ FROM pg_settings WHERE name = 'server_version_num';
f
(1 row)

/* Run tests as unprivileged user */
SET ROLE TO periods_unprivileged_user;
/* Basic SYSTEM VERSIONING */
CREATE TABLE sysver (val text, flap boolean);
SELECT periods.add_system_time_period('sysver', excluded_column_names => ARRAY['flap']);
Expand Down
2 changes: 2 additions & 0 deletions expected/system_versioning_1.out
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ FROM pg_settings WHERE name = 'server_version_num';
t
(1 row)

/* Run tests as unprivileged user */
SET ROLE TO periods_unprivileged_user;
/* Basic SYSTEM VERSIONING */
CREATE TABLE sysver (val text, flap boolean);
SELECT periods.add_system_time_period('sysver', excluded_column_names => ARRAY['flap']);
Expand Down
1 change: 1 addition & 0 deletions expected/uninstall.out
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
DROP EXTENSION periods;
DROP ROLE periods_unprivileged_user;
2 changes: 2 additions & 0 deletions expected/unique_foreign.out
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ FROM pg_settings WHERE name = 'server_version_num';
f
(1 row)

/* Run tests as unprivileged user */
SET ROLE TO periods_unprivileged_user;
-- Unique keys are already pretty much guaranteed by the underlying features of
-- PostgreSQL, but test them anyway.
CREATE TABLE uk (id integer, s integer, e integer, CONSTRAINT uk_pkey PRIMARY KEY (id, s, e));
Expand Down
2 changes: 2 additions & 0 deletions expected/unique_foreign_1.out
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ FROM pg_settings WHERE name = 'server_version_num';
t
(1 row)

/* Run tests as unprivileged user */
SET ROLE TO periods_unprivileged_user;
-- Unique keys are already pretty much guaranteed by the underlying features of
-- PostgreSQL, but test them anyway.
CREATE TABLE uk (id integer, s integer, e integer, CONSTRAINT uk_pkey PRIMARY KEY (id, s, e));
Expand Down
6 changes: 6 additions & 0 deletions periods--1.2.sql
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ CREATE TABLE periods.periods (

CHECK (start_column_name <> end_column_name)
);
GRANT SELECT ON TABLE periods.periods TO PUBLIC;
SELECT pg_catalog.pg_extension_config_dump('periods.periods', '');

CREATE TABLE periods.system_time_periods (
Expand All @@ -48,6 +49,7 @@ CREATE TABLE periods.system_time_periods (

CHECK (period_name = 'system_time')
);
GRANT SELECT ON TABLE periods.system_time_periods TO PUBLIC;
SELECT pg_catalog.pg_extension_config_dump('periods.system_time_periods', '');

COMMENT ON TABLE periods.periods IS 'The main catalog for periods. All "DDL" operations for periods must first take an exclusive lock on this table.';
Expand Down Expand Up @@ -75,6 +77,7 @@ CREATE TABLE periods.for_portion_views (

UNIQUE (view_name)
);
GRANT SELECT ON TABLE periods.for_portion_views TO PUBLIC;
SELECT pg_catalog.pg_extension_config_dump('periods.for_portion_views', '');

CREATE TABLE periods.unique_keys (
Expand All @@ -89,6 +92,7 @@ CREATE TABLE periods.unique_keys (

FOREIGN KEY (table_name, period_name) REFERENCES periods.periods
);
GRANT SELECT ON TABLE periods.unique_keys TO PUBLIC;
SELECT pg_catalog.pg_extension_config_dump('periods.unique_keys', '');

COMMENT ON TABLE periods.unique_keys IS 'A registry of UNIQUE/PRIMARY keys using periods WITHOUT OVERLAPS';
Expand All @@ -115,6 +119,7 @@ CREATE TABLE periods.foreign_keys (
CHECK (delete_action NOT IN ('CASCADE', 'SET NULL', 'SET DEFAULT')),
CHECK (update_action NOT IN ('CASCADE', 'SET NULL', 'SET DEFAULT'))
);
GRANT SELECT ON TABLE periods.foreign_keys TO PUBLIC;
SELECT pg_catalog.pg_extension_config_dump('periods.foreign_keys', '');

COMMENT ON TABLE periods.foreign_keys IS 'A registry of foreign keys using periods WITHOUT OVERLAPS';
Expand Down Expand Up @@ -144,6 +149,7 @@ CREATE TABLE periods.system_versioning (
UNIQUE (func_between_symmetric),
UNIQUE (func_from_to)
);
GRANT SELECT ON TABLE periods.system_versioning TO PUBLIC;
SELECT pg_catalog.pg_extension_config_dump('periods.system_versioning', '');

COMMENT ON TABLE periods.system_versioning IS 'A registry of tables with SYSTEM VERSIONING';
Expand Down
3 changes: 3 additions & 0 deletions sql/drop_protection.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
SELECT setting::integer < 90600 AS pre_96
FROM pg_settings WHERE name = 'server_version_num';

/* Run tests as unprivileged user */
SET ROLE TO periods_unprivileged_user;

/* Make sure nobody drops the objects we keep track of in our catalogs. */

CREATE TYPE integerrange AS RANGE (SUBTYPE = integer);
Expand Down
3 changes: 3 additions & 0 deletions sql/excluded_columns.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
SELECT setting::integer < 90600 AS pre_96
FROM pg_settings WHERE name = 'server_version_num';

/* Run tests as unprivileged user */
SET ROLE TO periods_unprivileged_user;

CREATE TABLE excl (
value text NOT NULL,
null_value integer,
Expand Down
3 changes: 3 additions & 0 deletions sql/for_portion_of.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ SELECT setting::integer < 100000 AS pre_10,
setting::integer < 120000 AS pre_12
FROM pg_settings WHERE name = 'server_version_num';

/* Run tests as unprivileged user */
SET ROLE TO periods_unprivileged_user;

/*
* Create a sequence to test non-serial primary keys. This actually tests
* things like uuid primary keys, but makes for reproducible test cases.
Expand Down
3 changes: 3 additions & 0 deletions sql/health_checks.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
SELECT setting::integer < 90600 AS pre_96
FROM pg_settings WHERE name = 'server_version_num';

/* Run tests as unprivileged user */
SET ROLE TO periods_unprivileged_user;

/* Ensure tables with periods are persistent */
CREATE UNLOGGED TABLE log (id bigint, s date, e date);
SELECT periods.add_period('log', 'p', 's', 'e'); -- fails
Expand Down
3 changes: 3 additions & 0 deletions sql/install.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ ALTER EXTENSION periods UPDATE TO '1.2';
SELECT extversion
FROM pg_extension
WHERE extname = 'periods';

DROP ROLE periods_unprivileged_user;
CREATE ROLE periods_unprivileged_user;
3 changes: 3 additions & 0 deletions sql/issues.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
SELECT setting::integer < 100000 AS pre_10
FROM pg_settings WHERE name = 'server_version_num';

/* Run tests as unprivileged user */
SET ROLE TO periods_unprivileged_user;

/* https://github.com/xocolatl/periods/issues/5 */

CREATE TABLE issue5 (
Expand Down
3 changes: 3 additions & 0 deletions sql/periods.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
SELECT setting::integer < 130000 AS pre_13
FROM pg_settings WHERE name = 'server_version_num';

/* Run tests as unprivileged user */
SET ROLE TO periods_unprivileged_user;

/* Basic period definitions with dates */
CREATE TABLE basic (val text, s date, e date);
TABLE periods.periods;
Expand Down
3 changes: 3 additions & 0 deletions sql/predicates.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/* Run tests as unprivileged user */
SET ROLE TO periods_unprivileged_user;

CREATE TABLE preds (s integer, e integer);
SELECT periods.add_period('preds', 'p', 's', 'e');

Expand Down
3 changes: 3 additions & 0 deletions sql/rename_following.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
SELECT setting::integer < 90600 AS pre_96
FROM pg_settings WHERE name = 'server_version_num';

/* Run tests as unprivileged user */
SET ROLE TO periods_unprivileged_user;

/*
* If anything we store as "name" is renamed, we need to update our catalogs or
* throw an error.
Expand Down
3 changes: 3 additions & 0 deletions sql/system_time_periods.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
SELECT setting::integer < 90600 AS pre_96
FROM pg_settings WHERE name = 'server_version_num';

/* Run tests as unprivileged user */
SET ROLE TO periods_unprivileged_user;

/* SYSTEM_TIME with date */

BEGIN;
Expand Down
3 changes: 3 additions & 0 deletions sql/system_versioning.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
SELECT setting::integer < 120000 AS pre_12
FROM pg_settings WHERE name = 'server_version_num';

/* Run tests as unprivileged user */
SET ROLE TO periods_unprivileged_user;

/* Basic SYSTEM VERSIONING */

CREATE TABLE sysver (val text, flap boolean);
Expand Down
1 change: 1 addition & 0 deletions sql/uninstall.sql
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
DROP EXTENSION periods;
DROP ROLE periods_unprivileged_user;
3 changes: 3 additions & 0 deletions sql/unique_foreign.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
SELECT setting::integer < 90600 AS pre_96
FROM pg_settings WHERE name = 'server_version_num';

/* Run tests as unprivileged user */
SET ROLE TO periods_unprivileged_user;

-- Unique keys are already pretty much guaranteed by the underlying features of
-- PostgreSQL, but test them anyway.
CREATE TABLE uk (id integer, s integer, e integer, CONSTRAINT uk_pkey PRIMARY KEY (id, s, e));
Expand Down

0 comments on commit b3e7d54

Please sign in to comment.