Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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;
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
});
}
} else {
record.assert.deleted(clientExpression, recordName, called)
}
})
Then(/^(.+) receives? an? "([^"]*)" error on record "([^"]*)"$/, record.assert.receivedRecordError)
Then(/^(.+) receives? an update for record "([^"]*)" with data '([^']+)'$/, record.assert.receivedUpdate)
Then(/^(.+) receives? an update for record "([^"]*)" and path "([^"]*)" with data '([^']+)'$/, record.assert.receivedUpdateForPath)
Then(/^(.+) (?:don't|doesn't|does not) receive an update for record "([^"]*)"$/, record.assert.receivedNoUpdate)
Then(/^(.+) don't receive an update for record "([^"]*)" and path "([^"]*)"$/, record.assert.receivedNoUpdateForPath)
Given(/^(.+) subscribes? to record "([^"]*)"( with immediate flag)?$/, record.subscribe)
Given(/^(.+) unsubscribes? to record "([^"]*)"$/, record.unsubscribe)
Given(/^(.+) subscribes? to record "([^"]*)" with path "([^"]*)"( with immediate flag)?$/, record.subscribeWithPath)
Given(/^(.+) unsubscribes? to record "([^"]*)" with path "([^"]*)"$/, record.unsubscribeFromPath)
Then(/^(.+) (?:have|has) record "([^"]*)" with data '([^']+)'$/, record.assert.hasData)
Then(/^(.+) (?:have|has) record "([^"]*)" with(out)? providers$/, record.assert.hasProviders)
Then(/^(.+) (?:have|has) record "([^"]*)" with path "([^"]*)" and data '([^']+)'$/, record.assert.hasDataAtPath)
Given(/^(.+) discards record "([^"]*)"$/, (clientExpression: string, recordName: string, done) => {
record.discard(clientExpression, recordName)
setTimeout(done, defaultDelay)
})
} else {
record.assert.deleted(clientExpression, recordName, called)
}
})
Then(/^(.+) receives? an? "([^"]*)" error on record "([^"]*)"$/, record.assert.receivedRecordError)
Then(/^(.+) receives? an update for record "([^"]*)" with data '([^']+)'$/, record.assert.receivedUpdate)
Then(/^(.+) receives? an update for record "([^"]*)" and path "([^"]*)" with data '([^']+)'$/, record.assert.receivedUpdateForPath)
Then(/^(.+) (?:don't|doesn't|does not) receive an update for record "([^"]*)"$/, record.assert.receivedNoUpdate)
Then(/^(.+) don't receive an update for record "([^"]*)" and path "([^"]*)"$/, record.assert.receivedNoUpdateForPath)
Given(/^(.+) subscribes? to record "([^"]*)"( with immediate flag)?$/, record.subscribe)
Given(/^(.+) unsubscribes? to record "([^"]*)"$/, record.unsubscribe)
Given(/^(.+) subscribes? to record "([^"]*)" with path "([^"]*)"( with immediate flag)?$/, record.subscribeWithPath)
Given(/^(.+) unsubscribes? to record "([^"]*)" with path "([^"]*)"$/, record.unsubscribeFromPath)
Then(/^(.+) (?:have|has) record "([^"]*)" with data '([^']+)'$/, record.assert.hasData)
Then(/^(.+) (?:have|has) record "([^"]*)" with(out)? providers$/, record.assert.hasProviders)
Then(/^(.+) (?:have|has) record "([^"]*)" with path "([^"]*)" and data '([^']+)'$/, record.assert.hasDataAtPath)
Given(/^(.+) discards record "([^"]*)"$/, (clientExpression: string, recordName: string, done) => {
record.discard(clientExpression, recordName)
setTimeout(done, defaultDelay)
})
'use strict';
const fs = require('mz/fs');
const request = require('../support/request');
const path = require('path');
const Assert = require('chai').assert;
const { Given, Then, When } = require('cucumber');
Given(/^a (valid|invalid)\b job-level template$/, function step(templateType) {
let targetFile = '';
switch (templateType) {
case 'valid':
targetFile = path.resolve(__dirname, '../data/valid-template.yaml');
break;
case 'invalid':
targetFile = path.resolve(__dirname, '../data/invalid-template.yaml');
break;
default:
return Promise.reject('Template type is neither valid or invalid');
}
return fs.readFile(targetFile, 'utf8')
.then((contents) => {
this.templateContents = contents;
const request = require('../support/request');
const jwt = require('jsonwebtoken');
const TIMEOUT = 240 * 1000;
const { Before, Given, Then } = require('cucumber');
Before('@auth', function hook() {
this.repoOrg = this.testOrg;
this.repoName = 'functional-auth';
this.pipelineId = null;
});
Given(/^an existing repository with these users and permissions:$/, table => table);
Given(/^an existing pipeline with that repository$/, () => null);
Given(/^"([^"]*)" is logged in$/, { timeout: TIMEOUT }, function step(user) {
if (!(this.apiToken)) {
throw new Error('insufficient set up, missing access key');
}
return this.getJwt(this.apiToken).then((response) => {
const accessToken = response.body.token;
const decodedToken = jwt.decode(accessToken);
this.jwt = accessToken;
Assert.equal(response.statusCode, 200);
switch (user) {
case 'calvin':
Assert.strictEqual(decodedToken.username, this.username);
break;