mirror of
https://github.com/bitwarden/mobile.git
synced 2024-12-26 16:57:59 +01:00
[KnownUsernameField] Engine update (make the system more flexible) (#1011)
* [KnownUsernameField] Engine update (make the system more flexible) * [KnownUsernameField] Engine update (make the system more flexible) * Use of tuples array instead of multidimensional array (string[,]) * Use of tuples array instead of multidimensional array (string[,]) * [FIX] IndexOf -> Contains
This commit is contained in:
parent
3b4ef4d238
commit
22570e08aa
@ -133,12 +133,12 @@ namespace Bit.Droid.Accessibility
|
||||
// Be sure to keep these entries sorted alphabetically
|
||||
public static Dictionary<string, KnownUsernameField> KnownUsernameFields => new List<KnownUsernameField>
|
||||
{
|
||||
new KnownUsernameField("accounts.google.com", "ServiceLogin", "Email"),
|
||||
new KnownUsernameField("amazon.com", "signin", "ap_email_login"),
|
||||
new KnownUsernameField("github.com", "", "user[login]-footer"),
|
||||
new KnownUsernameField("paypal.com", "signin", "email"),
|
||||
new KnownUsernameField("signin.aws.amazon.com", "signin", "resolving_input"),
|
||||
new KnownUsernameField("signin.ebay.com", "eBayISAPI.dll", "userid"),
|
||||
new KnownUsernameField("accounts.google.com", new (string, string)[] { ("ServiceLogin", "Email") }),
|
||||
new KnownUsernameField("amazon.com", new (string, string)[] { ("signin", "ap_email_login") }),
|
||||
new KnownUsernameField("github.com", new (string, string)[] { ("", "user[login]-footer") }),
|
||||
new KnownUsernameField("paypal.com", new (string, string)[] { ("signin", "email") }),
|
||||
new KnownUsernameField("signin.aws.amazon.com", new (string, string)[] { ("signin", "resolving_input") }),
|
||||
new KnownUsernameField("signin.ebay.com", new (string, string)[] { ("eBayISAPI.dll", "userid") }),
|
||||
}.ToDictionary(n => n.UriAuthority);
|
||||
|
||||
public static void PrintTestData(AccessibilityNodeInfo root, AccessibilityEvent e)
|
||||
@ -314,7 +314,7 @@ namespace Bit.Droid.Accessibility
|
||||
if (Uri.TryCreate(uriString, UriKind.Absolute, out var uri))
|
||||
{
|
||||
uriAuthority = uri.Authority;
|
||||
uriKey = uriAuthority.StartsWith("www.") ? uriAuthority.Substring(4) : uriAuthority;
|
||||
uriKey = uriAuthority.StartsWith("www.", StringComparison.Ordinal) ? uriAuthority.Substring(4) : uriAuthority;
|
||||
uriLocalPath = uri.LocalPath;
|
||||
}
|
||||
|
||||
@ -330,11 +330,59 @@ namespace Bit.Droid.Accessibility
|
||||
if (KnownUsernameFields.ContainsKey(uriKey))
|
||||
{
|
||||
var usernameField = KnownUsernameFields[uriKey];
|
||||
if (uriLocalPath.EndsWith(usernameField.UriPathEnd))
|
||||
(string UriPathWanted, string UsernameViewId)[] accessOptions = usernameField.AccessOptions;
|
||||
|
||||
for (int i = 0; i < accessOptions.Length; i++)
|
||||
{
|
||||
string curUriPathWanted = accessOptions[i].UriPathWanted;
|
||||
string curUsernameViewId = accessOptions[i].UsernameViewId;
|
||||
bool uriLocalPathMatches = false;
|
||||
|
||||
// Case-sensitive comparison
|
||||
if (curUriPathWanted.StartsWith("startswith:", StringComparison.Ordinal))
|
||||
{
|
||||
curUriPathWanted = curUriPathWanted.Substring(11);
|
||||
uriLocalPathMatches = uriLocalPath.StartsWith(curUriPathWanted, StringComparison.Ordinal);
|
||||
}
|
||||
else if (curUriPathWanted.StartsWith("contains:", StringComparison.Ordinal))
|
||||
{
|
||||
curUriPathWanted = curUriPathWanted.Substring(9);
|
||||
uriLocalPathMatches = uriLocalPath.Contains(curUriPathWanted, StringComparison.Ordinal);
|
||||
}
|
||||
else if (curUriPathWanted.StartsWith("endswith:", StringComparison.Ordinal))
|
||||
{
|
||||
curUriPathWanted = curUriPathWanted.Substring(9);
|
||||
uriLocalPathMatches = uriLocalPath.EndsWith(curUriPathWanted, StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
// Case-insensitive comparison
|
||||
else if (curUriPathWanted.StartsWith("istartswith:", StringComparison.Ordinal))
|
||||
{
|
||||
curUriPathWanted = curUriPathWanted.Substring(12);
|
||||
uriLocalPathMatches = uriLocalPath.StartsWith(curUriPathWanted, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
else if (curUriPathWanted.StartsWith("icontains:", StringComparison.Ordinal))
|
||||
{
|
||||
curUriPathWanted = curUriPathWanted.Substring(10);
|
||||
uriLocalPathMatches = uriLocalPath.Contains(curUriPathWanted, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
else if (curUriPathWanted.StartsWith("iendswith:", StringComparison.Ordinal))
|
||||
{
|
||||
curUriPathWanted = curUriPathWanted.Substring(10);
|
||||
uriLocalPathMatches = uriLocalPath.EndsWith(curUriPathWanted, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
// Default type of comparison
|
||||
else
|
||||
{
|
||||
uriLocalPathMatches = uriLocalPath.EndsWith(curUriPathWanted, StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
if (uriLocalPathMatches)
|
||||
{
|
||||
foreach (var editText in allEditTexts)
|
||||
{
|
||||
foreach (var usernameViewId in usernameField.UsernameViewId.Split(","))
|
||||
foreach (var usernameViewId in curUsernameViewId.Split(","))
|
||||
{
|
||||
if (usernameViewId == editText.ViewIdResourceName)
|
||||
{
|
||||
@ -345,6 +393,7 @@ namespace Bit.Droid.Accessibility
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// no match found, attempt to establish username field based on password field
|
||||
return GetUsernameEditTextIfPasswordExists(allEditTexts);
|
||||
|
@ -2,15 +2,13 @@
|
||||
{
|
||||
public class KnownUsernameField
|
||||
{
|
||||
public KnownUsernameField(string uriAuthority, string uriPathEnd, string usernameViewId)
|
||||
public KnownUsernameField(string uriAuthority, (string UriPathWanted, string UsernameViewId)[] accessOptions)
|
||||
{
|
||||
UriAuthority = uriAuthority;
|
||||
UriPathEnd = uriPathEnd;
|
||||
UsernameViewId = usernameViewId;
|
||||
AccessOptions = accessOptions;
|
||||
}
|
||||
|
||||
public string UriAuthority { get; set; }
|
||||
public string UriPathEnd { get; set; }
|
||||
public string UsernameViewId { get; set; }
|
||||
public (string UriPathWanted, string UsernameViewId)[] AccessOptions { get; set; }
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user