|
|
@ -1,18 +1,17 @@ |
|
|
|
import 'package:clock/clock.dart'; |
|
|
|
import 'package:clock/clock.dart'; |
|
|
|
import 'package:kdbx/kdbx.dart'; |
|
|
|
import 'package:kdbx/kdbx.dart'; |
|
|
|
|
|
|
|
import 'package:logging/logging.dart'; |
|
|
|
import 'package:test/test.dart'; |
|
|
|
import 'package:test/test.dart'; |
|
|
|
|
|
|
|
|
|
|
|
import '../internal/test_utils.dart'; |
|
|
|
import '../internal/test_utils.dart'; |
|
|
|
import 'package:logging/logging.dart'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final _logger = Logger('kdbx_merge_test'); |
|
|
|
final _logger = Logger('kdbx_merge_test'); |
|
|
|
|
|
|
|
|
|
|
|
void main() { |
|
|
|
void main() { |
|
|
|
TestUtil.setupLogging(); |
|
|
|
TestUtil.setupLogging(); |
|
|
|
DateTime now = DateTime.fromMillisecondsSinceEpoch(0); |
|
|
|
var now = DateTime.fromMillisecondsSinceEpoch(0); |
|
|
|
|
|
|
|
|
|
|
|
final fakeClock = Clock(() => now); |
|
|
|
final fakeClock = Clock(() => now); |
|
|
|
final kdbxFormat = TestUtil.kdbxFormat(); |
|
|
|
|
|
|
|
void proceedSeconds(int seconds) { |
|
|
|
void proceedSeconds(int seconds) { |
|
|
|
now = now.add(Duration(seconds: seconds)); |
|
|
|
now = now.add(Duration(seconds: seconds)); |
|
|
|
} |
|
|
|
} |
|
|
@ -21,26 +20,29 @@ void main() { |
|
|
|
DateTime.fromMillisecondsSinceEpoch(0); |
|
|
|
DateTime.fromMillisecondsSinceEpoch(0); |
|
|
|
}); |
|
|
|
}); |
|
|
|
group('Simple merges', () { |
|
|
|
group('Simple merges', () { |
|
|
|
test('Noop merge', () async { |
|
|
|
Future<KdbxFile> createSimpleFile() async { |
|
|
|
final file = kdbxFormat.create( |
|
|
|
final file = TestUtil.createEmptyFile(); |
|
|
|
Credentials.composite(ProtectedValue.fromString('asdf'), null), |
|
|
|
|
|
|
|
'example'); |
|
|
|
|
|
|
|
_createEntry(file, file.body.rootGroup, 'test1', 'test1'); |
|
|
|
_createEntry(file, file.body.rootGroup, 'test1', 'test1'); |
|
|
|
|
|
|
|
final subGroup = |
|
|
|
|
|
|
|
file.createGroup(parent: file.body.rootGroup, name: 'Sub Group'); |
|
|
|
|
|
|
|
_createEntry(file, subGroup, 'test2', 'test2'); |
|
|
|
|
|
|
|
proceedSeconds(10); |
|
|
|
|
|
|
|
return await TestUtil.saveAndRead(file); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
test('Noop merge', () async { |
|
|
|
|
|
|
|
final file = await createSimpleFile(); |
|
|
|
final file2 = await TestUtil.saveAndRead(file); |
|
|
|
final file2 = await TestUtil.saveAndRead(file); |
|
|
|
final merge = file.merge(file2); |
|
|
|
final merge = file.merge(file2); |
|
|
|
final set = Set<KdbxUuid>.from(merge.merged.keys); |
|
|
|
final set = Set<KdbxUuid>.from(merge.merged.keys); |
|
|
|
expect(set, hasLength(2)); |
|
|
|
expect(set, hasLength(4)); |
|
|
|
expect(merge.changes, isEmpty); |
|
|
|
expect(merge.changes, isEmpty); |
|
|
|
}); |
|
|
|
}); |
|
|
|
test('Username change', () async { |
|
|
|
test('Username change', () async { |
|
|
|
await withClock(fakeClock, () async { |
|
|
|
await withClock(fakeClock, () async { |
|
|
|
final file = kdbxFormat.create( |
|
|
|
final file = await createSimpleFile(); |
|
|
|
Credentials.composite(ProtectedValue.fromString('asdf'), null), |
|
|
|
|
|
|
|
'example'); |
|
|
|
|
|
|
|
_createEntry(file, file.body.rootGroup, 'test1', 'test1'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final fileMod = await TestUtil.saveAndRead(file); |
|
|
|
final fileMod = await TestUtil.saveAndRead(file); |
|
|
|
proceedSeconds(10); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fileMod.body.rootGroup.entries.first |
|
|
|
fileMod.body.rootGroup.entries.first |
|
|
|
.setString(KdbxKey('UserName'), PlainValue('changed.')); |
|
|
|
.setString(KdbxKey('UserName'), PlainValue('changed.')); |
|
|
@ -52,11 +54,27 @@ void main() { |
|
|
|
|
|
|
|
|
|
|
|
_logger.info('\n\n\nstarting merge.\n'); |
|
|
|
_logger.info('\n\n\nstarting merge.\n'); |
|
|
|
final merge = file.merge(file2); |
|
|
|
final merge = file.merge(file2); |
|
|
|
|
|
|
|
expect(file.body.rootGroup.entries.first.history, hasLength(1)); |
|
|
|
final set = Set<KdbxUuid>.from(merge.merged.keys); |
|
|
|
final set = Set<KdbxUuid>.from(merge.merged.keys); |
|
|
|
expect(set, hasLength(2)); |
|
|
|
expect(set, hasLength(4)); |
|
|
|
expect(merge.changes, hasLength(1)); |
|
|
|
expect(merge.changes, hasLength(1)); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
test( |
|
|
|
|
|
|
|
'Change Group Name', |
|
|
|
|
|
|
|
() async => await withClock(fakeClock, () async { |
|
|
|
|
|
|
|
final file = await createSimpleFile(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final fileMod = await TestUtil.saveAndRead(file); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fileMod.body.rootGroup.groups.first.name.set('Sub Group New Name.'); |
|
|
|
|
|
|
|
final file2 = await TestUtil.saveAndRead(fileMod); |
|
|
|
|
|
|
|
final merge = file.merge(file2); |
|
|
|
|
|
|
|
final set = Set<KdbxUuid>.from(merge.merged.keys); |
|
|
|
|
|
|
|
expect(set, hasLength(4)); |
|
|
|
|
|
|
|
expect(merge.changes, hasLength(1)); |
|
|
|
|
|
|
|
}), |
|
|
|
|
|
|
|
); |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|