@sasjs/cli 4.18.6 → 4.20.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.
- package/build/commands/add/spec/addCommand.spec.js +0 -21
- package/build/commands/auth/authCommand.d.ts +10 -0
- package/build/commands/auth/authCommand.js +207 -0
- package/build/commands/auth/login.d.ts +33 -0
- package/build/commands/auth/login.js +237 -0
- package/build/commands/auth/spec/authCommand.spec.d.ts +1 -0
- package/build/commands/auth/spec/authCommand.spec.js +258 -0
- package/build/commands/auth/spec/login.spec.d.ts +1 -0
- package/build/commands/auth/spec/login.spec.js +665 -0
- package/build/commands/deploy/internal/executeDeployScriptSasViya.js +2 -1
- package/build/commands/fs/internal/executeCode.js +2 -1
- package/build/commands/help/help.js +3 -2
- package/build/commands/run/run.js +2 -1
- package/build/types/command/commandAliases.js +0 -1
- package/build/types/command/commandBase.js +1 -0
- package/build/types/command/commandFactory.js +2 -0
- package/build/utils/auth.d.ts +35 -16
- package/build/utils/auth.js +97 -37
- package/build/utils/config.d.ts +13 -2
- package/build/utils/config.js +125 -55
- package/build/utils/spec/auth.spec.d.ts +1 -0
- package/build/utils/spec/auth.spec.js +255 -0
- package/build/utils/spec/config.spec.js +334 -32
- package/package.json +4 -3
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
35
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
36
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
37
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
38
|
+
function step(op) {
|
|
39
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
40
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
41
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
42
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
43
|
+
switch (op[0]) {
|
|
44
|
+
case 0: case 1: t = op; break;
|
|
45
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
46
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
47
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
48
|
+
default:
|
|
49
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
50
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
51
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
52
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
53
|
+
if (t[2]) _.ops.pop();
|
|
54
|
+
_.trys.pop(); continue;
|
|
55
|
+
}
|
|
56
|
+
op = body.call(thisArg, _);
|
|
57
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
58
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
62
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
63
|
+
if (!m) return o;
|
|
64
|
+
var i = m.call(o), r, ar = [], e;
|
|
65
|
+
try {
|
|
66
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
67
|
+
}
|
|
68
|
+
catch (error) { e = { error: error }; }
|
|
69
|
+
finally {
|
|
70
|
+
try {
|
|
71
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
72
|
+
}
|
|
73
|
+
finally { if (e) throw e.error; }
|
|
74
|
+
}
|
|
75
|
+
return ar;
|
|
76
|
+
};
|
|
77
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
78
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
79
|
+
if (ar || !(i in from)) {
|
|
80
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
81
|
+
ar[i] = from[i];
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
85
|
+
};
|
|
86
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
87
|
+
var authCommand_1 = require("../authCommand");
|
|
88
|
+
var addCredentialModule = __importStar(require("../../add/addCredential"));
|
|
89
|
+
var authLoginModule = __importStar(require("../login"));
|
|
90
|
+
var configUtils = __importStar(require("../../../utils/config"));
|
|
91
|
+
var setConstantsUtils = __importStar(require("../../../utils/setConstants"));
|
|
92
|
+
var utils_1 = require("@sasjs/utils");
|
|
93
|
+
var types_1 = require("../../../types");
|
|
94
|
+
var command_1 = require("../../../types/command");
|
|
95
|
+
describe('AuthCommand', function () {
|
|
96
|
+
var defaultArgs = ['node', 'sasjs'];
|
|
97
|
+
var target = new utils_1.Target({
|
|
98
|
+
name: 'test',
|
|
99
|
+
appLoc: '/Public/test/',
|
|
100
|
+
serverType: utils_1.ServerType.SasViya,
|
|
101
|
+
contextName: 'test context'
|
|
102
|
+
});
|
|
103
|
+
beforeEach(function () {
|
|
104
|
+
process.logger = new utils_1.Logger(utils_1.LogLevel.Off);
|
|
105
|
+
jest.resetAllMocks();
|
|
106
|
+
jest.mock('../../add/addCredential');
|
|
107
|
+
jest.mock('../../../utils/config');
|
|
108
|
+
jest
|
|
109
|
+
.spyOn(addCredentialModule, 'addCredential')
|
|
110
|
+
.mockImplementation(function () { return Promise.resolve(target); });
|
|
111
|
+
jest
|
|
112
|
+
.spyOn(configUtils, 'findTargetInConfiguration')
|
|
113
|
+
.mockImplementation(function () { return Promise.resolve({ target: target, isLocal: true }); });
|
|
114
|
+
jest
|
|
115
|
+
.spyOn(configUtils, 'getLocalConfig')
|
|
116
|
+
.mockImplementation(function () { return Promise.resolve({}); });
|
|
117
|
+
jest
|
|
118
|
+
.spyOn(setConstantsUtils, 'setConstants')
|
|
119
|
+
.mockImplementation(function () { return Promise.resolve(); });
|
|
120
|
+
jest.spyOn(process.logger, 'success');
|
|
121
|
+
jest.spyOn(process.logger, 'error');
|
|
122
|
+
});
|
|
123
|
+
it('should parse a sasjs auth login command', function () {
|
|
124
|
+
var args = __spreadArray(__spreadArray([], __read(defaultArgs), false), ['auth', 'login', '-t', 'test'], false);
|
|
125
|
+
var command = new authCommand_1.AuthCommand(args);
|
|
126
|
+
expect(command.name).toEqual('auth');
|
|
127
|
+
expect(command.subCommand).toEqual('login');
|
|
128
|
+
});
|
|
129
|
+
it('should call the authLogin handler when executed with the login sub command', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
130
|
+
var args, command, returnCode;
|
|
131
|
+
return __generator(this, function (_a) {
|
|
132
|
+
switch (_a.label) {
|
|
133
|
+
case 0:
|
|
134
|
+
jest
|
|
135
|
+
.spyOn(authLoginModule, 'authLogin')
|
|
136
|
+
.mockImplementation(function () { return Promise.resolve(); });
|
|
137
|
+
args = __spreadArray(__spreadArray([], __read(defaultArgs), false), ['auth', 'login', '-t', 'test'], false);
|
|
138
|
+
command = new authCommand_1.AuthCommand(args);
|
|
139
|
+
return [4 /*yield*/, command.execute()];
|
|
140
|
+
case 1:
|
|
141
|
+
returnCode = _a.sent();
|
|
142
|
+
expect(authLoginModule.authLogin).toHaveBeenCalledWith(target, false, false);
|
|
143
|
+
expect(returnCode).toEqual(command_1.ReturnCode.Success);
|
|
144
|
+
return [2 /*return*/];
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
}); });
|
|
148
|
+
it('should pass the insecure flag to authLogin when --insecure is provided', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
149
|
+
var args, command, returnCode;
|
|
150
|
+
return __generator(this, function (_a) {
|
|
151
|
+
switch (_a.label) {
|
|
152
|
+
case 0:
|
|
153
|
+
jest
|
|
154
|
+
.spyOn(authLoginModule, 'authLogin')
|
|
155
|
+
.mockImplementation(function () { return Promise.resolve(); });
|
|
156
|
+
args = __spreadArray(__spreadArray([], __read(defaultArgs), false), ['auth', 'login', '-t', 'test', '--insecure'], false);
|
|
157
|
+
command = new authCommand_1.AuthCommand(args);
|
|
158
|
+
return [4 /*yield*/, command.execute()];
|
|
159
|
+
case 1:
|
|
160
|
+
returnCode = _a.sent();
|
|
161
|
+
expect(authLoginModule.authLogin).toHaveBeenCalledWith(target, true, false);
|
|
162
|
+
expect(returnCode).toEqual(command_1.ReturnCode.Success);
|
|
163
|
+
return [2 /*return*/];
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
}); });
|
|
167
|
+
it('should pass passwordStdin=true to authLogin when --password-stdin is provided', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
168
|
+
var args, command, returnCode;
|
|
169
|
+
return __generator(this, function (_a) {
|
|
170
|
+
switch (_a.label) {
|
|
171
|
+
case 0:
|
|
172
|
+
jest
|
|
173
|
+
.spyOn(authLoginModule, 'authLogin')
|
|
174
|
+
.mockImplementation(function () { return Promise.resolve(); });
|
|
175
|
+
args = __spreadArray(__spreadArray([], __read(defaultArgs), false), [
|
|
176
|
+
'auth',
|
|
177
|
+
'login',
|
|
178
|
+
'-t',
|
|
179
|
+
'test',
|
|
180
|
+
'--password-stdin'
|
|
181
|
+
], false);
|
|
182
|
+
command = new authCommand_1.AuthCommand(args);
|
|
183
|
+
return [4 /*yield*/, command.execute()];
|
|
184
|
+
case 1:
|
|
185
|
+
returnCode = _a.sent();
|
|
186
|
+
expect(authLoginModule.authLogin).toHaveBeenCalledWith(target, false, true);
|
|
187
|
+
expect(returnCode).toEqual(command_1.ReturnCode.Success);
|
|
188
|
+
return [2 /*return*/];
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
}); });
|
|
192
|
+
it('should pass both insecure and passwordStdin flags to authLogin', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
193
|
+
var args, command, returnCode;
|
|
194
|
+
return __generator(this, function (_a) {
|
|
195
|
+
switch (_a.label) {
|
|
196
|
+
case 0:
|
|
197
|
+
jest
|
|
198
|
+
.spyOn(authLoginModule, 'authLogin')
|
|
199
|
+
.mockImplementation(function () { return Promise.resolve(); });
|
|
200
|
+
args = __spreadArray(__spreadArray([], __read(defaultArgs), false), [
|
|
201
|
+
'auth',
|
|
202
|
+
'login',
|
|
203
|
+
'-t',
|
|
204
|
+
'test',
|
|
205
|
+
'--insecure',
|
|
206
|
+
'--password-stdin'
|
|
207
|
+
], false);
|
|
208
|
+
command = new authCommand_1.AuthCommand(args);
|
|
209
|
+
return [4 /*yield*/, command.execute()];
|
|
210
|
+
case 1:
|
|
211
|
+
returnCode = _a.sent();
|
|
212
|
+
expect(authLoginModule.authLogin).toHaveBeenCalledWith(target, true, true);
|
|
213
|
+
expect(returnCode).toEqual(command_1.ReturnCode.Success);
|
|
214
|
+
return [2 /*return*/];
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
}); });
|
|
218
|
+
it('should return an error code when login fails', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
219
|
+
var args, command, returnCode;
|
|
220
|
+
return __generator(this, function (_a) {
|
|
221
|
+
switch (_a.label) {
|
|
222
|
+
case 0:
|
|
223
|
+
jest
|
|
224
|
+
.spyOn(authLoginModule, 'authLogin')
|
|
225
|
+
.mockImplementation(function () { return Promise.reject(new Error('Login failed')); });
|
|
226
|
+
args = __spreadArray(__spreadArray([], __read(defaultArgs), false), ['auth', 'login', '-t', 'test'], false);
|
|
227
|
+
command = new authCommand_1.AuthCommand(args);
|
|
228
|
+
return [4 /*yield*/, command.execute()];
|
|
229
|
+
case 1:
|
|
230
|
+
returnCode = _a.sent();
|
|
231
|
+
expect(returnCode).toEqual(command_1.ReturnCode.InternalError);
|
|
232
|
+
expect(process.logger.error).toHaveBeenCalled();
|
|
233
|
+
return [2 /*return*/];
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
}); });
|
|
237
|
+
it('should parse a bare sasjs auth command (legacy alias of sasjs add cred)', function () {
|
|
238
|
+
var args = __spreadArray(__spreadArray([], __read(defaultArgs), false), ['auth', '-i'], false);
|
|
239
|
+
var command = new authCommand_1.AuthCommand(args);
|
|
240
|
+
expect(command.name).toEqual('auth');
|
|
241
|
+
expect(command.insecure).toEqual(true);
|
|
242
|
+
});
|
|
243
|
+
it('should call the addCredential handler when executed without a sub command', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
244
|
+
var args, command;
|
|
245
|
+
return __generator(this, function (_a) {
|
|
246
|
+
switch (_a.label) {
|
|
247
|
+
case 0:
|
|
248
|
+
args = __spreadArray(__spreadArray([], __read(defaultArgs), false), ['auth', '-t', 'test'], false);
|
|
249
|
+
command = new authCommand_1.AuthCommand(args);
|
|
250
|
+
return [4 /*yield*/, command.execute()];
|
|
251
|
+
case 1:
|
|
252
|
+
_a.sent();
|
|
253
|
+
expect(addCredentialModule.addCredential).toHaveBeenCalledWith(target, false, types_1.TargetScope.Local);
|
|
254
|
+
return [2 /*return*/];
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
}); });
|
|
258
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|