| @@ -64,7 +64,7 @@ struct CryptSaveTests { |
| 64 | var asked = 0 |
64 | var asked = 0 |
| 65 | session.storedPassphrase = { _ in asked += 1; return "pw" } |
65 | session.storedPassphrase = { _ in asked += 1; return "pw" } |
| 66 | var written: [String] = [] |
66 | var written: [String] = [] |
| 67 | session.fileSaved = { written.append($0) } |
67 | session.fileWritten = { written.append($0) } |
| 68 | session.open(file.path) |
68 | session.open(file.path) |
| 69 | try replace(with: Self.file) |
69 | try replace(with: Self.file) |
| 70 | #expect(!session.save()) |
70 | #expect(!session.save()) |
| @@ -98,10 +98,13 @@ struct CryptSaveTests { |
| 98 | |
98 | |
| 99 | @Test func holdsTheWholeFileWithoutThePassphrase() throws { |
99 | @Test func holdsTheWholeFileWithoutThePassphrase() throws { |
| 100 | try notes.write("a.org", "* Plain\nOpen text.\n") |
100 | try notes.write("a.org", "* Plain\nOpen text.\n") |
| |
101 | var written: [String] = [] |
| |
102 | session.fileWritten = { written.append($0) } |
| 101 | session.open(file.path) |
103 | session.open(file.path) |
| 102 | try replace(with: Self.file) |
104 | try replace(with: Self.file) |
| 103 | #expect(!session.save()) |
105 | #expect(!session.save()) |
| 104 | #expect(session.held[file.path] == .entries(1)) |
106 | #expect(session.held[file.path] == .entries(1)) |
| |
107 | #expect(written.isEmpty) |
| 105 | #expect(disk == "* Plain\nOpen text.\n") |
108 | #expect(disk == "* Plain\nOpen text.\n") |
| 106 | #expect(recoveryFiles.isEmpty) |
109 | #expect(recoveryFiles.isEmpty) |
| 107 | #expect(session.isDirty) |
110 | #expect(session.isDirty) |
| @@ -112,14 +115,27 @@ struct CryptSaveTests { |
| 112 | #expect(disk == "* Plain\nOpen text.\n") |
115 | #expect(disk == "* Plain\nOpen text.\n") |
| 113 | #expect(recoveryFiles.isEmpty) |
116 | #expect(recoveryFiles.isEmpty) |
| 114 | // The passphrase, when given, encrypts and saves. |
117 | // The passphrase, when given, encrypts and saves. |
| |
118 | #expect(written.isEmpty) |
| 115 | #expect(session.unlock("pw", for: file.path) == nil) |
119 | #expect(session.unlock("pw", for: file.path) == nil) |
| 116 | #expect(session.held.isEmpty) |
120 | #expect(session.held.isEmpty) |
| 117 | #expect(!session.isDirty) |
121 | #expect(!session.isDirty) |
| |
122 | #expect(written == [file.path]) |
| 118 | #expect(!disk.contains(Self.secret)) |
123 | #expect(!disk.contains(Self.secret)) |
| 119 | #expect(recoveryFiles.allSatisfy { !$0.contains(Self.secret) }) |
124 | #expect(recoveryFiles.allSatisfy { !$0.contains(Self.secret) }) |
| 120 | #expect(session.openTexts[file.path] == nil) |
125 | #expect(session.openTexts[file.path] == nil) |
| 121 | } |
126 | } |
| 122 | |
127 | |
| |
128 | @Test func restoringAVersionOfAHeldFileKeepsNoPlaintext() throws { |
| |
129 | try notes.write("a.org", "* Plain\nOpen text.\n") |
| |
130 | session.open(file.path) |
| |
131 | try replace(with: Self.file) |
| |
132 | #expect(!session.save()) |
| |
133 | #expect(session.restore(text: "* Plain\nOpen text.\n* Other\n") == nil) |
| |
134 | #expect(recoveryFiles.isEmpty) |
| |
135 | #expect(session.save()) |
| |
136 | #expect(recoveryFiles.allSatisfy { !$0.contains(Self.secret) }) |
| |
137 | } |
| |
138 | |
| 123 | @Test func aHeldFileIsReleasedWhenTheEntryGoes() throws { |
139 | @Test func aHeldFileIsReleasedWhenTheEntryGoes() throws { |
| 124 | session.saveMode = .automatic |
140 | session.saveMode = .automatic |
| 125 | session.autosaveDelay = .seconds(60) |
141 | session.autosaveDelay = .seconds(60) |
| @@ -222,7 +238,7 @@ struct CryptSaveTests { |
| 222 | let path = notes.url.appendingPathComponent("diary.org.gpg") |
238 | let path = notes.url.appendingPathComponent("diary.org.gpg") |
| 223 | try message.write(to: path) |
239 | try message.write(to: path) |
| 224 | var written: [String] = [] |
240 | var written: [String] = [] |
| 225 | session.fileSaved = { written.append($0) } |
241 | session.fileWritten = { written.append($0) } |
| 226 | session.open(path.path) |
242 | session.open(path.path) |
| 227 | #expect(session.unlockRequest == path.path) |
243 | #expect(session.unlockRequest == path.path) |
| 228 | #expect(!session.isOpen(path.path)) |
244 | #expect(!session.isOpen(path.path)) |