Skip to content
Merged
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
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@ Rules:
`Unreleased`.
- Add the date and the compare link once the version tag exists.

## Unreleased

### Added

- Locked Word, Excel, PowerPoint, Pages, Numbers and Keynote files open with
their password.

### Changed

- The engine is odrcore 7.7.0, up from 7.6.1.

## [1.50]

### Added
Expand Down
2 changes: 1 addition & 1 deletion OpenDocumentReader.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,7 @@
repositoryURL = "https://github.com/opendocument-app/OpenDocument.core.git";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 7.6.1;
minimumVersion = 7.7.0;
};
};
AD584FCD41577C8CDEE974AA /* XCRemoteSwiftPackageReference "swift-package-manager-google-mobile-ads" */ = {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions OpenDocumentReader/CoreWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ let CoreWrapperErrorDomain = "app.opendocument.CoreWrapperErrorDomain"
case wrongPassword = 2
/// Not something odrcore renders for us — see the guard in `translate`.
case unsupportedFileType = 3
/// Locked, and odrcore has no way in whatever the password — a legacy Word,
/// Excel or PowerPoint file.
/// Locked with a cipher odrcore cannot decrypt, whatever the password, for
/// example a legacy Word file with XOR obfuscation.
case undecryptable = 4
}

Expand Down Expand Up @@ -143,6 +143,7 @@ private func selectViews(_ views: [HtmlView], _ documentType: DocumentType) -> [
throw coreWrapperError(.wrongPassword, "wrong password")
} catch let error as NSError
where error.code == ODRError.unsupportedOperation.rawValue
|| error.code == ODRError.unsupportedCryptoAlgorithm.rawValue
{
throw coreWrapperError(.undecryptable, "odrcore cannot decrypt this format")
}
Expand Down
2 changes: 1 addition & 1 deletion OpenDocumentReader/DocumentViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1646,7 +1646,7 @@ class DocumentViewController: UIViewController, DocumentDelegate, UISearchBarDel
enum FailedToOpen {
/// odrcore does not read this format at all.
case unsupported
/// A legacy Word, Excel or PowerPoint file no password opens.
/// A locked file that no password opens.
case locked
/// odrcore took it and it still did not appear.
case broken
Expand Down
42 changes: 22 additions & 20 deletions OpenDocumentReaderTests/LockedDocumentTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,12 @@ class LockedDocumentTests: XCTestCase {
return url
}

/// Its own code, not `wrongPassword`: that one puts the prompt up, and the
/// prompt would only come back.
func testALockedLegacyFileReportsItsOwnError() throws {
/// The password of `test-encrypted.doc`, from `OpenDocument.test/index.csv`.
private let fixturePassword = "password"

/// odrcore 7.7.0 decrypts RC4, so a locked legacy Word file asks for its
/// password like any other locked file.
func testALockedLegacyFileAsksForItsPassword() throws {
let wrapper = CoreWrapper()

for password in [nil, "secret"] {
Expand All @@ -48,38 +51,37 @@ class LockedDocumentTests: XCTestCase {
documentURL.path, into: temporaryDirectory, with: password,
editable: false, scope: .document)
) { error in
XCTAssertEqual((error as NSError).code, CoreWrapperError.undecryptable.rawValue)
XCTAssertEqual((error as NSError).code, CoreWrapperError.wrongPassword.rawValue)
}
}
}

/// Its own message rather than the broken-file one: no password opens it.
func testALockedLegacyFileSaysWhyItDidNotOpen() throws {
try present(documentURL)

let opened = expectation(description: "opened")
document.open { _ in opened.fulfill() }
wait(for: [opened], timeout: 60)
func testALockedLegacyFileOpensWithItsPassword() throws {
let wrapper = CoreWrapper()

let alert = try XCTUnwrap(waitForAlert())
try wrapper.translate(
documentURL.path, into: temporaryDirectory, with: fixturePassword,
editable: false, scope: .document)

XCTAssertEqual(alert.message, NSLocalizedString("toast_error_password_protected", comment: ""))
XCTAssertEqual(
alert.actions.map(\.title), [NSLocalizedString("ok", comment: "")],
"a locked file is not ours to hear about")
XCTAssertFalse(wrapper.pageURLs.isEmpty)
}

/// The reader is taken off the screen before the message.
func testTheReaderIsClosedBeforeTheMessage() throws {
/// The reader keeps the document and puts the password prompt up.
func testALockedLegacyFileShowsThePasswordPrompt() throws {
try present(documentURL)

let opened = expectation(description: "opened")
document.open { _ in opened.fulfill() }
wait(for: [opened], timeout: 60)

_ = waitForAlert()
let alert = try XCTUnwrap(waitForAlert())

XCTAssertNil(controller.document, "the reader is still holding the document")
XCTAssertEqual(alert.title, NSLocalizedString("toast_error_password_protected", comment: ""))
XCTAssertEqual(alert.textFields?.count, 1)
XCTAssertEqual(
alert.actions.map(\.title),
[NSLocalizedString("cancel", comment: ""), NSLocalizedString("ok", comment: "")])
XCTAssertNotNil(controller.document, "the reader let go of the document")
}

private func waitForAlert() -> UIAlertController? {
Expand Down
Loading