Introduce utility methods to test for unknowns and OTP keywords
This commit is contained in:
parent
bb6e44950f
commit
68dd60fb8e
3 changed files with 25 additions and 3 deletions
|
|
@ -112,8 +112,8 @@ public class Password {
|
||||||
return title != Constants.USERNAME_KEYWORD
|
return title != Constants.USERNAME_KEYWORD
|
||||||
&& title != Constants.LOGIN_KEYWORD
|
&& title != Constants.LOGIN_KEYWORD
|
||||||
&& title != Constants.PASSWORD_KEYWORD
|
&& title != Constants.PASSWORD_KEYWORD
|
||||||
&& (!field.title.hasPrefix(Constants.UNKNOWN) || !SharedDefaults[.isHideUnknownOn])
|
&& (!Constants.isUnknown(title) || !SharedDefaults[.isHideUnknownOn])
|
||||||
&& (!Constants.OTP_KEYWORDS.contains(title) || !SharedDefaults[.isHideOTPOn])
|
&& (!Constants.isOtpKeyword(title) || !SharedDefaults[.isHideOTPOn])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,15 @@ public struct Constants {
|
||||||
|
|
||||||
public static func isOtpRelated(line: String) -> Bool {
|
public static func isOtpRelated(line: String) -> Bool {
|
||||||
let (key, _) = Parser.getKeyValuePair(from: line)
|
let (key, _) = Parser.getKeyValuePair(from: line)
|
||||||
return OTP_KEYWORDS.contains(key ?? "")
|
return key != nil && isOtpKeyword(key!)
|
||||||
|
}
|
||||||
|
|
||||||
|
static func isOtpKeyword(_ keyword: String) -> Bool {
|
||||||
|
return OTP_KEYWORDS.contains(keyword.lowercased())
|
||||||
|
}
|
||||||
|
|
||||||
|
static func isUnknown(_ string: String) -> Bool {
|
||||||
|
return string.starts(with: UNKNOWN)
|
||||||
}
|
}
|
||||||
|
|
||||||
static func unknown(_ number: UInt) -> String {
|
static func unknown(_ number: UInt) -> String {
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,20 @@ class ConstantsTest: XCTestCase {
|
||||||
XCTAssertFalse(Constants.isOtpRelated(line: "otp"))
|
XCTAssertFalse(Constants.isOtpRelated(line: "otp"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testIsOtpKeyword() {
|
||||||
|
XCTAssertTrue(Constants.isOtpKeyword("otpauth"))
|
||||||
|
XCTAssertTrue(Constants.isOtpKeyword("oTP_DigITS"))
|
||||||
|
XCTAssertFalse(Constants.isOtpKeyword("otp"))
|
||||||
|
XCTAssertFalse(Constants.isOtpKeyword("no keyword"))
|
||||||
|
}
|
||||||
|
|
||||||
|
func testIsUnknown() {
|
||||||
|
XCTAssertTrue(Constants.isUnknown("unknown"))
|
||||||
|
XCTAssertTrue(Constants.isUnknown("unknown string"))
|
||||||
|
XCTAssertFalse(Constants.isUnknown("otp"))
|
||||||
|
XCTAssertFalse(Constants.isUnknown("Unknown"))
|
||||||
|
}
|
||||||
|
|
||||||
func testUnknown() {
|
func testUnknown() {
|
||||||
XCTAssertEqual(Constants.unknown(0), "unknown 0")
|
XCTAssertEqual(Constants.unknown(0), "unknown 0")
|
||||||
XCTAssertEqual(Constants.unknown(10), "unknown 10")
|
XCTAssertEqual(Constants.unknown(10), "unknown 10")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue