Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
test("regexp matches will provide proper variables", async () => {
const body = await request.post(url + "/api/login/123").then(toJson);
expect(body.requesterInformation.receivedParams.action).toEqual("login");
expect(body.requesterInformation.receivedParams.userID).toEqual("123");
const bodyAgain = await request
.post(url + "/api/login/admin")
.then(toJson);
expect(bodyAgain.requesterInformation.receivedParams.action).toEqual(
"login"
);
expect(bodyAgain.requesterInformation.receivedParams.userID).toEqual(
"admin"
);
});
test("Server should sendBuffer", async () => {
const body = await request.get(url + "/api/sendBufferTest");
expect(body).toEqual("Example of data buffer");
});
test("returns application/json when the mime type cannot be determined for an action", async () => {
const response = await request.get(
url + "/api/mimeTestAction/thing.bogus",
{ resolveWithFullResponse: true }
);
expect(response.headers["content-type"]).toMatch(/json/);
const body = JSON.parse(response.body);
expect(body.matchedRoute.path).toEqual("/mimeTestAction/:key");
expect(body.matchedRoute.action).toEqual("mimeTestAction");
});
test("should send back the cache-control header", async () => {
const response = await request.get(url + "/simple.html", {
resolveWithFullResponse: true
});
expect(response.statusCode).toEqual(200);
expect(response.headers["cache-control"]).toBeTruthy();
});
test('Server should sendBuffer', async () => {
const body = await request.get(url + '/api/sendBufferTest')
expect(body).toEqual('Example of data buffer')
})
constructor(githubRepo, githubTokenOfCI) {
this.githubRepo = githubRepo;
this.request = req.defaults({
headers: {
"User-Agent": "AutoRest CI",
"Authorization": "token " + githubTokenOfCI
}
});
}
downloadFile(url, destinationFilePath) {
console.log('Start downloading file from ' + url);
const requestPromiseCall = requestPromise.get(url, { json: false }, (error, response, body) => {
console.log('content-type:', response.headers['content-type']);
console.log('content-length:', response.headers['content-length']);
if (response.statusCode < 200 || response.statusCode > 299) {
throw new Error('Failed to load page, status code: ' + response.statusCode);
}
return body;
}).then(body => {
const buffer = Buffer.from(body, 'utf8');
fs.writeFileSync(destinationFilePath, buffer);
console.log('File downloaded!');
});
return requestPromiseCall;
}
sleep(ms) {
public async get(endpoint: string) {
let url = `${this._jenkinsUri}/${endpoint}`;
return request.get(url).catch(err => {
console.log(err);
vscode.window.showWarningMessage(this._cantConnectMessage);
return undefined;
});
}
public static getAccessToken(host: string, apiToken: string) {
const base64ApiToken = new Buffer('apitoken:' + apiToken).toString('base64');
const options = {
url: host + '/services/mtm/v1/oauth2/token',
headers: { 'Authorization': 'Basic ' + base64ApiToken },
form: { grant_type: 'client_credentials' }
};
return rp.post(options)
.then(response => JSON.parse(response)['access_token']);
}
async sendChunk(rows: Hub.JsonDetail.Row[], mapping: any) {
const chunk = rows.slice(0)
const body: MparticleBulkEvent[] = []
chunk.forEach((row: Hub.JsonDetail.Row) => {
const eventEntry = this.createEvent(row, mapping)
body.push(eventEntry)
})
const options = this.postOptions(body)
await httpRequest.post(options).promise().catch((e: any) => {
this.errors.push(`${e.statusCode} - ${mparticleErrorCodes[e.statusCode]}`)
})
}