Skip to content

Commit 8d9f060

Browse files
committed
Use a better way of skipping all subscription tests on Windows
This way we only need to specify the number of tests in one place, and the output is also less verbose.
1 parent d99d58c commit 8d9f060

File tree

2 files changed

+90
-83
lines changed

2 files changed

+90
-83
lines changed

src/test/authentication/t/001_password.pl

+36-32
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,16 @@
1010
use warnings;
1111
use PostgresNode;
1212
use TestLib;
13-
use Test::More tests => 8;
13+
use Test::More;
14+
if ($windows_os)
15+
{
16+
plan skip_all => "authentication tests cannot run on Windows";
17+
}
18+
else
19+
{
20+
plan tests => 8;
21+
}
22+
1423

1524
# Delete pg_hba.conf from the given node, add a new entry to it
1625
# and then execute a reload to refresh it.
@@ -40,39 +49,34 @@ sub test_role
4049
"authentication $status_string for method $method, role $role");
4150
}
4251

43-
SKIP:
44-
{
45-
skip "authentication tests cannot run on Windows", 12 if ($windows_os);
46-
47-
# Initialize master node
48-
my $node = get_new_node('master');
49-
$node->init;
50-
$node->start;
52+
# Initialize master node
53+
my $node = get_new_node('master');
54+
$node->init;
55+
$node->start;
5156

52-
# Create 3 roles with different password methods for each one. The same
53-
# password is used for all of them.
54-
$node->safe_psql('postgres', "SET password_encryption='scram-sha-256'; CREATE ROLE scram_role LOGIN PASSWORD 'pass';");
55-
$node->safe_psql('postgres', "SET password_encryption='md5'; CREATE ROLE md5_role LOGIN PASSWORD 'pass';");
56-
$ENV{"PGPASSWORD"} = 'pass';
57+
# Create 3 roles with different password methods for each one. The same
58+
# password is used for all of them.
59+
$node->safe_psql('postgres', "SET password_encryption='scram-sha-256'; CREATE ROLE scram_role LOGIN PASSWORD 'pass';");
60+
$node->safe_psql('postgres', "SET password_encryption='md5'; CREATE ROLE md5_role LOGIN PASSWORD 'pass';");
61+
$ENV{"PGPASSWORD"} = 'pass';
5762

58-
# For "trust" method, all users should be able to connect.
59-
reset_pg_hba($node, 'trust');
60-
test_role($node, 'scram_role', 'trust', 0);
61-
test_role($node, 'md5_role', 'trust', 0);
63+
# For "trust" method, all users should be able to connect.
64+
reset_pg_hba($node, 'trust');
65+
test_role($node, 'scram_role', 'trust', 0);
66+
test_role($node, 'md5_role', 'trust', 0);
6267

63-
# For plain "password" method, all users should also be able to connect.
64-
reset_pg_hba($node, 'password');
65-
test_role($node, 'scram_role', 'password', 0);
66-
test_role($node, 'md5_role', 'password', 0);
68+
# For plain "password" method, all users should also be able to connect.
69+
reset_pg_hba($node, 'password');
70+
test_role($node, 'scram_role', 'password', 0);
71+
test_role($node, 'md5_role', 'password', 0);
6772

68-
# For "scram-sha-256" method, user "scram_role" should be able to connect.
69-
reset_pg_hba($node, 'scram-sha-256');
70-
test_role($node, 'scram_role', 'scram-sha-256', 0);
71-
test_role($node, 'md5_role', 'scram-sha-256', 2);
73+
# For "scram-sha-256" method, user "scram_role" should be able to connect.
74+
reset_pg_hba($node, 'scram-sha-256');
75+
test_role($node, 'scram_role', 'scram-sha-256', 0);
76+
test_role($node, 'md5_role', 'scram-sha-256', 2);
7277

73-
# For "md5" method, all users should be able to connect (SCRAM
74-
# authentication will be performed for the user with a scram verifier.)
75-
reset_pg_hba($node, 'md5');
76-
test_role($node, 'scram_role', 'md5', 0);
77-
test_role($node, 'md5_role', 'md5', 0);
78-
}
78+
# For "md5" method, all users should be able to connect (SCRAM
79+
# authentication will be performed for the user with a scram verifier.)
80+
reset_pg_hba($node, 'md5');
81+
test_role($node, 'scram_role', 'md5', 0);
82+
test_role($node, 'md5_role', 'md5', 0);

src/test/authentication/t/002_saslprep.pl

+54-51
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,15 @@
77
use warnings;
88
use PostgresNode;
99
use TestLib;
10-
use Test::More tests => 12;
10+
use Test::More;
11+
if ($windows_os)
12+
{
13+
plan skip_all => "authentication tests cannot run on Windows";
14+
}
15+
else
16+
{
17+
plan tests => 12;
18+
}
1119

1220
# Delete pg_hba.conf from the given node, add a new entry to it
1321
# and then execute a reload to refresh it.
@@ -38,62 +46,57 @@ sub test_login
3846
"authentication $status_string for role $role with password $password");
3947
}
4048

41-
SKIP:
42-
{
43-
skip "authentication tests cannot run on Windows", 12 if ($windows_os);
49+
# Initialize master node. Force UTF-8 encoding, so that we can use non-ASCII
50+
# characters in the passwords below.
51+
my $node = get_new_node('master');
52+
$node->init(extra => ['--locale=C', '--encoding=UTF8']);
53+
$node->start;
4454

45-
# Initialize master node. Force UTF-8 encoding, so that we can use non-ASCII
46-
# characters in the passwords below.
47-
my $node = get_new_node('master');
48-
$node->init(extra => ['--locale=C', '--encoding=UTF8']);
49-
$node->start;
50-
51-
# These tests are based on the example strings from RFC4013.txt,
52-
# Section "3. Examples":
53-
#
54-
# # Input Output Comments
55-
# - ----- ------ --------
56-
# 1 I<U+00AD>X IX SOFT HYPHEN mapped to nothing
57-
# 2 user user no transformation
58-
# 3 USER USER case preserved, will not match #2
59-
# 4 <U+00AA> a output is NFKC, input in ISO 8859-1
60-
# 5 <U+2168> IX output is NFKC, will match #1
61-
# 6 <U+0007> Error - prohibited character
62-
# 7 <U+0627><U+0031> Error - bidirectional check
63-
64-
# Create test roles.
65-
$node->safe_psql('postgres',
55+
# These tests are based on the example strings from RFC4013.txt,
56+
# Section "3. Examples":
57+
#
58+
# # Input Output Comments
59+
# - ----- ------ --------
60+
# 1 I<U+00AD>X IX SOFT HYPHEN mapped to nothing
61+
# 2 user user no transformation
62+
# 3 USER USER case preserved, will not match #2
63+
# 4 <U+00AA> a output is NFKC, input in ISO 8859-1
64+
# 5 <U+2168> IX output is NFKC, will match #1
65+
# 6 <U+0007> Error - prohibited character
66+
# 7 <U+0627><U+0031> Error - bidirectional check
67+
68+
# Create test roles.
69+
$node->safe_psql('postgres',
6670
"SET password_encryption='scram-sha-256';
67-
SET client_encoding='utf8';
68-
CREATE ROLE saslpreptest1_role LOGIN PASSWORD 'IX';
69-
CREATE ROLE saslpreptest4a_role LOGIN PASSWORD 'a';
70-
CREATE ROLE saslpreptest4b_role LOGIN PASSWORD E'\\xc2\\xaa';
71-
CREATE ROLE saslpreptest6_role LOGIN PASSWORD E'foo\\x07bar';
72-
CREATE ROLE saslpreptest7_role LOGIN PASSWORD E'foo\\u0627\\u0031bar';
71+
SET client_encoding='utf8';
72+
CREATE ROLE saslpreptest1_role LOGIN PASSWORD 'IX';
73+
CREATE ROLE saslpreptest4a_role LOGIN PASSWORD 'a';
74+
CREATE ROLE saslpreptest4b_role LOGIN PASSWORD E'\\xc2\\xaa';
75+
CREATE ROLE saslpreptest6_role LOGIN PASSWORD E'foo\\x07bar';
76+
CREATE ROLE saslpreptest7_role LOGIN PASSWORD E'foo\\u0627\\u0031bar';
7377
");
7478

75-
# Require password from now on.
76-
reset_pg_hba($node, 'scram-sha-256');
79+
# Require password from now on.
80+
reset_pg_hba($node, 'scram-sha-256');
7781

78-
# Check that #1 and #5 are treated the same as just 'IX'
79-
test_login($node, 'saslpreptest1_role', "I\xc2\xadX", 0);
80-
test_login($node, 'saslpreptest1_role', "\xe2\x85\xa8", 0);
82+
# Check that #1 and #5 are treated the same as just 'IX'
83+
test_login($node, 'saslpreptest1_role', "I\xc2\xadX", 0);
84+
test_login($node, 'saslpreptest1_role', "\xe2\x85\xa8", 0);
8185

82-
# but different from lower case 'ix'
83-
test_login($node, 'saslpreptest1_role', "ix", 2);
86+
# but different from lower case 'ix'
87+
test_login($node, 'saslpreptest1_role', "ix", 2);
8488

85-
# Check #4
86-
test_login($node, 'saslpreptest4a_role', "a", 0);
87-
test_login($node, 'saslpreptest4a_role', "\xc2\xaa", 0);
88-
test_login($node, 'saslpreptest4b_role', "a", 0);
89-
test_login($node, 'saslpreptest4b_role', "\xc2\xaa", 0);
89+
# Check #4
90+
test_login($node, 'saslpreptest4a_role', "a", 0);
91+
test_login($node, 'saslpreptest4a_role', "\xc2\xaa", 0);
92+
test_login($node, 'saslpreptest4b_role', "a", 0);
93+
test_login($node, 'saslpreptest4b_role', "\xc2\xaa", 0);
9094

91-
# Check #6 and #7 - In PostgreSQL, contrary to the spec, if the password
92-
# contains prohibited characters, we use it as is, without normalization.
93-
test_login($node, 'saslpreptest6_role', "foo\x07bar", 0);
94-
test_login($node, 'saslpreptest6_role', "foobar", 2);
95+
# Check #6 and #7 - In PostgreSQL, contrary to the spec, if the password
96+
# contains prohibited characters, we use it as is, without normalization.
97+
test_login($node, 'saslpreptest6_role', "foo\x07bar", 0);
98+
test_login($node, 'saslpreptest6_role', "foobar", 2);
9599

96-
test_login($node, 'saslpreptest7_role', "foo\xd8\xa71bar", 0);
97-
test_login($node, 'saslpreptest7_role', "foo1\xd8\xa7bar", 2);
98-
test_login($node, 'saslpreptest7_role', "foobar", 2);
99-
}
100+
test_login($node, 'saslpreptest7_role', "foo\xd8\xa71bar", 0);
101+
test_login($node, 'saslpreptest7_role', "foo1\xd8\xa7bar", 2);
102+
test_login($node, 'saslpreptest7_role', "foobar", 2);

0 commit comments

Comments
 (0)