Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PM-16445] Renamed most uses of CXP acronym to CXF #1265

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ extension JSONDecoder {
return decoder
}()

/// A `JSONDecoder` instance that handles decoding JSON from CXP format to Apple's expected format.
static let cxpDecoder: JSONDecoder = {
/// A `JSONDecoder` instance that handles decoding JSON from Credential Exchange format to Apple's expected format.
static let cxfDecoder: JSONDecoder = {
let decoder = JSONDecoder()
decoder.keyDecodingStrategy = .custom { keys in
let key = keys.last!.stringValue
let camelCaseKey = keyToCamelCase(key: key)
return AnyKey(stringValue: customTransformCodingKeyForCXP(key: camelCaseKey))
return AnyKey(stringValue: customTransformCodingKeyForCXF(key: camelCaseKey))
}
decoder.dateDecodingStrategy = .secondsSince1970
return decoder
Expand All @@ -84,8 +84,9 @@ extension JSONDecoder {

// MARK: Private Static Functions

/// Transforms the keys from CXP format handled by the Bitwarden SDK into the keys that Apple expects.
private static func customTransformCodingKeyForCXP(key: String) -> String {
/// Transforms the keys from Credential Exchange format handled by the Bitwarden SDK
/// into the keys that Apple expects.
private static func customTransformCodingKeyForCXF(key: String) -> String {
return switch key {
case "credentialId":
"credentialID"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import XCTest
class JSONDecoderBitwardenTests: BitwardenTestCase {
// MARK: Tests

/// `JSONDecoder.cxpDecoder` can decode Credential Exchange Format.
func test_cxpDecoder_decodesISO8601DateWithFractionalSeconds() {
let subject = JSONDecoder.cxpDecoder
/// `JSONDecoder.cxfDecoder` can decode Credential Exchange Format.
func test_cxfDecoder_decodesISO8601DateWithFractionalSeconds() {
let subject = JSONDecoder.cxfDecoder
let toDecode = #"{"credentialId":"credential","date":1697790414,"otherKey":"other","rpId":"rp"}"#

struct JSONBody: Codable, Equatable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,24 @@ extension JSONEncoder {
}()

/// The default `JSONEncoder` used to encode JSON payloads when in Credential Exchange flow.
static let cxpEncoder: JSONEncoder = {
static let cxfEncoder: JSONEncoder = {
let jsonEncoder = JSONEncoder()
jsonEncoder.dateEncodingStrategy = .custom { date, encoder in
var container = encoder.singleValueContainer()
try container.encode(Int(date.timeIntervalSince1970))
}
jsonEncoder.keyEncodingStrategy = .custom { keys in
let key = keys.last!.stringValue
return AnyKey(stringValue: customTransformCodingKeyForCXP(key: key))
return AnyKey(stringValue: customTransformCodingKeyForCXF(key: key))
}
return jsonEncoder
}()

// MARK: Static Functions

/// Transforms the keys from CXP format handled by the Bitwarden SDK into the keys that Apple expects.
static func customTransformCodingKeyForCXP(key: String) -> String {
/// Transforms the keys from Credential Exchange format handled by the Bitwarden SDK
/// into the keys that Apple expects.
static func customTransformCodingKeyForCXF(key: String) -> String {
return switch key {
case "credentialID":
"credentialId"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import XCTest
class JSONEncoderBitwardenTests: BitwardenTestCase {
// MARK: Tests

/// `JSONEncoder.cxpEncoder` encodes for Credential Exchange Format.
/// `JSONEncoder.cxfEncoder` encodes for Credential Exchange Format.
func test_cxfpEncoder_encodesISO8601DateWithFractionalSeconds() throws {
let subject = JSONEncoder.cxpEncoder
let subject = JSONEncoder.cxfEncoder
subject.outputFormatting = .sortedKeys // added for test consistency so output is ordered.

struct JSONBody: Codable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
name: account.profile.name
)
let serializedCXF = try await clientService.exporters().exportCxf(account: sdkAccount, ciphers: ciphers)
return try JSONDecoder.cxpDecoder.decode(ASImportableAccount.self, from: Data(serializedCXF.utf8))
return try JSONDecoder.cxfDecoder.decode(ASImportableAccount.self, from: Data(serializedCXF.utf8))

Check warning on line 130 in BitwardenShared/Core/Tools/Repositories/ExportCXFCiphersRepository.swift

View check run for this annotation

Codecov / codecov/patch

BitwardenShared/Core/Tools/Repositories/ExportCXFCiphersRepository.swift#L130

Added line #L130 was not covered by tests
}

#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
throw ImportCiphersRepositoryError.noDataFound
}

let accountJsonData = try JSONEncoder.cxpEncoder.encode(accountData)
let accountJsonData = try JSONEncoder.cxfEncoder.encode(accountData)

Check warning on line 87 in BitwardenShared/Core/Tools/Repositories/ImportCiphersRepository.swift

View check run for this annotation

Codecov / codecov/patch

BitwardenShared/Core/Tools/Repositories/ImportCiphersRepository.swift#L87

Added line #L87 was not covered by tests
guard let accountJsonString = String(data: accountJsonData, encoding: .utf8) else {
// this should never happen.
throw ImportCiphersRepositoryError.dataEncodingFailed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ class ImportCiphersRepositoryTests: BitwardenTestCase {

@available(iOS 18.2, *)
private func getASExportedCredentialDataAsJson(data: ASExportedCredentialData) throws -> String {
let credentialData = try JSONEncoder.cxpEncoder.encode(data)
let credentialData = try JSONEncoder.cxfEncoder.encode(data)
guard let credentialDataJsonString = String(data: credentialData, encoding: .utf8) else {
throw BitwardenError.dataError("Failed to encode ASExportedCredentialData")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ class MockCredentialExportManager: CredentialExportManager {
/// A JSON encoded `String` is used as the value instead of the actual object
/// to avoid crashing on simulators older than iOS 18.2 because of not finding the symbol
/// thus resulting in bad access error when running the test suite.
/// Use `JSONDecoder.cxpDecoder.decode` to decode data for this.
/// Use `JSONDecoder.cxfDecoder.decode` to decode data for this.
var exportCredentialsJSONData: String?
var exportCredentialsError: Error?

@available(iOS 18.2, *)
func exportCredentials(_ credentialData: ASExportedCredentialData) async throws {
exportCredentialsCalled = true

let data = try JSONEncoder.cxpEncoder.encode(credentialData)
let data = try JSONEncoder.cxfEncoder.encode(credentialData)
guard let dataJsonString = String(data: data, encoding: .utf8) else {
// this should never happen.
throw BitwardenError.dataError("Failed encoding credential data")
Expand All @@ -51,15 +51,15 @@ class MockCredentialImportManager: CredentialImportManager {
/// A JSON encoded `String` is used as the value instead of the actual object
/// to avoid crashing on simulators older than iOS 18.2 because of not finding the symbol
/// thus resulting in bad access error when running the test suite.
/// Use `JSONEncoder.cxpEncoder.encode` to encode data for this.
/// Use `JSONEncoder.cxfEncoder.encode` to encode data for this.
var importCredentialsResult: Result<String, Error> = .failure(BitwardenTestError.example)

@available(iOS 18.2, *)
func importCredentials(token: UUID) async throws -> ASExportedCredentialData {
guard let data = try importCredentialsResult.get().data(using: .utf8) else {
throw BitwardenError.dataError("importCredentialsResult data not set or not in UTF8")
}
return try JSONDecoder.cxpDecoder.decode(
return try JSONDecoder.cxfDecoder.decode(
ASExportedCredentialData.self,
from: data
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@
/// - Parameter credentialImportToken: The credentials import token to user with the `ASCredentialImportManager`.
@available(iOSApplicationExtension 18.2, *)
public func handleImportCredentials(credentialImportToken: UUID) async {
let route = AppRoute.tab(.vault(.importCXP(
let route = AppRoute.tab(.vault(.importCXF(

Check warning on line 216 in BitwardenShared/UI/Platform/Application/AppProcessor.swift

View check run for this annotation

Codecov / codecov/patch

BitwardenShared/UI/Platform/Application/AppProcessor.swift#L216

Added line #L216 was not covered by tests
.importCredentials(credentialImportToken: credentialImportToken)
)))
await checkIfLockedAndPerformNavigation(route: route)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1071,7 +1071,7 @@
"FailedToAutofillItem" = "Failed to autofill item %1$@";
"ExportingFailed" = "Exporting failed";
"YouMayNeedToEnableDevicePasscodeOrBiometrics" = "You may need to enable device passcode or biometrics.";
"StartImportCXPDescriptionLong" = "Import passwords, passkeys, credit cards, and any personal identity information from another password manager.\n\nYour data will **not** be deleted from your previous provider.";
"StartImportCXFDescriptionLong" = "Import passwords, passkeys, credit cards, and any personal identity information from another password manager.\n\nYour data will **not** be deleted from your previous provider.";
"ImportPasswords" = "Import passwords";
"ImportingEllipsis" = "Importing...";
"AreYouSureYouWantToCancelTheImportProcessQuestionMark" = "Are you sure you want to cancel the import process?";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class PageHeaderViewTests: BitwardenTestCase {
image: Asset.Images.plus24,
style: .largeTextTintedIcon,
title: Localizations.importPasswords,
message: Localizations.startImportCXPDescriptionLong
message: Localizations.startImportCXFDescriptionLong
)
assertSnapshots(
of: subject,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import SwiftUI

// MARK: - ImportCXPView
// MARK: - ExportCXFView

/// A view to export credentials in the Credential Exchange flow.
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ class ExportCXFCoordinator: Coordinator, HasStackNavigator {
}

func start() {
showExportCXP()
showExportCXF()
}

// MARK: Private Methods

private func showExportCXP() {
private func showExportCXF() {
let processor = ExportCXFProcessor(
coordinator: asAnyCoordinator(),
delegate: self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class ExportCXFCoordinatorTests: BitwardenTestCase {

/// `start()` shows the Credential Exchange export view.
@MainActor
func test_start_showsExportCXP() {
func test_start_showsExportCXF() {
subject.start()

XCTAssertTrue(stackNavigator.actions.last?.view is ExportCXFView)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import Foundation

// MARK: - ImportCXPEffect
// MARK: - ImportCXFEffect

/// Effects that can be processed by a `ImportCXPProcessor`.
/// Effects that can be processed by a `ImportCXFProcessor`.
///
enum ImportCXPEffect: Equatable {
enum ImportCXFEffect: Equatable {
/// The view appeared.
case appeared

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import AuthenticationServices
import BitwardenSdk

// MARK: - ImportCXPProcessor
// MARK: - ImportCXFProcessor

/// The processor used to manage state and handle actions/effects for the Credential Exchange import screen.
///
class ImportCXPProcessor: StateProcessor<ImportCXPState, Void, ImportCXPEffect> {
class ImportCXFProcessor: StateProcessor<ImportCXFState, Void, ImportCXFEffect> {
// MARK: Types

typealias Services = HasConfigService
Expand All @@ -16,24 +16,24 @@ class ImportCXPProcessor: StateProcessor<ImportCXPState, Void, ImportCXPEffect>
// MARK: Private Properties

/// The coordinator that handles navigation.
private let coordinator: AnyCoordinator<ImportCXPRoute, Void>
private let coordinator: AnyCoordinator<ImportCXFRoute, Void>

/// The services used by this processor.
private let services: Services

// MARK: Initialization

/// Creates a new `ImportCXPProcessor`.
/// Creates a new `ImportCXFProcessor`.
///
/// - Parameters:
/// - coordinator: The coordinator that handles navigation.
/// - services: The services used by the processor.
/// - state: The initial state of the processor.
///
init(
coordinator: AnyCoordinator<ImportCXPRoute, Void>,
coordinator: AnyCoordinator<ImportCXFRoute, Void>,
services: Services,
state: ImportCXPState
state: ImportCXFState
) {
self.coordinator = coordinator
self.services = services
Expand All @@ -42,7 +42,7 @@ class ImportCXPProcessor: StateProcessor<ImportCXPState, Void, ImportCXPEffect>

// MARK: Methods

override func perform(_ effect: ImportCXPEffect) async {
override func perform(_ effect: ImportCXFEffect) async {
switch effect {
case .appeared:
await checkEnabled()
Expand All @@ -62,7 +62,7 @@ class ImportCXPProcessor: StateProcessor<ImportCXPState, Void, ImportCXPEffect>

// MARK: Private

/// Checks whether the CXP import feature is enabled.
/// Checks whether the CXF import feature is enabled.
private func checkEnabled() async {
guard #available(iOS 18.2, *), await services.configService.getFeatureFlag(.cxpImportMobile) else {
state.status = .failure(message: Localizations.importingFromAnotherProviderIsNotAvailableForThisDevice)
Expand Down Expand Up @@ -115,7 +115,7 @@ class ImportCXPProcessor: StateProcessor<ImportCXPState, Void, ImportCXPEffect>
return
}

coordinator.showAlert(.confirmCancelCXPImport { [weak self] in
coordinator.showAlert(.confirmCancelCXFImport { [weak self] in
guard let self else { return }
coordinator.navigate(to: .dismiss)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,31 @@ import XCTest

@testable import BitwardenShared

// MARK: - ImportCXPProcessorTests
// MARK: - ImportCXFProcessorTests

class ImportCXPProcessorTests: BitwardenTestCase {
class ImportCXFProcessorTests: BitwardenTestCase {
// MARK: Properties

var configService: MockConfigService!
var coordinator: MockCoordinator<ImportCXPRoute, Void>!
var coordinator: MockCoordinator<ImportCXFRoute, Void>!
var errorReporter: MockErrorReporter!
var importCiphersRepository: MockImportCiphersRepository!
var state: ImportCXPState!
var state: ImportCXFState!
var stateService: MockStateService!
var subject: ImportCXPProcessor!
var subject: ImportCXFProcessor!

// MARK: Setup & Teardown

override func setUp() {
super.setUp()

configService = MockConfigService()
coordinator = MockCoordinator<ImportCXPRoute, Void>()
coordinator = MockCoordinator<ImportCXFRoute, Void>()
errorReporter = MockErrorReporter()
importCiphersRepository = MockImportCiphersRepository()
state = ImportCXPState()
state = ImportCXFState()
stateService = MockStateService()
subject = ImportCXPProcessor(
subject = ImportCXFProcessor(
coordinator: coordinator.asAnyCoordinator(),
services: ServiceContainer.withMocks(
configService: configService,
Expand Down Expand Up @@ -297,7 +297,7 @@ class ImportCXPProcessorTests: BitwardenTestCase {
#endif
}

/// Checks whether the alert is shown when not in the correct iOS version for CXP Import to work.
/// Checks whether the alert is shown when not in the correct iOS version for CXF Import to work.
@MainActor
private func checkAlertShownWhenNotInCorrectIOSVersion() -> Bool {
guard #available(iOS 18.2, *) else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import Foundation

// MARK: - ImportCXPState
// MARK: - ImportCXFState

/// The state used to present the `ImportCXPView`.
/// The state used to present the `ImportCXFView`.
///
struct ImportCXPState: Equatable, Sendable {
struct ImportCXFState: Equatable, Sendable {
// MARK: Types

/// The status of the import process.
enum ImportCXPStatus: Equatable, Sendable {
enum ImportCXFStatus: Equatable, Sendable {
/// The import flow is at the start point.
case start

Expand All @@ -27,7 +27,7 @@ struct ImportCXPState: Equatable, Sendable {
/// The token used in `ASCredentialImportManager` to get the credentials to import.
var credentialImportToken: UUID?

/// Whether the CXP import feature is available.
/// Whether the Credential Exchange import feature is available.
var isFeatureUnvailable: Bool = false

/// The title of the main button.
Expand Down Expand Up @@ -60,7 +60,7 @@ struct ImportCXPState: Equatable, Sendable {
var message: String {
return switch status {
case .start:
Localizations.startImportCXPDescriptionLong
Localizations.startImportCXFDescriptionLong
case .importing:
""
case let .success(total, _):
Expand Down Expand Up @@ -103,5 +103,5 @@ struct ImportCXPState: Equatable, Sendable {
}

/// The current status of the import process.
var status: ImportCXPStatus = .start
var status: ImportCXFStatus = .start
}
Loading
Loading