Skip to content

Commit 031c900

Browse files
committed
feat: security feature - login history
Adjust the format and add the test case
1 parent d94b85f commit 031c900

File tree

3 files changed

+83
-17
lines changed

3 files changed

+83
-17
lines changed

external/polar_login_history/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ include $(top_srcdir)/contrib/contrib-global.mk
1717
endif
1818

1919
check:
20-
$(prove_check)
20+
$(prove_check)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
comment = 'record user login information'
22
default_version = '1.0'
33
module_pathname = '$libdir/polar_login_history'
4-
relocatable = true
4+
relocatable = true

external/polar_login_history/t/polar_login_history.pl

Lines changed: 81 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,91 @@
1111
use PostgreSQL::Test::Utils;
1212
use Test::More;
1313

14-
my $node = PostgreSQL::Test::Cluster->new('primary');
15-
$node->init();
16-
$node->start;
17-
18-
$node->append_conf('postgresql.conf',
14+
############### init primary/replica/standby ##############
15+
my $node_primary = PostgreSQL::Test::Cluster->new('primary');
16+
$node_primary->polar_init_primary;
17+
$node_primary->append_conf('postgresql.conf',
1918
"shared_preload_libraries = 'polar_login_history'");
20-
$node->restart;
2119

22-
$node->append_conf('postgresql.conf', "polar_login_history.enable = on");
23-
$node->restart;
20+
my $node_replica = PostgreSQL::Test::Cluster->new('replica');
21+
$node_replica->polar_init_replica($node_primary);
22+
23+
my $node_standby = PostgreSQL::Test::Cluster->new('standby');
24+
$node_standby->polar_init_standby($node_primary);
25+
26+
$node_primary->start;
27+
28+
$node_primary->polar_create_slot($node_replica->name);
29+
$node_primary->polar_create_slot($node_standby->name);
30+
31+
$node_replica->start;
32+
$node_standby->start;
33+
34+
$node_standby->polar_drop_all_slots;
35+
36+
37+
############### enable login history ##############
38+
$node_primary->append_conf('postgresql.conf',
39+
"polar_login_history.enable = on");
40+
$node_primary->restart;
41+
is( $node_primary->safe_psql('postgres', 'show polar_login_history.enable;'),
42+
'on',
43+
'login history function is enabled');
44+
45+
$node_replica->append_conf('postgresql.conf',
46+
"polar_login_history.enable = on");
47+
$node_replica->restart;
48+
is( $node_replica->safe_psql('postgres', 'show polar_login_history.enable;'),
49+
'on',
50+
'login history function is enabled');
51+
52+
$node_standby->append_conf('postgresql.conf',
53+
"polar_login_history.enable = on");
54+
$node_standby->restart;
55+
is( $node_standby->safe_psql('postgres', 'show polar_login_history.enable;'),
56+
'on',
57+
'login history function is enabled');
58+
59+
60+
############### log in to the database with the new user ##############
61+
$node_primary->safe_psql('postgres', 'create user zhangsan;');
62+
$node_replica->restart;
63+
64+
is( $node_primary->psql(
65+
'postgres', undef, extra_params => [ '-U', 'zhangsan' ]),
66+
0,
67+
'login success');
68+
isnt(
69+
$node_primary->psql(
70+
'postgres1', undef, extra_params => [ '-U', 'zhangsan' ]),
71+
0,
72+
'login success');
73+
74+
is( $node_replica->psql(
75+
'postgres', undef, extra_params => [ '-U', 'zhangsan' ]),
76+
0,
77+
'login success');
78+
isnt(
79+
$node_replica->psql(
80+
'postgres1', undef, extra_params => [ '-U', 'zhangsan' ]),
81+
0,
82+
'login success');
2483

25-
is($node->safe_psql('postgres', 'show polar_login_history.enable;'),
26-
'on', 'login history function is enabled');
84+
is( $node_standby->psql(
85+
'postgres', undef, extra_params => [ '-U', 'zhangsan' ]),
86+
0,
87+
'login success');
88+
isnt(
89+
$node_standby->psql(
90+
'postgres1', undef, extra_params => [ '-U', 'zhangsan' ]),
91+
0,
92+
'login success');
2793

28-
$node->safe_psql('postgres', 'create user zhangsan;');
29-
is($node->psql('postgres', undef, extra_params => [ '-U', 'zhangsan' ]),
30-
0, 'login success');
31-
$node->safe_psql('postgres', 'drop user zhangsan;');
94+
$node_primary->safe_psql('postgres', 'drop user zhangsan;');
3295

33-
$node->stop;
3496

97+
############### stop ##############
98+
$node_primary->stop;
99+
$node_replica->stop;
100+
$node_standby->stop;
35101
done_testing();

0 commit comments

Comments
 (0)