@drifted/raven 0.0.3 → 0.0.5

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
@@ -1,6 +1,7 @@
1
1
 
2
2
  # raven
3
3
 
4
+
4
5
  ---
5
6
 
6
7
  ```bash
package/index.js CHANGED
@@ -4,7 +4,7 @@ const fs = require('fs');
4
4
 
5
5
  const ivLength = 16;
6
6
 
7
- class JSONDataFile {
7
+ class RavenDataFile {
8
8
  constructor(options={}) {
9
9
  Object.assign(this, options)
10
10
  if (this.data != undefined && typeof this.data == 'string') {
@@ -51,22 +51,30 @@ class JSONDataFile {
51
51
  var times = 0;
52
52
 
53
53
  await file.read();
54
-
55
- while(times < options.iterations) {
56
- file.data = file.encrypt(file.data)
57
- times += 1;
58
- }
54
+
55
+ while(times < iterations) {
56
+ try {
57
+ file.data = file.decrypt(file.data)
58
+ } catch(error) {
59
+ //console.log(error);
60
+ }
59
61
 
60
- var json = JSON.parse(file.data.toString());
62
+ times = times + 1;
63
+ }
61
64
 
62
- //console.log(json);
65
+ try {
66
+ file.data = JSON.parse(file.data.trim());
67
+ } catch(error) {
68
+ console.log(error);
69
+ }
63
70
 
64
- resolve(json)
71
+ resolve(file.data)
65
72
  })
66
73
  }
67
74
 
68
75
  static toEnv(options={}) {
69
76
  var self = this;
77
+
70
78
  return new Promise((resolve) => {
71
79
  self.eval(options).then((json) => {
72
80
  Object.assign(process.env, json);
@@ -208,7 +216,7 @@ class JSONDataFile {
208
216
  }
209
217
 
210
218
 
211
- module.exports = JSONDataFile;
219
+ module.exports = RavenDataFile;
212
220
 
213
221
 
214
222
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drifted/raven",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "description": "",
5
5
  "homepage": "https://github.com/driftless-group/raven",
6
6
  "bin": {
package/test/cli.test.js CHANGED
@@ -2,7 +2,7 @@ const path = require('path');
2
2
  const assert = require('assert');
3
3
  const fs = require('fs');
4
4
 
5
- const JSONDataFile = require(path.join(__dirname, '..'));
5
+ const RavenDataFile = require(path.join(__dirname, '..'));
6
6
  var { exec } = require('child_process');
7
7
 
8
8
  const {
@@ -82,7 +82,7 @@ describe('raven', function() {
82
82
 
83
83
  describe('files', function() {
84
84
  it('conceal/expose', function(done) {
85
- var secret = JSONDataFile.secret();
85
+ var secret = RavenDataFile.secret();
86
86
  var file = path.join(__dirname, 'theraven.txt');
87
87
  var initial = fs.readFileSync(file).toString();
88
88
 
@@ -101,7 +101,7 @@ describe('raven', function() {
101
101
  })
102
102
 
103
103
  it('repeatedly concealing/exposing', function(done) {
104
- var secret = JSONDataFile.secret();
104
+ var secret = RavenDataFile.secret();
105
105
  var file = path.join(__dirname, 'theraven.txt');
106
106
  var initial = fs.readFileSync(file).toString();
107
107
  run('conceal', '-f', file, '-s', secret).then(() => {
@@ -2,24 +2,42 @@ const path = require('path');
2
2
  const assert = require('assert');
3
3
  process.env.NODE_ENV = 'test';
4
4
 
5
- const JSONDataFile = require(path.join(__dirname, '..'));
5
+ const RavenDataFile = require(path.join(__dirname, '..'));
6
6
 
7
7
  var defaults = {
8
8
  secret: 'ffdnZY17Fw+sup2+lhOOt6PW++/RkLTXRaLL3RJsjzE='
9
9
  }
10
10
 
11
- // this seems to work. i should write a test to make sure that it works
12
- //JSONDataFile.toEnv({file: path.join(__dirname, '..', 'config', process.env.NODE_ENV+'.json')});
11
+ const {
12
+ doneMessage
13
+ } = require('@drifted/qa');
14
+
15
+ const {
16
+ run, ensure, remove
17
+ } = require(path.join(__dirname, 'helpers'));
18
+
13
19
 
14
20
 
15
21
  process.chdir(path.join(__dirname, 'workspace'));
16
22
 
23
+ console.log(__dirname);
24
+
25
+ //console.log(process.env)
26
+
17
27
  describe('raven', function() {
18
28
 
19
29
 
20
- it('read', function(done) {
21
-
22
- done();
30
+ it('eval', function(done) {
31
+
32
+ // this seems to work. i should write a test to make sure that it works
33
+ RavenDataFile.eval({
34
+ secret: defaults.secret,
35
+ iterations: 2,
36
+ file: path.join(__dirname, 'workspace', 'example.json.encrypted')
37
+ }).then((json) => {
38
+ done()
39
+ }).catch(doneMessage(done))
40
+
23
41
  })
24
42
 
25
43
  it('write', function(done) {
@@ -27,7 +45,7 @@ describe('raven', function() {
27
45
  })
28
46
 
29
47
  it('encrypt/decrypt', function(done) {
30
- var jdf = new JSONDataFile({secret: defaults.secret, data: {test: true}});
48
+ var jdf = new RavenDataFile({secret: defaults.secret, data: {test: true}});
31
49
  var result = jdf.encrypt(JSON.stringify(jdf.data));
32
50
  result = JSON.parse(jdf.decrypt(result));
33
51
  assert.equal(result.test, true);
@@ -0,0 +1 @@
1
+ 100ac0d8b2d2519e65222eac9b08bbef:b5ce9cdbbb5c54453e2dfddf2d64e16a:a9d72d894df8323e9de43ba14c42603c26432452330fc235d340008ee7967f87614893d689aaeea81635be5c544a8661c9eb3c1f9d2978f2c6f1310aeab3801ad15121ba77c9c88ec93193f4127b5ced7a17e480f984b4cc717289671dbf24f7