@webex/internal-plugin-board 3.0.0-beta.9 → 3.0.0-bnr.0

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.
@@ -11,29 +11,33 @@ describe('plugin-board', () => {
11
11
  let webex;
12
12
  const encryptedData = 'encryptedData';
13
13
  const decryptedText = 'decryptedText';
14
- const fakeURL = `${process.env.ENCRYPTION_SERVICE_URL || 'https://encryption-a.wbx2.com'}/encryption/api/v1/keys/8a7d3d78-ce75-48aa-a943-2e8acf63fbc9`;
14
+ const fakeURL = `${
15
+ process.env.ENCRYPTION_SERVICE_URL || 'https://encryption-a.wbx2.com'
16
+ }/encryption/api/v1/keys/8a7d3d78-ce75-48aa-a943-2e8acf63fbc9`;
15
17
 
16
18
  before(() => {
17
19
  webex = new MockWebex({
18
20
  children: {
19
- board: Board
20
- }
21
+ board: Board,
22
+ },
21
23
  });
22
24
 
23
25
  Object.assign(webex.internal, {
24
26
  device: {
25
- deviceType: 'FAKE_DEVICE'
27
+ deviceType: 'FAKE_DEVICE',
26
28
  },
27
29
  encryption: {
28
30
  decryptText: sinon.stub().returns(Promise.resolve(decryptedText)),
29
31
  encryptText: sinon.stub().returns(Promise.resolve(encryptedData)),
30
- encryptBinary: sinon.stub().returns(Promise.resolve({
31
- scr: {},
32
- cdata: encryptedData
33
- })),
32
+ encryptBinary: sinon.stub().returns(
33
+ Promise.resolve({
34
+ scr: {},
35
+ cdata: encryptedData,
36
+ })
37
+ ),
34
38
  decryptScr: sinon.stub().returns(Promise.resolve('decryptedFoo')),
35
- encryptScr: sinon.stub().returns(Promise.resolve('encryptedFoo'))
36
- }
39
+ encryptScr: sinon.stub().returns(Promise.resolve('encryptedFoo')),
40
+ },
37
41
  });
38
42
 
39
43
  webex.config.board = boardConfig.board;
@@ -42,7 +46,9 @@ describe('plugin-board', () => {
42
46
  describe('encryption', () => {
43
47
  describe('#decryptContents', () => {
44
48
  before(() => {
45
- sinon.stub(webex.internal.board, 'decryptSingleContent').callsFake(sinon.stub().returns(Promise.resolve({})));
49
+ sinon
50
+ .stub(webex.internal.board, 'decryptSingleContent')
51
+ .callsFake(sinon.stub().returns(Promise.resolve({})));
46
52
  sinon.spy(webex.internal.board, 'decryptSingleFileContent');
47
53
  });
48
54
 
@@ -60,123 +66,142 @@ describe('plugin-board', () => {
60
66
 
61
67
  it('calls decryptSingleContent when type is not image', () => {
62
68
  const curveContents = {
63
- items: [{
64
- type: 'STRING',
65
- payload: encryptedData,
66
- encryptionKeyUrl: fakeURL
67
- }]
69
+ items: [
70
+ {
71
+ type: 'STRING',
72
+ payload: encryptedData,
73
+ encryptionKeyUrl: fakeURL,
74
+ },
75
+ ],
68
76
  };
69
77
 
70
- return webex.internal.board.decryptContents(curveContents)
71
- .then(() => {
72
- assert.calledWith(webex.internal.board.decryptSingleContent, fakeURL, encryptedData);
73
- assert.notCalled(webex.internal.encryption.decryptScr);
74
- assert.notCalled(webex.internal.encryption.decryptText);
75
- });
78
+ return webex.internal.board.decryptContents(curveContents).then(() => {
79
+ assert.calledWith(webex.internal.board.decryptSingleContent, fakeURL, encryptedData);
80
+ assert.notCalled(webex.internal.encryption.decryptScr);
81
+ assert.notCalled(webex.internal.encryption.decryptText);
82
+ });
76
83
  });
77
84
 
78
85
  it('calls decryptSingleFileContent when type is FILE', () => {
79
86
  const imageContents = {
80
- items: [{
81
- type: 'FILE',
82
- payload: JSON.stringify({
83
- type: 'image',
84
- displayName: 'encryptedDisplayName'
85
- }),
86
- file: {
87
- scr: 'encryptedScr'
87
+ items: [
88
+ {
89
+ type: 'FILE',
90
+ payload: JSON.stringify({
91
+ type: 'image',
92
+ displayName: 'encryptedDisplayName',
93
+ }),
94
+ file: {
95
+ scr: 'encryptedScr',
96
+ },
97
+ encryptionKeyUrl: fakeURL,
88
98
  },
89
- encryptionKeyUrl: fakeURL
90
- }]
99
+ ],
91
100
  };
92
101
 
93
- return webex.internal.board.decryptContents(imageContents)
94
- .then(() => {
95
- assert.calledOnce(webex.internal.board.decryptSingleFileContent);
96
- assert.calledWith(webex.internal.encryption.decryptText, fakeURL, JSON.stringify({type: 'image', displayName: 'encryptedDisplayName'}));
97
- assert.calledWith(webex.internal.encryption.decryptScr, fakeURL, 'encryptedScr');
98
- });
102
+ return webex.internal.board.decryptContents(imageContents).then(() => {
103
+ assert.calledOnce(webex.internal.board.decryptSingleFileContent);
104
+ assert.calledWith(
105
+ webex.internal.encryption.decryptText,
106
+ fakeURL,
107
+ JSON.stringify({type: 'image', displayName: 'encryptedDisplayName'})
108
+ );
109
+ assert.calledWith(webex.internal.encryption.decryptScr, fakeURL, 'encryptedScr');
110
+ });
99
111
  });
100
112
 
101
113
  it('does not require payload when type is FILE', () => {
102
114
  const imageContents = {
103
- items: [{
104
- type: 'FILE',
105
- file: {
106
- scr: 'encryptedScr'
115
+ items: [
116
+ {
117
+ type: 'FILE',
118
+ file: {
119
+ scr: 'encryptedScr',
120
+ },
121
+ encryptionKeyUrl: fakeURL,
107
122
  },
108
- encryptionKeyUrl: fakeURL
109
- }]
123
+ ],
110
124
  };
111
125
 
112
- return webex.internal.board.decryptContents(imageContents)
113
- .then(() => {
114
- assert.calledOnce(webex.internal.board.decryptSingleFileContent);
115
- assert.notCalled(webex.internal.encryption.decryptText);
116
- assert.calledWith(webex.internal.encryption.decryptScr, fakeURL, 'encryptedScr');
117
- });
126
+ return webex.internal.board.decryptContents(imageContents).then(() => {
127
+ assert.calledOnce(webex.internal.board.decryptSingleFileContent);
128
+ assert.notCalled(webex.internal.encryption.decryptText);
129
+ assert.calledWith(webex.internal.encryption.decryptScr, fakeURL, 'encryptedScr');
130
+ });
118
131
  });
119
132
 
120
133
  it('decrypts FILE metadata displayName', () => {
121
134
  const imageContentsWithMetadata = {
122
- items: [{
123
- type: 'FILE',
124
- payload: JSON.stringify({
125
- type: 'image',
126
- displayName: 'encryptedDisplayName'
127
- }),
128
- file: {
129
- scr: 'encryptedScr'
135
+ items: [
136
+ {
137
+ type: 'FILE',
138
+ payload: JSON.stringify({
139
+ type: 'image',
140
+ displayName: 'encryptedDisplayName',
141
+ }),
142
+ file: {
143
+ scr: 'encryptedScr',
144
+ },
145
+ encryptionKeyUrl: fakeURL,
130
146
  },
131
- encryptionKeyUrl: fakeURL
132
- }]
147
+ ],
133
148
  };
134
149
 
135
- webex.internal.encryption.decryptText.onFirstCall().returns(JSON.stringify({displayName: 'decryptedDisplayName'}));
150
+ webex.internal.encryption.decryptText
151
+ .onFirstCall()
152
+ .returns(JSON.stringify({displayName: 'decryptedDisplayName'}));
136
153
 
137
- return webex.internal.board.decryptContents(imageContentsWithMetadata)
138
- .then((contents) => {
139
- assert.calledOnce(webex.internal.board.decryptSingleFileContent);
140
- assert.calledWith(webex.internal.encryption.decryptScr, fakeURL, 'encryptedScr');
141
- assert.calledWith(webex.internal.encryption.decryptText, fakeURL, JSON.stringify({type: 'image', displayName: 'encryptedDisplayName'}));
142
- assert.equal(contents[0].metadata.displayName, 'decryptedDisplayName');
143
- });
154
+ return webex.internal.board.decryptContents(imageContentsWithMetadata).then((contents) => {
155
+ assert.calledOnce(webex.internal.board.decryptSingleFileContent);
156
+ assert.calledWith(webex.internal.encryption.decryptScr, fakeURL, 'encryptedScr');
157
+ assert.calledWith(
158
+ webex.internal.encryption.decryptText,
159
+ fakeURL,
160
+ JSON.stringify({type: 'image', displayName: 'encryptedDisplayName'})
161
+ );
162
+ assert.equal(contents[0].metadata.displayName, 'decryptedDisplayName');
163
+ });
144
164
  });
145
165
 
146
166
  it('assigns FILE payload metadata to decrypted file', () => {
147
167
  const imageContentsWithMetadata = {
148
- items: [{
149
- type: 'FILE',
150
- payload: JSON.stringify({
151
- type: 'image',
152
- size: 123
153
- }),
154
- file: {
155
- scr: 'encryptedScr'
168
+ items: [
169
+ {
170
+ type: 'FILE',
171
+ payload: JSON.stringify({
172
+ type: 'image',
173
+ size: 123,
174
+ }),
175
+ file: {
176
+ scr: 'encryptedScr',
177
+ },
178
+ encryptionKeyUrl: fakeURL,
156
179
  },
157
- encryptionKeyUrl: fakeURL
158
- }]
180
+ ],
159
181
  };
160
182
 
161
- webex.internal.encryption.decryptText.onFirstCall().returns(JSON.stringify({type: 'image', size: 123}));
183
+ webex.internal.encryption.decryptText
184
+ .onFirstCall()
185
+ .returns(JSON.stringify({type: 'image', size: 123}));
162
186
 
163
- return webex.internal.board.decryptContents(imageContentsWithMetadata)
164
- .then((contents) => {
165
- assert.calledOnce(webex.internal.board.decryptSingleFileContent);
166
- assert.deepEqual(contents[0].metadata, {
167
- type: 'image',
168
- size: 123
169
- });
187
+ return webex.internal.board.decryptContents(imageContentsWithMetadata).then((contents) => {
188
+ assert.calledOnce(webex.internal.board.decryptSingleFileContent);
189
+ assert.deepEqual(contents[0].metadata, {
190
+ type: 'image',
191
+ size: 123,
170
192
  });
193
+ });
171
194
  });
172
195
  });
173
196
 
174
197
  describe('#encryptContents', () => {
175
198
  before(() => {
176
- sinon.stub(webex.internal.board, 'encryptSingleContent').returns(Promise.resolve({
177
- encryptedData,
178
- encryptionKeyUrl: fakeURL
179
- }));
199
+ sinon.stub(webex.internal.board, 'encryptSingleContent').returns(
200
+ Promise.resolve({
201
+ encryptedData,
202
+ encryptionKeyUrl: fakeURL,
203
+ })
204
+ );
180
205
  });
181
206
 
182
207
  afterEach(() => {
@@ -184,43 +209,50 @@ describe('plugin-board', () => {
184
209
  });
185
210
 
186
211
  it('calls encryptSingleContent when type is not image', () => {
187
- const curveContents = [{
188
- type: 'curve'
189
- }];
190
-
191
- return webex.internal.board.encryptContents(fakeURL, curveContents)
192
- .then(() => {
193
- assert.calledWith(webex.internal.board.encryptSingleContent, fakeURL, curveContents[0]);
194
- assert.notCalled(webex.internal.encryption.encryptScr);
195
- });
212
+ const curveContents = [
213
+ {
214
+ type: 'curve',
215
+ },
216
+ ];
217
+
218
+ return webex.internal.board.encryptContents(fakeURL, curveContents).then(() => {
219
+ assert.calledWith(webex.internal.board.encryptSingleContent, fakeURL, curveContents[0]);
220
+ assert.notCalled(webex.internal.encryption.encryptScr);
221
+ });
196
222
  });
197
223
 
198
224
  it('calls encryptText and encryptScr when scr is found in content', () => {
199
- const imageContents = [{
200
- displayName: 'FileName',
201
- file: {
202
- scr: {
203
- loc: fakeURL
204
- }
205
- }
206
- }];
207
-
208
- return webex.internal.board.encryptContents(fakeURL, imageContents)
209
- .then(() => {
210
- assert.calledWith(webex.internal.encryption.encryptScr, fakeURL, {loc: fakeURL});
211
- assert.calledWith(webex.internal.encryption.encryptText, fakeURL, JSON.stringify({displayName: 'FileName'}));
212
- });
225
+ const imageContents = [
226
+ {
227
+ displayName: 'FileName',
228
+ file: {
229
+ scr: {
230
+ loc: fakeURL,
231
+ },
232
+ },
233
+ },
234
+ ];
235
+
236
+ return webex.internal.board.encryptContents(fakeURL, imageContents).then(() => {
237
+ assert.calledWith(webex.internal.encryption.encryptScr, fakeURL, {loc: fakeURL});
238
+ assert.calledWith(
239
+ webex.internal.encryption.encryptText,
240
+ fakeURL,
241
+ JSON.stringify({displayName: 'FileName'})
242
+ );
243
+ });
213
244
  });
214
245
 
215
246
  it('sets the device to config deviceType', () => {
216
- const curveContents = [{
217
- type: 'curve'
218
- }];
247
+ const curveContents = [
248
+ {
249
+ type: 'curve',
250
+ },
251
+ ];
219
252
 
220
- return webex.internal.board.encryptContents(fakeURL, curveContents)
221
- .then((res) => {
222
- assert.equal(res[0].device, 'FAKE_DEVICE');
223
- });
253
+ return webex.internal.board.encryptContents(fakeURL, curveContents).then((res) => {
254
+ assert.equal(res[0].device, 'FAKE_DEVICE');
255
+ });
224
256
  });
225
257
  });
226
258
  });