Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
luckyrat committed Mar 4, 2024
1 parent 29ffc8b commit e5e5563
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 10 deletions.
4 changes: 2 additions & 2 deletions lib/src/kee_vault_model/browser_entry_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<dynamic>?)?.cast<String>() ??
[],
Expand Down Expand Up @@ -168,7 +168,7 @@ class BrowserEntrySettings {
return <String, dynamic>{
'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)
Expand Down
7 changes: 4 additions & 3 deletions lib/src/kee_vault_model/field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/kee_vault_model/field_matcher_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, dynamic>)
: null,
Expand Down
21 changes: 17 additions & 4 deletions test/browser_entry_settings_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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"}]}]}',
Expand All @@ -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}',
Expand Down

0 comments on commit e5e5563

Please sign in to comment.