orgnote-api 0.7.15 → 0.7.17
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.
- package/encryption/__tests__/__snapshots__/note-encryption.spec.ts.snap +22 -0
- package/encryption/__tests__/encryption.spec.ts +5 -5
- package/encryption/__tests__/note-encryption.spec.ts +30 -0
- package/encryption/encryption.ts +4 -4
- package/encryption/note-encryption.ts +1 -0
- package/package.json +1 -1
|
@@ -82,6 +82,28 @@ exports[`Should encrypt note with empty encrypted property 1`] = `
|
|
|
82
82
|
}
|
|
83
83
|
`;
|
|
84
84
|
|
|
85
|
+
exports[`Should not decrypt note without provided encrypted type 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": undefined,
|
|
97
|
+
"id": "id",
|
|
98
|
+
"meta": {
|
|
99
|
+
"description": "Awesome description",
|
|
100
|
+
"images": [],
|
|
101
|
+
"published": false,
|
|
102
|
+
"title": "My note title",
|
|
103
|
+
},
|
|
104
|
+
}
|
|
105
|
+
`;
|
|
106
|
+
|
|
85
107
|
exports[`Should not encrypt public note 1`] = `
|
|
86
108
|
{
|
|
87
109
|
"author": {
|
|
@@ -3,8 +3,8 @@ import {
|
|
|
3
3
|
decryptViaKeys,
|
|
4
4
|
encryptViaPassword,
|
|
5
5
|
decryptViaPassword,
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
NoKeysProvidedError,
|
|
7
|
+
NoPasswordProvidedError,
|
|
8
8
|
IncorrectOrMissingPrivateKeyPasswordError,
|
|
9
9
|
} from '../encryption';
|
|
10
10
|
import { test, expect } from 'vitest';
|
|
@@ -125,7 +125,7 @@ YQ==
|
|
|
125
125
|
try {
|
|
126
126
|
await decryptViaPassword(encryptedMsg, 'password');
|
|
127
127
|
} catch (e) {
|
|
128
|
-
expect(e).toBeInstanceOf(
|
|
128
|
+
expect(e).toBeInstanceOf(NoKeysProvidedError);
|
|
129
129
|
}
|
|
130
130
|
});
|
|
131
131
|
|
|
@@ -147,7 +147,7 @@ aGW80jwBXEQ7uTjT8akpOKiH7BIuhEUZIXh+vDveG0Uwf63s2dIklznAEo+E
|
|
|
147
147
|
}
|
|
148
148
|
});
|
|
149
149
|
|
|
150
|
-
test('Should raise
|
|
150
|
+
test('Should raise NoPasswordProvidedError error when try to use keys instead of password', async () => {
|
|
151
151
|
const encryptedMsg = `-----BEGIN PGP MESSAGE-----
|
|
152
152
|
|
|
153
153
|
wy4ECQMI6KFWGqyVV+DgYl0qUEeTe1kAdjkoR4FxFJxx+6QiOP+sZ6h7bn//
|
|
@@ -160,6 +160,6 @@ aGW80jwBXEQ7uTjT8akpOKiH7BIuhEUZIXh+vDveG0Uwf63s2dIklznAEo+E
|
|
|
160
160
|
try {
|
|
161
161
|
await decryptViaKeys(encryptedMsg, armoredPrivateKey, privateKeyPassphrase);
|
|
162
162
|
} catch (e) {
|
|
163
|
-
expect(e).toBeInstanceOf(
|
|
163
|
+
expect(e).toBeInstanceOf(NoPasswordProvidedError);
|
|
164
164
|
}
|
|
165
165
|
});
|
|
@@ -229,3 +229,33 @@ test('Should encrypt note with empty encrypted property', async () => {
|
|
|
229
229
|
delete encryptedNote.content;
|
|
230
230
|
expect(encryptedNote).toMatchSnapshot();
|
|
231
231
|
});
|
|
232
|
+
|
|
233
|
+
test('Should not decrypt note without provided encrypted type', async () => {
|
|
234
|
+
const content = `#+ID: qweqwe
|
|
235
|
+
#+TITLE: Hello worlld
|
|
236
|
+
|
|
237
|
+
* Hello?`;
|
|
238
|
+
const note: Note = {
|
|
239
|
+
id: 'id',
|
|
240
|
+
meta: {
|
|
241
|
+
title: 'My note title',
|
|
242
|
+
images: [],
|
|
243
|
+
published: false,
|
|
244
|
+
description: 'Awesome description',
|
|
245
|
+
},
|
|
246
|
+
encrypted: undefined,
|
|
247
|
+
content,
|
|
248
|
+
author: {
|
|
249
|
+
id: '1',
|
|
250
|
+
name: 'John Doe',
|
|
251
|
+
email: 'test@mail.com',
|
|
252
|
+
},
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
const decryptedNote = await decryptNote(note, {
|
|
256
|
+
type: 'gpgPassword',
|
|
257
|
+
password: '123',
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
expect(decryptedNote).toMatchSnapshot();
|
|
261
|
+
});
|
package/encryption/encryption.ts
CHANGED
|
@@ -11,8 +11,8 @@ import {
|
|
|
11
11
|
export class IncorrectOrMissingPrivateKeyPasswordError extends Error {}
|
|
12
12
|
export class ImpossibleToDecryptWithProvidedKeysError extends Error {}
|
|
13
13
|
export class IncorrectEncryptionPasswordError extends Error {}
|
|
14
|
-
export class
|
|
15
|
-
export class
|
|
14
|
+
export class NoKeysProvidedError extends Error {}
|
|
15
|
+
export class NoPasswordProvidedError extends Error {}
|
|
16
16
|
|
|
17
17
|
const noPrivateKeyPassphraseProvidedErrorMsg =
|
|
18
18
|
'Error: Signing key is not decrypted.';
|
|
@@ -159,11 +159,11 @@ function withCustomErrors<P extends unknown[], T>(
|
|
|
159
159
|
throw new IncorrectEncryptionPasswordError();
|
|
160
160
|
}
|
|
161
161
|
if (e.message === noSymmetricallyEncryptedSessionKeyErrorMsg) {
|
|
162
|
-
throw new
|
|
162
|
+
throw new NoKeysProvidedError();
|
|
163
163
|
}
|
|
164
164
|
|
|
165
165
|
if (e.message === notPrivateKeyErrprMsg) {
|
|
166
|
-
throw new
|
|
166
|
+
throw new NoPasswordProvidedError();
|
|
167
167
|
}
|
|
168
168
|
|
|
169
169
|
throw e;
|