-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* issue #714 pr updates * issue #714 update pub keys sorting Co-authored-by: Tom <[email protected]>
- Loading branch information
1 parent
7d8f694
commit d7a6586
Showing
2 changed files
with
26 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,27 +13,27 @@ class RecipientTests: XCTestCase { | |
private let calendar = Calendar.current | ||
|
||
func testRecipientWithRevokedKey() { | ||
let keyDetails = generateKey(expiration: nil, revoked: true) | ||
let keyDetails = createFakeKeyDetails(expiration: nil, revoked: true) | ||
let recipient = RecipientWithSortedPubKeys(email: "[email protected]", keyDetails: [keyDetails]) | ||
|
||
XCTAssertEqual(recipient.keyState, .revoked) | ||
} | ||
|
||
func testRecipientWithExpiredKey() { | ||
let expiration = Date().timeIntervalSince1970 - 60 * 60 | ||
let keyDetails = generateKey(expiration: Int(expiration), revoked: false) | ||
let keyDetails = createFakeKeyDetails(expiration: Int(expiration), revoked: false) | ||
|
||
let recipient = RecipientWithSortedPubKeys(email: "[email protected]", keyDetails: [keyDetails]) | ||
XCTAssertEqual(recipient.keyState, .expired) | ||
} | ||
|
||
func testRecipientWithValidKey() { | ||
let expiration = Date().timeIntervalSince1970 + 60 * 60 | ||
let keyDetails = generateKey(expiration: Int(expiration), revoked: false) | ||
let keyDetails = createFakeKeyDetails(expiration: Int(expiration), revoked: false) | ||
let recipient = RecipientWithSortedPubKeys(email: "[email protected]", keyDetails: [keyDetails]) | ||
XCTAssertEqual(recipient.keyState, .active) | ||
|
||
let keyDetails2 = generateKey(expiration: nil, revoked: false) | ||
let keyDetails2 = createFakeKeyDetails(expiration: nil, revoked: false) | ||
let recipient2 = RecipientWithSortedPubKeys(email: "[email protected]", keyDetails: [keyDetails2]) | ||
XCTAssertEqual(recipient2.keyState, .active) | ||
} | ||
|
@@ -45,23 +45,23 @@ class RecipientTests: XCTestCase { | |
|
||
func testRecipientKeysOrder() { | ||
let now = Int(Date().timeIntervalSince1970) | ||
let revokedKey = generateKey(expiration: now + 60 * 60, revoked: true) | ||
let revokedKey = createFakeKeyDetails(expiration: now + 1 * 3600, revoked: true) | ||
|
||
let activeKey1 = generateKey(expiration: now + 60 * 60) | ||
let activeKey2 = generateKey(expiration: now + 48 * 60 * 60) | ||
let activeKey3 = generateKey(expiration: now + 24 * 60 * 60) | ||
let activeKey1 = createFakeKeyDetails(expiration: now + 1 * 3600) | ||
let activeKey2 = createFakeKeyDetails(expiration: now + 2 * 3600) | ||
let activeKey3 = createFakeKeyDetails(expiration: now + 3 * 3600) | ||
|
||
let nonExpiringKey = generateKey(expiration: nil) | ||
let expiredKey = generateKey(expiration: now - 60 * 60) | ||
let oldExpiredKey = generateKey(expiration: now - 24 * 60 * 60) | ||
let nonExpiringKey = createFakeKeyDetails(expiration: nil) | ||
let expiredKey = createFakeKeyDetails(expiration: now - 1 * 3600) | ||
let oldExpiredKey = createFakeKeyDetails(expiration: now - 2 * 3600) | ||
|
||
let keyDetails = [revokedKey, oldExpiredKey, activeKey1, expiredKey, activeKey2, nonExpiringKey, activeKey3] | ||
let recipient = RecipientWithSortedPubKeys(email: "[email protected]", | ||
keyDetails: keyDetails) | ||
|
||
XCTAssertEqual(recipient.pubKeys[0].fingerprint, nonExpiringKey.primaryFingerprint) | ||
XCTAssertEqual(recipient.pubKeys[1].fingerprint, activeKey2.primaryFingerprint) | ||
XCTAssertEqual(recipient.pubKeys[2].fingerprint, activeKey3.primaryFingerprint) | ||
XCTAssertEqual(recipient.pubKeys[1].fingerprint, activeKey3.primaryFingerprint) | ||
XCTAssertEqual(recipient.pubKeys[2].fingerprint, activeKey2.primaryFingerprint) | ||
XCTAssertEqual(recipient.pubKeys[3].fingerprint, activeKey1.primaryFingerprint) | ||
XCTAssertEqual(recipient.pubKeys[4].fingerprint, expiredKey.primaryFingerprint) | ||
XCTAssertEqual(recipient.pubKeys[5].fingerprint, oldExpiredKey.primaryFingerprint) | ||
|
@@ -70,14 +70,14 @@ class RecipientTests: XCTestCase { | |
} | ||
|
||
extension RecipientTests { | ||
private func generateKey(expiration: Int?, revoked: Bool = false) -> KeyDetails { | ||
private func createFakeKeyDetails(expiration: Int?, revoked: Bool = false) -> KeyDetails { | ||
KeyDetails( | ||
public: "Public part", | ||
private: nil, | ||
isFullyDecrypted: false, | ||
isFullyEncrypted: false, | ||
ids: [KeyId(longid: randomString(length: 16), | ||
fingerprint: randomString(length: 16))], | ||
ids: [KeyId(longid: randomString(length: 40), | ||
fingerprint: randomString(length: 40))], | ||
created: 1, | ||
lastModified: nil, | ||
expiration: expiration, | ||
|