diff --git a/lib/src/kee_vault_model/browser_entry_settings.dart b/lib/src/kee_vault_model/browser_entry_settings.dart index 894a5ed..9d86aeb 100644 --- a/lib/src/kee_vault_model/browser_entry_settings.dart +++ b/lib/src/kee_vault_model/browser_entry_settings.dart @@ -107,36 +107,36 @@ class BrowserEntrySettings { static Map> parseUrls( List includeUrls, List excludeUrls) { - final altURLs = []; - final regExURLs = []; - final blockedURLs = []; - final regExBlockedURLs = []; + final altUrls = []; + final regExUrls = []; + final blockedUrls = []; + final regExBlockedUrls = []; for (final p in includeUrls) { if (p is RegExp) { - regExURLs.add(p.pattern); + regExUrls.add(p.pattern); } else if (p is String) { - altURLs.add(p); + altUrls.add(p); } } for (final p in excludeUrls) { if (p is RegExp) { - regExBlockedURLs.add(p.pattern); + regExBlockedUrls.add(p.pattern); } else if (p is String) { - blockedURLs.add(p); + blockedUrls.add(p); } } return >{ - if (altURLs.isNotEmpty) 'altURLs': altURLs, - if (regExURLs.isNotEmpty) 'regExURLs': regExURLs, - if (blockedURLs.isNotEmpty) 'blockedURLs': blockedURLs, - if (regExBlockedURLs.isNotEmpty) 'regExBlockedURLs': regExBlockedURLs, + if (altUrls.isNotEmpty) 'altUrls': altUrls, + if (regExUrls.isNotEmpty) 'regExUrls': regExUrls, + if (blockedUrls.isNotEmpty) 'blockedUrls': blockedUrls, + if (regExBlockedUrls.isNotEmpty) 'regExBlockedUrls': regExBlockedUrls, }; } static List getIncludeUrls(Map map) { final includeUrls = []; - final altUrls = (map['altURLs'] as List?)?.cast(); - final regExURLs = (map['regExURLs'] as List?)?.cast(); + final altUrls = (map['altUrls'] as List?)?.cast(); + final regExURLs = (map['regExUrls'] as List?)?.cast(); if (altUrls != null) { altUrls.forEach(includeUrls.add); } @@ -150,9 +150,9 @@ class BrowserEntrySettings { static List getExcludeUrls(Map map) { final excludeUrls = []; - final blockedURLs = (map['blockedURLs'] as List?)?.cast(); + final blockedURLs = (map['blockedUrls'] as List?)?.cast(); final regExBlockedURLs = - (map['regExBlockedURLs'] as List?)?.cast(); + (map['regExBlockedUrls'] as List?)?.cast(); if (blockedURLs != null) { blockedURLs.forEach(excludeUrls.add); } diff --git a/test/browser_entry_settings_test.dart b/test/browser_entry_settings_test.dart index a5ba1e8..17ef271 100644 --- a/test/browser_entry_settings_test.dart +++ b/test/browser_entry_settings_test.dart @@ -71,6 +71,10 @@ void main() { testCase( '{"version":2,"authenticationMethods":["password"],"matcherConfigs":[{"matcherType":"Url"}],"fields":[{"page":-1,"valuePath":"UserName","uuid":"00000000-0000-0000-0000-000000000000","type":"Text","matcherConfigs":[{"matcherType":"UsernameDefaultHeuristic"}]},{"page":-1,"valuePath":"Password","uuid":"00000000-0000-0000-0000-000000000000","type":"Password","matcherConfigs":[{"matcherType":"PasswordDefaultHeuristic"}]}]}', '{"version":1,"priority":0,"hide":false,"hTTPRealm":"","formFieldList":[{"displayName":"KeePass username","name":"","type":"FFTusername","id":"","page":-1,"placeholderHandling":"Default","value":"{USERNAME}"},{"displayName":"KeePass password","name":"","type":"FFTpassword","id":"","page":-1,"placeholderHandling":"Default","value":"{PASSWORD}"}],"alwaysAutoFill":false,"alwaysAutoSubmit":false,"neverAutoFill":false,"neverAutoSubmit":false,"blockDomainOnlyMatch":false,"blockHostnameOnlyMatch":false,"altURLs":[],"regExURLs":[],"blockedURLs":[],"regExBlockedURLs":[]}'); + + testCase( + '{"version":2,"altUrls":["http://test.com/1","http://test.com/2"],"regExUrls":["3","4"],"blockedUrls":["5","6"],"regExBlockedUrls":["7","8"],"authenticationMethods":["password"],"matcherConfigs":[{"matcherType":"Url"}],"fields":[{"page":-1,"valuePath":"Password","uuid":"00000000-0000-0000-0000-000000000000","type":"Password","matcherConfigs":[{"customMatcher":{"ids":["password"],"names":["password"],"types":["password"],"queries":[]}}]},{"page":-1,"valuePath":"UserName","uuid":"00000000-0000-0000-0000-000000000000","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":["http://test.com/1","http://test.com/2"],"regExURLs":["3","4"],"blockedURLs":["5","6"],"regExBlockedURLs":["7","8"]}'); }); test('config v1->v2', () async { @@ -86,6 +90,10 @@ void main() { '{"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":"00000000-0000-0000-0000-000000000000","type":"Password","matcherConfigs":[{"customMatcher":{"ids":["password"],"names":["password"],"types":["password"]}}]},{"page":1,"valuePath":"UserName","uuid":"00000000-0000-0000-0000-000000000000","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}', + '{"version":2,"authenticationMethods":["password"],"matcherConfigs":[{"matcherType":"Url"}],"fields":[{"page":1,"valuePath":"Password","uuid":"00000000-0000-0000-0000-000000000000","type":"Password","matcherConfigs":[{"customMatcher":{"ids":["password"],"names":["password"],"types":["password"]}}]},{"page":1,"valuePath":"UserName","uuid":"00000000-0000-0000-0000-000000000000","type":"Text","matcherConfigs":[{"customMatcher":{"ids":["username"],"names":["username"],"types":["text"]}}]}],"altUrls":["http://test.com/1","http://test.com/2"],"regExUrls":["3","4"],"blockedUrls":["5","6"],"regExBlockedUrls":["7","8"]}'); + testCaseToV2('', '{"version":2,"authenticationMethods":["password"],"matcherConfigs":[{"matcherType":"Url"}],"fields":[{"page":1,"valuePath":"UserName","uuid":"00000000-0000-0000-0000-000000000000","type":"Text","matcherConfigs":[{"matcherType":"UsernameDefaultHeuristic"}]},{"page":1,"valuePath":"Password","uuid":"00000000-0000-0000-0000-000000000000","type":"Password","matcherConfigs":[{"matcherType":"PasswordDefaultHeuristic"}]}]}'); });