Skip to content

Commit

Permalink
Fix url match property name case
Browse files Browse the repository at this point in the history
  • Loading branch information
luckyrat committed Feb 22, 2024
1 parent a28d62a commit 82dc44f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
32 changes: 16 additions & 16 deletions lib/src/kee_vault_model/browser_entry_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -107,36 +107,36 @@ class BrowserEntrySettings {

static Map<String, List<String>> parseUrls(
List<Pattern> includeUrls, List<Pattern> excludeUrls) {
final altURLs = <String>[];
final regExURLs = <String>[];
final blockedURLs = <String>[];
final regExBlockedURLs = <String>[];
final altUrls = <String>[];
final regExUrls = <String>[];
final blockedUrls = <String>[];
final regExBlockedUrls = <String>[];
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 <String, List<String>>{
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<Pattern> getIncludeUrls(Map<String, dynamic> map) {
final includeUrls = <Pattern>[];
final altUrls = (map['altURLs'] as List<dynamic>?)?.cast<String>();
final regExURLs = (map['regExURLs'] as List<dynamic>?)?.cast<String>();
final altUrls = (map['altUrls'] as List<dynamic>?)?.cast<String>();
final regExURLs = (map['regExUrls'] as List<dynamic>?)?.cast<String>();
if (altUrls != null) {
altUrls.forEach(includeUrls.add);
}
Expand All @@ -150,9 +150,9 @@ class BrowserEntrySettings {

static List<Pattern> getExcludeUrls(Map<String, dynamic> map) {
final excludeUrls = <Pattern>[];
final blockedURLs = (map['blockedURLs'] as List<dynamic>?)?.cast<String>();
final blockedURLs = (map['blockedUrls'] as List<dynamic>?)?.cast<String>();
final regExBlockedURLs =
(map['regExBlockedURLs'] as List<dynamic>?)?.cast<String>();
(map['regExBlockedUrls'] as List<dynamic>?)?.cast<String>();
if (blockedURLs != null) {
blockedURLs.forEach(excludeUrls.add);
}
Expand Down
8 changes: 8 additions & 0 deletions test/browser_entry_settings_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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"}]}]}');
});
Expand Down

0 comments on commit 82dc44f

Please sign in to comment.