orgnote-api 0.7.10 → 0.7.12
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,69 @@ exports[`Should encrypt note via keys 1`] = `
|
|
|
65
65
|
},
|
|
66
66
|
}
|
|
67
67
|
`;
|
|
68
|
+
|
|
69
|
+
exports[`Should not encrypt note with disabled encryption 1`] = `
|
|
70
|
+
{
|
|
71
|
+
"author": {
|
|
72
|
+
"email": "test@mail.com",
|
|
73
|
+
"id": "1",
|
|
74
|
+
"name": "John Doe",
|
|
75
|
+
},
|
|
76
|
+
"content": "#+ID: qweqwe
|
|
77
|
+
#+TITLE: Hello worlld
|
|
78
|
+
|
|
79
|
+
* Hello?",
|
|
80
|
+
"encrypted": null,
|
|
81
|
+
"id": "id",
|
|
82
|
+
"meta": {
|
|
83
|
+
"description": "Awesome description",
|
|
84
|
+
"images": [],
|
|
85
|
+
"published": false,
|
|
86
|
+
"title": "My note title",
|
|
87
|
+
},
|
|
88
|
+
}
|
|
89
|
+
`;
|
|
90
|
+
|
|
91
|
+
exports[`Should not encrypt public note 1`] = `
|
|
92
|
+
{
|
|
93
|
+
"author": {
|
|
94
|
+
"email": "test@mail.com",
|
|
95
|
+
"id": "1",
|
|
96
|
+
"name": "John Doe",
|
|
97
|
+
},
|
|
98
|
+
"content": "#+ID: qweqwe
|
|
99
|
+
#+TITLE: Hello worlld
|
|
100
|
+
|
|
101
|
+
* Hello?",
|
|
102
|
+
"encrypted": "gpgPassword",
|
|
103
|
+
"id": "id",
|
|
104
|
+
"meta": {
|
|
105
|
+
"description": "Awesome description",
|
|
106
|
+
"images": [],
|
|
107
|
+
"published": true,
|
|
108
|
+
"title": "My note title",
|
|
109
|
+
},
|
|
110
|
+
}
|
|
111
|
+
`;
|
|
112
|
+
|
|
113
|
+
exports[`Should not encrypt publick note 1`] = `
|
|
114
|
+
{
|
|
115
|
+
"author": {
|
|
116
|
+
"email": "test@mail.com",
|
|
117
|
+
"id": "1",
|
|
118
|
+
"name": "John Doe",
|
|
119
|
+
},
|
|
120
|
+
"content": "#+ID: qweqwe
|
|
121
|
+
#+TITLE: Hello worlld
|
|
122
|
+
|
|
123
|
+
* Hello?",
|
|
124
|
+
"encrypted": "gpgPassword",
|
|
125
|
+
"id": "id",
|
|
126
|
+
"meta": {
|
|
127
|
+
"description": "Awesome description",
|
|
128
|
+
"images": [],
|
|
129
|
+
"published": true,
|
|
130
|
+
"title": "My note title",
|
|
131
|
+
},
|
|
132
|
+
}
|
|
133
|
+
`;
|
|
@@ -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,71 @@ 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 not encrypt note with disabled encryption', async () => {
|
|
199
|
+
const content = `#+ID: qweqwe
|
|
200
|
+
#+TITLE: Hello worlld
|
|
201
|
+
|
|
202
|
+
* Hello?`;
|
|
203
|
+
|
|
204
|
+
const note: Note = {
|
|
205
|
+
id: 'id',
|
|
206
|
+
encrypted: null,
|
|
207
|
+
meta: {
|
|
208
|
+
title: 'My note title',
|
|
209
|
+
images: [],
|
|
210
|
+
published: false,
|
|
211
|
+
description: 'Awesome description',
|
|
212
|
+
},
|
|
213
|
+
content,
|
|
214
|
+
author: {
|
|
215
|
+
id: '1',
|
|
216
|
+
name: 'John Doe',
|
|
217
|
+
email: 'test@mail.com',
|
|
218
|
+
},
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
const encryptedNote = await encryptNote(note, {
|
|
222
|
+
type: 'gpgPassword',
|
|
223
|
+
password: '123',
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
expect(encryptedNote.content.startsWith('-----BEGIN PGP MESSAGE-----')).toBe(
|
|
227
|
+
false
|
|
228
|
+
);
|
|
229
|
+
expect(encryptedNote).toMatchSnapshot();
|
|
230
|
+
});
|
|
@@ -23,6 +23,7 @@ export async function encryptNote<T extends AbstractEncryptedNote>(
|
|
|
23
23
|
encryptionParams: OrgNoteEncryption
|
|
24
24
|
): Promise<T> {
|
|
25
25
|
if (
|
|
26
|
+
!note.encrypted ||
|
|
26
27
|
!encryptionParams.type ||
|
|
27
28
|
encryptionParams.type === ModelsPublicNoteEncryptedEnum.Disabled ||
|
|
28
29
|
note.meta.published
|
|
@@ -79,6 +80,7 @@ export async function decryptNote<T extends AbstractEncryptedNote>(
|
|
|
79
80
|
encryptionParams: OrgNoteEncryption
|
|
80
81
|
): Promise<T> {
|
|
81
82
|
if (
|
|
83
|
+
!note.encrypted ||
|
|
82
84
|
!encryptionParams.type ||
|
|
83
85
|
encryptionParams.type === ModelsPublicNoteEncryptedEnum.Disabled
|
|
84
86
|
) {
|