Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
const url = require('url');
const http = require('http');
const { setWorldConstructor, After, AfterAll, Before, BeforeAll, Given, When, Then } = require('cucumber');
const { registerHooks, World: BaseWorld, registerSteps } = require('../../../src/index');
class World extends BaseWorld {
constructor() {
super();
}
}
setWorldConstructor(World);
registerHooks({ After, AfterAll, Before, BeforeAll });
registerSteps({ Given, Then, When });
process.env.GRAPHQL_BASE_URL = 'http://localhost:3000/graphql';
// a custom login step
Given('I am logged in as a {string}', async function (role) {
// does an agent for this role already exist?
const roleAgent = this.getAgentByRole(role);
if (roleAgent) {
this.setAgentByRole(role, roleAgent);
return;
}
// construct and send a login request
const agent = this.newAgent();
const sdapi = require('../support/sdapi');
const { Before, Given, When, Then } = require('cucumber');
const TIMEOUT = 240 * 1000;
const WAIT_TIME = 3;
Before({
tags: '@workflow'
}, function hook() {
this.repoOrg = this.testOrg;
this.repoName = 'functional-workflow';
this.pipelineId = null;
this.builds = null;
});
Given(/^an existing pipeline on "(.*)" branch with the workflow jobs:$/, {
timeout: TIMEOUT
}, function step(branch, table) {
return this.getJwt(this.apiToken)
.then((response) => {
this.jwt = response.body.token;
return github.createBranch(branch, this.repoOrg, this.repoName);
})
// wait not to trigger builds when create a pipeline
.then(() => this.promiseToWait(WAIT_TIME))
.then(() => this.createPipeline(this.repoName, branch))
.then((response) => {
Assert.oneOf(response.statusCode, [409, 201]);
if (response.statusCode === 201) {
this.pipelineId = response.body.id;
this.repoName = 'functional-events';
// Reset shared information
this.pipelineId = null;
this.eventId = null;
this.jwt = null;
});
Given(/^an existing pipeline with the workflow:$/, { timeout: TIMEOUT }, function step(table) {
return this.ensurePipelineExists({ repoName: this.repoName })
.then(() => table);
});
Given(/^"calvin" has admin permission to the pipeline$/, () => null);
Then(/^an event is created$/, { timeout: TIMEOUT }, function step() {
return request({
uri: `${this.instance}/${this.namespace}/pipelines/${this.pipelineId}/events`,
method: 'GET',
json: true,
auth: {
bearer: this.jwt
}
}).then(response => Assert.equal(response.body[0].id, this.eventId));
});
Then(/^the "main" build succeeds$/, { timeout: TIMEOUT }, function step() {
return this.waitForBuild(this.buildId).then((resp) => {
Assert.equal(resp.body.status, 'SUCCESS');
Assert.equal(resp.statusCode, 200);
});
});
case 'calvin':
Assert.strictEqual(decodedToken.username, this.username);
break;
case 'github:calvin':
Assert.strictEqual(decodedToken.username, this.username);
Assert.strictEqual(decodedToken.scmContext, this.scmContext);
break;
default:
return Promise.resolve('pending');
}
return null;
});
});
Then(/^they can see the pipeline$/, { timeout: TIMEOUT }, function step() {
return request({ // make sure pipeline exists (TODO: move to Given an existing pipeline with that repository scenario)
uri: `${this.instance}/${this.namespace}/pipelines`,
method: 'POST',
auth: {
bearer: this.jwt
},
body: {
checkoutUrl: `git@${this.scmHostname}:${this.repoOrg}/${this.repoName}.git#master`
},
json: true
}).then((response) => {
Assert.oneOf(response.statusCode, [409, 201]);
if (response.statusCode === 201) {
this.pipelineId = response.body.id;
} else {
return {
headers,
body: await res.json(),
}
},
method,
url,
)
// Store response for further assertions
this.response = response
}
}
setWorldConstructor(World)
'use strict';
const Assert = require('chai').assert;
const request = require('../support/request');
const { Before, Given, Then } = require('cucumber');
const TIMEOUT = 240 * 1000;
Before('@events', function hook() {
this.repoName = 'functional-events';
// Reset shared information
this.pipelineId = null;
this.eventId = null;
this.jwt = null;
});
Given(/^an existing pipeline with the workflow:$/, { timeout: TIMEOUT }, function step(table) {
return this.ensurePipelineExists({ repoName: this.repoName })
.then(() => table);
});
Given(/^"calvin" has admin permission to the pipeline$/, () => null);
Then(/^an event is created$/, { timeout: TIMEOUT }, function step() {
'use strict';
const Assert = require('chai').assert;
const request = require('../support/request');
const { Before, Given, When, Then } = require('cucumber');
const TIMEOUT = 240 * 1000;
Before({
tags: '@sd-cmd'
}, function hook() {
this.repoOrg = this.testOrg;
this.repoName = 'functional-commands';
this.pipelineId = null;
this.configPipelineId = null;
this.buildPipelineIds = {};
this.jwt = null;
this.image = null;
this.command = null;
this.commandNamespace = 'screwdriver-cd-test';
return request({ // TODO : perform this in the before-hook for all func tests
method: 'GET',
url: `${this.instance}/${this.namespace}/auth/token?api_token=${this.apiToken}`,
followAllRedirects: true,
const Assert = require('chai').assert;
const request = require('../support/request');
const { Before, Given, Then } = require('cucumber');
const TIMEOUT = 240 * 1000;
Before('@events', function hook() {
this.repoName = 'functional-events';
// Reset shared information
this.pipelineId = null;
this.eventId = null;
this.jwt = null;
});
Given(/^an existing pipeline with the workflow:$/, { timeout: TIMEOUT }, function step(table) {
return this.ensurePipelineExists({ repoName: this.repoName })
.then(() => table);
});
Given(/^"calvin" has admin permission to the pipeline$/, () => null);
Then(/^an event is created$/, { timeout: TIMEOUT }, function step() {
return request({
uri: `${this.instance}/${this.namespace}/pipelines/${this.pipelineId}/events`,
method: 'GET',
json: true,
auth: {
bearer: this.jwt
}
}).then(response => Assert.equal(response.body[0].id, this.eventId));
});
this.jwt = null;
this.image = null;
this.command = null;
this.commandNamespace = 'screwdriver-cd-test';
return request({ // TODO : perform this in the before-hook for all func tests
method: 'GET',
url: `${this.instance}/${this.namespace}/auth/token?api_token=${this.apiToken}`,
followAllRedirects: true,
json: true
}).then((response) => {
this.jwt = response.body.token;
});
});
Given(/^(.*) command in (.*) format$/,
{ timeout: TIMEOUT }, function step(command, format) {
return request({
uri: `${this.instance}/${this.namespace}/commands/${this.commandNamespace}`
+ `/${this.command}/latest`,
method: 'GET',
json: true,
auth: {
bearer: this.jwt
}
}).then((response) => {
Assert.equal(response.body.name, command);
Assert.equal(response.body.namespace, this.commandNamespace);
Assert.equal(response.body.format, format);
this.command = command;
});
steps.forEach((step) => {
const matchPattern = "([^']*)?";
const matcher = step.matcher
.replace(new RegExp(`(${placeholders.join('|')})`, 'g'), matchPattern);
Given(new RegExp(`^${matcher}$`), {}, require(step.path));
step.regex = new RegExp(`^${matcher}$`); // eslint-disable-line no-param-reassign
});
}