@contrail/cli 3.6.0-alpha.c22a682 → 3.6.0-alpha.eec506e
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/README.md +1 -1
- package/dist/auth/login.js +5 -5
- package/dist/auth/login.spec.js +5 -3
- package/dist/auth/sso.js +9 -3
- package/dist/auth/sso.spec.js +10 -0
- package/oclif.manifest.json +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -17,7 +17,7 @@ $ npm install -g @contrail/cli
|
|
|
17
17
|
$ contrail COMMAND
|
|
18
18
|
running command...
|
|
19
19
|
$ contrail (--version)
|
|
20
|
-
@contrail/cli/3.6.0-alpha.
|
|
20
|
+
@contrail/cli/3.6.0-alpha.eec506e linux-x64 node-v24.22.1
|
|
21
21
|
$ contrail --help [COMMAND]
|
|
22
22
|
USAGE
|
|
23
23
|
$ contrail COMMAND
|
package/dist/auth/login.js
CHANGED
|
@@ -17,7 +17,7 @@ const COGNITO_CONFIGS = {
|
|
|
17
17
|
clientId: '209s9c62o165cqab0fu5ihjtu9',
|
|
18
18
|
sso: {
|
|
19
19
|
domain: 'https://dev-vibeiq.auth.us-east-1.amazoncognito.com',
|
|
20
|
-
clientId: '
|
|
20
|
+
clientId: '7qlu7d55oog9dv0kd3k30kjr2v',
|
|
21
21
|
pastedCodeCallbackUrl: 'https://login.dev.vibeiq.com/cli',
|
|
22
22
|
},
|
|
23
23
|
},
|
|
@@ -90,7 +90,7 @@ async function signIn(options) {
|
|
|
90
90
|
return signInWithSso(params, domainCheck.identityProvider, options);
|
|
91
91
|
}
|
|
92
92
|
if (domainCheck.kind === 'legacy') {
|
|
93
|
-
|
|
93
|
+
console.log('The CLI does not support your SSO provider yet. Sign in with your VibeIQ password, or set CONTRAIL_CLI_API_KEY.');
|
|
94
94
|
}
|
|
95
95
|
return authenticateWithUsernamePassword(params);
|
|
96
96
|
}
|
|
@@ -110,12 +110,12 @@ async function signInWithSso(params, identityProvider, options) {
|
|
|
110
110
|
let code;
|
|
111
111
|
if (usesLoopback) {
|
|
112
112
|
const loopbackListener = await (0, sso_1.listenForLoopbackCode)(pkce.state);
|
|
113
|
-
|
|
114
|
-
await (0, sso_1.openBrowser)(authorizeUrl).catch(() =>
|
|
113
|
+
console.log(`Opening your browser to sign in. If it does not open, visit:\n${authorizeUrl}`);
|
|
114
|
+
await (0, sso_1.openBrowser)(authorizeUrl).catch(() => console.log('Could not open a browser. Open the URL above to sign in.'));
|
|
115
115
|
code = await loopbackListener.code;
|
|
116
116
|
}
|
|
117
117
|
else {
|
|
118
|
-
|
|
118
|
+
console.log(`Open this URL in any browser to sign in:\n${authorizeUrl}`);
|
|
119
119
|
const answers = await inquirer_1.default.prompt([
|
|
120
120
|
{ type: 'input', name: 'signInCode', validate: (val) => !!val, message: 'Sign-in code' },
|
|
121
121
|
]);
|
package/dist/auth/login.spec.js
CHANGED
|
@@ -5,7 +5,6 @@ const amazon_cognito_identity_js_1 = require("amazon-cognito-identity-js");
|
|
|
5
5
|
const sdk_1 = require("@contrail/sdk");
|
|
6
6
|
const inquirer_1 = tslib_1.__importDefault(require("inquirer"));
|
|
7
7
|
const config_1 = require("../helpers/config/config");
|
|
8
|
-
const logger_1 = tslib_1.__importDefault(require("../logger"));
|
|
9
8
|
const login_1 = require("./login");
|
|
10
9
|
const mockAuthenticateUser = jest.fn();
|
|
11
10
|
jest.mock('amazon-cognito-identity-js', () => ({
|
|
@@ -219,9 +218,10 @@ describe('signIn with SSO', () => {
|
|
|
219
218
|
const DEV_COGNITO_DOMAIN = 'https://dev-vibeiq.auth.us-east-1.amazoncognito.com';
|
|
220
219
|
let fetchMock;
|
|
221
220
|
let promptSpy;
|
|
221
|
+
let consoleLogSpy;
|
|
222
222
|
function pasteCodeFromPrintedSignInUrl() {
|
|
223
223
|
promptSpy.mockImplementation(async () => {
|
|
224
|
-
const printed =
|
|
224
|
+
const printed = consoleLogSpy.mock.calls.map(([message]) => message).join('\n');
|
|
225
225
|
const signInUrl = new URL(printed.match(/https:\/\/\S+oauth2\/authorize\S+/)[0]);
|
|
226
226
|
return { signInCode: `pasted-code#${signInUrl.searchParams.get('state')}` };
|
|
227
227
|
});
|
|
@@ -233,6 +233,7 @@ describe('signIn with SSO', () => {
|
|
|
233
233
|
config_1.getConfig.mockResolvedValue({ apiGateway: DEV_GATEWAY, orgSlug: 'adam-zone-1' });
|
|
234
234
|
sdk_1.getCurrentUser.mockResolvedValue({ id: 'user-1' });
|
|
235
235
|
mockAuthenticateUser.mockImplementation((_details, callbacks) => callbacks.onSuccess({ idToken: { jwtToken: 'cognito-id-token' } }));
|
|
236
|
+
consoleLogSpy = jest.spyOn(console, 'log').mockImplementation(() => undefined);
|
|
236
237
|
promptSpy = jest.spyOn(inquirer_1.default, 'prompt');
|
|
237
238
|
pasteCodeFromPrintedSignInUrl();
|
|
238
239
|
fetchMock = jest.fn();
|
|
@@ -240,6 +241,7 @@ describe('signIn with SSO', () => {
|
|
|
240
241
|
});
|
|
241
242
|
afterEach(() => {
|
|
242
243
|
promptSpy.mockRestore();
|
|
244
|
+
consoleLogSpy.mockRestore();
|
|
243
245
|
global.fetch = originalFetch;
|
|
244
246
|
restoreEnv('CONTRAIL_CLI_EMAIL', originalEmail);
|
|
245
247
|
restoreEnv('CONTRAIL_CLI_PASSWORD', originalPassword);
|
|
@@ -286,7 +288,7 @@ describe('signIn with SSO', () => {
|
|
|
286
288
|
promptSpy.mockResolvedValue({ password: 'secret' });
|
|
287
289
|
const context = await (0, login_1.signIn)({ openBrowser: false });
|
|
288
290
|
expect(context.apiUserToken).toBe('vibe-access');
|
|
289
|
-
expect(
|
|
291
|
+
expect(consoleLogSpy).toHaveBeenCalledWith(expect.stringContaining('The CLI does not support your SSO provider yet.'));
|
|
290
292
|
});
|
|
291
293
|
it('should refresh a stored SSO token through Cognito instead of the VibeIQ refresh endpoint', async () => {
|
|
292
294
|
config_1.getConfig.mockResolvedValue({
|
package/dist/auth/sso.js
CHANGED
|
@@ -78,7 +78,7 @@ function listenForLoopbackCode(expectedState) {
|
|
|
78
78
|
: 'Sign-in failed. Return to your terminal.';
|
|
79
79
|
response
|
|
80
80
|
.writeHead(signedIn ? 200 : 400, { 'Content-Type': 'text/plain', Connection: 'close' })
|
|
81
|
-
.end(page, () => stopListening(() => {
|
|
81
|
+
.end(page, () => stopListening(request.socket, () => {
|
|
82
82
|
if (error) {
|
|
83
83
|
rejectCode(new Error(`SSO sign-in failed: ${error}`));
|
|
84
84
|
}
|
|
@@ -90,10 +90,16 @@ function listenForLoopbackCode(expectedState) {
|
|
|
90
90
|
}
|
|
91
91
|
}));
|
|
92
92
|
});
|
|
93
|
-
const
|
|
94
|
-
|
|
93
|
+
const openSockets = new Set();
|
|
94
|
+
server.on('connection', (socket) => {
|
|
95
|
+
openSockets.add(socket);
|
|
96
|
+
socket.once('close', () => openSockets.delete(socket));
|
|
97
|
+
});
|
|
98
|
+
const timeout = setTimeout(() => stopListening(undefined, () => rejectCode(new Error('Timed out waiting for the browser sign-in.'))), BROWSER_SIGN_IN_TIMEOUT_MS);
|
|
99
|
+
function stopListening(respondingSocket, settle) {
|
|
95
100
|
clearTimeout(timeout);
|
|
96
101
|
server.close();
|
|
102
|
+
openSockets.forEach((socket) => socket !== respondingSocket && socket.destroy());
|
|
97
103
|
settle();
|
|
98
104
|
}
|
|
99
105
|
return new Promise((resolve, reject) => {
|
package/dist/auth/sso.spec.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const node_crypto_1 = require("node:crypto");
|
|
4
|
+
const node_net_1 = require("node:net");
|
|
4
5
|
const sso_1 = require("./sso");
|
|
5
6
|
const ssoClient = {
|
|
6
7
|
domain: 'https://dev-vibeiq.auth.us-east-1.amazoncognito.com',
|
|
@@ -117,6 +118,15 @@ describe('listenForLoopbackCode', () => {
|
|
|
117
118
|
await fetch(`${sso_1.LOOPBACK_CALLBACK_URL}?error=access_denied&error_description=User%20cancelled&state=the-state`);
|
|
118
119
|
await rejection;
|
|
119
120
|
});
|
|
121
|
+
it('should close idle browser connections once the code arrives', async () => {
|
|
122
|
+
const listener = await (0, sso_1.listenForLoopbackCode)('the-state');
|
|
123
|
+
const idleConnection = (0, node_net_1.connect)(7731, 'localhost');
|
|
124
|
+
await new Promise((resolve) => idleConnection.once('connect', resolve));
|
|
125
|
+
const idleConnectionClosed = new Promise((resolve) => idleConnection.once('close', resolve));
|
|
126
|
+
await fetch(`${sso_1.LOOPBACK_CALLBACK_URL}?code=the-code&state=the-state`);
|
|
127
|
+
await expect(listener.code).resolves.toBe('the-code');
|
|
128
|
+
await expect(idleConnectionClosed).resolves.toBe(false);
|
|
129
|
+
});
|
|
120
130
|
it('should tell the user to paste a code instead when the port is taken', async () => {
|
|
121
131
|
const listener = await (0, sso_1.listenForLoopbackCode)('the-state');
|
|
122
132
|
await expect((0, sso_1.listenForLoopbackCode)('another-state')).rejects.toThrow('Port 7731 is in use. Run contrail login --no-browser instead.');
|
package/oclif.manifest.json
CHANGED