Skip to content

Commit 3aac647

Browse files
committed
WIP Concept
1 parent ca2dc8f commit 3aac647

15 files changed

+298
-0
lines changed

src/bin/pg_resetwal/t/001_basic.pl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
use PostgreSQL::Test::Utils;
99
use Test::More;
1010

11+
if (defined($ENV{TDE_MODE}))
12+
{
13+
plan skip_all => "ASSERT triggers in pg_resetwal";
14+
}
15+
1116
program_help_ok('pg_resetwal');
1217
program_version_ok('pg_resetwal');
1318
program_options_handling_ok('pg_resetwal');

src/bin/pg_resetwal/t/002_corrupted.pl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010
use PostgreSQL::Test::Utils;
1111
use Test::More;
1212

13+
if (defined($ENV{TDE_MODE}))
14+
{
15+
plan skip_all => "ASSERT triggers in pg_resetwal";
16+
}
17+
1318
my $node = PostgreSQL::Test::Cluster->new('main');
1419
$node->init;
1520

src/bin/pg_rewind/t/002_databases.pl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111

1212
use RewindTest;
1313

14+
if (defined($ENV{TDE_MODE}))
15+
{
16+
plan skip_all => "Something weird going on with file modes";
17+
}
18+
1419
sub run_test
1520
{
1621
my $test_mode = shift;

src/test/modules/worker_spi/t/001_worker_spi.pl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
use PostgreSQL::Test::Utils;
99
use Test::More;
1010

11+
if (defined($ENV{TDE_MODE})) {
12+
plan skip_all => "PANIC: could not locate a valid checkpoint record";
13+
}
14+
1115
my $node = PostgreSQL::Test::Cluster->new('mynode');
1216
$node->init;
1317
$node->start;

src/test/perl/PostgreSQL/Test/Cluster.pm

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ use Text::ParseWords qw(shellwords);
115115
use Time::HiRes qw(usleep);
116116
use Scalar::Util qw(blessed);
117117

118+
use if defined($ENV{TDE_MODE}), 'PostgreSQL::Test::TdeCluster';
119+
118120
our ($use_tcp, $test_localhost, $test_pghost, $last_host_assigned,
119121
$last_port_assigned, @all_nodes, $died, $portdir);
120122

@@ -1527,6 +1529,10 @@ sub new
15271529
}
15281530
}
15291531

1532+
if (defined($ENV{TDE_MODE})) {
1533+
bless $node, 'PostgreSQL::Test::TdeCluster';
1534+
}
1535+
15301536
# Add node to list of nodes
15311537
push(@all_nodes, $node);
15321538

Lines changed: 228 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,228 @@
1+
2+
3+
package PostgreSQL::Test::TdeCluster;
4+
5+
use parent 'PostgreSQL::Test::Cluster';
6+
7+
use strict;
8+
use warnings FATAL => 'all';
9+
10+
use PostgreSQL::Test::RecursiveCopy ();
11+
use PostgreSQL::Test::Utils ();
12+
13+
sub init
14+
{
15+
my ($self, %params) = @_;
16+
17+
$self->SUPER::init(%params);
18+
19+
# TODO: This will not be enough for tests that add other preload libraries
20+
$self->append_conf('postgresql.conf', 'shared_preload_libraries = pg_tde');
21+
$self->append_conf('postgresql.conf', 'pg_tde.wal_encrypt = on');
22+
23+
$self->_setup_keyfile;
24+
25+
unless (-e $self->pg_tde_dir)
26+
{
27+
mkdir($self->pg_tde_dir);
28+
$self->_setup_default_key;
29+
PostgreSQL::Test::Utils::chmod_recursive($self->pg_tde_dir, 0700, 0600);
30+
}
31+
32+
PostgreSQL::Test::Utils::run_log([
33+
'pg_tde_change_key_provider',
34+
'-D', $self->data_dir,
35+
'1664',
36+
'global_test_provider',
37+
'file',
38+
$self->pg_tde_keyfile,
39+
]);
40+
}
41+
42+
sub backup
43+
{
44+
my ($self, $backup_name, %params) = @_;
45+
my $backup_dir = $self->backup_dir . '/' . $backup_name;
46+
47+
mkdir $backup_dir or die "mkdir($backup_dir) failed: $!";
48+
49+
PostgreSQL::Test::RecursiveCopy::copypath($self->pg_tde_dir, $backup_dir . '/pg_tde');
50+
PostgreSQL::Test::Utils::chmod_recursive($backup_dir . '/pg_tde', 0750, 0640);
51+
52+
$self->SUPER::backup($backup_name, %params);
53+
}
54+
55+
sub pg_tde_dir
56+
{
57+
my ($self) = @_;
58+
return $self->data_dir . '/pg_tde';
59+
}
60+
61+
sub pg_tde_keyfile
62+
{
63+
my ($self) = @_;
64+
return $self->basedir . '/pg_tde_test_keys';
65+
}
66+
67+
sub _setup_keyfile
68+
{
69+
my ($self) = @_;
70+
71+
$self->_write_binary_file($self->pg_tde_keyfile, $self->_key_provider_file);
72+
73+
}
74+
75+
sub _setup_default_key
76+
{
77+
my ($self, %params) = @_;
78+
79+
$self->_write_binary_file(
80+
$self->pg_tde_dir . '/1664_providers',
81+
$self->_provider_config_file
82+
);
83+
chmod(0600, $self->pg_tde_dir . '/1664_providers');
84+
85+
$self->_write_binary_file(
86+
$self->pg_tde_dir . '/1663_keys',
87+
$self->_default_key_file
88+
);
89+
chmod(0600, $self->pg_tde_dir . '/1663_keys');
90+
}
91+
92+
sub _write_binary_file
93+
{
94+
# TODO: We need a better way since this will break if format changes
95+
# and will not work on ARM.
96+
97+
my ($self, $filename, $data) = @_;
98+
99+
my $fh;
100+
101+
open($fh, '>:raw', $filename) or die("could not create \"$filename\"");
102+
$fh->print($data);
103+
close($fh);
104+
}
105+
106+
107+
sub _provider_config_file {
108+
"\xff\xff\xff\xff\x67\x6c\x6f\x62\x61\x6c\x5f\x74\x65\x73\x74\x5f" .
109+
"\x70\x72\x6f\x76\x69\x64\x65\x72\x00\x00\x00\x00\x00\x00\x00\x00" .
110+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
111+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
112+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
113+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
114+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
115+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
116+
"\x00\x00\x00\x00\x7b\x22\x70\x61\x74\x68\x22\x3a\x22\x50\x4c\x41" .
117+
"\x43\x45\x48\x4f\x4c\x44\x45\x52\x22\x7d\x00\x00\x00\x00\x00\x00" .
118+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
119+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
120+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
121+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
122+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
123+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
124+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
125+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
126+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
127+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
128+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
129+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
130+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
131+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
132+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
133+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
134+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
135+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
136+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
137+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
138+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
139+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
140+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
141+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
142+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
143+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
144+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
145+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
146+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
147+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
148+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
149+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
150+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
151+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
152+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
153+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
154+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
155+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
156+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
157+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
158+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
159+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
160+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
161+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
162+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
163+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
164+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
165+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
166+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
167+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
168+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
169+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
170+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
171+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
172+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
173+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
174+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
175+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
176+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
177+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
178+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
179+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
180+
"\x00\x00\x00\x00\x01\x00\x00\x00";
181+
}
182+
183+
sub _default_key_file {
184+
"\x54\x44\x45\x03\x71\x61\x00\x00\x7f\x06\x00\x00\xff\xff\xff\xff" .
185+
"\xd0\xdf\x9c\x68\x00\x00\x00\x00\xe6\x7b\x05\x00\x00\x00\x00\x00" .
186+
"\x64\x65\x66\x61\x75\x6c\x74\x5f\x74\x65\x73\x74\x5f\x6b\x65\x79" .
187+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
188+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
189+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
190+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
191+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
192+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
193+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
194+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
195+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
196+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
197+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
198+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
199+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
200+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
201+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
202+
"\x43\xfd\x05\xe2\x94\x23\x1c\xfe\xc1\x20\x7f\x47\xd1\xaa\xeb\xf8" .
203+
"\x46\x12\x9c\x12\x69\x3e\xd0\x9e\x8d\xe1\x0b\x73\x53\xcc\xfa\x3d";
204+
}
205+
206+
sub _key_provider_file {
207+
"\x64\x65\x66\x61\x75\x6c\x74\x5f\x74\x65\x73\x74\x5f\x6b\x65\x79" .
208+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
209+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
210+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
211+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
212+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
213+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
214+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
215+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
216+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
217+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
218+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
219+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
220+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
221+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
222+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
223+
"\x3e\xe9\xe6\xc1\x4b\x39\xcd\x2e\x60\x5e\x9e\xf1\xd5\xdf\x93\x50" .
224+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" .
225+
"\x10\x00\x00\x00";
226+
}
227+
228+
1;

src/test/recovery/t/003_recovery_targets.pl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
use Test::More;
1010
use Time::HiRes qw(usleep);
1111

12+
if (defined($ENV{TDE_MODE}))
13+
{
14+
plan skip_all => "ASSERT triggers in pg_resetwal";
15+
}
16+
1217
# Create and test a standby from given backup, with a certain recovery target.
1318
# Choose $until_lsn later than the transaction commit that causes the row
1419
# count to reach $num_rows, yet not later than the recovery target.

src/test/recovery/t/009_twophase.pl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
use PostgreSQL::Test::Utils;
1010
use Test::More;
1111

12+
if (defined($ENV{TDE_MODE}))
13+
{
14+
plan skip_all => "ASSERT triggers in critical section";
15+
}
16+
1217
my $psql_out = '';
1318
my $psql_rc = '';
1419

src/test/recovery/t/013_crash_restart.pl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717
use PostgreSQL::Test::Utils;
1818
use Test::More;
1919

20+
if (defined($ENV{TDE_MODE}))
21+
{
22+
plan skip_all => "could not locate a valid checkpoint record";
23+
}
24+
2025
my $psql_timeout = IPC::Run::timer($PostgreSQL::Test::Utils::timeout_default);
2126

2227
my $node = PostgreSQL::Test::Cluster->new('primary');

src/test/recovery/t/019_replslot_limit.pl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
use Test::More;
1313
use Time::HiRes qw(usleep);
1414

15+
if (defined($ENV{TDE_MODE}))
16+
{
17+
plan skip_all => "requested WAL segment has already been removed";
18+
}
19+
1520
# Initialize primary node, setting wal-segsize to 1MB
1621
my $node_primary = PostgreSQL::Test::Cluster->new('primary');
1722
$node_primary->init(allows_streaming => 1, extra => ['--wal-segsize=1']);

0 commit comments

Comments
 (0)