botium-core 1.13.19 → 1.14.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.
Files changed (32) hide show
  1. package/dist/botium-cjs.js +298 -382
  2. package/dist/botium-cjs.js.map +1 -1
  3. package/dist/botium-es.js +298 -380
  4. package/dist/botium-es.js.map +1 -1
  5. package/package.json +20 -25
  6. package/samples/extensions/asserterHooks/botium.json +1 -0
  7. package/samples/extensions/logichooks/botium.json +1 -0
  8. package/samples/extensions/logichooks/custom/MyAsserter.js +3 -3
  9. package/src/Capabilities.js +2 -1
  10. package/src/containers/PluginConnectorContainer.js +8 -0
  11. package/src/containers/plugins/SimpleRestContainer.js +17 -9
  12. package/src/containers/plugins/index.js +29 -41
  13. package/src/helpers/HookUtils.js +32 -68
  14. package/src/scripting/ScriptingMemory.js +0 -24
  15. package/src/scripting/logichook/LogicHookUtils.js +27 -47
  16. package/test/compiler/precompilerscript.spec.js +24 -26
  17. package/test/connectors/pluginconnectorcontainer.spec.js +60 -0
  18. package/test/connectors/simplerest.spec.js +24 -27
  19. package/test/convo/fillAndApplyScriptingMemory.spec.js +1 -47
  20. package/test/hooks/customhooks.spec.js +3 -25
  21. package/test/logichooks/hookfromsrc.spec.js +13 -3
  22. package/test/plugins/plugins.spec.js +29 -2
  23. package/test/security/allowUnsafe.spec.js +20 -129
  24. package/LICENSES-3RDPARTY.txt +0 -6450
  25. package/test/scripting/asserters/convos/customembeddedasserterwithhugo.convo.txt +0 -7
  26. package/test/scripting/asserters/convos/customembeddedasserterwithouthugo.convo.txt +0 -7
  27. package/test/scripting/asserters/customEmbeddedAsserter.json +0 -14
  28. package/test/scripting/asserters/customEmbeddedAsserter.spec.js +0 -55
  29. package/test/scripting/logichooks/convos/custom_embedded.convo.txt +0 -8
  30. package/test/scripting/logichooks/customEmbedded.json +0 -14
  31. package/test/scripting/logichooks/customEmbedded.spec.js +0 -44
  32. package/test/security/convos/withscriptingmemoryfunction.convo.txt +0 -5
@@ -5,7 +5,6 @@ chai.use(chaiAsPromised)
5
5
  const assert = chai.assert
6
6
  const BotDriver = require('../../').BotDriver
7
7
  const Capabilities = require('../../').Capabilities
8
- const { BotiumError } = require('../../src/scripting/BotiumError')
9
8
  const HookUtils = require('../../src/helpers/HookUtils')
10
9
 
11
10
  const myCapsSimpleRest = {
@@ -17,21 +16,6 @@ const myCapsSimpleRest = {
17
16
  [Capabilities.SIMPLEREST_RESPONSE_JSONPATH]: ['$']
18
17
  }
19
18
 
20
- const echoConnector = ({ queueBotSays }) => {
21
- return {
22
- UserSays (msg) {
23
- const botMsg = { sender: 'bot', sourceData: msg.sourceData, messageText: `You said: "${msg.messageText}"` }
24
- queueBotSays(botMsg)
25
- }
26
- }
27
- }
28
-
29
- const myCapsEcho = {
30
- [Capabilities.CONTAINERMODE]: echoConnector,
31
- [Capabilities.SECURITY_ALLOW_UNSAFE]: false,
32
- [Capabilities.SCRIPTING_ENABLE_MEMORY]: true
33
- }
34
-
35
19
  const _getSimpleRestCaps = (caps) => {
36
20
  return Object.assign(
37
21
  {},
@@ -57,11 +41,6 @@ const functionConnector = ({ queueBotSays }) => {
57
41
 
58
42
  describe('security.allowUnsafe', function () {
59
43
  describe('hook utils', function () {
60
- it('should accept string hook in safe mode', async function () {
61
- HookUtils.getHook({
62
- [Capabilities.SECURITY_ALLOW_UNSAFE]: false
63
- }, '1+1')
64
- })
65
44
  it('should accept javascript hook in safe mode', async function () {
66
45
  HookUtils.getHook({
67
46
  [Capabilities.SECURITY_ALLOW_UNSAFE]: false
@@ -74,20 +53,26 @@ describe('security.allowUnsafe', function () {
74
53
  }, 'test/security/resources/hook-as-file.js')
75
54
  assert.fail('should have failed')
76
55
  } catch (err) {
77
- assert.isTrue(err instanceof BotiumError)
78
- assert.exists(err.context)
79
- assert.equal(err.context.message, 'Security Error. Using unsafe custom hook with require is not allowed')
80
- assert.equal(err.context.source, 'HookUtils.js')
81
- assert.equal(err.context.type, 'security')
82
- assert.equal(err.context.subtype, 'allow unsafe')
83
- assert.exists(err.context.cause)
84
- assert.equal(err.context.cause.hookData, 'test/security/resources/hook-as-file.js')
56
+ console.log(err.message)
57
+ assert.isTrue(err.message.indexOf('invalid') >= 0)
85
58
  }
86
59
  })
87
- it('should accept file hook in unsafe mode', async function () {
60
+ it('should accept file hook from safe dir in unsafe mode', async function () {
88
61
  HookUtils.getHook({
89
- [Capabilities.SECURITY_ALLOW_UNSAFE]: true
90
- }, 'test/security/resources/hook-as-file.js')
62
+ [Capabilities.SECURITY_ALLOW_UNSAFE]: true,
63
+ [Capabilities.SAFEDIR]: 'test/security/'
64
+ }, 'resources/hook-as-file.js')
65
+ })
66
+ it('should not accept file hook from outside safe dir', async function () {
67
+ try {
68
+ HookUtils.getHook({
69
+ [Capabilities.SECURITY_ALLOW_UNSAFE]: true,
70
+ [Capabilities.SAFEDIR]: 'test/security/'
71
+ }, '../hook-as-file.js')
72
+ assert.fail('should have failed')
73
+ } catch (err) {
74
+ assert.isTrue(err.message.indexOf('invalid') >= 0)
75
+ }
91
76
  })
92
77
  it('should accept require hook in unsafe mode', async function () {
93
78
  HookUtils.getHook({
@@ -96,19 +81,6 @@ describe('security.allowUnsafe', function () {
96
81
  })
97
82
  })
98
83
 
99
- describe('scripting memory', function () {
100
- it('should not throw security error for using inline function', async function () {
101
- const driver = new BotDriver(myCapsEcho)
102
- const compiler = driver.BuildCompiler()
103
- const container = await driver.Build()
104
- await container.Start()
105
-
106
- compiler.ReadScript(path.resolve(__dirname, 'convos'), 'withscriptingmemoryfunction.convo.txt')
107
- await compiler.convos[0].Run(container)
108
- await container.Clean()
109
- }).timeout(50000)
110
- })
111
-
112
84
  describe('simple rest, scripting memory', function () {
113
85
  it('should use variables succesful', async function () {
114
86
  const myCaps = _getSimpleRestCaps(
@@ -145,19 +117,6 @@ describe('security.allowUnsafe', function () {
145
117
  })
146
118
 
147
119
  describe('simple rest, hooks', function () {
148
- it('should create and use simplerest with javascript hook', async function () {
149
- const driver = new BotDriver(_getSimpleRestCaps(
150
- {
151
- [Capabilities.SIMPLEREST_REQUEST_HOOK]: '1+1'
152
- }
153
- ))
154
-
155
- const compiler = driver.BuildCompiler()
156
- const container = await driver.Build()
157
- await container.Start()
158
-
159
- compiler.ReadScript(path.resolve(__dirname, 'convos'), 'dummy.convo.txt')
160
- })
161
120
  it('should create and use simplerest with function hooks', async function () {
162
121
  const driver = new BotDriver(_getSimpleRestCaps(
163
122
  {
@@ -173,35 +132,6 @@ describe('security.allowUnsafe', function () {
173
132
  })
174
133
  })
175
134
 
176
- describe('precompilers', function () {
177
- it('should not throw security error for inline script type', async function () {
178
- const driver = new BotDriver(_getSimpleRestCaps(
179
- {
180
- [Capabilities.PRECOMPILERS]: {
181
- NAME: 'SCRIPT',
182
- SCRIPT: '1+1'
183
- }
184
- }
185
- ))
186
-
187
- const compiler = driver.BuildCompiler()
188
- const container = await driver.Build()
189
- const fileName = 'dummy.convo.txt'
190
- compiler.ReadScript(path.resolve(__dirname, 'convos'), fileName)
191
- assert.equal(compiler.convos.length, 1)
192
- await container.Clean()
193
- })
194
- })
195
-
196
- describe('base container, hooks', function () {
197
- it('should not throw security error for using inline hook', async function () {
198
- const driver = new BotDriver(_getSimpleRestCaps(
199
- { [Capabilities.CUSTOMHOOK_ONUSERSAYS]: '1+1' }
200
- ))
201
- await driver.Build()
202
- })
203
- })
204
-
205
135
  describe('logic hook, asserter', function () {
206
136
  it('should load asserter from file', async function () {
207
137
  const driver = new BotDriver(_getSimpleRestCaps(
@@ -216,45 +146,6 @@ describe('security.allowUnsafe', function () {
216
146
 
217
147
  driver.BuildCompiler()
218
148
  })
219
- it('should not throw security error for logic hook with inline src', async function () {
220
- const driver = new BotDriver(_getSimpleRestCaps(
221
- {
222
- [Capabilities.LOGIC_HOOKS]: [
223
- {
224
- ref: 'MY-LOGICHOOK-NAME',
225
- src: {
226
- onMeStart: '1+1'
227
- },
228
- global: false,
229
- args: {
230
- 'my-arg-1': 'something'
231
- }
232
- }
233
- ]
234
- }
235
- ))
236
-
237
- driver.BuildCompiler()
238
- })
239
- it('should not throw security error for global logic hook with inline src', async function () {
240
- const driver = new BotDriver(_getSimpleRestCaps(
241
- {
242
- [Capabilities.LOGIC_HOOKS]: [
243
- {
244
- ref: 'MY-LOGICHOOK-NAME',
245
- src: {
246
- onMeStart: '1+1'
247
- },
248
- global: true,
249
- args: {
250
- 'my-arg-1': 'something'
251
- }
252
- }
253
- ]
254
- }
255
- ))
256
- driver.BuildCompiler()
257
- })
258
149
  })
259
150
 
260
151
  describe('connectors', function () {
@@ -270,10 +161,10 @@ describe('security.allowUnsafe', function () {
270
161
  })
271
162
  await driver.Build()
272
163
  })
273
-
274
- it('should create any connector from file/dir, if its starts with botium-connector prefix', async function () {
164
+ it('should create any connector from safedir', async function () {
275
165
  const driver = new BotDriver({
276
- [Capabilities.CONTAINERMODE]: 'botium-connector-as-file',
166
+ [Capabilities.SAFEDIR]: 'test/security/',
167
+ [Capabilities.CONTAINERMODE]: 'resources/botium-connector-as-file.js',
277
168
  [Capabilities.SECURITY_ALLOW_UNSAFE]: false
278
169
  })
279
170
  await driver.Build()