cloudcmd 18.5.2 → 18.6.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.
@@ -1,105 +0,0 @@
1
- import {createRequire} from 'node:module';
2
- import {test, stub} from 'supertape';
3
- import {createConfig, _cryptoPass} from './config.js';
4
- import {apiURL} from '../common/cloudfunc.js';
5
- import {connect} from '../test/before.mjs';
6
-
7
- const require = createRequire(import.meta.url);
8
- const fixture = require('./config.fixture.json');
9
-
10
- const config = createConfig();
11
-
12
- test('config: manage', (t) => {
13
- t.equal(undefined, config(), 'should return "undefined"');
14
- t.end();
15
- });
16
-
17
- test('config: manage: get', async (t) => {
18
- const editor = 'deepword';
19
- const configManager = createConfig();
20
-
21
- const {done} = await connect({
22
- config: {
23
- editor,
24
- },
25
- configManager,
26
- });
27
-
28
- done();
29
-
30
- t.equal(configManager('editor'), editor, 'should get config');
31
- t.end();
32
- });
33
-
34
- test('config: manage: get: config', async (t) => {
35
- const editor = 'deepword';
36
- const conf = {
37
- editor,
38
- };
39
-
40
- const {done} = await connect({
41
- config: conf,
42
- });
43
-
44
- config('editor', 'dword');
45
- done();
46
-
47
- t.equal('dword', config('editor'), 'should set config');
48
- t.end();
49
- });
50
-
51
- test('config: manage: get: *', (t) => {
52
- const data = config('*');
53
- const keys = Object.keys(data);
54
-
55
- t.ok(keys.length > 1, 'should return config data');
56
- t.end();
57
- });
58
-
59
- test('config: cryptoPass: no password', (t) => {
60
- const json = {
61
- hello: 'world',
62
- };
63
-
64
- const config = createConfig();
65
- const result = _cryptoPass(config, json);
66
-
67
- t.deepEqual(result, [config, json], 'should not change json');
68
- t.end();
69
- });
70
-
71
- test('config: cryptoPass', (t) => {
72
- const json = {
73
- password: 'hello',
74
- };
75
-
76
- const {password} = fixture;
77
-
78
- const expected = {
79
- password,
80
- };
81
-
82
- const config = createConfig();
83
- const result = _cryptoPass(config, json);
84
-
85
- t.deepEqual(result, [config, expected], 'should crypt password');
86
- t.end();
87
- });
88
-
89
- test('config: middle: no', (t) => {
90
- const {middle} = config;
91
- const next = stub();
92
- const res = null;
93
- const url = `${apiURL}/config`;
94
- const method = 'POST';
95
-
96
- const req = {
97
- url,
98
- method,
99
- };
100
-
101
- middle(req, res, next);
102
-
103
- t.calledWithNoArgs(next, 'should call next');
104
- t.end();
105
- });
@@ -1,68 +0,0 @@
1
- import {once} from 'node:events';
2
- import test from 'supertape';
3
- import io from 'socket.io-client';
4
- import Config from '../config.js';
5
- import {connect} from '../../test/before.mjs';
6
-
7
- const config = Config.createConfig();
8
-
9
- test('distribute: export', async (t) => {
10
- const defaultConfig = {
11
- export: true,
12
- exportToken: 'a',
13
- vim: true,
14
- log: false,
15
- prefix: '',
16
- };
17
-
18
- const {port, done} = await connect({
19
- config: defaultConfig,
20
- configManager: config,
21
- });
22
-
23
- const url = `http://localhost:${port}/distribute?port=1111`;
24
- const socket = io.connect(url);
25
-
26
- await once(socket, 'connect');
27
- socket.emit('auth', 'a');
28
-
29
- await once(socket, 'accept');
30
- config('vim', false);
31
- config('auth', true);
32
-
33
- await once(socket, 'change');
34
-
35
- socket.close();
36
- await done();
37
-
38
- t.pass('should emit change');
39
- t.end();
40
- });
41
-
42
- test('distribute: export: config', async (t) => {
43
- const defaultConfig = {
44
- export: true,
45
- exportToken: 'a',
46
- vim: true,
47
- log: false,
48
- };
49
-
50
- const {port, done} = await connect({
51
- config: defaultConfig,
52
- });
53
-
54
- const url = `http://localhost:${port}/distribute?port=1111`;
55
- const socket = io.connect(url);
56
-
57
- socket.once('connect', () => {
58
- socket.emit('auth', 'a');
59
- });
60
-
61
- const data = await once(socket, 'config');
62
-
63
- socket.close();
64
- await done();
65
-
66
- t.equal(typeof data, 'object', 'should emit object');
67
- t.end();
68
- });
@@ -1,285 +0,0 @@
1
- import process from 'node:process';
2
- import {promisify} from 'node:util';
3
- import test from 'supertape';
4
- import tryToCatch from 'try-to-catch';
5
- import {connect} from '../../test/before.mjs';
6
- import {createConfigManager} from '../cloudcmd.mjs';
7
- import {distributeImport} from './import.mjs';
8
-
9
- const distribute = {
10
- import: promisify(distributeImport),
11
- };
12
-
13
- const config = createConfigManager();
14
-
15
- process.on('unhandledRejection', console.log);
16
-
17
- test('distribute: import: canceled', async (t) => {
18
- const {done} = await connect({
19
- config: {
20
- export: false,
21
- import: false,
22
- importListen: false,
23
- log: false,
24
- },
25
- });
26
-
27
- const {status} = await distribute.import(config);
28
-
29
- await done();
30
-
31
- t.equal(status, 'canceled');
32
- t.end();
33
- });
34
-
35
- test('distribute: import: received: no error', async (t) => {
36
- const {done, port} = await connect({
37
- config: {
38
- import: true,
39
- importListen: false,
40
- export: true,
41
- log: false,
42
- },
43
- });
44
-
45
- config('importUrl', `http://localhost:${port}`);
46
-
47
- const [e] = await tryToCatch(distribute.import, config);
48
-
49
- await done();
50
-
51
- t.notOk(e, 'should not be error');
52
- t.end();
53
- });
54
-
55
- test('distribute: import: received', async (t) => {
56
- const configManager = createConfigManager();
57
- const {done, port} = await connect({
58
- configManager,
59
- config: {
60
- name: 'bill',
61
- import: true,
62
- importToken: 'a',
63
- exportToken: 'a',
64
- export: true,
65
- importListen: false,
66
- log: false,
67
- },
68
- });
69
-
70
- configManager('importUrl', `http://localhost:${port}`);
71
-
72
- const {status} = await distribute.import(configManager);
73
- await done();
74
-
75
- t.equal(status, 'received');
76
- t.end();
77
- });
78
-
79
- test('distribute: import: received: auth: reject', async (t) => {
80
- const configManager = createConfigManager();
81
- const {done, port} = await connect({
82
- configManager,
83
- config: {
84
- name: 'bill',
85
- import: true,
86
- importToken: 'xxxxx',
87
- exportToken: 'bbbbb',
88
- export: true,
89
- importListen: false,
90
- log: false,
91
- },
92
- });
93
-
94
- configManager('importUrl', `http://localhost:${port}`);
95
-
96
- const {status} = await distribute.import(configManager);
97
- await done();
98
-
99
- t.equal(status, 'reject');
100
- t.end();
101
- });
102
-
103
- test('distribute: import: received: auth: accept', async (t) => {
104
- const configManager = createConfigManager();
105
- const {done, port} = await connect({
106
- configManager,
107
- config: {
108
- name: 'bill',
109
- import: true,
110
- importToken: 'xxxxx',
111
- exportToken: 'xxxxx',
112
- export: true,
113
- importListen: false,
114
- log: false,
115
- },
116
- });
117
-
118
- configManager('importUrl', `http://localhost:${port}`);
119
-
120
- const {status} = await distribute.import(configManager);
121
- await done();
122
-
123
- t.equal(status, 'received');
124
- t.end();
125
- });
126
-
127
- test('distribute: import: received: no name', async (t) => {
128
- const configManager = createConfigManager();
129
- const {done, port} = await connect({
130
- configManager,
131
- config: {
132
- name: '',
133
- import: true,
134
- export: true,
135
- importListen: false,
136
- log: false,
137
- },
138
- });
139
-
140
- configManager('importUrl', `http://localhost:${port}`);
141
-
142
- const {status} = await distribute.import(configManager);
143
- await done();
144
-
145
- t.equal(status, 'received');
146
- t.end();
147
- });
148
-
149
- test('distribute: import: error', async (t) => {
150
- const configManager = createConfigManager();
151
- const {done} = await connect({
152
- configManager,
153
- config: {
154
- import: true,
155
- export: false,
156
- importListen: false,
157
- log: false,
158
- },
159
- });
160
-
161
- configManager('importUrl', `http://localhost:0`);
162
-
163
- const {status} = await distribute.import(configManager, {
164
- reconnection: false,
165
- });
166
-
167
- await done();
168
-
169
- t.equal(status, 'connect_error');
170
- t.end();
171
- });
172
-
173
- test('distribute: import: config:change: no export', async (t) => {
174
- const configManager = createConfigManager();
175
- const {done} = await connect({
176
- configManager,
177
- config: {
178
- import: true,
179
- export: false,
180
- importListen: true,
181
- log: false,
182
- },
183
- });
184
-
185
- const {status} = await distribute.import(configManager, {
186
- reconnection: false,
187
- });
188
-
189
- await done();
190
-
191
- t.equal(status, 'connect_error');
192
- t.end();
193
- });
194
-
195
- test('distribute: import: env', async (t) => {
196
- const configManager = createConfigManager();
197
- const configManagerImport = createConfigManager();
198
-
199
- const exporter = await connect({
200
- configManager,
201
- config: {
202
- name: 'bill',
203
- import: false,
204
- importListen: false,
205
- export: true,
206
- exportToken: 'a',
207
- log: false,
208
- editor: 'edward',
209
- },
210
- });
211
-
212
- const importer = await connect({
213
- configManager: configManagerImport,
214
- config: {
215
- name: 'jack',
216
- import: true,
217
- importToken: 'a',
218
- export: false,
219
- importListen: false,
220
- log: false,
221
- editor: 'deepword',
222
- },
223
- });
224
-
225
- process.env.cloudcmd_editor = 'some editor';
226
-
227
- configManagerImport('importUrl', `http://localhost:${exporter.port}`);
228
-
229
- await distribute.import(configManagerImport);
230
-
231
- await importer.done();
232
- await exporter.done();
233
-
234
- delete process.env.cloudcmd_editor;
235
-
236
- const result = configManagerImport('editor');
237
- const expected = 'deepword';
238
-
239
- t.equal(result, expected);
240
- t.end();
241
- });
242
-
243
- test('distribute: import: no env', async (t) => {
244
- const configManager = createConfigManager();
245
- const configManagerImport = createConfigManager();
246
-
247
- const exporter = await connect({
248
- configManager,
249
- config: {
250
- name: 'bill',
251
- import: false,
252
- importListen: false,
253
- export: true,
254
- exportToken: 'a',
255
- log: false,
256
- editor: 'edward',
257
- },
258
- });
259
-
260
- const importer = await connect({
261
- configManager: configManagerImport,
262
- config: {
263
- name: 'jack',
264
- import: true,
265
- importToken: 'a',
266
- export: false,
267
- importListen: false,
268
- log: false,
269
- editor: 'deepword',
270
- },
271
- });
272
-
273
- configManagerImport('importUrl', `http://localhost:${exporter.port}`);
274
-
275
- await distribute.import(configManagerImport);
276
-
277
- await importer.done();
278
- await exporter.done();
279
-
280
- const result = configManagerImport('editor');
281
- const expected = 'edward';
282
-
283
- t.equal(result, expected);
284
- t.end();
285
- });
@@ -1,34 +0,0 @@
1
- import test from 'supertape';
2
- import log from './log.mjs';
3
- import {createConfig} from '../config.js';
4
-
5
- test('distribute: log: getMessage', (t) => {
6
- const e = 'hello';
7
- const result = log.getMessage(e);
8
-
9
- t.equal(e, result);
10
- t.end();
11
- });
12
-
13
- test('distribute: log: getMessage: message', (t) => {
14
- const message = 'hello';
15
- const result = log.getMessage({
16
- message,
17
- });
18
-
19
- t.equal(result, message);
20
- t.end();
21
- });
22
-
23
- test('distribute: log: config', (t) => {
24
- const config = createConfig();
25
- const logOriginal = config('log');
26
-
27
- config('log', true);
28
- log('log', 'test message');
29
- config('log', logOriginal);
30
-
31
- t.end();
32
- }, {
33
- checkAssertionsCount: false,
34
- });
@@ -1,126 +0,0 @@
1
- import fs from 'node:fs';
2
- import {join} from 'node:path';
3
- import {promisify} from 'node:util';
4
- import tryToCatch from 'try-to-catch';
5
- import test from 'supertape';
6
- import serveOnce from 'serve-once';
7
- import markdown from './index.js';
8
- import cloudcmd from '../cloudcmd.mjs';
9
-
10
- const config = {
11
- auth: false,
12
- };
13
-
14
- const configManager = cloudcmd.createConfigManager();
15
-
16
- const {request} = serveOnce(cloudcmd, {
17
- config,
18
- configManager,
19
- });
20
-
21
- const fixtureDir = new URL('fixture', import.meta.url).pathname;
22
-
23
- const _markdown = promisify(markdown);
24
-
25
- test('cloudcmd: markdown: error', async (t) => {
26
- const {body} = await request.get('/api/v1/markdown/not-found');
27
-
28
- t.match(body, 'ENOENT', 'should not found');
29
- t.end();
30
- });
31
-
32
- test('cloudcmd: markdown: relative: error', async (t) => {
33
- const {body} = await request.get('/api/v1/markdown/not-found?relative');
34
-
35
- t.match(body, 'ENOENT', 'should not found');
36
- t.end();
37
- });
38
-
39
- test('cloudcmd: markdown: relative', async (t) => {
40
- const {body} = await request.get('/api/v1/markdown/HELP.md?relative');
41
-
42
- t.notOk(/ENOENT/.test(body), 'should not return error');
43
- t.end();
44
- });
45
-
46
- test('cloudcmd: markdown: put', async (t) => {
47
- const md = join(fixtureDir, 'markdown.md');
48
- const html = join(fixtureDir, 'markdown.html');
49
-
50
- const mdStream = fs.createReadStream(md);
51
- const htmlFile = fs.readFileSync(html, 'utf8');
52
-
53
- const {body} = await request.put('/api/v1/markdown', {
54
- body: mdStream,
55
- });
56
-
57
- t.equal(body, htmlFile, 'should render markdown input to html');
58
- t.end();
59
- });
60
-
61
- test('cloudcmd: markdown: put: error', async (t) => {
62
- const md = join(fixtureDir, 'markdown-not-exist.md');
63
-
64
- const name = 'hello';
65
- const mdStream = fs.createReadStream(md);
66
-
67
- mdStream.url = 'http://hello.world';
68
- mdStream.method = 'PUT';
69
-
70
- const [e] = await tryToCatch(_markdown, name, '/', mdStream);
71
-
72
- t.match(e.message, 'ENOENT: no such file or directory', 'should emit error');
73
- t.end();
74
- });
75
-
76
- test('cloudcmd: markdown: no name', async (t) => {
77
- const [e] = await tryToCatch(_markdown);
78
-
79
- t.equal(e.message, 'name should be string!', 'should throw when no name');
80
- t.end();
81
- });
82
-
83
- test('cloudcmd: markdown: no request', async (t) => {
84
- const [e] = await tryToCatch(_markdown, 'hello');
85
-
86
- t.equal(e.message, 'request could not be empty!', 'should throw when no request');
87
- t.end();
88
- });
89
-
90
- test('cloudcmd: markdown', async (t) => {
91
- const configManager = cloudcmd.createConfigManager();
92
- const fixtureDir = new URL('fixture', import.meta.url).pathname;
93
- const config = {
94
- auth: false,
95
- root: fixtureDir,
96
- };
97
-
98
- const {request} = serveOnce(cloudcmd, {
99
- config,
100
- configManager,
101
- });
102
-
103
- const {body} = await request.get('/api/v1/markdown/markdown.md');
104
-
105
- t.equal(body, '<h1>hello</h1>\n');
106
- t.end();
107
- });
108
-
109
- test('cloudcmd: markdown: zip', async (t) => {
110
- const configManager = cloudcmd.createConfigManager();
111
- const fixtureDir = new URL('fixture', import.meta.url).pathname;
112
- const config = {
113
- auth: false,
114
- root: fixtureDir,
115
- };
116
-
117
- const {request} = serveOnce(cloudcmd, {
118
- config,
119
- configManager,
120
- });
121
-
122
- const {body} = await request.get('/api/v1/markdown/markdown.zip/markdown.md');
123
-
124
- t.equal(body, '<h1>hello</h1>\n');
125
- t.end();
126
- });