-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FtpUploadV2] Resolve dependabot alert about shelljs (#15881)
* 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
1 parent
81594a9
commit 82f0b6a
Showing
19 changed files
with
1,031 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
Oops, something went wrong.