Skip to content

Commit

Permalink
[FtpUploadV2] Resolve dependabot alert about shelljs (#15881)
Browse files Browse the repository at this point in the history
* fix dependencies

* fix build

build error are caused by tasklib 3.x return types change from "<type>" to "<type> | undefined"
functionally, these method calls should be identical

* bump task version

* Add simple unit tests to check getting input parameters and start of task

* Delete debug

* Fix EOL

* Updated task version to 201

* Added test for successful execution

Co-authored-by: Tatyana Kostromskaya (Akvelon) <[email protected]>
Co-authored-by: Tatyana Kostromskaya <[email protected]>
Co-authored-by: Denis Tikhomirov <[email protected]>
Co-authored-by: Denis Tikhomirov <[email protected]>
Co-authored-by: Anatoly Bolshakov <[email protected]>
  • Loading branch information
6 people authored Feb 21, 2022
1 parent 81594a9 commit 82f0b6a
Show file tree
Hide file tree
Showing 19 changed files with 1,031 additions and 37 deletions.
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');

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

0 comments on commit 82f0b6a

Please sign in to comment.