Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
luckyrat committed Feb 20, 2024
1 parent 80fd9c0 commit 28c4b5c
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 33 deletions.
7 changes: 4 additions & 3 deletions lib/src/kee_vault_model/browser_entry_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,11 @@ class BrowserEntrySettings {
return <String, dynamic>{
'version': version,
'authenticationMethods': authenticationMethods,
'hTTPRealm': realm,
if (fields != null) 'fields': fields?.map((x) => x.toMap()).toList(),
'behaviour': behaviour?.name,
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)
'behaviour': behaviour?.name,
...parseUrls(includeUrls, excludeUrls),
};
}
Expand Down
12 changes: 8 additions & 4 deletions lib/src/kee_vault_model/browser_entry_settings_v1.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,14 @@ class BrowserEntrySettingsV1 {
}

factory BrowserEntrySettingsV1.fromJson(String source,
{required MatchAccuracy minimumMatchAccuracy}) =>
BrowserEntrySettingsV1.fromMap(
json.decode(source) as Map<String, dynamic>?,
minimumMatchAccuracy: minimumMatchAccuracy);
{required MatchAccuracy minimumMatchAccuracy}) {
if (source.isEmpty) {
return BrowserEntrySettingsV1(minimumMatchAccuracy: minimumMatchAccuracy);
}
return BrowserEntrySettingsV1.fromMap(
json.decode(source) as Map<String, dynamic>?,
minimumMatchAccuracy: minimumMatchAccuracy);
}

int version;
// enum
Expand Down
11 changes: 6 additions & 5 deletions lib/src/kee_vault_model/entry_matcher_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,12 @@ class EntryMatcherConfig {
Map<String, dynamic> toMap() {
return {
'matcherType': matcherType?.name,
'customMatcher': customMatcher?.toMap(),
'urlMatchMethod': urlMatchMethod?.name,
'weight': weight,
'actionOnMatch': actionOnMatch?.name,
'actionOnNoMatch': actionOnNoMatch?.name,
if (customMatcher != null) 'customMatcher': customMatcher?.toMap(),
if (urlMatchMethod != null && urlMatchMethod != MatchAccuracy.Domain)
'urlMatchMethod': urlMatchMethod?.name,
if (weight != null) 'weight': weight,
if (actionOnMatch != null) 'actionOnMatch': actionOnMatch?.name,
if (actionOnNoMatch != null) 'actionOnNoMatch': actionOnNoMatch?.name,
};
}

Expand Down
12 changes: 7 additions & 5 deletions lib/src/kee_vault_model/field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,16 @@ class Field {

Map<String, dynamic> toMap() {
return {
'uuid': uuid,
'name': name,
'valuePath': valuePath,
'value': value,
'page': page,
'valuePath': valuePath,
'uuid': uuid,
'type': type?.name,
'placeholderHandling': placeholderHandling?.name,
'matcherConfigs': matcherConfigs?.map((x) => x.toMap()).toList(),
if (name?.isNotEmpty ?? false) 'name': name,
if (value?.isNotEmpty ?? false) 'value': value,
if (placeholderHandling != null &&
placeholderHandling != PlaceholderHandling.Default)
'placeholderHandling': placeholderHandling?.name,
};
}

Expand Down
20 changes: 11 additions & 9 deletions lib/src/kee_vault_model/field_matcher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,17 @@ class FieldMatcher {

Map<String, dynamic> toMap() {
return {
'matchLogic': matchLogic?.name,
'ids': ids,
'names': names,
'types': types,
'queries': queries,
'labels': labels,
'autocompleteValues': autocompleteValues,
'maxLength': maxLength,
'minLength': minLength,
if (matchLogic != null && matchLogic != MatcherLogic.Client)
'matchLogic': matchLogic?.name,
if (ids.isNotEmpty) 'ids': ids,
if (names.isNotEmpty) 'names': names,
if (types.isNotEmpty) 'types': types,
if (queries.isNotEmpty) 'queries': queries,
if (labels.isNotEmpty) 'labels': labels,
if (autocompleteValues.isNotEmpty)
'autocompleteValues': autocompleteValues,
if (maxLength != null) 'maxLength': maxLength,
if (minLength != null) 'minLength': minLength,
};
}

Expand Down
9 changes: 5 additions & 4 deletions lib/src/kee_vault_model/field_matcher_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,11 @@ class FieldMatcherConfig {

Map<String, dynamic> toMap() {
return {
'matcherType': matcherType?.name,
'customMatcher': customMatcher?.toMap(),
'weight': weight,
'actionOnMatch': actionOnMatch?.name,
if (matcherType != null && matcherType != FieldMatcherType.Custom)
'matcherType': matcherType?.name,
if (customMatcher != null) 'customMatcher': customMatcher?.toMap(),
if (weight != null) 'weight': weight,
if (actionOnMatch != null) 'actionOnMatch': actionOnMatch?.name,
};
}

Expand Down
13 changes: 10 additions & 3 deletions test/browser_entry_settings_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,18 @@ void main() {
test('config v1->v2', () async {
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":"FFTradio","id":"username","page":-1,"placeholderHandling":"Default"}],"alwaysAutoFill":false,"neverAutoFill":false,"alwaysAutoSubmit":false,"neverAutoSubmit":false,"priority":0,"altURLs":[],"hide":true,"blockHostnameOnlyMatch":false,"blockDomainOnlyMatch":false}',
'{"version":2,"authenticationMethods":["password"],"matcherConfigs":[{"matcherType":"Url"},{"matcherType":"Hide"}],"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":[]}}]}],"altUrls":[]}');
'{"version":2,"authenticationMethods":["password"],"matcherConfigs":[{"matcherType":"Url"},{"matcherType":"Hide"}],"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"]}}]}]}');

// testCase("{\"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\":\"FFTradio\",\"id\":\"username\",\"page\":-1,\"placeholderHandling\":\"Default\"}],\"alwaysAutoFill\":false,\"neverAutoFill\":false,\"alwaysAutoSubmit\":false,\"neverAutoSubmit\":false,\"priority\":0,\"altURLs\":[],\"hide\":true,\"blockHostnameOnlyMatch\":false,\"blockDomainOnlyMatch\":false}",
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":"FFTradio","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":[],"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"]}}]}]}');

// "{\"version\":2,\"altUrls\":[],\"authenticationMethods\":[\"password\"],\"matcherConfigs\":[{\"matcherType\":\"Url\"},{\"matcherType\":\"Hide\"}],\"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\":[]}}]}]}");
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"}]}]}');
});
});
}

0 comments on commit 28c4b5c

Please sign in to comment.