@adobe/ccweb-add-on-ssl 0.1.0

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 (90) hide show
  1. package/.c8rc.json +7 -0
  2. package/.mocharc.json +5 -0
  3. package/CODE_OF_CONDUCT.md +79 -0
  4. package/CONTRIBUTING.md +47 -0
  5. package/LICENSE +21 -0
  6. package/README.md +21 -0
  7. package/bin/run.cmd +3 -0
  8. package/bin/run.js +8 -0
  9. package/dist/AnalyticsMarkers.d.ts +35 -0
  10. package/dist/AnalyticsMarkers.d.ts.map +1 -0
  11. package/dist/AnalyticsMarkers.js +37 -0
  12. package/dist/app/CommandExecutor.d.ts +36 -0
  13. package/dist/app/CommandExecutor.d.ts.map +1 -0
  14. package/dist/app/CommandExecutor.js +25 -0
  15. package/dist/app/SSLReader.d.ts +48 -0
  16. package/dist/app/SSLReader.d.ts.map +1 -0
  17. package/dist/app/SSLReader.js +25 -0
  18. package/dist/app/SetupCommandExecutor.d.ts +64 -0
  19. package/dist/app/SetupCommandExecutor.d.ts.map +1 -0
  20. package/dist/app/SetupCommandExecutor.js +243 -0
  21. package/dist/app/WxpSSLReader.d.ts +60 -0
  22. package/dist/app/WxpSSLReader.d.ts.map +1 -0
  23. package/dist/app/WxpSSLReader.js +113 -0
  24. package/dist/app/index.d.ts +28 -0
  25. package/dist/app/index.d.ts.map +1 -0
  26. package/dist/app/index.js +28 -0
  27. package/dist/commands/setup.d.ts +54 -0
  28. package/dist/commands/setup.d.ts.map +1 -0
  29. package/dist/commands/setup.js +118 -0
  30. package/dist/config/index.d.ts +26 -0
  31. package/dist/config/index.d.ts.map +1 -0
  32. package/dist/config/index.js +26 -0
  33. package/dist/config/inversify.config.d.ts +27 -0
  34. package/dist/config/inversify.config.d.ts.map +1 -0
  35. package/dist/config/inversify.config.js +42 -0
  36. package/dist/config/inversify.types.d.ts +29 -0
  37. package/dist/config/inversify.types.d.ts.map +1 -0
  38. package/dist/config/inversify.types.js +29 -0
  39. package/dist/constants.d.ts +25 -0
  40. package/dist/constants.d.ts.map +1 -0
  41. package/dist/constants.js +25 -0
  42. package/dist/index.d.ts +28 -0
  43. package/dist/index.d.ts.map +1 -0
  44. package/dist/index.js +28 -0
  45. package/dist/models/SetupCommandOptions.d.ts +49 -0
  46. package/dist/models/SetupCommandOptions.d.ts.map +1 -0
  47. package/dist/models/SetupCommandOptions.js +53 -0
  48. package/dist/models/Types.d.ts +57 -0
  49. package/dist/models/Types.d.ts.map +1 -0
  50. package/dist/models/Types.js +40 -0
  51. package/dist/models/index.d.ts +26 -0
  52. package/dist/models/index.d.ts.map +1 -0
  53. package/dist/models/index.js +26 -0
  54. package/dist/tsconfig.tsbuildinfo +1 -0
  55. package/dist/validators/CommandValidator.d.ts +36 -0
  56. package/dist/validators/CommandValidator.d.ts.map +1 -0
  57. package/dist/validators/CommandValidator.js +25 -0
  58. package/dist/validators/SetupCommandValidator.d.ts +52 -0
  59. package/dist/validators/SetupCommandValidator.d.ts.map +1 -0
  60. package/dist/validators/SetupCommandValidator.js +94 -0
  61. package/dist/validators/index.d.ts +26 -0
  62. package/dist/validators/index.d.ts.map +1 -0
  63. package/dist/validators/index.js +26 -0
  64. package/package.json +65 -0
  65. package/src/AnalyticsMarkers.ts +36 -0
  66. package/src/app/CommandExecutor.ts +37 -0
  67. package/src/app/SSLReader.ts +51 -0
  68. package/src/app/SetupCommandExecutor.ts +310 -0
  69. package/src/app/WxpSSLReader.ts +121 -0
  70. package/src/app/index.ts +28 -0
  71. package/src/commands/setup.ts +146 -0
  72. package/src/config/index.ts +26 -0
  73. package/src/config/inversify.config.ts +49 -0
  74. package/src/config/inversify.types.ts +29 -0
  75. package/src/constants.ts +25 -0
  76. package/src/index.ts +28 -0
  77. package/src/models/SetupCommandOptions.ts +56 -0
  78. package/src/models/Types.ts +61 -0
  79. package/src/models/index.ts +26 -0
  80. package/src/test/app/SetupCommandExecutor.spec.ts +800 -0
  81. package/src/test/app/WxpSSLReader.spec.ts +244 -0
  82. package/src/test/commands/setup.spec.ts +161 -0
  83. package/src/test/data/cert/cert.pem +19 -0
  84. package/src/test/data/cert/key.pem +27 -0
  85. package/src/test/models/SetupCommandOptions.spec.ts +53 -0
  86. package/src/test/validators/SetupCommandValidator.spec.ts +168 -0
  87. package/src/validators/CommandValidator.ts +37 -0
  88. package/src/validators/SetupCommandValidator.ts +116 -0
  89. package/src/validators/index.ts +26 -0
  90. package/tsconfig.json +31 -0
@@ -0,0 +1,244 @@
1
+ /********************************************************************************
2
+ * MIT License
3
+
4
+ * © Copyright 2023 Adobe. All rights reserved.
5
+
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ ********************************************************************************/
24
+
25
+ import type { Preferences, Logger } from "@adobe/ccweb-add-on-core";
26
+ import { ADD_ON_PREFERENCES_FILE, PreferenceJson } from "@adobe/ccweb-add-on-core";
27
+ import { assert } from "chai";
28
+ import devcert from "@adobe/ccweb-add-on-devcert";
29
+ import type { Stats } from "fs-extra";
30
+ import fs from "fs-extra";
31
+ import "mocha";
32
+ import sinon from "sinon";
33
+ import type { StubbedInstance } from "ts-sinon";
34
+ import { stubInterface } from "ts-sinon";
35
+ import type { SSLReader } from "../../app/index.js";
36
+ import { WxpSSLReader } from "../../app/index.js";
37
+
38
+ describe("WxpSSLReader", () => {
39
+ let sandbox: sinon.SinonSandbox;
40
+
41
+ let preferences: StubbedInstance<Preferences>;
42
+ let logger: StubbedInstance<Logger>;
43
+ let sslReader: SSLReader;
44
+
45
+ beforeEach(() => {
46
+ sandbox = sinon.createSandbox();
47
+
48
+ preferences = stubInterface<Preferences>();
49
+ logger = stubInterface<Logger>();
50
+ sslReader = new WxpSSLReader(preferences, logger);
51
+ });
52
+
53
+ afterEach(() => {
54
+ sandbox.restore();
55
+ });
56
+
57
+ describe("isCustomSSL", () => {
58
+ it(`should return false if SSL settings are not present in '${ADD_ON_PREFERENCES_FILE}' for the provided hostname.`, async () => {
59
+ const hostname = "localhost";
60
+ const userPreference = new PreferenceJson({});
61
+
62
+ preferences.get.returns(userPreference);
63
+
64
+ const isCustomSSL = sslReader.isCustomSSL(hostname);
65
+
66
+ assert.equal(isCustomSSL, false);
67
+ });
68
+
69
+ it(`should return true if SSL settings are present in '${ADD_ON_PREFERENCES_FILE}' for the provided hostname.`, async () => {
70
+ const hostname = "localhost";
71
+ const userPreference = new PreferenceJson({
72
+ ssl: {
73
+ [hostname]: {
74
+ certificatePath: "/some-directory/localhost/ssl/certificate.cert",
75
+ keyPath: "/some-directory/localhost/ssl/private-key.key"
76
+ }
77
+ }
78
+ });
79
+
80
+ preferences.get.returns(userPreference);
81
+
82
+ const isCustomSSL = sslReader.isCustomSSL(hostname);
83
+
84
+ assert.equal(isCustomSSL, true);
85
+ });
86
+ });
87
+
88
+ describe("isWxpSSL", () => {
89
+ it("should return false if devcert SSL certificate is not present for the provided hostname.", async () => {
90
+ const hostname = "localhost";
91
+
92
+ sandbox.stub(devcert, "hasCertificateFor").withArgs(hostname).returns(false);
93
+
94
+ const isWxpSSL = sslReader.isWxpSSL(hostname);
95
+
96
+ assert.equal(isWxpSSL, false);
97
+ });
98
+
99
+ it("should return false if devcert SSL certificate is not present for the provided hostname.", async () => {
100
+ const hostname = "localhost";
101
+
102
+ sandbox.stub(devcert, "hasCertificateFor").withArgs(hostname).returns(false);
103
+
104
+ const isWxpSSL = sslReader.isWxpSSL(hostname);
105
+
106
+ assert.equal(isWxpSSL, false);
107
+ });
108
+ });
109
+
110
+ describe("read", async () => {
111
+ it("should log error and exit when SSL certificate path is invalid for manually set up SSL.", async () => {
112
+ const hostname = "localhost";
113
+
114
+ const certificatePath = "/some-directory/localhost/ssl/";
115
+ const keyPath = "/some-directory/localhost/ssl/private-key.key";
116
+ const userPreference = new PreferenceJson({
117
+ ssl: { [hostname]: { certificatePath, keyPath } }
118
+ });
119
+ preferences.get.returns(userPreference);
120
+
121
+ const existsStub = sandbox.stub(fs, "existsSync");
122
+ existsStub.withArgs(certificatePath).returns(true);
123
+ existsStub.withArgs(keyPath).returns(true);
124
+
125
+ const certificateStats = <Stats>{ isFile: () => false };
126
+ const keyStats = <Stats>{ isFile: () => true };
127
+ const lstatStub = sandbox.stub(fs, "lstatSync");
128
+ lstatStub.withArgs(certificatePath).returns(certificateStats);
129
+ lstatStub.withArgs(keyPath).returns(keyStats);
130
+
131
+ logger.error.returns();
132
+ const exitStub = sandbox.stub(process, "exit");
133
+
134
+ await sslReader.read(hostname);
135
+
136
+ assert.equal(logger.error.calledOnceWith("Invalid SSL certificate file path."), true);
137
+ assert.equal(exitStub.calledWith(1), true);
138
+ });
139
+
140
+ it("should log error and exit when SSL key path is invalid for manually set up SSL.", async () => {
141
+ const hostname = "localhost";
142
+
143
+ const certificatePath = "/some-directory/localhost/ssl/certificate.cert";
144
+ const keyPath = "/some-directory/localhost/ssl/";
145
+ const userPreference = new PreferenceJson({
146
+ ssl: { [hostname]: { certificatePath, keyPath } }
147
+ });
148
+ preferences.get.returns(userPreference);
149
+
150
+ const existsStub = sandbox.stub(fs, "existsSync");
151
+ existsStub.withArgs(certificatePath).returns(true);
152
+ existsStub.withArgs(keyPath).returns(true);
153
+
154
+ const certificateStats = <Stats>{ isFile: () => true };
155
+ const keyStats = <Stats>{ isFile: () => false };
156
+ const lstatStub = sandbox.stub(fs, "lstatSync");
157
+ lstatStub.withArgs(certificatePath).returns(certificateStats);
158
+ lstatStub.withArgs(keyPath).returns(keyStats);
159
+
160
+ logger.error.returns();
161
+ const exitStub = sandbox.stub(process, "exit");
162
+
163
+ await sslReader.read(hostname);
164
+
165
+ assert.equal(logger.error.calledOnceWith("Invalid SSL key file path."), true);
166
+ assert.equal(exitStub.calledWith(1), true);
167
+ });
168
+
169
+ it("should read and return SSL certificate and key data for manually set up SSL.", async () => {
170
+ const hostname = "localhost";
171
+
172
+ const certificatePath = "/some-directory/localhost/ssl/certificate.cert";
173
+ const keyPath = "/some-directory/localhost/ssl/private-key.key";
174
+ const userPreference = new PreferenceJson({
175
+ ssl: { [hostname]: { certificatePath, keyPath } }
176
+ });
177
+ preferences.get.returns(userPreference);
178
+
179
+ const existsStub = sandbox.stub(fs, "existsSync");
180
+ existsStub.withArgs(certificatePath).returns(true);
181
+ existsStub.withArgs(keyPath).returns(true);
182
+
183
+ const stats = <Stats>{ isFile: () => true };
184
+ const lstatStub = sandbox.stub(fs, "lstatSync");
185
+ lstatStub.withArgs(certificatePath).returns(stats);
186
+ lstatStub.withArgs(keyPath).returns(stats);
187
+
188
+ const certificateData = <Buffer>{};
189
+ const keyData = <Buffer>{};
190
+ const readFileStub = sandbox.stub(fs, "readFileSync");
191
+ readFileStub.withArgs(certificatePath).returns(certificateData);
192
+ readFileStub.withArgs(keyPath).returns(keyData);
193
+
194
+ const sslData = await sslReader.read(hostname);
195
+
196
+ assert.equal(sslData.cert, certificateData);
197
+ assert.equal(sslData.key, keyData);
198
+ });
199
+
200
+ it("should read and return SSL certificate and key data for automatically set up SSL.", async () => {
201
+ const hostname = "localhost";
202
+
203
+ const userPreference = new PreferenceJson({});
204
+ preferences.get.returns(userPreference);
205
+
206
+ sandbox.stub(devcert, "hasCertificateFor").withArgs(hostname).returns(true);
207
+
208
+ const certificateData = <Buffer>{};
209
+ const keyData = <Buffer>{};
210
+
211
+ const certificateForStub = sandbox.stub(devcert, "certificateFor");
212
+ // @ts-ignore -- IReturnData mock response
213
+ certificateForStub.withArgs(hostname).returns({ cert: certificateData, key: keyData });
214
+
215
+ const sslData = await sslReader.read(hostname);
216
+
217
+ assert.equal(sslData.cert, certificateData);
218
+ assert.equal(sslData.key, keyData);
219
+ });
220
+
221
+ it("should log error and exit when SSL is not set up.", async () => {
222
+ const hostname = "localhost";
223
+
224
+ const userPreference = new PreferenceJson({});
225
+ preferences.get.returns(userPreference);
226
+
227
+ sandbox.stub(devcert, "hasCertificateFor").returns(false);
228
+
229
+ logger.error.returns();
230
+ const exitStub = sandbox.stub(process, "exit");
231
+
232
+ await sslReader.read(hostname);
233
+
234
+ assert.equal(
235
+ logger.error.calledOnceWith(
236
+ "No SSL related certificate or key files were found. Please retry after setting them up.",
237
+ { postfix: "\n" }
238
+ ),
239
+ true
240
+ );
241
+ assert.equal(exitStub.calledWith(1), true);
242
+ });
243
+ });
244
+ });
@@ -0,0 +1,161 @@
1
+ /********************************************************************************
2
+ * MIT License
3
+
4
+ * © Copyright 2023 Adobe. All rights reserved.
5
+
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ ********************************************************************************/
24
+
25
+ import type { AnalyticsConsent, AnalyticsService } from "@adobe/ccweb-add-on-analytics";
26
+ import { ITypes as IAnalyticsTypes } from "@adobe/ccweb-add-on-analytics";
27
+ import type { AccountService } from "@adobe/ccweb-add-on-developer-terms";
28
+ import { ITypes as IDeveloperTermsTypes } from "@adobe/ccweb-add-on-developer-terms";
29
+ import { Config } from "@oclif/core";
30
+ import chai, { assert, expect } from "chai";
31
+ import chaiAsPromised from "chai-as-promised";
32
+ import "mocha";
33
+ import { createRequire } from "module";
34
+ import sinon from "sinon";
35
+ import type { StubbedInstance } from "ts-sinon";
36
+ import { stubInterface } from "ts-sinon";
37
+ import { AnalyticsErrorMarkers } from "../../AnalyticsMarkers.js";
38
+ import type { CommandExecutor, SetupCommandExecutor } from "../../app/index.js";
39
+ import { Setup } from "../../commands/setup.js";
40
+ import { IContainer, ITypes } from "../../config/index.js";
41
+ import { SetupCommandOptions } from "../../models/SetupCommandOptions.js";
42
+ import type { CommandValidator } from "../../validators/CommandValidator.js";
43
+ import type { SetupCommandValidator } from "../../validators/SetupCommandValidator.js";
44
+
45
+ chai.use(chaiAsPromised);
46
+
47
+ const { test } = createRequire(import.meta.url)("@oclif/test");
48
+
49
+ describe("Setup", () => {
50
+ let sandbox: sinon.SinonSandbox;
51
+
52
+ let container: sinon.SinonStub;
53
+ let namedContainer: sinon.SinonStub;
54
+
55
+ let commandExecutor: StubbedInstance<CommandExecutor>;
56
+ let commandValidator: StubbedInstance<CommandValidator>;
57
+
58
+ let accountService: StubbedInstance<AccountService>;
59
+
60
+ let analyticsConsent: StubbedInstance<AnalyticsConsent>;
61
+ let analyticsService: StubbedInstance<AnalyticsService>;
62
+
63
+ beforeEach(() => {
64
+ sandbox = sinon.createSandbox();
65
+
66
+ commandExecutor = stubInterface<SetupCommandExecutor>();
67
+ commandExecutor.execute.resolves();
68
+
69
+ commandValidator = stubInterface<SetupCommandValidator>();
70
+ commandValidator.validate.resolves();
71
+
72
+ namedContainer = sandbox.stub(IContainer, "getNamed");
73
+ namedContainer.withArgs(ITypes.CommandValidator, "setup").returns(commandValidator);
74
+ namedContainer.withArgs(ITypes.CommandExecutor, "setup").returns(commandExecutor);
75
+
76
+ accountService = stubInterface();
77
+ accountService.invalidateToken.resolves();
78
+ accountService.seekTermsOfUseConsent.resolves();
79
+
80
+ analyticsConsent = stubInterface();
81
+ analyticsService = stubInterface();
82
+
83
+ container = sandbox.stub(IContainer, "get");
84
+ container.withArgs(IDeveloperTermsTypes.AccountService).returns(accountService);
85
+ container.withArgs(IAnalyticsTypes.AnalyticsConsent).returns(analyticsConsent);
86
+ container.withArgs(IAnalyticsTypes.AnalyticsService).returns(analyticsService);
87
+ });
88
+
89
+ afterEach(() => {
90
+ sandbox.restore();
91
+ });
92
+
93
+ describe("setup", () => {
94
+ test.stdout()
95
+ .command(["setup", "--hostname=localhost", "--login", "--analytics=on", "--verbose"])
96
+ .it("should execute succesfully when correct parameters are passed.", async () => {
97
+ analyticsConsent.set.resolves();
98
+
99
+ const options = new SetupCommandOptions("localhost", false, true);
100
+ assert.equal(commandValidator.validate.calledOnceWith(options), true);
101
+ assert.equal(commandExecutor.execute.calledOnceWith(options), true);
102
+ });
103
+ });
104
+
105
+ describe("run", () => {
106
+ it("should execute succesfully when correct parameters are passed without analytics.", async () => {
107
+ analyticsConsent.get.resolves(true);
108
+
109
+ const hostname = "localhost";
110
+ const setup = new Setup(["--hostname", hostname, "--login", "--verbose"], new Config({ root: "." }));
111
+
112
+ await setup.run();
113
+
114
+ assert.equal(accountService.invalidateToken.callCount, 1);
115
+ assert.equal(accountService.seekTermsOfUseConsent.callCount, 1);
116
+
117
+ assert.equal(analyticsConsent.get.callCount, 1);
118
+
119
+ const options = new SetupCommandOptions(hostname, false, true);
120
+ assert.equal(commandValidator.validate.calledOnceWith(options), true);
121
+ assert.equal(commandExecutor.execute.calledOnceWith(options), true);
122
+ });
123
+
124
+ it("should execute succesfully when correct parameters are passed with analytics.", async () => {
125
+ analyticsConsent.get.resolves(true);
126
+ analyticsConsent.set.withArgs(false).resolves();
127
+
128
+ const hostname = "localhost";
129
+ const setup = new Setup(
130
+ ["--hostname", hostname, "--login", "--analytics", "off", "--verbose"],
131
+ new Config({ root: "." })
132
+ );
133
+
134
+ await setup.run();
135
+
136
+ assert.equal(accountService.invalidateToken.callCount, 1);
137
+ assert.equal(accountService.seekTermsOfUseConsent.callCount, 1);
138
+
139
+ assert.equal(analyticsConsent.set.calledOnceWith(false), true);
140
+
141
+ const options = new SetupCommandOptions(hostname, false, true);
142
+ assert.equal(commandValidator.validate.calledOnceWith(options), true);
143
+ assert.equal(commandExecutor.execute.calledOnceWith(options), true);
144
+ });
145
+ });
146
+
147
+ describe("catch", () => {
148
+ it("should fail when incorrect parameters are passed.", async () => {
149
+ const setup = new Setup(["--incorrect-flag"], new Config({ root: "." }));
150
+
151
+ const error = new Error("Nonexistent flag: --incorrect-flag\nSee more help with --help");
152
+
153
+ await expect(setup.catch(error)).to.be.rejectedWith();
154
+
155
+ assert.equal(
156
+ analyticsService.postEvent.calledOnceWith(AnalyticsErrorMarkers.ERROR_SSL_SETUP, error.message, false),
157
+ true
158
+ );
159
+ });
160
+ });
161
+ });
@@ -0,0 +1,19 @@
1
+ -----BEGIN CERTIFICATE-----
2
+ MIIDDTCCAfWgAwIBAgIJANy345GHiO8LMA0GCSqGSIb3DQEBCwUAMBIxEDAOBgNV
3
+ BAMMB2RldmNlcnQwHhcNMjMwMT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17
+ SX6lh67OiIYVQYpzv4/40kFY9/ErlSozU8efb2pbtHtQpKDjlzYrJqeCLihH5reZ
18
+ ufnDz2bkYk5lU9B2E95luqJMdw0ROxVqAKoqFfkCgYByM/LV/AQnyR5PmG4JmBza
19
+ pOyyigznnua6U24g+ZFz+WPcQ/HvBm6nyji/p9CBm5/69WkbMVdgNsS5lAgNzmYD
20
+ gygeS+JBEDDYu1lojomkeqvq+4i2C1vsK+sddxRAfC/pblpz7/AEyE1qX6Y6CIQJ
21
+ CkoLGzeERc/mpee/aV25WwKBgQCgXPIdTZERzH1Gc+9TzUOKW2S2LksceOGDpjPM
22
+ 5l7vBkjKQC3c3+e0nYV9m+yMTd9fFV7r8j1q9hbnJMCYCEOTjVq0DO05tseyaVUy
23
+ jXPXSPhsj3FJk0tNIRV7aQA7ITouXPK/Yt6X+AfEiRItiQGRpKrt80e2ByoC1Mzd
24
+ mu6r+QKBgEGqJvUG148rhUuuirC+JLxzcSymAHpEnRggFDXI0szKLogClZfs8z8k
25
+ TYDmERfjCLNH/RtmyY20APdN32DBWgS/MOGtp9yKumTJq//nXD8oNKFj2ejNLFZH
26
+ SmQgjKI4E/CcX4LQzaLI/FIf191MISR9/p+Ah/eF38VCEnJfAWrp
27
+ -----END RSA PRIVATE KEY-----
@@ -0,0 +1,53 @@
1
+ /********************************************************************************
2
+ * MIT License
3
+
4
+ * © Copyright 2023 Adobe. All rights reserved.
5
+
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ ********************************************************************************/
24
+
25
+ import { assert } from "chai";
26
+ import "mocha";
27
+ import { SetupCommandOptions } from "../../models/index.js";
28
+
29
+ describe("SetupCommandOptions", () => {
30
+ describe("constructor", () => {
31
+ const runs = [
32
+ {
33
+ hostname: "localhost",
34
+ useExisting: false,
35
+ verbose: false
36
+ },
37
+ {
38
+ hostname: "localhost.adobe.com",
39
+ useExisting: true,
40
+ verbose: true
41
+ }
42
+ ];
43
+ runs.forEach(run => {
44
+ it("should create a new instance.", () => {
45
+ const commandOptions = new SetupCommandOptions(run.hostname, run.useExisting, run.verbose);
46
+
47
+ assert.equal(commandOptions.hostname, run.hostname);
48
+ assert.equal(commandOptions.useExisting, run.useExisting);
49
+ assert.equal(commandOptions.verbose, run.verbose);
50
+ });
51
+ });
52
+ });
53
+ });
@@ -0,0 +1,168 @@
1
+ /********************************************************************************
2
+ * MIT License
3
+
4
+ * © Copyright 2023 Adobe. All rights reserved.
5
+
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ ********************************************************************************/
24
+
25
+ import type { AnalyticsService } from "@adobe/ccweb-add-on-analytics";
26
+ import type { Logger } from "@adobe/ccweb-add-on-core";
27
+ import { DEFAULT_HOST_NAME } from "@adobe/ccweb-add-on-core";
28
+ import type { AccountService } from "@adobe/ccweb-add-on-developer-terms";
29
+ import chai, { assert, expect } from "chai";
30
+ import chaiAsPromised from "chai-as-promised";
31
+ import "mocha";
32
+ import type { SinonStub } from "sinon";
33
+ import sinon from "sinon";
34
+ import type { StubbedInstance } from "ts-sinon";
35
+ import { stubInterface } from "ts-sinon";
36
+ import { AnalyticsErrorMarkers } from "../../AnalyticsMarkers.js";
37
+ import { SetupCommandOptions } from "../../models/SetupCommandOptions.js";
38
+ import type { CommandValidator } from "../../validators/index.js";
39
+ import { SetupCommandValidator } from "../../validators/index.js";
40
+
41
+ chai.use(chaiAsPromised);
42
+
43
+ describe("SetupCommandValidator", () => {
44
+ let sandbox: sinon.SinonSandbox;
45
+
46
+ let processExitStub: SinonStub;
47
+
48
+ let accountService: StubbedInstance<AccountService>;
49
+
50
+ let analyticsService: StubbedInstance<AnalyticsService>;
51
+ let logger: StubbedInstance<Logger>;
52
+
53
+ let commandValidator: CommandValidator;
54
+
55
+ beforeEach(() => {
56
+ sandbox = sinon.createSandbox();
57
+
58
+ processExitStub = sandbox.stub(process, "exit");
59
+ processExitStub.throws();
60
+
61
+ accountService = stubInterface();
62
+
63
+ analyticsService = stubInterface();
64
+ logger = stubInterface();
65
+
66
+ commandValidator = new SetupCommandValidator(accountService, analyticsService, logger);
67
+ });
68
+
69
+ afterEach(() => {
70
+ sandbox.restore();
71
+ });
72
+
73
+ describe("validate", () => {
74
+ it(`should log error and exit when a non-privileged user provides a hostname other than ${DEFAULT_HOST_NAME}.`, async () => {
75
+ accountService.isUserPrivileged.resolves(false);
76
+
77
+ const options = new SetupCommandOptions("localhost.adobe.com", true, true);
78
+
79
+ const eventData = [
80
+ "--hostname",
81
+ options.hostname,
82
+ "--useExisting",
83
+ options.useExisting,
84
+ "--isUserPrivileged",
85
+ false
86
+ ];
87
+
88
+ await expect(commandValidator.validate(options)).to.be.rejected;
89
+
90
+ assert.equal(processExitStub.calledOnce, true);
91
+ assert.equal(
92
+ logger.error.calledOnceWith("Invalid hostname. Only 'localhost' is allowed.", {
93
+ prefix: "\n",
94
+ postfix: "\n"
95
+ }),
96
+ true
97
+ );
98
+ assert.equal(
99
+ analyticsService.postEvent.calledOnceWith(
100
+ AnalyticsErrorMarkers.ERROR_SSL_INVALID_HOSTNAME,
101
+ eventData.join(" "),
102
+ false
103
+ ),
104
+ true
105
+ );
106
+ });
107
+
108
+ it(`should return when a non-privileged user provides the hostname as ${DEFAULT_HOST_NAME}.`, async () => {
109
+ accountService.isUserPrivileged.resolves(false);
110
+
111
+ const options = new SetupCommandOptions("localhost", true, true);
112
+ await commandValidator.validate(options);
113
+
114
+ assert.equal(processExitStub.callCount, 0);
115
+ assert.equal(logger.error.callCount, 0);
116
+ });
117
+
118
+ let hostnames = ["", "foobar", "localhost.com"];
119
+ hostnames.forEach(hostname => {
120
+ it(`should log error and exit when a privileged user provides an invalid hostname: '${hostname}'.`, async () => {
121
+ accountService.isUserPrivileged.resolves(true);
122
+
123
+ const options = new SetupCommandOptions(hostname, true, true);
124
+
125
+ const eventData = [
126
+ "--hostname",
127
+ options.hostname,
128
+ "--useExisting",
129
+ options.useExisting,
130
+ "--isUserPrivileged",
131
+ true
132
+ ];
133
+
134
+ await expect(commandValidator.validate(options)).to.be.rejected;
135
+
136
+ assert.equal(processExitStub.calledOnce, true);
137
+ assert.equal(
138
+ logger.error.calledOnceWith("Invalid hostname. Only 'localhost' and '*.adobe.com' are allowed.", {
139
+ prefix: "\n",
140
+ postfix: "\n"
141
+ }),
142
+ true
143
+ );
144
+ assert.equal(
145
+ analyticsService.postEvent.calledOnceWith(
146
+ AnalyticsErrorMarkers.ERROR_SSL_INVALID_HOSTNAME,
147
+ eventData.join(" "),
148
+ false
149
+ ),
150
+ true
151
+ );
152
+ });
153
+ });
154
+
155
+ hostnames = ["localhost", "localhost.adobe.com", "random.adobe.com"];
156
+ hostnames.forEach(hostname => {
157
+ it(`should return when a privileged user provides a valid hostname: '${hostname}'.`, async () => {
158
+ accountService.isUserPrivileged.resolves(true);
159
+
160
+ const options = new SetupCommandOptions(hostname, true, true);
161
+ await commandValidator.validate(options);
162
+
163
+ assert.equal(processExitStub.callCount, 0);
164
+ assert.equal(logger.error.callCount, 0);
165
+ });
166
+ });
167
+ });
168
+ });