-
Notifications
You must be signed in to change notification settings - Fork 39
add non-ascii connection string tests #63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
isoos
merged 1 commit into
isoos:master
from
osaxma:support_non_acii_username_and_passwords
Sep 16, 2022
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,208 @@ | ||
import 'dart:io'; | ||
|
||
import 'package:docker_process/containers/postgres.dart'; | ||
import 'package:path/path.dart' as p; | ||
import 'package:postgres/postgres.dart'; | ||
import 'package:test/expect.dart'; | ||
import 'package:test/scaffolding.dart'; | ||
|
||
void main() { | ||
/// This cannot be run on CI as each test requires different pg_hba.conf | ||
/// to be mounted to the container. | ||
if (Platform.environment.containsKey('GITHUB_ACTION')) { | ||
test('NO NON-ASCII CONNECTION STRINGS TESTS ARE RUNNING.', () { | ||
// no-op | ||
}); | ||
return; | ||
} | ||
final user = 'abc@def'; | ||
final password = 'pöstgrēs_üšęr_pæsswœêrd'; | ||
final db = 'postgres'; | ||
|
||
group('non-ascii tests (clear password auth)', () { | ||
late final DockerProcess docker; | ||
final port = 54321; | ||
|
||
setUpAll( | ||
() async { | ||
docker = await startPostgres( | ||
name: 'non_ascii_test_clear_password', | ||
version: 'latest', | ||
pgPort: port, | ||
pgDatabase: db, | ||
pgUser: user, | ||
pgPassword: password, | ||
cleanup: true, | ||
pgHbaConfPath: _createTempFile( | ||
fileName: 'pg_hba.conf', | ||
contents: _sampleHbaConfigPassword, | ||
), | ||
); | ||
}, | ||
); | ||
|
||
tearDownAll(() { | ||
docker.stop(); | ||
docker.kill(); | ||
}); | ||
PostgreSQLConnection? conn; | ||
|
||
setUp(() async { | ||
conn = PostgreSQLConnection('localhost', port, db, | ||
username: user, password: password, allowClearTextPassword: true); | ||
await conn!.open(); | ||
}); | ||
|
||
tearDown(() async { | ||
await conn?.close(); | ||
}); | ||
|
||
test('- Connect with non-ascii connection string', () async { | ||
final res = await conn!.query('select 1;'); | ||
expect(res.length, 1); | ||
}); | ||
}); | ||
|
||
group('non-ascii tests (md5 auth)', () { | ||
late final DockerProcess docker; | ||
final port = 54322; | ||
setUpAll( | ||
() async { | ||
docker = await startPostgres( | ||
name: 'non_ascii_test_md5', | ||
version: 'latest', | ||
pgPort: port, | ||
pgDatabase: db, | ||
pgUser: user, | ||
pgPassword: password, | ||
cleanup: true, | ||
pgHbaConfPath: _createTempFile( | ||
fileName: 'pg_hba.conf', | ||
contents: _sampleHbaConfigMd5, | ||
), | ||
); | ||
}, | ||
); | ||
|
||
tearDownAll(() { | ||
docker.stop(); | ||
docker.kill(); | ||
}); | ||
PostgreSQLConnection? conn; | ||
|
||
setUp(() async { | ||
conn = PostgreSQLConnection( | ||
'localhost', | ||
port, | ||
db, | ||
username: user, | ||
password: password, | ||
); | ||
await conn!.open(); | ||
}); | ||
|
||
tearDown(() async { | ||
await conn?.close(); | ||
}); | ||
|
||
test('- Connect with non-ascii connection string', () async { | ||
final res = await conn!.query('select 1;'); | ||
expect(res.length, 1); | ||
}); | ||
}); | ||
|
||
group('non-ascii tests (scram-sha-256 auth)', () { | ||
late final DockerProcess docker; | ||
final port = 54323; | ||
setUpAll( | ||
() async { | ||
docker = await startPostgres( | ||
name: 'non_ascii_test_scram_sha256', | ||
version: 'latest', | ||
pgPort: port, | ||
pgDatabase: db, | ||
pgUser: user, | ||
pgPassword: password, | ||
cleanup: true, | ||
pgHbaConfPath: _createTempFile( | ||
fileName: 'pg_hba.conf', | ||
contents: _sampleHbaConfigScramSha256, | ||
), | ||
); | ||
}, | ||
); | ||
|
||
tearDownAll(() { | ||
docker.stop(); | ||
docker.kill(); | ||
}); | ||
PostgreSQLConnection? conn; | ||
|
||
setUp(() async { | ||
conn = PostgreSQLConnection( | ||
'localhost', | ||
port, | ||
db, | ||
username: user, | ||
password: password, | ||
); | ||
await conn!.open(); | ||
}); | ||
|
||
tearDown(() async { | ||
await conn?.close(); | ||
}); | ||
|
||
test('- Connect with non-ascii connection string', () async { | ||
final res = await conn!.query('select 1;'); | ||
expect(res.length, 1); | ||
}); | ||
}); | ||
} | ||
|
||
/* -------------------------------------------------------------------------- */ | ||
/* helper methods and getters */ | ||
/* -------------------------------------------------------------------------- */ | ||
|
||
String _createTempFile({ | ||
required String fileName, | ||
required String contents, | ||
}) { | ||
final file = File(p.join( | ||
Directory.systemTemp.path, | ||
DateTime.now().millisecondsSinceEpoch.toString(), | ||
fileName, | ||
)); | ||
|
||
file.createSync(recursive: true); | ||
file.writeAsStringSync(contents); | ||
return file.path; | ||
} | ||
|
||
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 | ||
'''; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't really checked yet, but IIRC Github Action is able to run
docker run
and other commands... have you tried it?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I believe it's possible but not with the current setup (e.g. using
services.postgres
)... I'll give it another shot later and try a different setup.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: a repository can have multiple workflows, and we can differentiate tests either via directory or tags.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Also: thank you for looking into this!)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that what I was thinking -- to tag tests with a
solo
tag and exclude them from common tests and then run allsolo
tests withconcurrency=1
.