Skip to content

Commit 1448ab6

Browse files
authored
[PM-17467] 🍒 Wrapped Credential Exchange related APIs into SUPPORTS_CXP compiler flag (#1295) (#1296)
1 parent 3d00a96 commit 1448ab6

18 files changed

+55
-18
lines changed

Bitwarden/Application/SceneDelegate.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
7373
appProcessor.handleAppLinks(incomingURL: incomingURL)
7474
}
7575

76-
#if compiler(>=6.0.3)
76+
#if SUPPORTS_CXP
7777

7878
if #available(iOS 18.2, *),
7979
let userActivity = connectionOptions.userActivities.first {
@@ -97,7 +97,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
9797
appProcessor.handleAppLinks(incomingURL: incomingURL)
9898
}
9999

100-
#if compiler(>=6.0.3)
100+
#if SUPPORTS_CXP
101101

102102
if #available(iOS 18.2, *) {
103103
Task {
@@ -182,7 +182,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
182182

183183
// MARK: - SceneDelegate 18.2
184184

185-
#if compiler(>=6.0.3)
185+
#if SUPPORTS_CXP
186186

187187
@available(iOS 18.2, *)
188188
extension SceneDelegate {

BitwardenShared/Core/Tools/Repositories/ImportCiphersRepository.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ extension DefaultImportCiphersRepository: ImportCiphersRepository {
6868
credentialImportToken: UUID,
6969
onProgress: @MainActor (Double) -> Void
7070
) async throws -> [ImportedCredentialsResult] {
71-
#if compiler(>=6.0.3)
71+
#if SUPPORTS_CXP
7272

7373
let credentialData = try await credentialManagerFactory.createImportManager().importCredentials(
7474
token: credentialImportToken

BitwardenShared/Core/Tools/Repositories/ImportCiphersRepositoryTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#if compiler(>=6.0.3)
1+
#if SUPPORTS_CXP
22
import AuthenticationServices
33
import XCTest
44

BitwardenShared/Core/Tools/Utilities/CredentialManagerFactory.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@ protocol CredentialImportManager: AnyObject {
1818
func importCredentials(token: UUID) async throws -> ASExportedCredentialData
1919
}
2020

21-
#if compiler(>=6.0.3)
21+
// MARK: - Helpers
22+
23+
// This section is needed for compiling the project on Xcode version < 16.2
24+
// and to ease unit testing.
25+
26+
#if SUPPORTS_CXP
2227

2328
@available(iOS 18.2, *)
2429
extension ASCredentialImportManager: CredentialImportManager {}

BitwardenShared/Core/Tools/Utilities/CredentialManagerFactoryTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#if compiler(>=6.0.3)
1+
#if SUPPORTS_CXP
22
import AuthenticationServices
33
#endif
44
import XCTest

BitwardenShared/Core/Tools/Utilities/TestHelpers/MockCredentialManagerFactory.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#if compiler(>=6.0.3)
1+
#if SUPPORTS_CXP
22
import AuthenticationServices
33
import BitwardenSdk
44

BitwardenShared/Core/Vault/Services/ExportVaultService.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ protocol ExportVaultService: AnyObject {
4343
///
4444
func exportVaultFileContents(format: ExportFileType) async throws -> String
4545

46-
#if compiler(>=6.0.3)
46+
#if SUPPORTS_CXP
4747
/// Exports the vault creating the `ASImportableAccount` to be used in Credential Exchange Protocol.
4848
/// - Returns: An `ASImportableAccount`
4949
@available(iOS 18.2, *)
@@ -196,7 +196,7 @@ class DefultExportVaultService: ExportVaultService {
196196
)
197197
}
198198

199-
#if compiler(>=6.0.3)
199+
#if SUPPORTS_CXP
200200

201201
@available(iOS 18.2, *)
202202
func exportVaultForCXP() async throws -> ASImportableAccount {

BitwardenShared/Core/Vault/Services/ExportVaultServiceTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ final class ExportVaultServiceTests: BitwardenTestCase { // swiftlint:disable:th
193193

194194
// MARK: Tests
195195

196-
#if compiler(>=6.0.3)
196+
#if SUPPORTS_CXP
197197

198198
/// `exportVaultForCXP()` CXP exporting the vault succeeds.
199199
func test_exportVaultForCXP_success() async throws {

BitwardenShared/Core/Vault/Services/TestHelpers/ASImportableAccount+Extensions.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#if compiler(>=6.0.3)
1+
#if SUPPORTS_CXP
22

33
import AuthenticationServices
44

BitwardenShared/Core/Vault/Services/TestHelpers/ASImportableItem+Extensions.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#if compiler(>=6.0.3)
1+
#if SUPPORTS_CXP
22
import AuthenticationServices
33

44
@available(iOS 18.2, *)

BitwardenShared/Core/Vault/Services/TestHelpers/MockExportVaultService.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class MockExportVaultService: ExportVaultService {
1919
didClearFiles = true
2020
}
2121

22-
#if compiler(>=6.0.3)
22+
#if SUPPORTS_CXP
2323
@available(iOS 18.2, *)
2424
func exportVaultForCXP() async throws -> ASImportableAccount {
2525
guard let result = try exportVaultForCXPResult.get() as? ASImportableAccount else {
@@ -48,7 +48,7 @@ class MockExportVaultService: ExportVaultService {
4848

4949
protocol ImportableAccountProxy {}
5050

51-
#if compiler(>=6.0.3)
51+
#if SUPPORTS_CXP
5252
@available(iOS 18.2, *)
5353
extension ASImportableAccount: ImportableAccountProxy {}
5454
#endif

BitwardenShared/UI/Platform/Settings/SettingsCoordinator.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,13 @@ final class SettingsCoordinator: Coordinator, HasStackNavigator { // swiftlint:d
343343
///
344344
@MainActor
345345
private func showExportVault() async {
346-
guard await services.configService.getFeatureFlag(.cxpExportMobile) else {
346+
#if SUPPORTS_CXP
347+
let cxpEnabled = true
348+
#else
349+
let cxpEnabled = false
350+
#endif
351+
352+
guard cxpEnabled, await services.configService.getFeatureFlag(.cxpExportMobile) else {
347353
navigate(to: .exportVaultToFile)
348354
return
349355
}

BitwardenShared/UI/Platform/Settings/SettingsCoordinatorTests.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,8 @@ class SettingsCoordinatorTests: BitwardenTestCase { // swiftlint:disable:this ty
201201
}
202202
defer { task.cancel() }
203203

204+
#if SUPPORTS_CXP
205+
204206
try await waitForAsync { [weak self] in
205207
guard let self else { return true }
206208
return stackNavigator.actions.last != nil
@@ -209,6 +211,19 @@ class SettingsCoordinatorTests: BitwardenTestCase { // swiftlint:disable:this ty
209211
let action = try XCTUnwrap(stackNavigator.actions.last)
210212
XCTAssertEqual(action.type, .pushed)
211213
XCTAssertTrue(action.view is UIHostingController<ExportSettingsView>)
214+
215+
#else
216+
217+
try await waitForAsync { [weak self] in
218+
guard let self else { return true }
219+
return stackNavigator.actions.last?.view is UINavigationController
220+
}
221+
222+
let navigationController = try XCTUnwrap(stackNavigator.actions.last?.view as? UINavigationController)
223+
XCTAssertTrue(stackNavigator.actions.last?.view is UINavigationController)
224+
XCTAssertTrue(navigationController.viewControllers.first is UIHostingController<ExportVaultView>)
225+
226+
#endif
212227
}
213228

214229
/// `navigate(to:)` with `.exportVaultToFile` presents the export vault to file view.

BitwardenShared/UI/Tools/ImportCXP/ImportCXP/ImportCXPProcessor.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class ImportCXPProcessor: StateProcessor<ImportCXPState, Void, ImportCXPEffect>
7272

7373
/// Starts the import process.
7474
private func startImport() async {
75-
#if compiler(>=6.0.3)
75+
#if SUPPORTS_CXP
7676

7777
guard #available(iOS 18.2, *), let credentialImportToken = state.credentialImportToken else {
7878
coordinator.showAlert(

BitwardenShared/UI/Tools/ImportCXP/ImportCXP/ImportCXPProcessorTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ class ImportCXPProcessorTests: BitwardenTestCase {
290290
/// Checks whether the appropriate compiler is being used to have the code available.
291291
/// - Returns: `true` if the compiler is correct, `false`otherwise.
292292
private func checkCompiler() throws -> Bool {
293-
#if compiler(>=6.0.3)
293+
#if SUPPORTS_CXP
294294
return true
295295
#else
296296
throw XCTSkip("CXP Import works only from 6.0.3 compiler.")
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#include "./Base-Debug.xcconfig"
2+
#include? "./Local.xcconfig"
3+
4+
SWIFT_ACTIVE_COMPILATION_CONDITIONS = $(inherited) $(BITWARDEN_FLAGS)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#include "./Base-Release.xcconfig"
2+
#include? "./Local.xcconfig"
3+
4+
SWIFT_ACTIVE_COMPILATION_CONDITIONS = $(inherited) $(BITWARDEN_FLAGS)

project.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,9 @@ targets:
418418
BitwardenSharedTests:
419419
type: bundle.unit-test
420420
platform: iOS
421+
configFiles:
422+
Debug: Configs/BitwardenSharedTests-Debug.xcconfig
423+
Release: Configs/BitwardenSharedTests-Release.xcconfig
421424
settings:
422425
base:
423426
BUNDLE_LOADER: "$(TEST_HOST)"

0 commit comments

Comments
 (0)