Skip to content

Commit

Permalink
Change tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vshepard committed Dec 12, 2023
1 parent 2b9c9b1 commit 61d3ff6
Show file tree
Hide file tree
Showing 56 changed files with 13,412 additions and 20,247 deletions.
53 changes: 18 additions & 35 deletions tests/CVE_2018_1058_test.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
import os
import unittest
from .helpers.ptrack_helpers import ProbackupTest, ProbackupException
from .helpers.ptrack_helpers import ProbackupTest

class CVE_2018_1058(ProbackupTest, unittest.TestCase):
class CVE_2018_1058(ProbackupTest):

# @unittest.skip("skip")
def test_basic_default_search_path(self):
""""""
backup_dir = os.path.join(self.tmp_path, self.module_name, self.fname, 'backup')
node = self.make_simple_node(
base_dir=os.path.join(self.module_name, self.fname, 'node'),
set_replication=True)
node = self.pg_node.make_simple('node', checksum=False, set_replication=True)

self.init_pb(backup_dir)
self.add_instance(backup_dir, 'node', node)
self.pb.init()
self.pb.add_instance('node', node)
node.slow_start()

node.safe_psql(
Expand All @@ -26,19 +23,16 @@ def test_basic_default_search_path(self):
"END "
"$$ LANGUAGE plpgsql")

self.backup_node(backup_dir, 'node', node, backup_type='full', options=['--stream'])
self.pb.backup_node('node', node, backup_type='full', options=['--stream'])

# @unittest.skip("skip")
def test_basic_backup_modified_search_path(self):
""""""
backup_dir = os.path.join(self.tmp_path, self.module_name, self.fname, 'backup')
node = self.make_simple_node(
base_dir=os.path.join(self.module_name, self.fname, 'node'),
set_replication=True)
self.set_auto_conf(node, options={'search_path': 'public,pg_catalog'})
node = self.pg_node.make_simple('node', checksum=False, set_replication=True)
node.set_auto_conf(options={'search_path': 'public,pg_catalog'})

self.init_pb(backup_dir)
self.add_instance(backup_dir, 'node', node)
self.pb.init()
self.pb.add_instance('node', node)
node.slow_start()

node.safe_psql(
Expand All @@ -62,7 +56,7 @@ def test_basic_backup_modified_search_path(self):
"$$ LANGUAGE plpgsql; "
"CREATE VIEW public.pg_proc AS SELECT proname FROM public.pg_proc()")

self.backup_node(backup_dir, 'node', node, backup_type='full', options=['--stream'])
self.pb.backup_node('node', node, backup_type='full', options=['--stream'])

log_file = os.path.join(node.logs_dir, 'postgresql.log')
with open(log_file, 'r') as f:
Expand All @@ -73,10 +67,8 @@ def test_basic_backup_modified_search_path(self):
# @unittest.skip("skip")
def test_basic_checkdb_modified_search_path(self):
""""""
node = self.make_simple_node(
base_dir=os.path.join(self.module_name, self.fname, 'node'),
initdb_params=['--data-checksums'])
self.set_auto_conf(node, options={'search_path': 'public,pg_catalog'})
node = self.pg_node.make_simple('node')
node.set_auto_conf(options={'search_path': 'public,pg_catalog'})
node.slow_start()

node.safe_psql(
Expand Down Expand Up @@ -110,20 +102,11 @@ def test_basic_checkdb_modified_search_path(self):
"CREATE VIEW public.pg_namespace AS SELECT * FROM public.pg_namespace();"
)

try:
self.checkdb_node(
self.pb.checkdb_node(
options=[
'--amcheck',
'--skip-block-validation',
'-d', 'postgres', '-p', str(node.port)])
self.assertEqual(
1, 0,
"Expecting Error because amcheck{,_next} not installed\n"
" Output: {0} \n CMD: {1}".format(
repr(self.output), self.cmd))
except ProbackupException as e:
self.assertIn(
"WARNING: Extension 'amcheck' or 'amcheck_next' are not installed in database postgres",
e.message,
"\n Unexpected Error Message: {0}\n CMD: {1}".format(
repr(e.message), self.cmd))
'-d', 'postgres', '-p', str(node.port)],
expect_error="because amcheck{,_next} not installed")
self.assertMessage(contains=
"WARNING: Extension 'amcheck' or 'amcheck_next' are not installed in database postgres")
13 changes: 11 additions & 2 deletions tests/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,21 @@ Run long (time consuming) tests:
export PG_PROBACKUP_LONG=ON
Usage:
sudo echo 0 > /proc/sys/kernel/yama/ptrace_scope
sudo sysctl kernel.yama.ptrace_scope=0 # only active until the next reboot
or
sudo sed -i 's/ptrace_scope = 1/ptrace_scope = 0/' /etc/sysctl.d/10-ptrace.conf # set permanently, needs a reboot to take effect
# see https://www.kernel.org/doc/Documentation/security/Yama.txt for possible implications of setting this parameter permanently
pip install testgres
export PG_CONFIG=/path/to/pg_config
python -m unittest [-v] tests[.specific_module][.class.test]
```

# Environment variables
| Variable | Possible values | Required | Default value | Description |
| - | - | - | - | - |
| KEEP_LOGS | Any | No | Not set | If this variable is set to '1', 'y' or 'Y' then test logs are kept after the successful execution of a test, otherwise test logs are deleted upon the successful execution of a test |
| PROBACKUP_S3_TYPE_FULL_TEST | Not set, minio, VK | No | Not set | If set, specifies the type of the S3 storage for the tests, otherwise signifies to the tests that the storage is not an S3 one |
| PGPROBACKUP_TMP_DIR | File path | No | tmp_dirs | The root of the temporary directory hierarchy where tests store data and logs. Relative paths start from the `tests` directory. |
# Troubleshooting FAQ

## Python tests failure
Expand Down
10 changes: 3 additions & 7 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

from . import init_test, merge_test, option_test, show_test, compatibility_test, \
backup_test, delete_test, delta_test, restore_test, validate_test, \
retention_test, pgpro560_test, pgpro589_test, pgpro2068_test, false_positive_test, replica_test, \
compression_test, page_test, ptrack_test, archive_test, exclude_test, cfs_backup_test, cfs_restore_test, \
cfs_validate_backup_test, auth_test, time_stamp_test, logging_test, \
retention_test, pgpro560_test, pgpro589_test, false_positive_test, replica_test, \
compression_test, page_test, ptrack_test, archive_test, exclude_test, \
auth_test, time_stamp_test, logging_test, \
locking_test, remote_test, external_test, config_test, checkdb_test, set_backup_test, incr_restore_test, \
catchup_test, CVE_2018_1058_test, time_consuming_test

Expand Down Expand Up @@ -35,9 +35,6 @@ def load_tests(loader, tests, pattern):
suite.addTests(loader.loadTestsFromModule(compatibility_test))
suite.addTests(loader.loadTestsFromModule(checkdb_test))
suite.addTests(loader.loadTestsFromModule(config_test))
suite.addTests(loader.loadTestsFromModule(cfs_backup_test))
suite.addTests(loader.loadTestsFromModule(cfs_restore_test))
suite.addTests(loader.loadTestsFromModule(cfs_validate_backup_test))
suite.addTests(loader.loadTestsFromModule(compression_test))
suite.addTests(loader.loadTestsFromModule(delete_test))
suite.addTests(loader.loadTestsFromModule(delta_test))
Expand All @@ -53,7 +50,6 @@ def load_tests(loader, tests, pattern):
suite.addTests(loader.loadTestsFromModule(page_test))
suite.addTests(loader.loadTestsFromModule(pgpro560_test))
suite.addTests(loader.loadTestsFromModule(pgpro589_test))
suite.addTests(loader.loadTestsFromModule(pgpro2068_test))
suite.addTests(loader.loadTestsFromModule(remote_test))
suite.addTests(loader.loadTestsFromModule(replica_test))
suite.addTests(loader.loadTestsFromModule(restore_test))
Expand Down
Loading

0 comments on commit 61d3ff6

Please sign in to comment.