orgnote-api 0.7.10 → 0.7.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -65,3 +65,41 @@ exports[`Should encrypt note via keys 1`] = `
|
|
|
65
65
|
},
|
|
66
66
|
}
|
|
67
67
|
`;
|
|
68
|
+
|
|
69
|
+
exports[`Should encrypt note with empty encrypted property 1`] = `
|
|
70
|
+
{
|
|
71
|
+
"author": {
|
|
72
|
+
"email": "test@mail.com",
|
|
73
|
+
"id": "1",
|
|
74
|
+
"name": "John Doe",
|
|
75
|
+
},
|
|
76
|
+
"encrypted": "gpgPassword",
|
|
77
|
+
"id": "id",
|
|
78
|
+
"meta": {
|
|
79
|
+
"id": undefined,
|
|
80
|
+
"published": false,
|
|
81
|
+
},
|
|
82
|
+
}
|
|
83
|
+
`;
|
|
84
|
+
|
|
85
|
+
exports[`Should not encrypt public note 1`] = `
|
|
86
|
+
{
|
|
87
|
+
"author": {
|
|
88
|
+
"email": "test@mail.com",
|
|
89
|
+
"id": "1",
|
|
90
|
+
"name": "John Doe",
|
|
91
|
+
},
|
|
92
|
+
"content": "#+ID: qweqwe
|
|
93
|
+
#+TITLE: Hello worlld
|
|
94
|
+
|
|
95
|
+
* Hello?",
|
|
96
|
+
"encrypted": "gpgPassword",
|
|
97
|
+
"id": "id",
|
|
98
|
+
"meta": {
|
|
99
|
+
"description": "Awesome description",
|
|
100
|
+
"images": [],
|
|
101
|
+
"published": true,
|
|
102
|
+
"title": "My note title",
|
|
103
|
+
},
|
|
104
|
+
}
|
|
105
|
+
`;
|
|
@@ -9,12 +9,14 @@ import {
|
|
|
9
9
|
|
|
10
10
|
test('Should encrypt note content via password', async () => {
|
|
11
11
|
const content = `#+ID: qweqwe
|
|
12
|
+
|
|
12
13
|
#+TITLE: Hello worlld
|
|
13
14
|
|
|
14
15
|
* Hello?`;
|
|
15
16
|
|
|
16
17
|
const note: Note = {
|
|
17
18
|
id: 'id',
|
|
19
|
+
encrypted: 'gpgPassword',
|
|
18
20
|
meta: {
|
|
19
21
|
title: 'My note title',
|
|
20
22
|
images: [],
|
|
@@ -44,6 +46,7 @@ test('Should encrypt note content via password', async () => {
|
|
|
44
46
|
test('Should decrypt note content via password', async () => {
|
|
45
47
|
const note: Note = {
|
|
46
48
|
id: 'id',
|
|
49
|
+
encrypted: 'gpgPassword',
|
|
47
50
|
meta: {
|
|
48
51
|
title: 'My note title',
|
|
49
52
|
images: [],
|
|
@@ -76,6 +79,7 @@ test('Should encrypt note via keys', async () => {
|
|
|
76
79
|
|
|
77
80
|
const note: Note = {
|
|
78
81
|
id: 'id',
|
|
82
|
+
encrypted: 'gpgKeys',
|
|
79
83
|
meta: {
|
|
80
84
|
title: 'My note title for encryption via keys',
|
|
81
85
|
images: [],
|
|
@@ -107,6 +111,7 @@ test('Should encrypt note via keys', async () => {
|
|
|
107
111
|
test('Should decrypt note via provided keys', async () => {
|
|
108
112
|
const note: Note = {
|
|
109
113
|
id: 'id',
|
|
114
|
+
encrypted: 'gpgKeys',
|
|
110
115
|
meta: {
|
|
111
116
|
title: 'My note title for decryption via keys',
|
|
112
117
|
images: [],
|
|
@@ -155,3 +160,72 @@ yEN8xpFUs7A9xryVZOosp9Sfe3IbBkO99sAQ7jV4EoMYk3/GKA==
|
|
|
155
160
|
|
|
156
161
|
expect(decryptedNote).toMatchSnapshot();
|
|
157
162
|
});
|
|
163
|
+
|
|
164
|
+
test('Should not encrypt public note', async () => {
|
|
165
|
+
const content = `#+ID: qweqwe
|
|
166
|
+
#+TITLE: Hello worlld
|
|
167
|
+
|
|
168
|
+
* Hello?`;
|
|
169
|
+
|
|
170
|
+
const note: Note = {
|
|
171
|
+
id: 'id',
|
|
172
|
+
encrypted: 'gpgPassword',
|
|
173
|
+
meta: {
|
|
174
|
+
title: 'My note title',
|
|
175
|
+
images: [],
|
|
176
|
+
published: true,
|
|
177
|
+
description: 'Awesome description',
|
|
178
|
+
},
|
|
179
|
+
content,
|
|
180
|
+
author: {
|
|
181
|
+
id: '1',
|
|
182
|
+
name: 'John Doe',
|
|
183
|
+
email: 'test@mail.com',
|
|
184
|
+
},
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
const encryptedNote = await encryptNote(note, {
|
|
188
|
+
type: 'gpgPassword',
|
|
189
|
+
password: '123',
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
expect(encryptedNote.content.startsWith('-----BEGIN PGP MESSAGE-----')).toBe(
|
|
193
|
+
false
|
|
194
|
+
);
|
|
195
|
+
expect(encryptedNote).toMatchSnapshot();
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
test('Should encrypt note with empty encrypted property', async () => {
|
|
199
|
+
const content = `#+ID: qweqwe
|
|
200
|
+
#+TITLE: Hello worlld
|
|
201
|
+
|
|
202
|
+
* Hello?`;
|
|
203
|
+
|
|
204
|
+
const note: Note = {
|
|
205
|
+
id: 'id',
|
|
206
|
+
meta: {
|
|
207
|
+
title: 'My note title',
|
|
208
|
+
images: [],
|
|
209
|
+
published: false,
|
|
210
|
+
description: 'Awesome description',
|
|
211
|
+
},
|
|
212
|
+
content,
|
|
213
|
+
author: {
|
|
214
|
+
id: '1',
|
|
215
|
+
name: 'John Doe',
|
|
216
|
+
email: 'test@mail.com',
|
|
217
|
+
},
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
const encryptedNote = await encryptNote(note, {
|
|
221
|
+
type: 'gpgPassword',
|
|
222
|
+
password: '123',
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
expect(encryptedNote.content.startsWith('-----BEGIN PGP MESSAGE-----')).toBe(
|
|
226
|
+
true
|
|
227
|
+
);
|
|
228
|
+
|
|
229
|
+
delete encryptedNote.content;
|
|
230
|
+
expect(encryptedNote).toMatchSnapshot();
|
|
231
|
+
});
|
|
@@ -79,6 +79,7 @@ export async function decryptNote<T extends AbstractEncryptedNote>(
|
|
|
79
79
|
encryptionParams: OrgNoteEncryption
|
|
80
80
|
): Promise<T> {
|
|
81
81
|
if (
|
|
82
|
+
note.meta.published ||
|
|
82
83
|
!encryptionParams.type ||
|
|
83
84
|
encryptionParams.type === ModelsPublicNoteEncryptedEnum.Disabled
|
|
84
85
|
) {
|