From e5e55638f4392508437b358e241857cdcd0d36af Mon Sep 17 00:00:00 2001 From: luckyrat Date: Mon, 4 Mar 2024 20:55:10 +0000 Subject: [PATCH] wip --- .../browser_entry_settings.dart | 4 ++-- lib/src/kee_vault_model/field.dart | 7 ++++--- .../kee_vault_model/field_matcher_config.dart | 2 +- test/browser_entry_settings_test.dart | 21 +++++++++++++++---- 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/lib/src/kee_vault_model/browser_entry_settings.dart b/lib/src/kee_vault_model/browser_entry_settings.dart index 9d86aeb..a8d45fd 100644 --- a/lib/src/kee_vault_model/browser_entry_settings.dart +++ b/lib/src/kee_vault_model/browser_entry_settings.dart @@ -32,7 +32,7 @@ class BrowserEntrySettings { version: map['version'] as int? ?? 2, includeUrls: getIncludeUrls(map), excludeUrls: getExcludeUrls(map), - realm: map['hTTPRealm'] as String?, + realm: map['httpRealm'] as String?, authenticationMethods: (map['authenticationMethods'] as List?)?.cast() ?? [], @@ -168,7 +168,7 @@ class BrowserEntrySettings { return { 'version': version, 'authenticationMethods': authenticationMethods, - if (realm?.isNotEmpty ?? false) 'hTTPRealm': realm, + if (realm?.isNotEmpty ?? false) 'httpRealm': realm, 'matcherConfigs': matcherConfigs.map((x) => x.toMap()).toList(), if (fields != null) 'fields': fields?.map((x) => x.toMap()).toList(), if (behaviour != null && behaviour != BrowserAutoFillBehaviour.Default) diff --git a/lib/src/kee_vault_model/field.dart b/lib/src/kee_vault_model/field.dart index 41da765..9bead61 100644 --- a/lib/src/kee_vault_model/field.dart +++ b/lib/src/kee_vault_model/field.dart @@ -136,12 +136,13 @@ class Field { final customMatcherConfig = matcherConfigs?.firstWhereOrNull((mc) => mc.customMatcher != null); if (customMatcherConfig != null) { - htmlName = customMatcherConfig.customMatcher?.names[0] ?? ''; - htmlId = customMatcherConfig.customMatcher?.ids[0] ?? ''; + htmlName = + customMatcherConfig.customMatcher?.names.elementAtOrNull(0) ?? ''; + htmlId = customMatcherConfig.customMatcher?.ids.elementAtOrNull(0) ?? ''; if (customMatcherConfig.customMatcher?.types != null) { htmlType = Utilities.formFieldTypeFromHtmlTypeOrFieldType( - customMatcherConfig.customMatcher!.types[0], + customMatcherConfig.customMatcher!.types.elementAtOrNull(0) ?? '', type ?? FieldType.Text); } } diff --git a/lib/src/kee_vault_model/field_matcher_config.dart b/lib/src/kee_vault_model/field_matcher_config.dart index 3a919b2..d972f7e 100644 --- a/lib/src/kee_vault_model/field_matcher_config.dart +++ b/lib/src/kee_vault_model/field_matcher_config.dart @@ -20,7 +20,7 @@ class FieldMatcherConfig { return FieldMatcherConfig( matcherType: FieldMatcherType.values - .firstWhereOrNull((v) => v.name == map['matchLogic']), + .firstWhereOrNull((v) => v.name == map['matcherType']), customMatcher: map['customMatcher'] != null ? FieldMatcher.fromMap(map['customMatcher'] as Map) : null, diff --git a/test/browser_entry_settings_test.dart b/test/browser_entry_settings_test.dart index b1dfcfa..4666065 100644 --- a/test/browser_entry_settings_test.dart +++ b/test/browser_entry_settings_test.dart @@ -54,6 +54,19 @@ void main() { expect(sut, expectedResult); } + void testCaseRT(String persistedV2) { + final bes = BrowserEntrySettings.fromJson(persistedV2, + minimumMatchAccuracy: MatchAccuracy.Domain); + final configV1 = bes.convertToV1(); + final jsonV1 = configV1.toJson(); + final besV1 = BrowserEntrySettingsV1.fromJson(jsonV1, + minimumMatchAccuracy: MatchAccuracy.Domain); + final configV2 = besV1.convertToV2(MockGuidService()); + final sut = configV2.toJson(); + + expect(sut, persistedV2); + } + group('BrowserEntrySettings', () { test('config v2->v1', () async { testCase( @@ -65,8 +78,8 @@ void main() { '{"version":1,"priority":0,"hide":false,"hTTPRealm":"","formFieldList":[{"displayName":"KeePass password","name":"password","type":"FFTpassword","id":"password","page":-1,"placeholderHandling":"Default","value":"{PASSWORD}"},{"displayName":"KeePass username","name":"username","type":"FFTusername","id":"username","page":-1,"placeholderHandling":"Default","value":"{USERNAME}"}],"alwaysAutoFill":false,"alwaysAutoSubmit":false,"neverAutoFill":false,"neverAutoSubmit":false,"blockDomainOnlyMatch":false,"blockHostnameOnlyMatch":false,"altURLs":[],"regExURLs":[],"blockedURLs":[],"regExBlockedURLs":[]}'); testCase( - '{"version":2,"altUrls":[],"authenticationMethods":["password"],"matcherConfigs":[{"matcherType":"Url"}],"fields":[{"page":-1,"valuePath":"Password","uuid":"AAAAAAAAAAAAAAAAAAAAAA==","type":"Password","matcherConfigs":[{"customMatcher":{"ids":["password"],"names":["password"],"types":["password"],"queries":[]}}]},{"page":-1,"valuePath":"UserName","uuid":"AAAAAAAAAAAAAAAAAAAAAA==","type":"Text","matcherConfigs":[{"customMatcher":{"ids":["username"],"names":["username"],"types":["text"],"queries":[]}}]}]}', - '{"version":1,"priority":0,"hide":false,"hTTPRealm":"","formFieldList":[{"displayName":"KeePass password","name":"password","type":"FFTpassword","id":"password","page":-1,"placeholderHandling":"Default","value":"{PASSWORD}"},{"displayName":"KeePass username","name":"username","type":"FFTusername","id":"username","page":-1,"placeholderHandling":"Default","value":"{USERNAME}"}],"alwaysAutoFill":false,"alwaysAutoSubmit":false,"neverAutoFill":false,"neverAutoSubmit":false,"blockDomainOnlyMatch":false,"blockHostnameOnlyMatch":false,"altURLs":[],"regExURLs":[],"blockedURLs":[],"regExBlockedURLs":[]}'); + '{"version":2,"httpRealm":"re","altUrls":[],"authenticationMethods":["password"],"matcherConfigs":[{"matcherType":"Url"}],"fields":[{"page":-1,"valuePath":"Password","uuid":"AAAAAAAAAAAAAAAAAAAAAA==","type":"Password","matcherConfigs":[{"customMatcher":{"ids":["password"],"names":["password"],"types":["password"],"queries":[]}}]},{"page":-1,"valuePath":"UserName","uuid":"AAAAAAAAAAAAAAAAAAAAAA==","type":"Text","matcherConfigs":[{"customMatcher":{"ids":["username"],"names":["username"],"types":["text"],"queries":[]}}]}]}', + '{"version":1,"priority":0,"hide":false,"hTTPRealm":"re","formFieldList":[{"displayName":"KeePass password","name":"password","type":"FFTpassword","id":"password","page":-1,"placeholderHandling":"Default","value":"{PASSWORD}"},{"displayName":"KeePass username","name":"username","type":"FFTusername","id":"username","page":-1,"placeholderHandling":"Default","value":"{USERNAME}"}],"alwaysAutoFill":false,"alwaysAutoSubmit":false,"neverAutoFill":false,"neverAutoSubmit":false,"blockDomainOnlyMatch":false,"blockHostnameOnlyMatch":false,"altURLs":[],"regExURLs":[],"blockedURLs":[],"regExBlockedURLs":[]}'); testCase( '{"version":2,"authenticationMethods":["password"],"matcherConfigs":[{"matcherType":"Url"}],"fields":[{"page":-1,"valuePath":"UserName","uuid":"AAAAAAAAAAAAAAAAAAAAAA==","type":"Text","matcherConfigs":[{"matcherType":"UsernameDefaultHeuristic"}]},{"page":-1,"valuePath":"Password","uuid":"AAAAAAAAAAAAAAAAAAAAAA==","type":"Password","matcherConfigs":[{"matcherType":"PasswordDefaultHeuristic"}]}]}', @@ -91,8 +104,8 @@ void main() { '{"version":2,"authenticationMethods":["password"],"matcherConfigs":[{"matcherType":"Url"}],"fields":[{"page":1,"valuePath":"Password","uuid":"AAAAAAAAAAAAAAAAAAAAAA==","type":"Password","matcherConfigs":[{"customMatcher":{"ids":["password"],"names":["password"],"types":["password"]}}]},{"page":1,"valuePath":"UserName","uuid":"AAAAAAAAAAAAAAAAAAAAAA==","type":"Text","matcherConfigs":[{"customMatcher":{"ids":["username"],"names":["username"],"types":["text"]}}]}]}'); testCaseToV2( - '{"version":1,"hTTPRealm":"","formFieldList":[{"name":"password","displayName":"KeePass password","value":"{PASSWORD}","type":"FFTpassword","id":"password","page":-1,"placeholderHandling":"Default"},{"name":"username","displayName":"KeePass username","value":"{USERNAME}","type":"FFTusername","id":"username","page":-1,"placeholderHandling":"Default"}],"alwaysAutoFill":false,"neverAutoFill":false,"alwaysAutoSubmit":false,"neverAutoSubmit":false,"priority":0,"altURLs":[],"hide":false,"blockHostnameOnlyMatch":false,"blockDomainOnlyMatch":false}', - '{"version":2,"authenticationMethods":["password"],"matcherConfigs":[{"matcherType":"Url"}],"fields":[{"page":1,"valuePath":"Password","uuid":"AAAAAAAAAAAAAAAAAAAAAA==","type":"Password","matcherConfigs":[{"customMatcher":{"ids":["password"],"names":["password"],"types":["password"]}}]},{"page":1,"valuePath":"UserName","uuid":"AAAAAAAAAAAAAAAAAAAAAA==","type":"Text","matcherConfigs":[{"customMatcher":{"ids":["username"],"names":["username"],"types":["text"]}}]}]}'); + '{"version":1,"hTTPRealm":"re","formFieldList":[{"name":"password","displayName":"KeePass password","value":"{PASSWORD}","type":"FFTpassword","id":"password","page":-1,"placeholderHandling":"Default"},{"name":"username","displayName":"KeePass username","value":"{USERNAME}","type":"FFTusername","id":"username","page":-1,"placeholderHandling":"Default"}],"alwaysAutoFill":false,"neverAutoFill":false,"alwaysAutoSubmit":false,"neverAutoSubmit":false,"priority":0,"altURLs":[],"hide":false,"blockHostnameOnlyMatch":false,"blockDomainOnlyMatch":false}', + '{"version":2,"authenticationMethods":["password"],"httpRealm":"re","matcherConfigs":[{"matcherType":"Url"}],"fields":[{"page":1,"valuePath":"Password","uuid":"AAAAAAAAAAAAAAAAAAAAAA==","type":"Password","matcherConfigs":[{"customMatcher":{"ids":["password"],"names":["password"],"types":["password"]}}]},{"page":1,"valuePath":"UserName","uuid":"AAAAAAAAAAAAAAAAAAAAAA==","type":"Text","matcherConfigs":[{"customMatcher":{"ids":["username"],"names":["username"],"types":["text"]}}]}]}'); testCaseToV2( '{"version":1,"hTTPRealm":"","formFieldList":[{"name":"password","displayName":"KeePass password","value":"{PASSWORD}","type":"FFTpassword","id":"password","page":-1,"placeholderHandling":"Default"},{"name":"username","displayName":"KeePass username","value":"{USERNAME}","type":"FFTusername","id":"username","page":-1,"placeholderHandling":"Default"}],"alwaysAutoFill":false,"neverAutoFill":false,"alwaysAutoSubmit":false,"neverAutoSubmit":false,"priority":0,"altURLs":["http://test.com/1","http://test.com/2"],"regExURLs":["3","4"],"blockedURLs":["5","6"],"regExBlockedURLs":["7","8"],"hide":false,"blockHostnameOnlyMatch":false,"blockDomainOnlyMatch":false}',