Skip to content
Closed
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
90 changes: 90 additions & 0 deletions Tests/NextcloudUnitTests/E2EETests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
//
// E2EETests.swift
// NextcloudTests
//
// Created by A200020526 on 26/05/23.
// Copyright © 2023 Marino Faggiana. All rights reserved.
//

@testable import Nextcloud
import XCTest
import TOPasscodeViewController

final class E2EETests: XCTestCase {

var manageE2EE: NCManageE2EE!

override func setUpWithError() throws {
// Put setup code here. This method is called before the invocation of each test method in the class.
manageE2EE = NCManageE2EE()
}

override func tearDownWithError() throws {
// Put teardown code here. This method is called after the invocation of each test method in the class.
manageE2EE = nil
}

func testExample() throws {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct results.
// Any test you write for XCTest can be annotated as throws and async.
// Mark your test throws to produce an unexpected failure when your test encounters an uncaught error.
// Mark your test async to allow awaiting for asynchronous code to complete. Check the results with assertions afterwards.
}

func testPerformanceExample() throws {
// This is an example of a performance test case.
self.measure {
// Put the code you want to measure the time of here.
}
}

// MARK: - Initialization

func testInitialization() {
XCTAssertTrue(manageE2EE.endToEndInitialize.delegate === manageE2EE)
XCTAssertFalse(manageE2EE.isEndToEndEnabled)
XCTAssertEqual(manageE2EE.statusOfService, NSLocalizedString("_status_in_progress_", comment: ""))
}

// MARK: - Delegate

func testEndToEndInitializeSuccess() {
manageE2EE.endToEndInitializeSuccess()
XCTAssertTrue(manageE2EE.isEndToEndEnabled)
}

// MARK: - Passcode

func testRequestPasscodeType() {
// TODO: Implement this test case
}

func testCorrectPasscode_startE2E() {
manageE2EE.passcodeType = "startE2E"
manageE2EE.correctPasscode()
// TODO: Add assertions for the expected behavior after entering the correct passcode for starting E2E
}

func testCorrectPasscode_readPassphrase() {
manageE2EE.passcodeType = "readPassphrase"
// TODO: Simulate entering the correct passcode and verify the expected behavior
}

func testCorrectPasscode_removeLocallyEncryption() {
manageE2EE.passcodeType = "removeLocallyEncryption"
// TODO: Simulate entering the correct passcode and verify the expected behavior
}

func testDidPerformBiometricValidationRequest() {
let passcodeViewController = TOPasscodeViewController(passcodeType: .sixDigits, allowCancel: true)
manageE2EE.didPerformBiometricValidationRequest(in: passcodeViewController)
// TODO: Add assertions for the expected behavior after performing biometric validation
}

func testDidTapCancel() {
let passcodeViewController = TOPasscodeViewController(passcodeType: .sixDigits, allowCancel: true)
manageE2EE.didTapCancel(in: passcodeViewController)
// TODO: Add assertions for the expected behavior after tapping cancel
}
}
4 changes: 2 additions & 2 deletions iOSClient/Settings/NCEndToEndInitialize.swift
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ class NCEndToEndInitialize: NSObject {
NCKeychain().setEndToEndPrivateKey(account: self.appDelegate.account, privateKey: privateKey)
} else {

let error = NKError(errorCode: NCGlobal.shared.errorInternalError, errorDescription: "Serious internal error to decrypt Private Key")
NCContentPresenter().messageNotification("E2E decrypt privateKey", error: error, delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, priority: .max)
let error = NKError(errorCode: NCGlobal.shared.errorInternalError, errorDescription: NSLocalizedString("_e2e_error_incorrect_passphrase_", comment: ""))
NCContentPresenter().messageNotification(NSLocalizedString("_e2e_error_passphrase_title", comment: ""), error: error, delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, priority: .max)

return
}
Expand Down
58 changes: 29 additions & 29 deletions iOSClient/Settings/NCManageE2EE.swift
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ struct NCViewE2EE: View {

List {

Section(header: Text(""), footer: Text(manageE2EE.statusOfService + "\n\n" + "End-to-End Encryption " + NCGlobal.shared.capabilityE2EEApiVersion)) {
Section(header: Text(""), footer: Text("End-to-End Encryption " + NCGlobal.shared.capabilityE2EEApiVersion)) {
Label {
Text(NSLocalizedString("_e2e_settings_activated_", comment: ""))
} icon: {
Expand All @@ -181,46 +181,46 @@ struct NCViewE2EE: View {
}
}

HStack {
Section(header: Text(""), footer: Text(NSLocalizedString("_read_passphrase_description_", comment: ""))) {
Label {
Text(NSLocalizedString("_e2e_settings_read_passphrase_", comment: ""))
} icon: {
Image(systemName: "eye")
.resizable()
.scaledToFit()
.foregroundColor(Color(UIColor.systemGray))
.foregroundColor(Color(NCBrandColor.shared.iconColor))
.frame(width: 20, height: 30)
}
Spacer()
}
.contentShape(Rectangle())
.onTapGesture {
if NCKeychain().passcode != nil {
manageE2EE.requestPasscodeType("readPassphrase")
} else {
NCContentPresenter().showInfo(error: NKError(errorCode: 0, errorDescription: "_e2e_settings_lock_not_active_"))
.onTapGesture {
if NCKeychain().passcode != nil {
manageE2EE.requestPasscodeType("readPassphrase")
} else {
NCContentPresenter().showInfo(error: NKError(errorCode: 0, errorDescription: "_e2e_settings_lock_not_active_"))
}
}
}

HStack {
let removeStrDesc1 = NSLocalizedString("_remove_passphrase_desc_1_", comment: "")
let removeStrDesc2 = NSLocalizedString("_remove_passphrase_desc_2_", comment: "")
let removeStrDesc = String(format: "%@\n\n%@", removeStrDesc1, removeStrDesc2)
Section(header: Text(""), footer: Text(removeStrDesc)) {
Label {
Text(NSLocalizedString("_e2e_settings_remove_", comment: ""))
} icon: {
Image(systemName: "trash.circle")
Image(systemName: "trash")
.resizable()
.scaledToFit()
.foregroundColor(Color.red)
.foregroundColor(Color(NCBrandColor.shared.iconColor))
.frame(width: 20, height: 30)
}
Spacer()
}
.contentShape(Rectangle())
.onTapGesture {
if NCKeychain().passcode != nil {
manageE2EE.requestPasscodeType("removeLocallyEncryption")
} else {
NCContentPresenter().showInfo(error: NKError(errorCode: 0, errorDescription: "_e2e_settings_lock_not_active_"))
.onTapGesture {
if NCKeychain().passcode != nil {
manageE2EE.requestPasscodeType("removeLocallyEncryption")
} else {
NCContentPresenter().showInfo(error: NKError(errorCode: 0, errorDescription: "_e2e_settings_lock_not_active_"))
}
}
}

#if DEBUG
DeleteCerificateSection()
#endif
Expand All @@ -229,16 +229,15 @@ struct NCViewE2EE: View {
} else {

List {

Section(header: Text(""), footer: Text(manageE2EE.statusOfService + "\n\n" + "End-to-End Encryption " + NCGlobal.shared.capabilityE2EEApiVersion)) {
let startE2EDesc1 = NSLocalizedString("_start_e2e_encryption_1_", comment: "");
let startE2EDesc2 = NSLocalizedString("_start_e2e_encryption_2_", comment: "");
let startE2EDesc3 = NSLocalizedString("_start_e2e_encryption_3_", comment: "");
let startE2EDesc = String(format: "%@\n\n%@\n\n%@",startE2EDesc1,startE2EDesc2,startE2EDesc3)
Section(header: Text(""), footer: Text(startE2EDesc)) {
HStack {
Label {
Text(NSLocalizedString("_e2e_settings_start_", comment: ""))
} icon: {
Image(systemName: "play.circle")
.resizable()
.scaledToFit()
.foregroundColor(.green)
}
Spacer()
}
Expand All @@ -256,6 +255,7 @@ struct NCViewE2EE: View {
DeleteCerificateSection()
#endif
}
.listStyle(GroupedListStyle())
}
}
.background(Color(UIColor.systemGroupedBackground))
Expand Down
Loading