generated from bitwarden/template
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into jubie/BIT-2300-mask-totp
- Loading branch information
Showing
132 changed files
with
2,307 additions
and
672 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
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
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
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 |
---|---|---|
|
@@ -12,6 +12,7 @@ class AuthRepositoryTests: BitwardenTestCase { // swiftlint:disable:this type_bo | |
var biometricsRepository: MockBiometricsRepository! | ||
var client: MockHTTPClient! | ||
var clientService: MockClientService! | ||
var configService: MockConfigService! | ||
var environmentService: MockEnvironmentService! | ||
var keychainService: MockKeychainRepository! | ||
var organizationService: MockOrganizationService! | ||
|
@@ -86,6 +87,7 @@ class AuthRepositoryTests: BitwardenTestCase { // swiftlint:disable:this type_bo | |
accountAPIService = APIService(client: client) | ||
authService = MockAuthService() | ||
biometricsRepository = MockBiometricsRepository() | ||
configService = MockConfigService() | ||
environmentService = MockEnvironmentService() | ||
keychainService = MockKeychainRepository() | ||
organizationService = MockOrganizationService() | ||
|
@@ -98,6 +100,7 @@ class AuthRepositoryTests: BitwardenTestCase { // swiftlint:disable:this type_bo | |
authService: authService, | ||
biometricsRepository: biometricsRepository, | ||
clientService: clientService, | ||
configService: configService, | ||
environmentService: environmentService, | ||
keychainService: keychainService, | ||
organizationAPIService: APIService(client: client), | ||
|
@@ -117,6 +120,7 @@ class AuthRepositoryTests: BitwardenTestCase { // swiftlint:disable:this type_bo | |
biometricsRepository = nil | ||
client = nil | ||
clientService = nil | ||
configService = nil | ||
environmentService = nil | ||
keychainService = nil | ||
organizationService = nil | ||
|
@@ -133,12 +137,12 @@ class AuthRepositoryTests: BitwardenTestCase { // swiftlint:disable:this type_bo | |
let userId = Account.fixture().profile.userId | ||
|
||
stateService.pinProtectedUserKeyValue[userId] = "123" | ||
stateService.pinKeyEncryptedUserKeyValue[userId] = "123" | ||
stateService.encryptedPinByUserId[userId] = "123" | ||
stateService.accountVolatileData[userId]?.pinProtectedUserKey = "123" | ||
|
||
try await subject.clearPins() | ||
XCTAssertNil(stateService.pinProtectedUserKeyValue[userId]) | ||
XCTAssertNil(stateService.pinKeyEncryptedUserKeyValue[userId]) | ||
XCTAssertNil(stateService.encryptedPinByUserId[userId]) | ||
XCTAssertNil(stateService.accountVolatileData[userId]?.pinProtectedUserKey) | ||
} | ||
|
||
|
@@ -171,6 +175,10 @@ class AuthRepositoryTests: BitwardenTestCase { // swiftlint:disable:this type_bo | |
XCTAssertEqual(clientService.mockAuth.makeRegisterTdeKeysEmail, "[email protected]") | ||
XCTAssertEqual(clientService.mockAuth.makeRegisterTdeKeysOrgPublicKey, "MIIBIjAN...2QIDAQAB") | ||
XCTAssertEqual(clientService.mockAuth.makeRegisterTdeKeysRememberDevice, true) | ||
XCTAssertEqual( | ||
stateService.accountEncryptionKeys["1"], | ||
AccountEncryptionKeys(encryptedPrivateKey: "privateKey", encryptedUserKey: nil) | ||
) | ||
} | ||
|
||
/// `createNewSsoUser()` creates a new account for sso JIT user and don't trust device. | ||
|
@@ -200,6 +208,10 @@ class AuthRepositoryTests: BitwardenTestCase { // swiftlint:disable:this type_bo | |
XCTAssertNil(trustDeviceService.trustDeviceWithExistingKeysValue) | ||
XCTAssertEqual(clientService.mockAuth.makeRegisterTdeKeysOrgPublicKey, "MIIBIjAN...2QIDAQAB") | ||
XCTAssertEqual(clientService.mockAuth.makeRegisterTdeKeysRememberDevice, false) | ||
XCTAssertEqual( | ||
stateService.accountEncryptionKeys["1"], | ||
AccountEncryptionKeys(encryptedPrivateKey: "privateKey", encryptedUserKey: nil) | ||
) | ||
} | ||
|
||
/// `deleteAccount()` deletes the active account and removes it from the state. | ||
|
@@ -1029,7 +1041,7 @@ class AuthRepositoryTests: BitwardenTestCase { // swiftlint:disable:this type_bo | |
let userId = account.profile.userId | ||
try await subject.setPins("123", requirePasswordAfterRestart: true) | ||
XCTAssertEqual(stateService.pinProtectedUserKeyValue[userId], "12") | ||
XCTAssertEqual(stateService.pinKeyEncryptedUserKeyValue[userId], "34") | ||
XCTAssertEqual(stateService.encryptedPinByUserId[userId], "34") | ||
XCTAssertEqual(stateService.accountVolatileData[ | ||
userId, | ||
default: AccountVolatileData() | ||
|
@@ -1299,7 +1311,7 @@ class AuthRepositoryTests: BitwardenTestCase { // swiftlint:disable:this type_bo | |
"1": AccountEncryptionKeys(encryptedPrivateKey: "PRIVATE_KEY", encryptedUserKey: "USER_KEY"), | ||
] | ||
|
||
stateService.pinKeyEncryptedUserKeyValue[account.profile.userId] = "123" | ||
stateService.encryptedPinByUserId[account.profile.userId] = "123" | ||
stateService.pinProtectedUserKeyValue[account.profile.userId] = "123" | ||
|
||
await assertAsyncDoesNotThrow { | ||
|
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
50 changes: 50 additions & 0 deletions
50
BitwardenShared/Core/Auth/Services/API/Auth/Requests/CheckLoginRequestRequestTests.swift
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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import Networking | ||
import XCTest | ||
|
||
@testable import BitwardenShared | ||
|
||
class CheckLoginRequestRequestTests: BitwardenTestCase { | ||
// MARK: Properties | ||
|
||
var subject: CheckLoginRequestRequest! | ||
|
||
// MARK: Setup & Teardown | ||
|
||
override func setUp() { | ||
super.setUp() | ||
subject = CheckLoginRequestRequest(accessCode: "ACCESS_CODE", id: "ID") | ||
} | ||
|
||
override func tearDown() { | ||
super.tearDown() | ||
subject = nil | ||
} | ||
|
||
// MARK: Tests | ||
|
||
/// `method` returns the method of the request. | ||
func test_method() { | ||
XCTAssertEqual(subject.method, .get) | ||
} | ||
|
||
/// `path` returns the path of the request. | ||
func test_path() { | ||
XCTAssertEqual(subject.path, "/auth-requests/ID/response") | ||
} | ||
|
||
/// `query` returns the query items of the request. | ||
func test_query() { | ||
XCTAssertEqual(subject.query, [URLQueryItem(name: "code", value: "ACCESS_CODE")]) | ||
} | ||
|
||
/// `validate(_:)` validates the response for the request and throws an error if the request is expired. | ||
func test_validate() { | ||
XCTAssertNoThrow(try subject.validate(.success())) | ||
XCTAssertNoThrow(try subject.validate(.failure(statusCode: 400))) | ||
XCTAssertNoThrow(try subject.validate(.failure(statusCode: 500))) | ||
|
||
XCTAssertThrowsError(try subject.validate(.failure(statusCode: 404))) { error in | ||
XCTAssertEqual(error as? CheckLoginRequestError, .expired) | ||
} | ||
} | ||
} |
Oops, something went wrong.