Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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')
})
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;
});
}
get(url: URL) {
log.http("GET", logFriendlyUrl(url))
return r
.get({
uri: url.href,
json: true,
headers: {
"user-agent": `speedcurve-cli/${VERSION}`
}
})
.catch(this.normaliseErrorResponse)
}
async form(request: Hub.ActionRequest) {
const form = new Hub.ActionForm()
if (!request.params.datarobot_api_token) {
form.error = "No DataRobot API Token configured; consult your Looker admin."
return form
}
if (request.params.datarobot_url) {
try {
const normalizedDataRobotUrl = normalizeUrl(request.params.datarobot_url)
await httpRequest.get(normalizedDataRobotUrl).promise()
this.dataRobotUrl = normalizedDataRobotUrl
} catch {
form.error = "URL for on-premise instance is not valid."
return form
}
}
try {
await this.validateDataRobotToken(request.params.datarobot_api_token)
form.fields = [
{
label: "The name of the project to be created",
name: "projectName",
required: false,
type: "string",
async getProjects() {
if (!this.tokens) {
throw "unauthenticated"
}
const baseUrl = await this.baseUrl()
return https.get({
url: `${baseUrl}/project`,
headers: {
Authorization: `Bearer ${this.tokens.access_token}`,
},
json: true,
})
}
public async provide(settings: ISettings, logger: ILogger): Promise{
let response = null;
if (this.userName && this.password){
logger.info(`Requesting swagger definitions from ${this.url} ...`);
response = await request.get(this.url).auth(this.userName, this.password, false);
logger.info(`Received swagger definitions from ${this.url} ...`);
return JSON.parse(response) as Swagger.Spec;
}
else{
logger.info(`Requesting swagger definitions from ${this.url} ...`);
response = await request.get(this.url);
logger.info(`Received swagger definitions from ${this.url} ...`);
return JSON.parse(response) as Swagger.Spec;
}
}
}