botium-core 1.13.18 → 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 (60) hide show
  1. package/dist/botium-cjs.js +326 -387
  2. package/dist/botium-cjs.js.map +1 -1
  3. package/dist/botium-es.js +326 -385
  4. package/dist/botium-es.js.map +1 -1
  5. package/package.json +21 -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/Convo.js +17 -5
  15. package/src/scripting/ScriptingMemory.js +0 -24
  16. package/src/scripting/logichook/LogicHookConsts.js +5 -1
  17. package/src/scripting/logichook/LogicHookUtils.js +27 -47
  18. package/src/scripting/logichook/asserter/ButtonsAsserter.js +5 -5
  19. package/src/scripting/logichook/logichooks/ConditionalBusinessHoursLogicHook.js +56 -0
  20. package/src/scripting/logichook/logichooks/ConditionalCapabilityValueBasedLogicHook.js +37 -0
  21. package/src/scripting/logichook/logichooks/ConditionalJsonPathBasedLogicHook.js +31 -0
  22. package/src/scripting/logichook/logichooks/ConditionalTimeBasedLogicHook.js +46 -0
  23. package/test/compiler/precompilerscript.spec.js +24 -26
  24. package/test/connectors/pluginconnectorcontainer.spec.js +60 -0
  25. package/test/connectors/simplerest.spec.js +24 -27
  26. package/test/convo/fillAndApplyScriptingMemory.spec.js +1 -47
  27. package/test/hooks/customhooks.spec.js +3 -25
  28. package/test/logichooks/hookfromsrc.spec.js +13 -3
  29. package/test/plugins/plugins.spec.js +29 -2
  30. package/test/scripting/logichooks/CustomConditionalLogicHook.js +21 -0
  31. package/test/scripting/logichooks/conditionalStepBusinessHoursLogicHook.spec.js +130 -0
  32. package/test/scripting/logichooks/conditionalStepCapabilityValueBasedLogicHook.spec.js +35 -0
  33. package/test/scripting/logichooks/conditionalStepJsonPathBasedLogicHook.spec.js +35 -0
  34. package/test/scripting/logichooks/conditionalStepTimeBasedLogicHook.spec.js +91 -0
  35. package/test/scripting/logichooks/convos/conditional_steps.convo.txt +12 -0
  36. package/test/scripting/logichooks/convos/conditional_steps_business_hours.convo.txt +16 -0
  37. package/test/scripting/logichooks/convos/conditional_steps_cap_value_based.convo.txt +12 -0
  38. package/test/scripting/logichooks/convos/conditional_steps_followed_by_bot_msg.convo.txt +15 -0
  39. package/test/scripting/logichooks/convos/conditional_steps_followed_by_me.convo.txt +18 -0
  40. package/test/scripting/logichooks/convos/conditional_steps_json_path_based.convo.txt.convo.txt +12 -0
  41. package/test/scripting/logichooks/convos/conditional_steps_multiple_condition_groups.convo.txt +20 -0
  42. package/test/scripting/logichooks/convos/conditional_steps_multiple_condition_groups_no_assertion.convo.txt +20 -0
  43. package/test/scripting/logichooks/convos/conditional_steps_time_based.convo.txt +12 -0
  44. package/test/scripting/logichooks/customConditionalStepLogicHook.spec.js +105 -0
  45. package/test/scripting/scriptingProvider.spec.js +1 -1
  46. package/test/security/allowUnsafe.spec.js +20 -129
  47. package/LICENSES-3RDPARTY.txt +0 -6450
  48. package/test/scripting/asserters/convos/customembeddedasserterwithhugo.convo.txt +0 -7
  49. package/test/scripting/asserters/convos/customembeddedasserterwithouthugo.convo.txt +0 -7
  50. package/test/scripting/asserters/customEmbeddedAsserter.json +0 -14
  51. package/test/scripting/asserters/customEmbeddedAsserter.spec.js +0 -55
  52. package/test/scripting/logichooks/convos/custom_embedded.convo.txt +0 -8
  53. package/test/scripting/logichooks/convos/custom_embedded_skip.convo.txt +0 -11
  54. package/test/scripting/logichooks/convos/custom_embedded_skip_followed_by_me.convo.txt +0 -11
  55. package/test/scripting/logichooks/convos/custom_embedded_skip_followed_by_nothing.convo.txt +0 -8
  56. package/test/scripting/logichooks/customEmbedded.json +0 -14
  57. package/test/scripting/logichooks/customEmbedded.spec.js +0 -44
  58. package/test/scripting/logichooks/customEmbeddedSkip.json +0 -14
  59. package/test/scripting/logichooks/customEmbeddedSkip.spec.js +0 -58
  60. package/test/security/convos/withscriptingmemoryfunction.convo.txt +0 -5
@@ -0,0 +1,12 @@
1
+ custom embedded
2
+
3
+ #me
4
+ hello
5
+
6
+ #bot
7
+ hello should not assert
8
+ CONDITIONAL_STEP_LOGIC_HOOK { "skip":true }|G1
9
+
10
+ #bot
11
+ hello
12
+ CONDITIONAL_STEP_LOGIC_HOOK { "skip":false }|G1
@@ -0,0 +1,16 @@
1
+ conditional_steps_time_based
2
+
3
+ #me
4
+ hello
5
+
6
+ #bot
7
+ hello, it's business hours
8
+ CONDITIONAL_STEP_BUSINESS_HOURS { "days": ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"], "start":"8:00", "end": "16:30" }
9
+
10
+ #bot
11
+ hello, it's non-business hours
12
+ CONDITIONAL_STEP_BUSINESS_HOURS { "days": ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"], "start":"16:31", "end": "7:59" }
13
+
14
+ #bot
15
+ hello, it's non-business hours
16
+ CONDITIONAL_STEP_BUSINESS_HOURS { "days": ["Saturday", "Sunday"] }
@@ -0,0 +1,12 @@
1
+ conditional_steps_time_based
2
+
3
+ #me
4
+ hello
5
+
6
+ #bot
7
+ hello
8
+ CONDITIONAL_STEP_CAPABILITY_VALUE_BASED { "capabilityName":"SIMPLE_TEXT", "value": "echo1" }
9
+
10
+ #bot
11
+ fail
12
+ CONDITIONAL_STEP_CAPABILITY_VALUE_BASED { "capabilityName":"SIMPLE_TEXT", "value": "echo2" }
@@ -0,0 +1,15 @@
1
+ custom embedded
2
+
3
+ #me
4
+ hello
5
+
6
+ #bot
7
+ hello should not assert
8
+ CONDITIONAL_STEP_LOGIC_HOOK { "skip":true }|G1
9
+
10
+ #bot
11
+ hello
12
+ CONDITIONAL_STEP_LOGIC_HOOK { "skip":false }|G1
13
+
14
+ #bot
15
+ hello Duplicate
@@ -0,0 +1,18 @@
1
+ custom embedded
2
+
3
+ #me
4
+ hello
5
+
6
+ #bot
7
+ hello should not assert
8
+ CONDITIONAL_STEP_LOGIC_HOOK { "skip":true }|G1
9
+
10
+ #bot
11
+ hello
12
+ CONDITIONAL_STEP_LOGIC_HOOK { "skip":false }|G1
13
+
14
+ #me
15
+ hello
16
+
17
+ #bot
18
+ hello
@@ -0,0 +1,12 @@
1
+ conditional_steps_time_based
2
+
3
+ #me
4
+ hello
5
+
6
+ #bot
7
+ hello
8
+ CONDITIONAL_STEP_JSON_PATH_BASED { "jsonPath":"$.messageText", "value": "hello" }
9
+
10
+ #bot
11
+ fail
12
+ CONDITIONAL_STEP_JSON_PATH_BASED { "jsonPath":"$.messageText", "value": "fail" }
@@ -0,0 +1,20 @@
1
+ custom embedded
2
+
3
+ #me
4
+ hello
5
+
6
+ #bot
7
+ hello should not assert
8
+ CONDITIONAL_STEP_LOGIC_HOOK { "skip":true }|G1
9
+
10
+ #bot
11
+ hello
12
+ CONDITIONAL_STEP_LOGIC_HOOK { "skip":false }|G1
13
+
14
+ #bot
15
+ hello Duplicate
16
+ CONDITIONAL_STEP_LOGIC_HOOK { "skip":false }|G2
17
+
18
+ #bot
19
+ hello should not assert
20
+ CONDITIONAL_STEP_LOGIC_HOOK { "skip":true }|G2
@@ -0,0 +1,20 @@
1
+ custom embedded
2
+
3
+ #me
4
+ hello
5
+
6
+ #bot
7
+ hello should not assert
8
+ CONDITIONAL_STEP_LOGIC_HOOK { "skip":true }|G1
9
+
10
+ #bot
11
+ hello should not assert
12
+ CONDITIONAL_STEP_LOGIC_HOOK { "skip":true }|G1
13
+
14
+ #bot
15
+ hello should not assert
16
+ CONDITIONAL_STEP_LOGIC_HOOK { "skip":true }|G2
17
+
18
+ #bot
19
+ hello should not assert
20
+ CONDITIONAL_STEP_LOGIC_HOOK { "skip":true }|G2
@@ -0,0 +1,12 @@
1
+ conditional_steps_time_based
2
+
3
+ #me
4
+ hello
5
+
6
+ #bot
7
+ hello, we are open
8
+ CONDITIONAL_STEP_TIME_BASED { "start":"8:00", "end": "16:30" }
9
+
10
+ #bot
11
+ hello, we are closed
12
+ CONDITIONAL_STEP_TIME_BASED { "start":"16:31", "end": "7:59" }
@@ -0,0 +1,105 @@
1
+ const path = require('path')
2
+ const assert = require('chai').assert
3
+ const BotDriver = require('../../..').BotDriver
4
+ const Capabilities = require('../../..').Capabilities
5
+ const CustomConditionalLogicHook = require('./CustomConditionalLogicHook')
6
+ const myCaps = {
7
+ LOGIC_HOOKS: [
8
+ {
9
+ ref: 'CONDITIONAL_STEP_LOGIC_HOOK',
10
+ src: CustomConditionalLogicHook,
11
+ global: false
12
+ }
13
+ ]
14
+ }
15
+ const echoConnector = () => ({ queueBotSays }) => {
16
+ return {
17
+ UserSays (msg) {
18
+ const botMsg = { sender: 'bot', sourceData: msg.sourceData, messageText: msg.messageText }
19
+ queueBotSays(botMsg)
20
+ }
21
+ }
22
+ }
23
+
24
+ const echoConnectorDuplicatedBotMsg = () => ({ queueBotSays }) => {
25
+ return {
26
+ UserSays (msg) {
27
+ const botMsg = { sender: 'bot', sourceData: msg.sourceData, messageText: msg.messageText }
28
+ queueBotSays(botMsg)
29
+
30
+ const botMsgDuplicate = { sender: 'bot', sourceData: msg.sourceData, messageText: msg.messageText + ' Duplicate' }
31
+ queueBotSays(botMsgDuplicate)
32
+ }
33
+ }
34
+ }
35
+
36
+ const buildDriver = async (mergeCaps, duplicateBotMsg) => {
37
+ const myCaps = Object.assign({
38
+ [Capabilities.PROJECTNAME]: 'convo.customassertersskip',
39
+ [Capabilities.CONTAINERMODE]: duplicateBotMsg ? echoConnectorDuplicatedBotMsg() : echoConnector()
40
+ }, mergeCaps)
41
+
42
+ const result = {}
43
+ result.driver = new BotDriver(myCaps)
44
+ result.compiler = result.driver.BuildCompiler()
45
+ result.container = await result.driver.Build()
46
+ return result
47
+ }
48
+
49
+ describe('convo with custom conditional logichook', function () {
50
+ describe('simple bot messages', function () {
51
+ beforeEach(async function () {
52
+ const { compiler, container } = await buildDriver(myCaps)
53
+ this.compiler = compiler
54
+ this.container = container
55
+ await this.container.Start()
56
+ })
57
+ afterEach(async function () {
58
+ await this.container.Stop()
59
+ await this.container.Clean()
60
+ })
61
+
62
+ it('should success', async function () {
63
+ this.compiler.ReadScript(path.resolve(__dirname, 'convos'), 'conditional_steps.convo.txt')
64
+ const transript = await this.compiler.convos[0].Run(this.container)
65
+ assert.equal(transript.steps.length, 2)
66
+ })
67
+
68
+ it('should success followed by me message', async function () {
69
+ this.compiler.ReadScript(path.resolve(__dirname, 'convos'), 'conditional_steps_followed_by_me.convo.txt')
70
+ const transript = await this.compiler.convos[0].Run(this.container)
71
+ assert.equal(transript.steps.length, 4)
72
+ })
73
+ })
74
+
75
+ describe('multiple bot messages', function () {
76
+ beforeEach(async function () {
77
+ const { compiler, container } = await buildDriver(myCaps, true)
78
+ this.compiler = compiler
79
+ this.container = container
80
+ await this.container.Start()
81
+ })
82
+ afterEach(async function () {
83
+ await this.container.Stop()
84
+ await this.container.Clean()
85
+ })
86
+
87
+ it('should success followed by bot message', async function () {
88
+ this.compiler.ReadScript(path.resolve(__dirname, 'convos'), 'conditional_steps_followed_by_bot_msg.convo.txt')
89
+ const transript = await this.compiler.convos[0].Run(this.container)
90
+ assert.equal(transript.steps.length, 3)
91
+ })
92
+
93
+ it('should success with multiple condition groups', async function () {
94
+ this.compiler.ReadScript(path.resolve(__dirname, 'convos'), 'conditional_steps_multiple_condition_groups.convo.txt')
95
+ const transript = await this.compiler.convos[0].Run(this.container)
96
+ assert.equal(transript.steps.length, 3)
97
+ })
98
+
99
+ it('should success with multiple condition groups no assertion', async function () {
100
+ this.compiler.ReadScript(path.resolve(__dirname, 'convos'), 'conditional_steps_multiple_condition_groups_no_assertion.convo.txt')
101
+ const transript = await this.compiler.convos[0].Run(this.container)
102
+ assert.equal(transript.steps.length, 3)
103
+ })
104
+ })
105
+ })
@@ -718,7 +718,7 @@ describe('scripting.scriptingProvider', function () {
718
718
  assert.equal(scriptingProvider.convos[1].header.name, 'utt1/utt1-L00002')
719
719
  assert.equal(scriptingProvider.convos[1].conversation[0].messageText, 'TEXT2')
720
720
  assert.equal(scriptingProvider.convos[1].toString(), '2 utt1/utt1-L00002 (Expanded Utterances - utt1) ({ origUttName: \'utt1\', origConvoName: \'utt1\' }): Step 1 - tell utterance: #me - TEXT2 SKIP_BOT_UNCONSUMED(no args) | Step 2 - check bot response: #bot - ')
721
- })
721
+ }).timeout(5000)
722
722
  it('should build incomprehension convos for utterance', async function () {
723
723
  const scriptingProvider = new ScriptingProvider(Object.assign({}, DefaultCapabilities, { SCRIPTING_UTTEXPANSION_INCOMPREHENSION: 'INCOMPREHENSION' }))
724
724
  await scriptingProvider.Build()
@@ -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()