-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
app.js
174 lines (141 loc) · 9.07 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
const test = require('ava');
const sinon = require('sinon');
const appRootDir = process.cwd();
const App = require('../../../../src/api/app/models/app');
// ////////////////////////////////////////////////
// getActiveFeatureFileUris
// ////////////////////////////////////////////////
const setupGetActiveFeatureFileUris = async ({ tagExpression }) => {
const theFeatureFilesThatExist = [`${appRootDir}/testResources/features/app_scan.feature`, `${appRootDir}/testResources/features/simple_math.feature`];
const configuration = {
pickleFilterOptions: { cwd: appRootDir, featurePaths: ['testResources/features'], names: [], tagExpression },
featurePaths: theFeatureFilesThatExist
};
const getConfigurationFake = sinon.fake.returns(configuration);
const cucumberCli = { getConfiguration: getConfigurationFake };
const appOptions = { log: undefined, strings: undefined, emissary: undefined, cucumber: undefined, cucumberConfig: undefined, results: undefined, publisher: undefined, runType: undefined, cloud: undefined, debug: undefined }; // eslint-disable-line max-len
const app = new App(appOptions);
return app.getActiveFeatureFileUris(cucumberCli);
};
test('Given tagExpression: (@app_scan) - when getActiveFeatureFileUris is invoked - then active feature file Uris app_scan.feature should be returned', async (t) => {
t.plan(1);
// Active feature files are based on the cucumber.tagExpression defined in config.
// https://cucumber.io/docs/cucumber/api/#tag-expressions
// https://github.com/cucumber/cucumber/tree/master/tag-expressions#migrating-from-old-style-tags
const tagExpression = '(@app_scan)';
const activeFeatureFileUris = await setupGetActiveFeatureFileUris({ tagExpression });
t.deepEqual(activeFeatureFileUris, [`${appRootDir}/testResources/features/app_scan.feature`]);
});
test('Given tagExpression: (@simple_math) - when getActiveFeatureFileUris is invoked - then active feature file Uris simple_math.feature should be returned', async (t) => {
t.plan(1);
// Active feature files are based on the cucumber.tagExpression defined in config.
// https://cucumber.io/docs/cucumber/api/#tag-expressions
// https://github.com/cucumber/cucumber/tree/master/tag-expressions#migrating-from-old-style-tags
const tagExpression = '(@simple_math)';
const activeFeatureFileUris = await setupGetActiveFeatureFileUris({ tagExpression });
t.deepEqual(activeFeatureFileUris, [`${appRootDir}/testResources/features/simple_math.feature`]);
});
test('Given tagExpression: (@app_scan or @simple_math) - when getActiveFeatureFileUris is invoked - then active feature file Uris app_scan.feature and simple_math.feature should be returned', async (t) => {
t.plan(1);
// Active feature files are based on the cucumber.tagExpression defined in config.
// https://cucumber.io/docs/cucumber/api/#tag-expressions
// https://github.com/cucumber/cucumber/tree/master/tag-expressions#migrating-from-old-style-tags
const tagExpression = '(@app_scan or @simple_math)';
const activeFeatureFileUris = await setupGetActiveFeatureFileUris({ tagExpression });
t.deepEqual(activeFeatureFileUris, [`${appRootDir}/testResources/features/app_scan.feature`, `${appRootDir}/testResources/features/simple_math.feature`]);
});
// Since cucumber.getTestCasesFromFilesystem was removed, the following test cases fail, including the ones not yet implemented.
test.failing('Given tagExpression: (@app_scan and @simple_math) - when getActiveFeatureFileUris is invoked - then no active feature file Uris should be returned', async (t) => {
t.plan(1);
// Active feature files are based on the cucumber.tagExpression defined in config.
// https://cucumber.io/docs/cucumber/api/#tag-expressions
// https://github.com/cucumber/cucumber/tree/master/tag-expressions#migrating-from-old-style-tags
const tagExpression = '(@app_scan and @simple_math)';
const activeFeatureFileUris = await setupGetActiveFeatureFileUris({ tagExpression });
t.deepEqual(activeFeatureFileUris, []);
// What we get is: [`${appRootDir}/testResources/features/app_scan.feature`, `${appRootDir}/testResources/features/simple_math.feature`]
});
test.failing('Given tagExpression: (not @simple_math) - when getActiveFeatureFileUris is invoked - then active feature file Uris app_scan.feature should be returned', async (t) => {
t.plan(1);
// Active feature files are based on the cucumber.tagExpression defined in config.
// https://cucumber.io/docs/cucumber/api/#tag-expressions
// https://github.com/cucumber/cucumber/tree/master/tag-expressions#migrating-from-old-style-tags
const tagExpression = '(not @simple_math)';
const activeFeatureFileUris = await setupGetActiveFeatureFileUris({ tagExpression });
t.deepEqual(activeFeatureFileUris, [`${appRootDir}/testResources/features/app_scan.feature`]);
// What we get is: [`${appRootDir}/testResources/features/simple_math.feature`]
});
// The following are also not catered for currently.
// Ideas for creating feature files with tags to test for here: https://cucumber.io/docs/cucumber/api/#tags
// @wip and not @slow
// Scenarios tagged with @wip that are not also tagged with @slow
// (@smoke or @ui) and (not @slow)
// Scenarios tagged with @smoke or @ui that are not also tagged with @slow
// not @foo and (@bar or @zap)
// Scenarios tagged with @bar or @zap that are not also tagged with @foo
// Continue implementing failing tests?
// ////////////////////////////////////////////////
// getTestPlanText
// ////////////////////////////////////////////////
test('Given activeFeatureFileUris: [appRootDir/testResources/features/app_scan.feature] - when getTestPlanText is invoked - then app_scan.feature test plan should be returned', async (t) => {
t.plan(1);
const activeFeatureFileUris = [`${appRootDir}/testResources/features/app_scan.feature`];
const appOptions = { log: undefined, strings: undefined, emissary: undefined, cucumber: undefined, cucumberConfig: undefined, results: undefined, publisher: undefined, runType: undefined, cloud: undefined, debug: undefined }; // eslint-disable-line max-len
const app = new App(appOptions);
const expectedTestPlanText = `@app_scan
Feature: Web application free of security vulnerabilities known to Zap
# Before hooks are run before Background
Background:
Given a new test session based on each build user supplied testSession
And each build user supplied route of each testSession is navigated
And a new scanning session based on each build user supplied testSession
And the application is spidered for each testSession
And all active scanners are disabled
Scenario: The application should not contain vulnerabilities known to Zap that exceed the build user defined threshold
Given all active scanners are enabled
When the active scan is run
Then the vulnerability count should not exceed the build user defined threshold of vulnerabilities known to Zap
`;
const testPlanText = await app.getTestPlanText(activeFeatureFileUris);
t.deepEqual(testPlanText, expectedTestPlanText);
});
test('Given activeFeatureFileUris: [appRootDir/testResources/features/app_scan.feature, appRootDir/testResources/features/simple_math.feature] - when getTestPlanText is invoked - then app_scan.feature and simple_math.feature test plans should be returned', async (t) => {
t.plan(1);
const activeFeatureFileUris = [`${appRootDir}/testResources/features/app_scan.feature`, `${appRootDir}/testResources/features/simple_math.feature`];
const appOptions = { log: undefined, strings: undefined, emissary: undefined, cucumber: undefined, cucumberConfig: undefined, results: undefined, publisher: undefined, runType: undefined, cloud: undefined, debug: undefined }; // eslint-disable-line max-len
const app = new App(appOptions);
const expectedTestPlanText = `@app_scan
Feature: Web application free of security vulnerabilities known to Zap
# Before hooks are run before Background
Background:
Given a new test session based on each build user supplied testSession
And each build user supplied route of each testSession is navigated
And a new scanning session based on each build user supplied testSession
And the application is spidered for each testSession
And all active scanners are disabled
Scenario: The application should not contain vulnerabilities known to Zap that exceed the build user defined threshold
Given all active scanners are enabled
When the active scan is run
Then the vulnerability count should not exceed the build user defined threshold of vulnerabilities known to Zap
@simple_math
Feature: Simple maths
In order to do maths
As a developer
I want to increment variables
Scenario: easy maths
Given a variable set to 1
When I increment the variable by 1
Then the variable should contain 2
Scenario Outline: much more complex stuff
Given a variable set to <var>
When I increment the variable by <increment>
Then the variable should contain <result>
Examples:
| var | increment | result |
| 100 | 5 | 105 |
| 99 | 1234 | 1333 |
| 12 | 5 | 17 |
`;
const testPlanText = await app.getTestPlanText(activeFeatureFileUris);
t.deepEqual(testPlanText, expectedTestPlanText);
});