secrez 2.1.0 → 2.1.1

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/README.md CHANGED
@@ -369,6 +369,11 @@ Secrez is not intended to compete with password managers, so do not expect it to
369
369
 
370
370
  ## History
371
371
 
372
+ **2.1.1**
373
+
374
+ - manage missing clipboard when in headless shells
375
+ - fix bug in creating a `totp` when the target Yaml file is empty
376
+
372
377
  **2.0.1**
373
378
 
374
379
  - fix commands to change password and number of iterations
@@ -839,25 +844,25 @@ Thank you for any contributions! 😉
839
844
  ## Test coverage
840
845
 
841
846
  ```
842
- 148 passing (15s)
847
+ 148 passing (16s)
843
848
  1 pending
844
849
 
845
850
  --------------------|---------|----------|---------|---------|--------------------------------------
846
851
  File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
847
852
  --------------------|---------|----------|---------|---------|--------------------------------------
848
- All files | 81.16 | 67.69 | 81.02 | 81.05 |
853
+ All files | 81.09 | 67.66 | 81.15 | 80.99 |
849
854
  src | 57.84 | 53.62 | 52.63 | 58.41 |
850
855
  Command.js | 79.66 | 78.72 | 76.92 | 81.03 | 32,55-62,73,80,119
851
856
  PreCommand.js | 8.82 | 0 | 0 | 8.82 | 6-97
852
857
  cliConfig.js | 100 | 100 | 100 | 100 |
853
- src/commands | 83.82 | 69.19 | 90.54 | 83.71 |
858
+ src/commands | 83.73 | 69.14 | 90.64 | 83.61 |
854
859
  Alias.js | 90.54 | 77.35 | 100 | 90.41 | 101,112,139,169,173,180,190
855
860
  Bash.js | 75 | 0 | 66.66 | 75 | 18-19
856
861
  Cat.js | 98.9 | 88.88 | 100 | 98.9 | 152
857
862
  Cd.js | 96.42 | 86.66 | 100 | 96.42 | 44
858
863
  Conf.js | 9.09 | 0 | 20 | 9.09 | 98-500
859
864
  Contacts.js | 87.17 | 74.32 | 100 | 87.06 | ...5-141,145,165,172,184,237,250,260
860
- Copy.js | 94.87 | 74.5 | 100 | 94.8 | 111,162,179,204
865
+ Copy.js | 92.94 | 73.58 | 100 | 92.85 | 114,165,182,200,216-217
861
866
  Ds.js | 92.53 | 82.05 | 100 | 92.42 | 99,108-113,125
862
867
  Edit.js | 13.58 | 0 | 40 | 13.58 | 88-214
863
868
  Export.js | 88.11 | 70.58 | 100 | 88.11 | ...0-175,185,197-201,206,218,227,230
@@ -879,7 +884,7 @@ All files | 81.16 | 67.69 | 81.02 | 81.05 |
879
884
  Show.js | 72 | 45.45 | 57.14 | 73.46 | ...8,100,106-114,117,123-126,132,143
880
885
  Ssh.js | 25 | 0 | 40 | 25 | 72-120
881
886
  Tag.js | 98.03 | 92.3 | 100 | 98.01 | 122,171
882
- Totp.js | 96.47 | 74.46 | 100 | 96.47 | 188-189,235
887
+ Totp.js | 94.56 | 73.58 | 100 | 94.56 | 188-189,229,239,277
883
888
  Touch.js | 95.91 | 81.48 | 100 | 95.83 | 152,202
884
889
  Use.js | 96.77 | 89.47 | 100 | 96.77 | 68
885
890
  Ver.js | 90 | 66.66 | 100 | 90 | 25
@@ -895,7 +900,7 @@ All files | 81.16 | 67.69 | 81.02 | 81.05 |
895
900
  Logger.js | 63.63 | 56.25 | 36.84 | 62.79 | ...25,37-49,57,65-69,74,84,88,93,105
896
901
  --------------------|---------|----------|---------|---------|--------------------------------------
897
902
 
898
- > secrez@2.1.0 posttest /Users/francescosullo/Projects/Secrez/secrez/packages/secrez
903
+ > secrez@2.1.1 posttest /Users/francescosullo/Projects/Secrez/secrez/packages/secrez
899
904
  > nyc check-coverage --statements 65 --branches 50 --functions 65 --lines 65
900
905
 
901
906
 
package/coverage.report CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
- > secrez@2.1.0 test /Users/francescosullo/Projects/Secrez/secrez/packages/secrez
2
+ > secrez@2.1.1 test /Users/francescosullo/Projects/Secrez/secrez/packages/secrez
3
3
  > cross-env NODE_ENV=test nyc --reporter=lcov --reporter=text mocha test/*.test.js test/**/*.test.js test/**/**/*.js --exit
4
4
 
5
5
 
@@ -29,10 +29,10 @@
29
29
  #Cat
30
30
  ✓ should return the help
31
31
  ✓ should show the content of a file
32
- ✓ should show either one or all the versions of a file (1036ms)
32
+ ✓ should show either one or all the versions of a file (1020ms)
33
33
  ✓ should throw if entry is not a file or file does not exist
34
34
  ✓ should throw if trying to cat a binary file
35
- ✓ should show the content of a Yaml file (1029ms)
35
+ ✓ should show the content of a Yaml file (1030ms)
36
36
 
37
37
  #Cd
38
38
  ✓ should return the help
@@ -51,9 +51,9 @@
51
51
 
52
52
  #Copy
53
53
  ✓ should return the help
54
- ✓ should copy a file to the clipboard (380ms)
55
- ✓ should copy a string to the clipboard (230ms)
56
- ✓ should copy a card to the clipboard (866ms)
54
+ ✓ should copy a file to the clipboard (405ms)
55
+ ✓ should copy a string to the clipboard (254ms)
56
+ ✓ should copy a card to the clipboard (937ms)
57
57
  ✓ should return an error if the file does not exist or is a folder
58
58
  ✓ should throw if copying to clipboard a binary files
59
59
 
@@ -69,14 +69,14 @@
69
69
  ✓ should export a file to the current local folder
70
70
  ✓ should export a binary file to the current local folder
71
71
  ✓ should export an encrypted file to the current local folder
72
- ✓ should export a file and delete it after 1 second (1205ms)
72
+ ✓ should export a file and delete it after 1 second (1203ms)
73
73
  ✓ should return an error if the file does not exist or is a folder
74
- ✓ should export a keystore json file if a private_key exists in the entry (672ms)
74
+ ✓ should export a keystore json file if a private_key exists in the entry (718ms)
75
75
  ✓ should export a cryptoenv file if a private_key exists in the entry
76
76
 
77
77
  #Find
78
78
  ✓ should return the help
79
- ✓ should show find a string in the tree (1018ms)
79
+ ✓ should show find a string in the tree (1017ms)
80
80
  ✓ should find no result without parameters
81
81
  ✓ should skip binary files from search
82
82
 
@@ -141,7 +141,7 @@
141
141
 
142
142
  #Mv
143
143
  ✓ should return the help
144
- ✓ should rename a file (1015ms)
144
+ ✓ should rename a file (1013ms)
145
145
  ✓ should move a file to another folder
146
146
  ✓ should move many files to another folder
147
147
  ✓ should move a file to another subfolder
@@ -155,9 +155,9 @@
155
155
 
156
156
  #Paste
157
157
  ✓ should return the help
158
- ✓ should paste the clipboard content to a new file (55ms)
159
- ✓ should paste the clipboard content to an existent file (61ms)
160
- ✓ should paste a single field to a yml card
158
+ ✓ should paste the clipboard content to a new file (52ms)
159
+ ✓ should paste the clipboard content to an existent file (77ms)
160
+ ✓ should paste a single field to a yml card (38ms)
161
161
 
162
162
  #Pwd
163
163
  ✓ should return the help
@@ -171,7 +171,7 @@
171
171
  ✓ should delete a file with one version
172
172
  ✓ should delete many files usign wildcards
173
173
  ✓ should return errors if wrong parameters
174
- ✓ should delete some versions of a file (1012ms)
174
+ ✓ should delete some versions of a file (1010ms)
175
175
 
176
176
  #Shell
177
177
  ✓ should return the help
@@ -191,13 +191,13 @@
191
191
 
192
192
  #Totp
193
193
  ✓ should return the help
194
- ✓ should totp a file to the clipboard (347ms)
194
+ ✓ should totp a file to the clipboard (425ms)
195
195
  ✓ should read a totp secret from an image and add the totp field to the card (39ms)
196
196
  ✓ should read a totp secret from an image and return the secret
197
197
  ✓ should throw if bad image
198
198
  ✓ should throw if missing parameters
199
199
  ✓ should throw if the yaml is malformed
200
- ✓ should read a totp secret from the clipboard (275ms)
200
+ ✓ should read a totp secret from the clipboard (115ms)
201
201
 
202
202
  #Touch
203
203
  ✓ should return the help
@@ -207,7 +207,7 @@
207
207
  ✓ should throw if wrong parameters
208
208
  ✓ should create a file and generate a wallet
209
209
  New file "/folder2/file1" created.
210
- ✓ should generate 5 prefixed wallet (65ms)
210
+ ✓ should generate 5 prefixed wallet (63ms)
211
211
  New file "/folder2/file1" created.
212
212
  ✓ should generate a wallet with mnemonic and 2 keys
213
213
 
@@ -223,25 +223,25 @@ New file "/folder2/file1" created.
223
223
  ✓ should see who am I
224
224
 
225
225
 
226
- 148 passing (15s)
226
+ 148 passing (16s)
227
227
  1 pending
228
228
 
229
229
  --------------------|---------|----------|---------|---------|--------------------------------------
230
230
  File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
231
231
  --------------------|---------|----------|---------|---------|--------------------------------------
232
- All files | 81.16 | 67.69 | 81.02 | 81.05 |
232
+ All files | 81.09 | 67.66 | 81.15 | 80.99 |
233
233
  src | 57.84 | 53.62 | 52.63 | 58.41 |
234
234
  Command.js | 79.66 | 78.72 | 76.92 | 81.03 | 32,55-62,73,80,119
235
235
  PreCommand.js | 8.82 | 0 | 0 | 8.82 | 6-97
236
236
  cliConfig.js | 100 | 100 | 100 | 100 |
237
- src/commands | 83.82 | 69.19 | 90.54 | 83.71 |
237
+ src/commands | 83.73 | 69.14 | 90.64 | 83.61 |
238
238
  Alias.js | 90.54 | 77.35 | 100 | 90.41 | 101,112,139,169,173,180,190
239
239
  Bash.js | 75 | 0 | 66.66 | 75 | 18-19
240
240
  Cat.js | 98.9 | 88.88 | 100 | 98.9 | 152
241
241
  Cd.js | 96.42 | 86.66 | 100 | 96.42 | 44
242
242
  Conf.js | 9.09 | 0 | 20 | 9.09 | 98-500
243
243
  Contacts.js | 87.17 | 74.32 | 100 | 87.06 | ...5-141,145,165,172,184,237,250,260
244
- Copy.js | 94.87 | 74.5 | 100 | 94.8 | 111,162,179,204
244
+ Copy.js | 92.94 | 73.58 | 100 | 92.85 | 114,165,182,200,216-217
245
245
  Ds.js | 92.53 | 82.05 | 100 | 92.42 | 99,108-113,125
246
246
  Edit.js | 13.58 | 0 | 40 | 13.58 | 88-214
247
247
  Export.js | 88.11 | 70.58 | 100 | 88.11 | ...0-175,185,197-201,206,218,227,230
@@ -263,7 +263,7 @@ All files | 81.16 | 67.69 | 81.02 | 81.05 |
263
263
  Show.js | 72 | 45.45 | 57.14 | 73.46 | ...8,100,106-114,117,123-126,132,143
264
264
  Ssh.js | 25 | 0 | 40 | 25 | 72-120
265
265
  Tag.js | 98.03 | 92.3 | 100 | 98.01 | 122,171
266
- Totp.js | 96.47 | 74.46 | 100 | 96.47 | 188-189,235
266
+ Totp.js | 94.56 | 73.58 | 100 | 94.56 | 188-189,229,239,277
267
267
  Touch.js | 95.91 | 81.48 | 100 | 95.83 | 152,202
268
268
  Use.js | 96.77 | 89.47 | 100 | 96.77 | 68
269
269
  Ver.js | 90 | 66.66 | 100 | 90 | 25
@@ -279,6 +279,6 @@ All files | 81.16 | 67.69 | 81.02 | 81.05 |
279
279
  Logger.js | 63.63 | 56.25 | 36.84 | 62.79 | ...25,37-49,57,65-69,74,84,88,93,105
280
280
  --------------------|---------|----------|---------|---------|--------------------------------------
281
281
 
282
- > secrez@2.1.0 posttest /Users/francescosullo/Projects/Secrez/secrez/packages/secrez
282
+ > secrez@2.1.1 posttest /Users/francescosullo/Projects/Secrez/secrez/packages/secrez
283
283
  > nyc check-coverage --statements 65 --branches 50 --functions 65 --lines 65
284
284
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "secrez",
3
- "version": "2.1.0",
3
+ "version": "2.1.1",
4
4
  "license": "MIT",
5
5
  "nyc": {
6
6
  "include": "src",
@@ -2,6 +2,7 @@ const path = require("path");
2
2
  const clipboardy = require("clipboardy");
3
3
  const { isYaml, yamlParse, TRUE, sleep, playMp3 } = require("@secrez/utils");
4
4
  const { Node } = require("@secrez/fs");
5
+ const { execSync } = require("child_process");
5
6
 
6
7
  class Copy extends require("../Command") {
7
8
  setHelpAndCompletion() {
@@ -67,7 +68,9 @@ class Copy extends require("../Command") {
67
68
 
68
69
  help() {
69
70
  return {
70
- description: ["Copy a text file to the clipboard."],
71
+ description: [
72
+ "Copy a text file to the clipboard. It won't work in headless shells.",
73
+ ],
71
74
  examples: [
72
75
  [
73
76
  "copy ethKeys",
@@ -189,6 +192,15 @@ class Copy extends require("../Command") {
189
192
  }
190
193
  }
191
194
 
195
+ isMacGuiSession() {
196
+ try {
197
+ execSync("echo test | pbcopy", { stdio: "ignore" });
198
+ return true;
199
+ } catch {
200
+ return false;
201
+ }
202
+ }
203
+
192
204
  async write(content, options, counter) {
193
205
  let duration = options.duration
194
206
  ? options.duration.map((e) => 1000 * e)
@@ -201,19 +213,25 @@ class Copy extends require("../Command") {
201
213
  let wait = i ? duration[1] : duration[0];
202
214
  await this.writeAndWait(content[i], wait, counter);
203
215
  if (this.counter === counter && !options.noBeep) {
204
- await playMp3(path.resolve(__dirname, "../../sounds/ding.mp3"));
216
+ try {
217
+ await playMp3(path.resolve(__dirname, "../../sounds/ding.mp3"));
218
+ } catch (e) {
219
+ // Ignore the error
220
+ }
205
221
  }
206
222
  }
207
223
  }
208
224
  }
209
225
 
210
226
  async writeAndWait(content, wait, counter) {
211
- let previousContent = await clipboardy.read();
212
- if (this.counter === counter) {
213
- await clipboardy.write(content);
214
- await sleep(wait);
215
- if (this.counter === counter && content === (await clipboardy.read())) {
216
- await clipboardy.write(previousContent);
227
+ if (this.isMacGuiSession()) {
228
+ let previousContent = await clipboardy.read();
229
+ if (this.counter === counter) {
230
+ await clipboardy.write(content);
231
+ await sleep(wait);
232
+ if (this.counter === counter && content === (await clipboardy.read())) {
233
+ await clipboardy.write(previousContent);
234
+ }
217
235
  }
218
236
  }
219
237
  }
@@ -77,7 +77,7 @@ class Totp extends require("../Command") {
77
77
  examples: [
78
78
  [
79
79
  "totp coinbase.yml",
80
- "prints a totp code and copies it to the clipboard for 5 seconds",
80
+ "prints a totp code and copies it to the clipboard for 5 seconds if not in a headless shell",
81
81
  ],
82
82
  [
83
83
  'totp coinbase.yml -s "9syh 34rd ge6s hey3 u874"',
@@ -225,10 +225,14 @@ class Totp extends require("../Command") {
225
225
  let { content } = entry;
226
226
  if (isYaml(p) && !options.allFile) {
227
227
  let parsed;
228
- try {
229
- parsed = yamlParse(content);
230
- } catch (e) {
231
- throw new Error("The yml is malformed");
228
+ if (content === undefined) {
229
+ parsed = {};
230
+ } else {
231
+ try {
232
+ parsed = yamlParse(content);
233
+ } catch (e) {
234
+ throw new Error("The yml is malformed");
235
+ }
232
236
  }
233
237
  if (secret) {
234
238
  if (parsed.totp && !options.force) {
@@ -249,11 +253,13 @@ class Totp extends require("../Command") {
249
253
  if (totp) {
250
254
  totp = totp.replace(/\s/g, "");
251
255
  const token = authenticator.generate(totp);
252
- this.prompt.commands.copy.copy({
253
- thisString: token,
254
- duration: [options.duration || this.defaults.duration],
255
- noBeep: options.noBeep,
256
- });
256
+ if (this.isMacGuiSession()) {
257
+ this.prompt.commands.copy.copy({
258
+ thisString: token,
259
+ duration: [options.duration || this.defaults.duration],
260
+ noBeep: options.noBeep,
261
+ });
262
+ }
257
263
  return token;
258
264
  }
259
265
  }
@@ -263,6 +269,15 @@ class Totp extends require("../Command") {
263
269
  throw new Error(err);
264
270
  }
265
271
 
272
+ isMacGuiSession() {
273
+ try {
274
+ execSync("echo test | pbcopy", { stdio: "ignore" });
275
+ return true;
276
+ } catch {
277
+ return false;
278
+ }
279
+ }
280
+
266
281
  async exec(options = {}) {
267
282
  if (options.help) {
268
283
  return this.showHelp();
@@ -273,10 +288,10 @@ class Totp extends require("../Command") {
273
288
  if (options.fromImage || options.fromClipboard) {
274
289
  this.Logger.grey(token);
275
290
  } else {
276
- this.Logger.grey("TOTP token: " + this.chalk.bold.black(token));
277
- if (!options.test) {
291
+ this.Logger.grey("TOTP token: " + this.chalk.bold(token));
292
+ if (!options.test && this.isMacGuiSession()) {
278
293
  this.Logger.grey(
279
- `It will stay in the clipboard for ${
294
+ `Copied to the clipboard. It will stay in it for ${
280
295
  options.duration || this.defaults.duration
281
296
  } seconds`
282
297
  );