azure-pipelines-tasks-webdeployment-common 4.230.1 → 4.230.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/Tests/L0.d.ts +1 -0
  2. package/Tests/L0.js +25 -0
  3. package/Tests/L0.ts +24 -0
  4. package/Tests/L0CopyDirectory.d.ts +1 -5
  5. package/Tests/L0CopyDirectory.js +89 -51
  6. package/Tests/L0CopyDirectory.ts +93 -55
  7. package/Tests/L0GenerateWebConfig.d.ts +1 -2
  8. package/Tests/L0GenerateWebConfig.js +55 -24
  9. package/Tests/L0GenerateWebConfig.ts +51 -31
  10. package/Tests/L0MSDeployUtility.d.ts +2 -16
  11. package/Tests/L0MSDeployUtility.js +91 -97
  12. package/Tests/L0MSDeployUtility.ts +89 -100
  13. package/Tests/L0ParameterParserUtility.d.ts +1 -0
  14. package/Tests/L0ParameterParserUtility.js +59 -0
  15. package/Tests/L0ParameterParserUtility.ts +65 -0
  16. package/Tests/L1JSONVarSubWithComments.d.ts +1 -1
  17. package/Tests/L1JSONVarSubWithComments.js +30 -46
  18. package/Tests/L1JSONVarSubWithComments.ts +39 -52
  19. package/Tests/L1JsonVarSub.d.ts +1 -1
  20. package/Tests/L1JsonVarSub.js +58 -66
  21. package/Tests/L1JsonVarSub.ts +67 -66
  22. package/Tests/L1JsonVarSubV2.d.ts +1 -1
  23. package/Tests/L1JsonVarSubV2.js +82 -93
  24. package/Tests/L1JsonVarSubV2.ts +82 -94
  25. package/Tests/L1ValidateFileEncoding.d.ts +2 -5
  26. package/Tests/L1ValidateFileEncoding.js +52 -65
  27. package/Tests/L1ValidateFileEncoding.ts +61 -77
  28. package/Tests/L1XdtTransform.d.ts +2 -3
  29. package/Tests/L1XdtTransform.js +48 -6
  30. package/Tests/L1XdtTransform.ts +57 -6
  31. package/Tests/L1XmlVarSub.d.ts +2 -3
  32. package/Tests/L1XmlVarSub.js +56 -20
  33. package/Tests/L1XmlVarSub.ts +81 -24
  34. package/ctt/ctt/ctt.exe +0 -0
  35. package/package.json +7 -3
  36. package/packageUtility.js +6 -5
  37. package/utility.js +1 -1
  38. package/webconfigutil.d.ts +3 -1
  39. package/xdttransformationutility.js +1 -1
@@ -1,101 +1,95 @@
1
- var msdeployUtility = require('azure-pipelines-tasks-webdeployment-common/msdeployutility.js');
2
- var errorMessages = {
3
- 'ERROR_INSUFFICIENT_ACCESS_TO_SITE_FOLDER': 'ERROR_INSUFFICIENT_ACCESS_TO_SITE_FOLDER',
4
- "An error was encountered when processing operation 'Delete Directory' on 'D:\\home\\site\\wwwroot\\app_data\\jobs\\continous'": "WebJobsInProgressIssue",
5
- "Cannot delete file main.dll. Error code: FILE_IN_USE": "FILE_IN_USE",
6
- "transport connection": "transport connection",
7
- "error code: ERROR_CONNECTION_TERMINATED": "ERROR_CONNECTION_TERMINATED"
8
- };
9
- function checkParametersIfPresent(argumentString, argumentCheckArray) {
10
- for (var argument of argumentCheckArray) {
11
- if (argumentString.indexOf(argument) == -1) {
12
- return false;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runGetWebDeployErrorCodeTests = exports.runGetMSDeployCmdArgsTests = void 0;
4
+ const assert = require("assert");
5
+ const msdeployutility_1 = require("../msdeployutility");
6
+ function runGetMSDeployCmdArgsTests() {
7
+ it('Should produce default valid args', () => {
8
+ const profile = createDefaultPublishProfile();
9
+ const args = msdeployutility_1.getMSDeployCmdArgs('package.zip', 'webapp_name', profile, true, false, true, null, null, null, true, false, false);
10
+ const expectedArgs = [
11
+ "-source:package=\"'package.zip'\"",
12
+ "-dest:auto,ComputerName=\"'https://http://webapp_name.scm.azurewebsites.net:443/msdeploy.axd?site=webapp_name'\",UserName=\"'$webapp_name'\",Password=\"'webapp_password'\",AuthType=\"'Basic'\"",
13
+ "-setParam:name=\"'IIS Web Application Name'\",value=\"'webapp_name'\"",
14
+ "-enableRule:AppOffline"
15
+ ];
16
+ const notExpectedArgs = ["-setParamFile"];
17
+ checkParametersIfPresent(args, expectedArgs);
18
+ checkParametersNotPresent(args, notExpectedArgs);
19
+ });
20
+ it('Should produce valid args with token auth', () => {
21
+ const profile = createDefaultPublishProfile();
22
+ const args = msdeployutility_1.getMSDeployCmdArgs('package.zip', 'webapp_name', profile, true, false, true, null, null, null, true, false, false, "Bearer");
23
+ checkParametersIfPresent(args, ["AuthType=\"'Bearer'\""]);
24
+ });
25
+ it('Should produce valid args with parameter file', () => {
26
+ const profile = createDefaultPublishProfile();
27
+ const args = msdeployutility_1.getMSDeployCmdArgs('package.zip', 'webapp_name', profile, false, false, true, null, 'temp_param.xml', null, false, false, true);
28
+ const expectedArgs = ['-setParamFile=temp_param.xml', "-dest:contentPath=\"'webapp_name'\"", '-enableRule:DoNotDelete'];
29
+ checkParametersIfPresent(args, expectedArgs);
30
+ });
31
+ it('Should produce valid args with folder package', () => {
32
+ const profile = createDefaultPublishProfile();
33
+ const args = msdeployutility_1.getMSDeployCmdArgs('c:/package/folder', 'webapp_name', profile, true, false, true, null, null, null, true, true, true);
34
+ const expectedArgs = [
35
+ "-source:IisApp=\"'c:/package/folder'\"",
36
+ " -dest:iisApp=\"'webapp_name'\""
37
+ ];
38
+ checkParametersIfPresent(args, expectedArgs);
39
+ });
40
+ it('Should produce valid args with exclude data', () => {
41
+ const profile = createDefaultPublishProfile();
42
+ const args = msdeployutility_1.getMSDeployCmdArgs('package.zip', 'webapp_name', profile, false, true, true, null, null, null, false, false, true);
43
+ checkParametersIfPresent(args, ['-skip:Directory=App_Data']);
44
+ });
45
+ it("Should produce valid args with war file", () => {
46
+ const profile = createDefaultPublishProfile();
47
+ const args = msdeployutility_1.getMSDeployCmdArgs('package.war', 'webapp_name', profile, false, true, true, null, null, null, false, false, true);
48
+ checkParametersIfPresent(args, [
49
+ " -source:contentPath=\"'package.war'\"",
50
+ " -dest:contentPath=\"'/site/webapps/package.war'\""
51
+ ]);
52
+ });
53
+ it("Should override retry arguments", () => {
54
+ const profile = createDefaultPublishProfile();
55
+ const args = msdeployutility_1.getMSDeployCmdArgs('package.zip', 'webapp_name', profile, false, true, true, null, null, '-retryAttempts:11 -retryInterval:5000', false, false, true);
56
+ checkParametersIfPresent(args, ['-retryAttempts:11', '-retryInterval:5000']);
57
+ });
58
+ function checkParametersIfPresent(argumentString, argumentCheckArray) {
59
+ for (const argument of argumentCheckArray) {
60
+ if (argumentString.indexOf(argument) === -1) {
61
+ assert.strictEqual(argumentString.indexOf(argument), -1, `Argument ${argument} not found in ${argumentString}`);
62
+ }
13
63
  }
14
64
  }
15
- return true;
16
- }
17
- var defaultMSBuildPackageArgument = msdeployUtility.getMSDeployCmdArgs('package.zip', 'webapp_name', {
18
- publishUrl: 'http://webapp_name.scm.azurewebsites.net:443', userName: '$webapp_name', userPWD: 'webapp_password'
19
- }, true, false, true, null, null, null, true, false, false);
20
- console.log(` * MSBUILD DEFAULT PARAMS: ${defaultMSBuildPackageArgument}`);
21
- if (checkParametersIfPresent(defaultMSBuildPackageArgument, ["-source:package=\"'package.zip'\"",
22
- " -dest:auto,ComputerName=\"'https://http://webapp_name.scm.azurewebsites.net:443/msdeploy.axd?site=webapp_name'\",UserName=\"'$webapp_name'\",Password=\"'webapp_password'\",AuthType=\"'Basic'\"",
23
- " -setParam:name=\"'IIS Web Application Name'\",value=\"'webapp_name'\"", '-enableRule:AppOffline']) && defaultMSBuildPackageArgument.indexOf('-setParamFile') == -1) {
24
- console.log("MSBUILD DEFAULT PARAMS PASSED");
25
- }
26
- else {
27
- throw new Error('MSBUILD PACKAGE DEFAULT PARAMS FAILED');
28
- }
29
- var tokenAuthMSBuildPackageArgument = msdeployUtility.getMSDeployCmdArgs('package.zip', 'webapp_name', {
30
- publishUrl: 'publishUrl', userName: 'user', userPWD: 'token'
31
- }, true, false, true, null, null, null, true, false, false, "Bearer");
32
- console.log(` * MSBUILD TOKEN AUTH PARAMS: ${tokenAuthMSBuildPackageArgument}`);
33
- if (checkParametersIfPresent(tokenAuthMSBuildPackageArgument, ["AuthType=\"'Bearer'\""])) {
34
- console.log("MSBUILD TOKEN AUTH PARAMS PASSED");
35
- }
36
- else {
37
- throw new Error('MSBUILD TOKEN AUTH PARAMS FAILED');
38
- }
39
- var packageWithSetParamArgument = msdeployUtility.getMSDeployCmdArgs('package.zip', 'webapp_name', {
40
- publishUrl: 'http://webapp_name.scm.azurewebsites.net:443', userName: '$webapp_name', userPWD: 'webapp_password'
41
- }, false, false, true, null, 'temp_param.xml', null, false, false, true);
42
- console.log(` * PACKAGE WITh SET PARAMS: ${packageWithSetParamArgument}`);
43
- if (checkParametersIfPresent(packageWithSetParamArgument, ['-setParamFile=temp_param.xml', "-dest:contentPath=\"'webapp_name'\"", '-enableRule:DoNotDelete'])) {
44
- console.log('ARGUMENTS WITH SET PARAMS PASSED');
45
- }
46
- else {
47
- throw Error('ARGUMENTS WITH SET PARAMS FAILED');
48
- }
49
- var folderPackageArgument = msdeployUtility.getMSDeployCmdArgs('c:/package/folder', 'webapp_name', {
50
- publishUrl: 'http://webapp_name.scm.azurewebsites.net:443', userName: '$webapp_name', userPWD: 'webapp_password'
51
- }, true, false, true, null, null, null, true, true, true);
52
- console.log(` * ARGUMENT WITh FOLDER AS PACKAGE: ${folderPackageArgument}`);
53
- if (checkParametersIfPresent(folderPackageArgument, [
54
- "-source:IisApp=\"'c:/package/folder'\"",
55
- " -dest:iisApp=\"'webapp_name'\""
56
- ])) {
57
- console.log('ARGUMENT WITH FOLDER PACKAGE PASSED');
58
- }
59
- else {
60
- throw Error('ARGUMENT WITH FOLDER PACKAGE FAILED');
61
- }
62
- var packageWithExcludeAppDataArgument = msdeployUtility.getMSDeployCmdArgs('package.zip', 'webapp_name', {
63
- publishUrl: 'http://webapp_name.scm.azurewebsites.net:443', userName: '$webapp_name', userPWD: 'webapp_password'
64
- }, false, true, true, null, null, null, false, false, true);
65
- console.log(` * ARGUMENT WITh FOLDER AS PACKAGE: ${packageWithExcludeAppDataArgument}`);
66
- if (checkParametersIfPresent(packageWithExcludeAppDataArgument, ['-skip:Directory=App_Data'])) {
67
- console.log('ARGUMENT WITH EXCLUDE APP DATA PASSED');
68
- }
69
- else {
70
- throw new Error('ARGUMENT WITH EXCLUDE APP DATA FAILED');
71
- }
72
- var warDeploymentArgument = msdeployUtility.getMSDeployCmdArgs('package.war', 'webapp_name', {
73
- publishUrl: 'http://webapp_name.scm.azurewebsites.net:443', userName: '$webapp_name', userPWD: 'webapp_password'
74
- }, false, true, true, null, null, null, false, false, true);
75
- console.log(` * ARGUMENT WITh WAR FILE AS PACKAGE: ${warDeploymentArgument}`);
76
- if (checkParametersIfPresent(warDeploymentArgument, [
77
- " -source:contentPath=\"'package.war'\"",
78
- " -dest:contentPath=\"'/site/webapps/package.war'\""
79
- ])) {
80
- console.log('ARGUMENT WITH WAR PACKAGE PASSED');
81
- }
82
- else {
83
- throw new Error('ARGUMENT WITH WAR PACKAGE FAILED');
84
- }
85
- var overrideRetryArgument = msdeployUtility.getMSDeployCmdArgs('package.zip', 'webapp_name', {
86
- publishUrl: 'http://webapp_name.scm.azurewebsites.net:443', userName: '$webapp_name', userPWD: 'webapp_password'
87
- }, false, true, true, null, null, '-retryAttempts:11 -retryInterval:5000', false, false, true);
88
- console.log(` * ARGUMENTS WITH WAR FILE: ${overrideRetryArgument}`);
89
- if (checkParametersIfPresent(overrideRetryArgument, ['-retryAttempts:11', '-retryInterval:5000'])) {
90
- console.log('ARGUMENT WITH OVERRIDE RETRY FLAG PASSED');
91
- }
92
- else {
93
- throw new Error('ARGUMENT WITH OVERRIDE RETRY FLAG FAILED');
94
- }
95
- // msdeployutility getWebDeployErrorCode
96
- for (var errorMessage in errorMessages) {
97
- if (msdeployUtility.getWebDeployErrorCode(errorMessage) != errorMessages[errorMessage]) {
98
- throw new Error('MSDEPLOY getWebDeployErrorCode failed');
65
+ function checkParametersNotPresent(argumentString, argumentCheckArray) {
66
+ for (var argument of argumentCheckArray) {
67
+ if (argumentString.indexOf(argument) !== -1) {
68
+ assert.strictEqual(argumentString.indexOf(argument), -1, `Argument ${argument} found in ${argumentString}`);
69
+ }
70
+ }
71
+ }
72
+ function createDefaultPublishProfile() {
73
+ return {
74
+ publishUrl: 'http://webapp_name.scm.azurewebsites.net:443',
75
+ userName: '$webapp_name',
76
+ userPWD: 'webapp_password'
77
+ };
99
78
  }
100
79
  }
101
- console.log('MSDEPLOY getWebDeployErrorCode passed');
80
+ exports.runGetMSDeployCmdArgsTests = runGetMSDeployCmdArgsTests;
81
+ function runGetWebDeployErrorCodeTests() {
82
+ it("Should return proper error messages", () => {
83
+ const errorMessages = {
84
+ 'ERROR_INSUFFICIENT_ACCESS_TO_SITE_FOLDER': 'ERROR_INSUFFICIENT_ACCESS_TO_SITE_FOLDER',
85
+ "An error was encountered when processing operation 'Delete Directory' on 'D:\\home\\site\\wwwroot\\app_data\\jobs\\continous'": "WebJobsInProgressIssue",
86
+ "Cannot delete file main.dll. Error code: FILE_IN_USE": "FILE_IN_USE",
87
+ "transport connection": "transport connection",
88
+ "error code: ERROR_CONNECTION_TERMINATED": "ERROR_CONNECTION_TERMINATED"
89
+ };
90
+ for (var errorMessage in errorMessages) {
91
+ assert.strictEqual(msdeployutility_1.getWebDeployErrorCode(errorMessage), errorMessages[errorMessage]);
92
+ }
93
+ });
94
+ }
95
+ exports.runGetWebDeployErrorCodeTests = runGetWebDeployErrorCodeTests;
@@ -1,128 +1,117 @@
1
- var msdeployUtility = require('azure-pipelines-tasks-webdeployment-common/msdeployutility.js');
2
-
3
- var errorMessages = {
4
- 'ERROR_INSUFFICIENT_ACCESS_TO_SITE_FOLDER': 'ERROR_INSUFFICIENT_ACCESS_TO_SITE_FOLDER',
5
- "An error was encountered when processing operation 'Delete Directory' on 'D:\\home\\site\\wwwroot\\app_data\\jobs\\continous'": "WebJobsInProgressIssue",
6
- "Cannot delete file main.dll. Error code: FILE_IN_USE": "FILE_IN_USE",
7
- "transport connection": "transport connection",
8
- "error code: ERROR_CONNECTION_TERMINATED": "ERROR_CONNECTION_TERMINATED"
9
- }
1
+ import assert = require("assert");
2
+ import { getMSDeployCmdArgs, getWebDeployErrorCode } from "../msdeployutility";
10
3
 
11
- function checkParametersIfPresent(argumentString: string, argumentCheckArray: Array<string>) {
12
- for(var argument of argumentCheckArray) {
13
- if(argumentString.indexOf(argument) == -1) {
14
- return false;
15
- }
16
- }
4
+ export function runGetMSDeployCmdArgsTests() {
17
5
 
18
- return true;
19
- }
6
+ it('Should produce default valid args', () => {
7
+ const profile = createDefaultPublishProfile();
8
+ const args = getMSDeployCmdArgs('package.zip', 'webapp_name', profile, true, false, true, null, null, null, true, false, false);
20
9
 
21
- var defaultMSBuildPackageArgument: string = msdeployUtility.getMSDeployCmdArgs('package.zip', 'webapp_name', {
22
- publishUrl: 'http://webapp_name.scm.azurewebsites.net:443', userName: '$webapp_name', userPWD: 'webapp_password'
23
- }, true, false, true, null, null, null, true, false, false);
10
+ const expectedArgs = [
11
+ "-source:package=\"'package.zip'\"",
12
+ "-dest:auto,ComputerName=\"'https://http://webapp_name.scm.azurewebsites.net:443/msdeploy.axd?site=webapp_name'\",UserName=\"'$webapp_name'\",Password=\"'webapp_password'\",AuthType=\"'Basic'\"",
13
+ "-setParam:name=\"'IIS Web Application Name'\",value=\"'webapp_name'\"",
14
+ "-enableRule:AppOffline"];
24
15
 
25
- console.log(` * MSBUILD DEFAULT PARAMS: ${defaultMSBuildPackageArgument}`);
26
- if(checkParametersIfPresent(defaultMSBuildPackageArgument, ["-source:package=\"'package.zip'\"",
27
- " -dest:auto,ComputerName=\"'https://http://webapp_name.scm.azurewebsites.net:443/msdeploy.axd?site=webapp_name'\",UserName=\"'$webapp_name'\",Password=\"'webapp_password'\",AuthType=\"'Basic'\"",
28
- " -setParam:name=\"'IIS Web Application Name'\",value=\"'webapp_name'\"", '-enableRule:AppOffline']) && defaultMSBuildPackageArgument.indexOf('-setParamFile') == -1) {
29
- console.log("MSBUILD DEFAULT PARAMS PASSED");
30
- }
31
- else {
32
- throw new Error('MSBUILD PACKAGE DEFAULT PARAMS FAILED');
33
- }
16
+ const notExpectedArgs = ["-setParamFile"];
34
17
 
35
- var tokenAuthMSBuildPackageArgument: string = msdeployUtility.getMSDeployCmdArgs('package.zip', 'webapp_name', {
36
- publishUrl: 'publishUrl', userName: 'user', userPWD: 'token'
37
- }, true, false, true, null, null, null, true, false, false, "Bearer");
18
+ checkParametersIfPresent(args, expectedArgs);
19
+ checkParametersNotPresent(args, notExpectedArgs);
20
+ });
38
21
 
39
- console.log(` * MSBUILD TOKEN AUTH PARAMS: ${tokenAuthMSBuildPackageArgument}`);
40
- if(checkParametersIfPresent(tokenAuthMSBuildPackageArgument, ["AuthType=\"'Bearer'\""])) {
41
- console.log("MSBUILD TOKEN AUTH PARAMS PASSED");
42
- }
43
- else {
44
- throw new Error('MSBUILD TOKEN AUTH PARAMS FAILED');
45
- }
46
22
 
23
+ it('Should produce valid args with token auth', () => {
24
+ const profile = createDefaultPublishProfile();
25
+ const args = getMSDeployCmdArgs('package.zip', 'webapp_name', profile, true, false, true, null, null, null, true, false, false, "Bearer");
26
+ checkParametersIfPresent(args, ["AuthType=\"'Bearer'\""]);
27
+ });
47
28
 
48
- var packageWithSetParamArgument: string = msdeployUtility.getMSDeployCmdArgs('package.zip', 'webapp_name', {
49
- publishUrl: 'http://webapp_name.scm.azurewebsites.net:443', userName: '$webapp_name', userPWD: 'webapp_password'
50
- }, false, false, true, null, 'temp_param.xml', null, false, false, true);
51
29
 
30
+ it('Should produce valid args with parameter file', () => {
31
+ const profile = createDefaultPublishProfile();
32
+ const args = getMSDeployCmdArgs('package.zip', 'webapp_name', profile, false, false, true, null, 'temp_param.xml', null, false, false, true);
52
33
 
53
- console.log(` * PACKAGE WITh SET PARAMS: ${packageWithSetParamArgument}`);
34
+ const expectedArgs = ['-setParamFile=temp_param.xml', "-dest:contentPath=\"'webapp_name'\"", '-enableRule:DoNotDelete'];
35
+ checkParametersIfPresent(args, expectedArgs);
36
+ });
54
37
 
55
38
 
56
- if(checkParametersIfPresent(packageWithSetParamArgument, ['-setParamFile=temp_param.xml', "-dest:contentPath=\"'webapp_name'\"" , '-enableRule:DoNotDelete'])) {
57
- console.log('ARGUMENTS WITH SET PARAMS PASSED');
58
- }
59
- else {
60
- throw Error('ARGUMENTS WITH SET PARAMS FAILED');
61
- }
39
+ it('Should produce valid args with folder package', () => {
62
40
 
63
- var folderPackageArgument: string = msdeployUtility.getMSDeployCmdArgs('c:/package/folder', 'webapp_name', {
64
- publishUrl: 'http://webapp_name.scm.azurewebsites.net:443', userName: '$webapp_name', userPWD: 'webapp_password'
65
- }, true, false, true, null, null, null, true, true, true);
41
+ const profile = createDefaultPublishProfile();
42
+ const args: string = getMSDeployCmdArgs('c:/package/folder', 'webapp_name', profile, true, false, true, null, null, null, true, true, true);
66
43
 
67
- console.log(` * ARGUMENT WITh FOLDER AS PACKAGE: ${folderPackageArgument}`);
68
- if(checkParametersIfPresent(folderPackageArgument, [
69
- "-source:IisApp=\"'c:/package/folder'\"",
70
- " -dest:iisApp=\"'webapp_name'\""
71
- ])) {
72
- console.log('ARGUMENT WITH FOLDER PACKAGE PASSED');
73
- }
74
- else {
75
- throw Error('ARGUMENT WITH FOLDER PACKAGE FAILED');
76
- }
44
+ const expectedArgs = [
45
+ "-source:IisApp=\"'c:/package/folder'\"",
46
+ " -dest:iisApp=\"'webapp_name'\""
47
+ ];
48
+ checkParametersIfPresent(args, expectedArgs);
49
+ });
77
50
 
78
51
 
79
- var packageWithExcludeAppDataArgument: string = msdeployUtility.getMSDeployCmdArgs('package.zip', 'webapp_name', {
80
- publishUrl: 'http://webapp_name.scm.azurewebsites.net:443', userName: '$webapp_name', userPWD: 'webapp_password'
81
- }, false, true, true, null, null, null, false, false, true);
52
+ it('Should produce valid args with exclude data', () => {
53
+ const profile = createDefaultPublishProfile();
54
+ const args: string = getMSDeployCmdArgs('package.zip', 'webapp_name', profile, false, true, true, null, null, null, false, false, true);
82
55
 
83
- console.log(` * ARGUMENT WITh FOLDER AS PACKAGE: ${packageWithExcludeAppDataArgument}`);
56
+ checkParametersIfPresent(args, ['-skip:Directory=App_Data']);
57
+ });
84
58
 
85
- if(checkParametersIfPresent(packageWithExcludeAppDataArgument, ['-skip:Directory=App_Data'])) {
86
- console.log('ARGUMENT WITH EXCLUDE APP DATA PASSED');
87
- }
88
- else {
89
- throw new Error('ARGUMENT WITH EXCLUDE APP DATA FAILED');
90
- }
91
59
 
60
+ it("Should produce valid args with war file", () => {
61
+ const profile = createDefaultPublishProfile();
62
+ const args = getMSDeployCmdArgs('package.war', 'webapp_name', profile, false, true, true, null, null, null, false, false, true);
92
63
 
93
- var warDeploymentArgument: string = msdeployUtility.getMSDeployCmdArgs('package.war', 'webapp_name', {
94
- publishUrl: 'http://webapp_name.scm.azurewebsites.net:443', userName: '$webapp_name', userPWD: 'webapp_password'
95
- }, false, true, true, null, null, null, false, false, true);
64
+ checkParametersIfPresent(args, [
65
+ " -source:contentPath=\"'package.war'\"",
66
+ " -dest:contentPath=\"'/site/webapps/package.war'\""
67
+ ]);
68
+ });
96
69
 
97
- console.log(` * ARGUMENT WITh WAR FILE AS PACKAGE: ${warDeploymentArgument}`);
98
- if(checkParametersIfPresent(warDeploymentArgument, [
99
- " -source:contentPath=\"'package.war'\"",
100
- " -dest:contentPath=\"'/site/webapps/package.war'\""
101
- ])) {
102
- console.log('ARGUMENT WITH WAR PACKAGE PASSED');
103
- }
104
- else {
105
- throw new Error('ARGUMENT WITH WAR PACKAGE FAILED');
106
- }
70
+ it("Should override retry arguments", () => {
71
+ const profile = createDefaultPublishProfile();
72
+ const args = getMSDeployCmdArgs('package.zip', 'webapp_name', profile, false, true, true, null, null, '-retryAttempts:11 -retryInterval:5000', false, false, true);
107
73
 
108
- var overrideRetryArgument: string = msdeployUtility.getMSDeployCmdArgs('package.zip', 'webapp_name', {
109
- publishUrl: 'http://webapp_name.scm.azurewebsites.net:443', userName: '$webapp_name', userPWD: 'webapp_password'
110
- }, false, true, true, null, null, '-retryAttempts:11 -retryInterval:5000', false, false, true);
74
+ checkParametersIfPresent(args, ['-retryAttempts:11', '-retryInterval:5000']);
75
+ });
111
76
 
112
- console.log(` * ARGUMENTS WITH WAR FILE: ${overrideRetryArgument}`);
77
+ function checkParametersIfPresent(argumentString: string, argumentCheckArray: string[]): void {
78
+ for (const argument of argumentCheckArray) {
79
+ if (argumentString.indexOf(argument) === -1) {
80
+ assert.strictEqual(argumentString.indexOf(argument), -1, `Argument ${argument} not found in ${argumentString}`);
81
+ }
82
+ }
83
+ }
113
84
 
114
- if(checkParametersIfPresent(overrideRetryArgument, ['-retryAttempts:11', '-retryInterval:5000'])) {
115
- console.log('ARGUMENT WITH OVERRIDE RETRY FLAG PASSED');
116
- }
117
- else {
118
- throw new Error('ARGUMENT WITH OVERRIDE RETRY FLAG FAILED');
119
- }
85
+ function checkParametersNotPresent(argumentString: string, argumentCheckArray: string[]): void {
86
+ for (var argument of argumentCheckArray) {
87
+ if (argumentString.indexOf(argument) !== -1) {
88
+ assert.strictEqual(argumentString.indexOf(argument), -1, `Argument ${argument} found in ${argumentString}`);
89
+ }
90
+ }
91
+ }
120
92
 
121
- // msdeployutility getWebDeployErrorCode
122
- for(var errorMessage in errorMessages) {
123
- if(msdeployUtility.getWebDeployErrorCode(errorMessage) != errorMessages[errorMessage]) {
124
- throw new Error('MSDEPLOY getWebDeployErrorCode failed');
93
+ function createDefaultPublishProfile(): { publishUrl: string, userName: string, userPWD: string } {
94
+ return {
95
+ publishUrl: 'http://webapp_name.scm.azurewebsites.net:443',
96
+ userName: '$webapp_name',
97
+ userPWD: 'webapp_password'
98
+ };
125
99
  }
126
100
  }
127
101
 
128
- console.log('MSDEPLOY getWebDeployErrorCode passed');
102
+ export function runGetWebDeployErrorCodeTests(): void {
103
+ it("Should return proper error messages", () => {
104
+
105
+ const errorMessages = {
106
+ 'ERROR_INSUFFICIENT_ACCESS_TO_SITE_FOLDER': 'ERROR_INSUFFICIENT_ACCESS_TO_SITE_FOLDER',
107
+ "An error was encountered when processing operation 'Delete Directory' on 'D:\\home\\site\\wwwroot\\app_data\\jobs\\continous'": "WebJobsInProgressIssue",
108
+ "Cannot delete file main.dll. Error code: FILE_IN_USE": "FILE_IN_USE",
109
+ "transport connection": "transport connection",
110
+ "error code: ERROR_CONNECTION_TERMINATED": "ERROR_CONNECTION_TERMINATED"
111
+ }
112
+
113
+ for (var errorMessage in errorMessages) {
114
+ assert.strictEqual(getWebDeployErrorCode(errorMessage), errorMessages[errorMessage]);
115
+ }
116
+ });
117
+ }
@@ -0,0 +1 @@
1
+ export declare function runParameterParserUtilityTests(): void;
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runParameterParserUtilityTests = void 0;
4
+ const assert = require("assert");
5
+ const ParameterParserUtility_1 = require("../ParameterParserUtility");
6
+ function runParameterParserUtilityTests() {
7
+ it("Should parse parameters", () => {
8
+ const paramString = "-port 8080 -Release.ReleaseName Release-1173";
9
+ const expectedJSON = {
10
+ "port": {
11
+ value: "8080"
12
+ },
13
+ "Release.ReleaseName": {
14
+ value: "Release-1173"
15
+ }
16
+ };
17
+ const result = ParameterParserUtility_1.parse(paramString);
18
+ assert.deepStrictEqual(result, expectedJSON);
19
+ });
20
+ it("Should parse parameters with empty values", () => {
21
+ const paramString = "-port 8080 -ErrorCode -ErrorMessage -Release.ReleaseName Release-1173";
22
+ const expectedJSON = {
23
+ "port": {
24
+ value: "8080"
25
+ },
26
+ "ErrorCode": {
27
+ value: ""
28
+ },
29
+ "ErrorMessage": {
30
+ value: ""
31
+ },
32
+ "Release.ReleaseName": {
33
+ value: "Release-1173"
34
+ }
35
+ };
36
+ const result = ParameterParserUtility_1.parse(paramString);
37
+ assert.deepStrictEqual(result, expectedJSON);
38
+ });
39
+ it("Should parse parameters with extra spaces", () => {
40
+ const paramString = "-port 8080 -ErrorCode -ErrorMessage -Release.ReleaseName Release-1173";
41
+ const expectedJSON = {
42
+ "port": {
43
+ value: "8080"
44
+ },
45
+ "ErrorCode": {
46
+ value: ""
47
+ },
48
+ "ErrorMessage": {
49
+ value: ""
50
+ },
51
+ "Release.ReleaseName": {
52
+ value: "Release-1173"
53
+ }
54
+ };
55
+ const result = ParameterParserUtility_1.parse(paramString);
56
+ assert.deepStrictEqual(result, expectedJSON);
57
+ });
58
+ }
59
+ exports.runParameterParserUtilityTests = runParameterParserUtilityTests;
@@ -0,0 +1,65 @@
1
+ import assert = require('assert');
2
+ import { parse } from '../ParameterParserUtility';
3
+
4
+ export function runParameterParserUtilityTests(): void {
5
+
6
+ it("Should parse parameters", () => {
7
+ const paramString = "-port 8080 -Release.ReleaseName Release-1173";
8
+ const expectedJSON = {
9
+ "port": {
10
+ value: "8080"
11
+ },
12
+ "Release.ReleaseName": {
13
+ value: "Release-1173"
14
+ }
15
+ };
16
+
17
+ const result = parse(paramString);
18
+
19
+ assert.deepStrictEqual(result, expectedJSON);
20
+ });
21
+
22
+ it("Should parse parameters with empty values", () => {
23
+ const paramString = "-port 8080 -ErrorCode -ErrorMessage -Release.ReleaseName Release-1173";
24
+ const expectedJSON = {
25
+ "port": {
26
+ value: "8080"
27
+ },
28
+ "ErrorCode": {
29
+ value: ""
30
+ },
31
+ "ErrorMessage": {
32
+ value: ""
33
+ },
34
+ "Release.ReleaseName": {
35
+ value: "Release-1173"
36
+ }
37
+ };
38
+
39
+ const result = parse(paramString);
40
+
41
+ assert.deepStrictEqual(result, expectedJSON);
42
+ });
43
+
44
+ it("Should parse parameters with extra spaces", () => {
45
+ const paramString = "-port 8080 -ErrorCode -ErrorMessage -Release.ReleaseName Release-1173";
46
+ const expectedJSON = {
47
+ "port": {
48
+ value: "8080"
49
+ },
50
+ "ErrorCode": {
51
+ value: ""
52
+ },
53
+ "ErrorMessage": {
54
+ value: ""
55
+ },
56
+ "Release.ReleaseName": {
57
+ value: "Release-1173"
58
+ }
59
+ };
60
+
61
+ const result = parse(paramString);
62
+
63
+ assert.deepStrictEqual(result, expectedJSON);
64
+ });
65
+ }
@@ -1 +1 @@
1
- export declare function validate(): void;
1
+ export declare function runL1JSONVarSubWithCommentsTests(): void;
@@ -1,51 +1,35 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validate = void 0;
4
- var jsonSubUtil = require('azure-pipelines-tasks-webdeployment-common/jsonvariablesubstitutionutility.js');
3
+ exports.runL1JSONVarSubWithCommentsTests = void 0;
5
4
  const fs = require("fs");
6
5
  const path = require("path");
7
- var envVarObject = jsonSubUtil.createEnvTree([
8
- { name: 'dataSourceBindings.0.target', value: 'AppServiceName', secret: false },
9
- { name: 'name', value: 'App Service Deploy', secret: false },
10
- { name: 'Hello.World', value: 'Hello World', secret: false },
11
- { name: 'dataSourceBindings.1.parameters.WebAppName', value: 'App Service Name params', secret: false },
12
- { name: 'messages.Invalidwebapppackageorfolderpathprovided', value: 'Invalidwebapppackageorfolderpathprovided', secret: true }
13
- ]);
14
- function validateJSONWithComments() {
15
- var fileContent = fs.readFileSync(path.join(__dirname, 'L1JSONVarSub', 'JSONWithComments.json'), 'utf-8');
16
- var jsonContent = jsonSubUtil.stripJsonComments(fileContent);
17
- var jsonObject = JSON.parse(jsonContent);
18
- jsonSubUtil.substituteJsonVariable(jsonObject, envVarObject);
19
- if (jsonObject['dataSourceBindings']['0']['target'] != 'AppServiceName') {
20
- throw new Error('JSON VAR SUB FAIL #1');
21
- }
22
- if (jsonObject['name'] != 'App Service Deploy') {
23
- throw new Error('JSON VAR SUB FAIL #2');
24
- }
25
- if (jsonObject['Hello']['World'] != 'Hello World') {
26
- throw new Error('JSON VAR SUB FAIL #3');
27
- }
28
- if (jsonObject['dataSourceBindings']['1']['parameters']['WebAppName'] != 'App Service Name params') {
29
- throw new Error('JSON VAR SUB FAIL #4');
30
- }
31
- if (jsonObject['messages']['Invalidwebapppackageorfolderpathprovided'] != 'Invalidwebapppackageorfolderpathprovided') {
32
- throw new Error('JSON VAR SUB FAIL #5');
33
- }
34
- console.log("VALID JSON COMMENTS TESTS PASSED");
6
+ const assert = require("assert");
7
+ const jsonvariablesubstitutionutility_1 = require("../jsonvariablesubstitutionutility");
8
+ function runL1JSONVarSubWithCommentsTests() {
9
+ it("Should substitute variables in JSON with comments", (done) => {
10
+ const envVarObject = jsonvariablesubstitutionutility_1.createEnvTree([
11
+ { name: 'dataSourceBindings.0.target', value: 'AppServiceName', secret: false },
12
+ { name: 'name', value: 'App Service Deploy', secret: false },
13
+ { name: 'Hello.World', value: 'Hello World', secret: false },
14
+ { name: 'dataSourceBindings.1.parameters.WebAppName', value: 'App Service Name params', secret: false },
15
+ { name: 'messages.Invalidwebapppackageorfolderpathprovided', value: 'Invalidwebapppackageorfolderpathprovided', secret: true }
16
+ ]);
17
+ const fileContent = fs.readFileSync(path.join(__dirname, 'L1JSONVarSub', 'JSONWithComments.json'), 'utf-8');
18
+ const jsonContent = jsonvariablesubstitutionutility_1.stripJsonComments(fileContent);
19
+ const jsonObject = JSON.parse(jsonContent);
20
+ jsonvariablesubstitutionutility_1.substituteJsonVariable(jsonObject, envVarObject);
21
+ assert.strictEqual(jsonObject['dataSourceBindings']['0']['target'], 'AppServiceName', 'Should have substituted target variable');
22
+ assert.strictEqual(jsonObject['name'], 'App Service Deploy', 'Should have substituted name variable');
23
+ assert.strictEqual(jsonObject['Hello']['World'], 'Hello World', 'Should have substituted Hello.World variable');
24
+ assert.strictEqual(jsonObject['dataSourceBindings']['1']['parameters']['WebAppName'], 'App Service Name params', 'Should have substituted WebAppName variable');
25
+ assert.strictEqual(jsonObject['messages']['Invalidwebapppackageorfolderpathprovided'], 'Invalidwebapppackageorfolderpathprovided', 'Should have substituted Invalidwebapppackageorfolderpathprovided variable');
26
+ done();
27
+ });
28
+ it("Should throw exception for invalid JSON with comments", (done) => {
29
+ const fileContent = fs.readFileSync(path.join(__dirname, 'L1JSONVarSub', 'InvalidJSONWithComments.json'), 'utf-8');
30
+ const jsonContent = jsonvariablesubstitutionutility_1.stripJsonComments(fileContent);
31
+ assert.throws(() => JSON.parse(jsonContent), "Parse is expected to throw an error");
32
+ done();
33
+ });
35
34
  }
36
- function validateInvalidJSONWithComments() {
37
- var fileContent = fs.readFileSync(path.join(__dirname, 'L1JSONVarSub', 'InvalidJSONWithComments.json'), 'utf-8');
38
- var jsonContent = jsonSubUtil.stripJsonComments(fileContent);
39
- try {
40
- var jsonObject = JSON.parse(jsonContent);
41
- throw new Error('JSON VAR SUB FAIL #6');
42
- }
43
- catch (error) {
44
- console.log("INVALID JSON COMMENTS TESTS PASSED");
45
- }
46
- }
47
- function validate() {
48
- validateJSONWithComments();
49
- validateInvalidJSONWithComments();
50
- }
51
- exports.validate = validate;
35
+ exports.runL1JSONVarSubWithCommentsTests = runL1JSONVarSubWithCommentsTests;