Browse Source

fix test loading of dynamic libraries.

remove-cryptography-dependency
Herbert Poul 4 years ago
parent
commit
bb07518294
  1. 5
      .github/workflows/dart.yml
  2. 1
      bin/kdbx.dart
  3. BIN
      libargon2_ffi.dylib
  4. 19
      test/internal/test_utils.dart
  5. 2
      test/kdbx4_test.dart

5
.github/workflows/dart.yml

@ -9,6 +9,7 @@ jobs:
os: ['ubuntu-latest', 'windows-2019', 'macos-latest'] os: ['ubuntu-latest', 'windows-2019', 'macos-latest']
dart_channel: ['stable'] dart_channel: ['stable']
fail-fast: false
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
steps: steps:
@ -16,6 +17,10 @@ jobs:
- uses: cedx/setup-dart@v2 - uses: cedx/setup-dart@v2
with: with:
release-channel: ${{ matrix.dart_channel }} release-channel: ${{ matrix.dart_channel }}
- run: |
which dart
codesign --remove-signature $(which dart)
if: startsWith(matrix.os, 'macos')
- name: Install dependencies - name: Install dependencies
run: pub get run: pub get
- name: Run tests - name: Run tests

1
bin/kdbx.dart

@ -94,6 +94,7 @@ abstract class KdbxFileCommand extends Command<void> {
final keyFileData = final keyFileData =
keyFile == null ? null : await File(keyFile).readAsBytes(); keyFile == null ? null : await File(keyFile).readAsBytes();
Argon2FfiFlutter.resolveLibraryForceDynamic = true;
final file = await KdbxFormat(Argon2FfiFlutter()).read( final file = await KdbxFormat(Argon2FfiFlutter()).read(
bytes, bytes,
Credentials.composite(ProtectedValue.fromString(password), keyFileData), Credentials.composite(ProtectedValue.fromString(password), keyFileData),

BIN
libargon2_ffi.dylib

Binary file not shown.

19
test/internal/test_utils.dart

@ -7,12 +7,27 @@ import 'package:kdbx/kdbx.dart';
// ignore_for_file: non_constant_identifier_names // ignore_for_file: non_constant_identifier_names
import 'package:logging/logging.dart';
final _logger = Logger('test_utils');
class TestUtil { class TestUtil {
static KdbxFormat kdbxFormat() {
Argon2FfiFlutter.resolveLibraryForceDynamic = true;
return KdbxFormat(Argon2FfiFlutter(resolveLibrary: (path) {
final cwd = Directory('.').absolute.uri;
final p = cwd.resolve(path);
final filePath = p.toFilePath();
_logger.fine('Resolving $path to: $filePath (${Platform.script})');
return filePath;
}));
}
static Future<KdbxFile> readKdbxFile( static Future<KdbxFile> readKdbxFile(
String filePath, { String filePath, {
String password = 'asdf', String password = 'asdf',
}) async { }) async {
final kdbxFormat = KdbxFormat(Argon2FfiFlutter()); final kdbxFormat = TestUtil.kdbxFormat();
final data = await File(filePath).readAsBytes(); final data = await File(filePath).readAsBytes();
final file = await kdbxFormat.read( final file = await kdbxFormat.read(
data, Credentials(ProtectedValue.fromString(password))); data, Credentials(ProtectedValue.fromString(password)));
@ -21,7 +36,7 @@ class TestUtil {
static Future<KdbxFile> readKdbxFileBytes(Uint8List data, static Future<KdbxFile> readKdbxFileBytes(Uint8List data,
{String password = 'asdf'}) async { {String password = 'asdf'}) async {
final kdbxFormat = KdbxFormat(Argon2FfiFlutter()); final kdbxFormat = TestUtil.kdbxFormat();
final file = await kdbxFormat.read( final file = await kdbxFormat.read(
data, Credentials(ProtectedValue.fromString(password))); data, Credentials(ProtectedValue.fromString(password)));
return file; return file;

2
test/kdbx4_test.dart

@ -16,7 +16,7 @@ final _logger = Logger('kdbx4_test');
void main() { void main() {
Logger.root.level = Level.ALL; Logger.root.level = Level.ALL;
PrintAppender().attachToLogger(Logger.root); PrintAppender().attachToLogger(Logger.root);
final kdbxFormat = KdbxFormat(Argon2FfiFlutter()); final kdbxFormat = TestUtil.kdbxFormat();
group('Reading', () { group('Reading', () {
test('bubb', () async { test('bubb', () async {
final data = await File('test/keepassxcpasswords.kdbx').readAsBytes(); final data = await File('test/keepassxcpasswords.kdbx').readAsBytes();

Loading…
Cancel
Save