Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FtpUploadV2] Resolve dependabot alert about shelljs #15881

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
132 changes: 128 additions & 4 deletions Tasks/FtpUploadV2/Tests/L0.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,140 @@
import fs = require('fs');
import assert = require('assert');
import path = require('path');
import * as ttm from 'azure-pipelines-task-lib/mock-test';

describe('FtpUploadV2 Suite', function () {
before(() => {
this.timeout(parseInt(process.env.TASK_TEST_TIMEOUT!) || 20000);

it('check args: no serverEndpoint', (done: Mocha.Done) => {
const tp = path.join(__dirname, 'L0NoServerEndpoint.js');
const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp);

tr.run();

assert(tr.stdOutContained('Input required: serverEndpoint'), 'Should have printed: Input required: serverEndpoint');
assert(tr.failed, 'task should have failed');

done();
});

it('check args: no rootFolder', (done: Mocha.Done) => {
const tp = path.join(__dirname, 'L0NoRootFolder.js');
const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp);

tr.run();

assert(tr.stdOutContained('Input required: rootFolder'), 'Should have printed: Input required: rootFolder');
assert(tr.failed, 'task should have failed');

done();
});

it('check args: no filePatterns', (done: Mocha.Done) => {
const tp = path.join(__dirname, 'L0NoFilePatterns.js');
const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp);

tr.run();

assert(tr.stdOutContained('Input required: filePatterns'), 'Should have printed: Input required: filePatterns');
assert(tr.failed, 'task should have failed');

done();
});

after(() => {
it('check args: no remotePath', (done: Mocha.Done) => {
const tp = path.join(__dirname, 'L0NoRemotePath.js');
const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp);

tr.run();

assert(tr.stdOutContained('Input required: remotePath'), 'Should have printed: Input required: remotePath');
assert(tr.failed, 'task should have failed');

done();
});

it('Does a basic hello world test', function(done: MochaDone) {
// TODO - add real tests
it('check args: no clean', (done: Mocha.Done) => {
const tp = path.join(__dirname, 'L0NoClean.js');
const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp);

tr.run();

assert(tr.stdOutContained('Input required: clean'), 'Should have printed: Input required: clean');
assert(tr.failed, 'task should have failed');

done();
});

it('check args: no preservePaths', (done: Mocha.Done) => {
const tp = path.join(__dirname, 'L0NoPreservePaths.js');
const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp);

tr.run();

assert(tr.stdOutContained('Input required: preservePaths'), 'Should have printed: Input required: preservePaths');
assert(tr.failed, 'task should have failed');

done();
});

it('check args: no trustSSL', (done: Mocha.Done) => {
const tp = path.join(__dirname, 'L0NoTrustSSL.js');
const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp);

tr.run();

assert(tr.invokedToolCount === 0, 'should not run anything');
assert(tr.stdOutContained('Input required: trustSSL'), 'Should have printed: Input required: trustSSL');
assert(tr.failed, 'task should have failed');

done();
});

it('check args: no protocol on server URL (ftp:// or ftps://)', (done: Mocha.Done) => {
const tp = path.join(__dirname, 'L0NoProtocol.js');
const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp);

tr.run();

assert(tr.stdOutContained('loc_mock_FTPNoProtocolSpecified'), 'Should have printed: loc_mock_FTPNoProtocolSpecified');
assert(tr.failed, 'task should have failed');

done();
});

it('check args: no host name on server URL', (done: Mocha.Done) => {
const tp = path.join(__dirname, 'L0NoHostName.js');
const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp);

tr.run();

assert(tr.stdOutContained('loc_mock_FTPNoHostSpecified'), 'Should have printed: loc_mock_FTPNoHostSpecified');
assert(tr.failed, 'task should have failed');

done();
});

it('check args: no files found', (done: Mocha.Done) => {
const tp = path.join(__dirname, 'L0NoFilesFound.js');
const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp);

tr.run();

assert(tr.stdOutContained('loc_mock_NoFilesFound'), 'Should have printed: loc_mock_NoFilesFound');
assert(tr.failed, 'task should have failed');

anatolybolshakov marked this conversation as resolved.
Show resolved Hide resolved
done();
});

it('task should complete successfully', (done: Mocha.Done) => {
const tp = path.join(__dirname, 'L0Successful.js');
const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp);

tr.run();
console.info(tr.stdout);
assert(tr.succeeded, 'task should succeed');

done();
});
});
39 changes: 39 additions & 0 deletions Tasks/FtpUploadV2/Tests/L0NoClean.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import ma = require('azure-pipelines-task-lib/mock-answer');
import tmrm = require('azure-pipelines-task-lib/mock-run');
import path = require('path');

let taskPath = path.join(__dirname, '..', 'ftpuploadtask.js');
let tr: tmrm.TaskMockRunner = new tmrm.TaskMockRunner(taskPath);

tr.setInput('serverEndpoint', 'ID1');
tr.setInput('credsType', 'serviceEndpoint');
process.env["ENDPOINT_URL_ID1"] = "ftp://valid.microsoft.com";
process.env["ENDPOINT_AUTH_ID1"] = "{\"scheme\":\"UsernamePassword\", \"parameters\": {\"username\": \"uname\", \"password\": \"pword\"}}";
process.env["build.sourcesDirectory"] = "/";
tr.setInput('rootFolder', 'rootFolder');
tr.setInput('filePatterns', '**');
tr.setInput('remotePath', '/upload/');

// provide answers for task mock
let a: ma.TaskLibAnswers = <ma.TaskLibAnswers>{
"exist": {
"rootFolder": true
},
"find": {
"rootFolder": [
"rootFolder/a",
"rootFolder/b",
"rootFolder/c"
]
},
"match": {
"*": [
"rootFolder/a",
"rootFolder/b",
"rootFolder/c"
]
}
};
tr.setAnswers(a);

tr.run();
37 changes: 37 additions & 0 deletions Tasks/FtpUploadV2/Tests/L0NoFilePatterns.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import ma = require('azure-pipelines-task-lib/mock-answer');
import tmrm = require('azure-pipelines-task-lib/mock-run');
import path = require('path');

let taskPath = path.join(__dirname, '..', 'ftpuploadtask.js');
let tr: tmrm.TaskMockRunner = new tmrm.TaskMockRunner(taskPath);

tr.setInput('serverEndpoint', 'ID1');
tr.setInput('rootFolder', 'rootFolder');
tr.setInput('credsType', 'serviceEndpoint');
process.env["ENDPOINT_URL_ID1"] = "ftp://valid.microsoft.com";
process.env["ENDPOINT_AUTH_ID1"] = "{\"scheme\":\"UsernamePassword\", \"parameters\": {\"username\": \"uname\", \"password\": \"pword\"}}";
process.env["build.sourcesDirectory"] = "/";

// provide answers for task mock
let a: ma.TaskLibAnswers = <ma.TaskLibAnswers>{
"exist": {
"rootFolder": true
},
"find": {
"rootFolder": [
"rootFolder/a",
"rootFolder/b",
"rootFolder/c"
]
},
"match": {
"*": [
"rootFolder/a",
"rootFolder/b",
"rootFolder/c"
]
}
};
tr.setAnswers(a);

tr.run();
39 changes: 39 additions & 0 deletions Tasks/FtpUploadV2/Tests/L0NoFilesFound.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import ma = require('azure-pipelines-task-lib/mock-answer');
import tmrm = require('azure-pipelines-task-lib/mock-run');
import path = require('path');

let taskPath = path.join(__dirname, '..', 'ftpuploadtask.js');
let tr: tmrm.TaskMockRunner = new tmrm.TaskMockRunner(taskPath);

tr.setInput('credsType', 'inputs');
tr.setInput('serverUrl', 'ftps://');
tr.setInput('username', 'username');
tr.setInput('password', 'password');
tr.setInput('rootFolder', 'rootFolder');
tr.setInput('filePatterns', '**');
tr.setInput('remotePath', '/upload/');
tr.setInput('clean', 'true');
tr.setInput('overwrite', 'true');
tr.setInput('preservePaths', 'true');
tr.setInput('trustSSL', 'true');
process.env["ENDPOINT_URL_ID1"] = "ftp://valid.microsoft.com";
process.env["ENDPOINT_AUTH_ID1"] = "{\"scheme\":\"UsernamePassword\", \"parameters\": {\"username\": \"uname\", \"password\": \"pword\"}}";
process.env["build.sourcesDirectory"] = "/";

// provide answers for task mock
let a: ma.TaskLibAnswers = <ma.TaskLibAnswers>{
"exist": {
"rootFolder": true
},
"find": {
"rootFolder": [
]
},
"match": {
"*": [
]
}
};
tr.setAnswers(a);

tr.run();
45 changes: 45 additions & 0 deletions Tasks/FtpUploadV2/Tests/L0NoHostName.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import ma = require('azure-pipelines-task-lib/mock-answer');
import tmrm = require('azure-pipelines-task-lib/mock-run');
import path = require('path');

let taskPath = path.join(__dirname, '..', 'ftpuploadtask.js');
let tr: tmrm.TaskMockRunner = new tmrm.TaskMockRunner(taskPath);

tr.setInput('credsType', 'inputs');
tr.setInput('serverUrl', 'ftps://');
tr.setInput('username', 'username');
tr.setInput('password', 'password');
tr.setInput('rootFolder', 'rootFolder');
tr.setInput('filePatterns', '**');
tr.setInput('remotePath', '/upload/');
tr.setInput('clean', 'true');
tr.setInput('overwrite', 'true');
tr.setInput('preservePaths', 'true');
tr.setInput('trustSSL', 'true');
process.env["ENDPOINT_URL_ID1"] = "ftp://valid.microsoft.com";
process.env["ENDPOINT_AUTH_ID1"] = "{\"scheme\":\"UsernamePassword\", \"parameters\": {\"username\": \"uname\", \"password\": \"pword\"}}";
process.env["build.sourcesDirectory"] = "/";

// provide answers for task mock
let a: ma.TaskLibAnswers = <ma.TaskLibAnswers>{
"exist": {
"rootFolder": true
},
"find": {
"rootFolder": [
"rootFolder/a",
"rootFolder/b",
"rootFolder/c"
]
},
"match": {
"*": [
"rootFolder/a",
"rootFolder/b",
"rootFolder/c"
]
}
};
tr.setAnswers(a);

tr.run();
41 changes: 41 additions & 0 deletions Tasks/FtpUploadV2/Tests/L0NoPreservePaths.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import ma = require('azure-pipelines-task-lib/mock-answer');
import tmrm = require('azure-pipelines-task-lib/mock-run');
import path = require('path');

let taskPath = path.join(__dirname, '..', 'ftpuploadtask.js');
let tr: tmrm.TaskMockRunner = new tmrm.TaskMockRunner(taskPath);

tr.setInput('serverEndpoint', 'ID1');
tr.setInput('credsType', 'serviceEndpoint');
process.env["ENDPOINT_URL_ID1"] = "ftp://valid.microsoft.com";
process.env["ENDPOINT_AUTH_ID1"] = "{\"scheme\":\"UsernamePassword\", \"parameters\": {\"username\": \"uname\", \"password\": \"pword\"}}";
process.env["build.sourcesDirectory"] = "/";
tr.setInput('rootFolder', 'rootFolder');
tr.setInput('filePatterns', '**');
tr.setInput('remotePath', '/upload/');
tr.setInput('clean', 'true');
tr.setInput('overwrite', 'true');

// provide answers for task mock
let a: ma.TaskLibAnswers = <ma.TaskLibAnswers>{
"exist": {
"rootFolder": true
},
"find": {
"rootFolder": [
"rootFolder/a",
"rootFolder/b",
"rootFolder/c"
]
},
"match": {
"*": [
"rootFolder/a",
"rootFolder/b",
"rootFolder/c"
]
}
};
tr.setAnswers(a);

tr.run();
45 changes: 45 additions & 0 deletions Tasks/FtpUploadV2/Tests/L0NoProtocol.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import ma = require('azure-pipelines-task-lib/mock-answer');
import tmrm = require('azure-pipelines-task-lib/mock-run');
import path = require('path');

let taskPath = path.join(__dirname, '..', 'ftpuploadtask.js');
let tr: tmrm.TaskMockRunner = new tmrm.TaskMockRunner(taskPath);

tr.setInput('credsType', 'inputs');
tr.setInput('serverUrl', 'noprotocol.microsoft.com');
tr.setInput('username', 'myUsername');
tr.setInput('password', 'myPassword');
tr.setInput('rootFolder', 'rootFolder');
tr.setInput('filePatterns', '**');
tr.setInput('remotePath', '/upload/');
tr.setInput('clean', 'true');
tr.setInput('overwrite', 'true');
tr.setInput('preservePaths', 'true');
tr.setInput('trustSSL', 'true');
process.env["ENDPOINT_URL_ID1"] = "ftp://valid.microsoft.com";
process.env["ENDPOINT_AUTH_ID1"] = "{\"scheme\":\"UsernamePassword\", \"parameters\": {\"username\": \"uname\", \"password\": \"pword\"}}";
process.env["build.sourcesDirectory"] = "/";

// provide answers for task mock
let a: ma.TaskLibAnswers = <ma.TaskLibAnswers>{
"exist": {
"rootFolder": true
},
"find": {
"rootFolder": [
"rootFolder/a",
"rootFolder/b",
"rootFolder/c"
]
},
"match": {
"*": [
"rootFolder/a",
"rootFolder/b",
"rootFolder/c"
]
}
};
tr.setAnswers(a);

tr.run();
Loading