Format code with SwiftFormat automatically in every build
This commit is contained in:
parent
f167ab7549
commit
7f9f0e43b2
100 changed files with 1124 additions and 1063 deletions
|
|
@ -8,11 +8,11 @@
|
|||
|
||||
import XCTest
|
||||
|
||||
// swiftformat:disable:next sortedImports
|
||||
@testable import passKit
|
||||
@testable import Crypto
|
||||
|
||||
class CryptoFrameworkTest: XCTestCase {
|
||||
|
||||
typealias MessageConverter = (CryptoPGPMessage, NSErrorPointer) -> CryptoPGPMessage?
|
||||
|
||||
private let testText = "Hello World!"
|
||||
|
|
@ -47,7 +47,7 @@ class CryptoFrameworkTest: XCTestCase {
|
|||
].forEach { testKeyInfo in
|
||||
var error: NSError?
|
||||
guard let publicKey = CryptoNewKeyFromArmored(testKeyInfo.publicKey, &error),
|
||||
let privateKey = CryptoNewKeyFromArmored(testKeyInfo.privateKey, &error) else {
|
||||
let privateKey = CryptoNewKeyFromArmored(testKeyInfo.privateKey, &error) else {
|
||||
XCTFail("Keys cannot be initialized.")
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@
|
|||
// Copyright © 2019 Bob Sun. All rights reserved.
|
||||
//
|
||||
|
||||
import XCTest
|
||||
import SwiftyUserDefaults
|
||||
import XCTest
|
||||
|
||||
@testable import passKit
|
||||
|
||||
|
|
@ -144,17 +144,17 @@ class PGPAgentTest: XCTestCase {
|
|||
passphraseRequestCalledCount += 1
|
||||
return "incorrect passphrase"
|
||||
}
|
||||
|
||||
|
||||
// Provide the correct passphrase.
|
||||
XCTAssertEqual(try basicEncryptDecrypt(using: pgpAgent, keyID: RSA2048.fingerprint, requestPassphrase: provideCorrectPassphrase), testData)
|
||||
XCTAssertEqual(passphraseRequestCalledCount, 1)
|
||||
|
||||
|
||||
// Provide the wrong passphrase.
|
||||
XCTAssertThrowsError(try basicEncryptDecrypt(using: pgpAgent, keyID: RSA2048.fingerprint, requestPassphrase: provideIncorrectPassphrase)) {
|
||||
XCTAssertEqual($0 as! AppError, AppError.WrongPassphrase)
|
||||
}
|
||||
XCTAssertEqual(passphraseRequestCalledCount, 2)
|
||||
|
||||
|
||||
// Ask for the passphrase because the previous decryption has failed.
|
||||
XCTAssertEqual(try basicEncryptDecrypt(using: pgpAgent, keyID: RSA2048.fingerprint, requestPassphrase: provideCorrectPassphrase), testData)
|
||||
XCTAssertEqual(passphraseRequestCalledCount, 3)
|
||||
|
|
@ -165,4 +165,3 @@ class PGPAgentTest: XCTestCase {
|
|||
try KeyFileManager(keyType: PgpKey.PRIVATE, keyPath: "", keyHandler: keychain.add).importKey(from: privateKey)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ import XCTest
|
|||
@testable import passKit
|
||||
|
||||
class ArraySlicesTest: XCTestCase {
|
||||
|
||||
func testZeroCount() {
|
||||
XCTAssertEqual([1, 2, 3].slices(count: 0), [])
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ import XCTest
|
|||
@testable import passKit
|
||||
|
||||
class StringUtilitiesTest: XCTestCase {
|
||||
|
||||
func testTrimmed() {
|
||||
[
|
||||
(" ", ""),
|
||||
|
|
|
|||
|
|
@ -6,20 +6,20 @@
|
|||
//
|
||||
|
||||
import Foundation
|
||||
import XCTest
|
||||
import ObjectiveGit
|
||||
import XCTest
|
||||
|
||||
@testable import passKit
|
||||
|
||||
class PasswordStoreTest: XCTestCase {
|
||||
let cloneOptions: [String : GTCredentialProvider] = {
|
||||
let credentialProvider = GTCredentialProvider { (_, _, _) -> (GTCredential?) in
|
||||
try? GTCredential(userName: "", password: "")
|
||||
}
|
||||
return [GTRepositoryCloneOptionsCredentialProvider: credentialProvider]
|
||||
}()
|
||||
let remoteRepoURL = URL(string: "https://github.com/mssun/passforios-password-store.git")!
|
||||
let cloneOptions: [String: GTCredentialProvider] = {
|
||||
let credentialProvider = GTCredentialProvider { (_, _, _) -> (GTCredential?) in
|
||||
try? GTCredential(userName: "", password: "")
|
||||
}
|
||||
return [GTRepositoryCloneOptionsCredentialProvider: credentialProvider]
|
||||
}()
|
||||
|
||||
let remoteRepoURL = URL(string: "https://github.com/mssun/passforios-password-store.git")!
|
||||
|
||||
func testCloneAndDecryptMultiKeys() throws {
|
||||
let url = URL(fileURLWithPath: "\(Globals.repositoryPath)-test")
|
||||
|
|
@ -38,8 +38,8 @@ class PasswordStoreTest: XCTestCase {
|
|||
|
||||
[
|
||||
("work/github.com", "4712286271220DB299883EA7062E678DA1024DAE"),
|
||||
("personal/github.com", "787EAE1A5FA3E749AA34CC6AA0645EBED862027E")
|
||||
].forEach {(path, id) in
|
||||
("personal/github.com", "787EAE1A5FA3E749AA34CC6AA0645EBED862027E"),
|
||||
].forEach { path, id in
|
||||
let keyID = findGPGID(from: url.appendingPathComponent(path))
|
||||
XCTAssertEqual(keyID, id)
|
||||
}
|
||||
|
|
@ -57,17 +57,14 @@ class PasswordStoreTest: XCTestCase {
|
|||
|
||||
let testPassword = Password(name: "test", url: URL(string: "test.gpg")!, plainText: "testpassword")
|
||||
let testPasswordEntity = try passwordStore.add(password: testPassword)!
|
||||
let testPasswordPlain = try passwordStore.decrypt(passwordEntity: testPasswordEntity, requestPGPKeyPassphrase: requestPGPKeyPassphrase )
|
||||
let testPasswordPlain = try passwordStore.decrypt(passwordEntity: testPasswordEntity, requestPGPKeyPassphrase: requestPGPKeyPassphrase)
|
||||
XCTAssertEqual(testPasswordPlain.plainText, "testpassword")
|
||||
|
||||
passwordStore.erase()
|
||||
}
|
||||
|
||||
private func decrypt(passwordStore: PasswordStore, path: String, passphrase: String) throws -> Password {
|
||||
private func decrypt(passwordStore: PasswordStore, path: String, passphrase _: String) throws -> Password {
|
||||
let entity = passwordStore.getPasswordEntity(by: path, isDir: false)!
|
||||
return try passwordStore.decrypt(passwordEntity: entity, requestPGPKeyPassphrase: requestPGPKeyPassphrase )
|
||||
|
||||
return try passwordStore.decrypt(passwordEntity: entity, requestPGPKeyPassphrase: requestPGPKeyPassphrase)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ import XCTest
|
|||
@testable import passKit
|
||||
|
||||
class PasswordTableEntryTest: XCTestCase {
|
||||
|
||||
func testExample() {
|
||||
let nameWithCategoryList = [
|
||||
"github",
|
||||
|
|
@ -27,13 +26,13 @@ class PasswordTableEntryTest: XCTestCase {
|
|||
]
|
||||
let searchTextList1 = [
|
||||
"github.com",
|
||||
"www.github.com"
|
||||
"www.github.com",
|
||||
]
|
||||
let searchTextList2 = [
|
||||
"xx.com",
|
||||
"www.xx.com"
|
||||
"www.xx.com",
|
||||
]
|
||||
|
||||
|
||||
for nameWithCategory in nameWithCategoryList {
|
||||
for searchText in searchTextList1 {
|
||||
XCTAssertTrue(PasswordTableEntry.match(nameWithCategory: nameWithCategory, searchText: searchText))
|
||||
|
|
@ -43,5 +42,4 @@ class PasswordTableEntryTest: XCTestCase {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ import XCTest
|
|||
@testable import passKit
|
||||
|
||||
class PasswordTest: XCTestCase {
|
||||
|
||||
func testUrl() {
|
||||
let password = getPasswordObjectWith(content: "")
|
||||
|
||||
|
|
@ -245,7 +244,6 @@ class PasswordTest: XCTestCase {
|
|||
XCTAssertEqual(password.nameFromPath, "exampleusername")
|
||||
}
|
||||
|
||||
|
||||
func testMultilineValues() {
|
||||
let lineBreakField = "with line breaks" => "|\n This is \n text spread over \n multiple lines! "
|
||||
let noLineBreakField = "without line breaks" => " > \n This is \n text spread over\n multiple lines!"
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ import XCTest
|
|||
@testable import passKit
|
||||
|
||||
class AdditionFieldTest: XCTestCase {
|
||||
|
||||
func testAdditionField() {
|
||||
let field1 = AdditionField(title: "key", content: "value")
|
||||
let field2 = AdditionField(title: "no content")
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ import XCTest
|
|||
@testable import passKit
|
||||
|
||||
class ConstantsTest: XCTestCase {
|
||||
|
||||
func testIsOtpRelated() {
|
||||
XCTAssert(Constants.isOtpRelated(line: "otpauth://something"))
|
||||
XCTAssert(Constants.isOtpRelated(line: "otp_algorithm: algorithm"))
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@ import XCTest
|
|||
@testable import passKit
|
||||
|
||||
class OTPTypeTest: XCTestCase {
|
||||
|
||||
func testInitFromToken() {
|
||||
let secret = "secret".data(using: .utf8)!
|
||||
|
||||
|
|
|
|||
|
|
@ -6,11 +6,10 @@
|
|||
// Copyright © 2018 Bob Sun. All rights reserved.
|
||||
//
|
||||
|
||||
@testable import passKit
|
||||
import XCTest
|
||||
@testable import passKit
|
||||
|
||||
class ParserTest: XCTestCase {
|
||||
|
||||
func testInit() {
|
||||
[
|
||||
("", "", "", []),
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@ import XCTest
|
|||
@testable import passKit
|
||||
|
||||
class TokenBuilderTest: XCTestCase {
|
||||
|
||||
private let SECRET = "secret"
|
||||
private let DIGITS = Constants.DEFAULT_DIGITS
|
||||
private let TIMER = Generator.Factor.timer(period: Constants.DEFAULT_PERIOD)
|
||||
|
|
|
|||
|
|
@ -11,10 +11,9 @@ import XCTest
|
|||
@testable import passKit
|
||||
|
||||
class PasswordGeneratorFlavorTest: XCTestCase {
|
||||
|
||||
func testLengthLimits() {
|
||||
// Ensure properly chosen length limits. So this check no longer needs to be performed in the code.
|
||||
PasswordGeneratorFlavor.allCases.map { $0.lengthLimits }.forEach {
|
||||
PasswordGeneratorFlavor.allCases.map(\.lengthLimits).forEach {
|
||||
XCTAssertLessThanOrEqual($0.min, $0.max)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ import XCTest
|
|||
@testable import passKit
|
||||
|
||||
class PasswordGeneratorTest: XCTestCase {
|
||||
|
||||
func testLimitedLength() {
|
||||
[
|
||||
PasswordGenerator(length: 15),
|
||||
|
|
|
|||
|
|
@ -21,15 +21,15 @@ class DictBasedKeychain: KeyStore {
|
|||
}
|
||||
|
||||
public func contains(key: String) -> Bool {
|
||||
return store[key] != nil
|
||||
store[key] != nil
|
||||
}
|
||||
|
||||
public func get(for key: String) -> Data? {
|
||||
return store[key] as? Data
|
||||
store[key] as? Data
|
||||
}
|
||||
|
||||
public func get(for key: String) -> String? {
|
||||
return store[key] as? String
|
||||
store[key] as? String
|
||||
}
|
||||
|
||||
public func removeContent(for key: String) {
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ let MULTILINE_BLOCK_START = "multiline block" => "|"
|
|||
let MULTILINE_LINE_START = "multiline line" => ">"
|
||||
|
||||
func getPasswordObjectWith(content: String, url: URL? = nil) -> Password {
|
||||
return Password(name: "password", url: url ?? PASSWORD_URL, plainText: content)
|
||||
Password(name: "password", url: url ?? PASSWORD_URL, plainText: content)
|
||||
}
|
||||
|
||||
func assertDefaults(in password: Password, with passwordString: String, and additions: String,
|
||||
|
|
@ -44,11 +44,11 @@ func assertDefaults(in password: Password, with passwordString: String, and addi
|
|||
}
|
||||
|
||||
infix operator ∈: AdditionPrecedence
|
||||
func ∈(field: AdditionField, password: Password) -> Bool {
|
||||
return password.getFilteredAdditions().contains(field)
|
||||
func ∈ (field: AdditionField, password: Password) -> Bool {
|
||||
password.getFilteredAdditions().contains(field)
|
||||
}
|
||||
|
||||
infix operator ∉: AdditionPrecedence
|
||||
func ∉(field: AdditionField, password: Password) -> Bool {
|
||||
return !(field ∈ password)
|
||||
func ∉ (field: AdditionField, password: Password) -> Bool {
|
||||
!(field ∈ password)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ import XCTest
|
|||
@testable import passKit
|
||||
|
||||
struct PGPTestSet {
|
||||
|
||||
fileprivate static var ALL_TEST_SETS: [String: PGPTestSet] = [:]
|
||||
|
||||
let publicKey: String
|
||||
|
|
@ -81,14 +80,14 @@ let NISTP384 = PGPTestSet(
|
|||
passphrase: "soirofssap"
|
||||
).collect()
|
||||
|
||||
let RSA2048_RSA4096 = MultiKeyPGPTestSet(
|
||||
let RSA2048_RSA4096 = MultiKeyPGPTestSet(
|
||||
publicKeys: PGP_RSA2048_PUBLIC_KEY | PGP_RSA4096_PUBLIC_KEY,
|
||||
privateKeys: PGP_RSA2048_PRIVATE_KEY | PGP_RSA4096_PRIVATE_KEY,
|
||||
fingerprints: ["a1024dae", "d862027e"],
|
||||
passphrases: ["passforios", "passforios"]
|
||||
)
|
||||
|
||||
let ED25519_NISTP384 = MultiKeyPGPTestSet(
|
||||
let ED25519_NISTP384 = MultiKeyPGPTestSet(
|
||||
publicKeys: PGP_ED25519_PUBLIC_KEY | PGP_NISTP384_PUBLIC_KEY,
|
||||
privateKeys: PGP_ED25519_PRIVATE_KEY | PGP_NISTP384_PRIVATE_KEY,
|
||||
fingerprints: ["e9444483", "5af3c085"],
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ import XCTest
|
|||
@testable import passKit
|
||||
|
||||
class passKitTests: XCTestCase {
|
||||
|
||||
override func setUp() {
|
||||
super.setUp()
|
||||
// Put setup code here. This method is called before the invocation of each test method in the class.
|
||||
|
|
@ -28,9 +27,8 @@ class passKitTests: XCTestCase {
|
|||
|
||||
func testPerformanceExample() {
|
||||
// This is an example of a performance test case.
|
||||
self.measure {
|
||||
measure {
|
||||
// Put the code you want to measure the time of here.
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue