forked from isoos/postgresql-dart
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnon_ascii_connection_strings_test.dart
100 lines (84 loc) · 3 KB
/
non_ascii_connection_strings_test.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import 'package:postgres/postgres.dart';
import 'package:test/expect.dart';
import 'package:test/scaffolding.dart';
import 'docker.dart';
void main() {
final username = 'abc@def';
final password = 'pöstgrēs_üšęr_pæsswœêrd';
withPostgresServer(
'non-ascii tests (clear password auth)',
pgUser: username,
pgPassword: password,
pgHbaConfContent: _sampleHbaConfigPassword,
(server) {
Connection? conn;
tearDown(() async {
await conn?.close();
});
test('- Connect with non-ascii connection string', () async {
conn = await server.newConnection(sslMode: SslMode.disable);
final res = await conn!.execute('select 1;');
expect(res.length, 1);
});
},
);
withPostgresServer(
'non-ascii tests (md5 auth)',
pgUser: username,
pgPassword: password,
pgHbaConfContent: _sampleHbaConfigMd5,
(server) {
Connection? conn;
tearDown(() async {
await conn?.close();
});
test('- Connect with non-ascii connection string', () async {
conn = await server.newConnection();
final res = await conn!.execute('select 1;');
expect(res.length, 1);
});
},
);
withPostgresServer(
'non-ascii tests (scram-sha-256 auth)',
pgUser: username,
pgPassword: password,
pgHbaConfContent: _sampleHbaConfigScramSha256,
(server) {
Connection? conn;
tearDown(() async {
await conn?.close();
});
test('- Connect with non-ascii connection string', () async {
conn = await server.newConnection();
final res = await conn!.execute('select 1;');
expect(res.length, 1);
});
},
);
}
/* -------------------------------------------------------------------------- */
/* helper methods and getters */
/* -------------------------------------------------------------------------- */
String get _sampleHbaConfigPassword =>
_sampleHbaContentTrust.replaceAll('trust', 'password');
String get _sampleHbaConfigMd5 =>
_sampleHbaContentTrust.replaceAll('trust', 'md5');
String get _sampleHbaConfigScramSha256 =>
_sampleHbaContentTrust.replaceAll('trust', 'scram-sha-256');
/// METHOD can be "trust", "reject", "md5", "password", "scram-sha-256",
/// "gss", "sspi", "ident", "peer", "pam", "ldap", "radius" or "cert".
///
/// Currently, the package only supports: 'md5', 'password', 'scram-sha-256'.
/// See [AuthenticationScheme] within `src/auth/auth.dart`
const _sampleHbaContentTrust = '''
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 trust
# IPv6 local connections:
host all all ::1/128 trust
# when using containers
host all all 0.0.0.0/0 trust
''';