@contrail/cli 3.6.0-alpha.aae3e70 → 3.6.0-alpha.c22a682
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 +2 -2
- package/dist/auth/login.spec.js +1 -0
- package/dist/auth/sso.js +9 -5
- package/dist/auth/sso.spec.js +27 -8
- 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.c22a682 linux-x64 node-v24.22.1
|
|
21
21
|
$ contrail --help [COMMAND]
|
|
22
22
|
USAGE
|
|
23
23
|
$ contrail COMMAND
|
package/dist/auth/login.js
CHANGED
|
@@ -240,11 +240,11 @@ async function refreshCurrentUserOrg() {
|
|
|
240
240
|
return returnAndStoreConfig(sdk_1.Auth.config, 'password');
|
|
241
241
|
}
|
|
242
242
|
async function refreshAccessToken(signInMethod) {
|
|
243
|
-
const newAccessToken = await
|
|
243
|
+
const newAccessToken = await fetchRefreshedAccessTokenForSignInMethod(signInMethod);
|
|
244
244
|
sdk_1.Auth.config = { ...sdk_1.Auth.config, apiUserToken: newAccessToken };
|
|
245
245
|
(0, sdk_1.setConfig)(sdk_1.Auth.config);
|
|
246
246
|
}
|
|
247
|
-
async function
|
|
247
|
+
async function fetchRefreshedAccessTokenForSignInMethod(signInMethod) {
|
|
248
248
|
const { apiRefreshToken, apiGateway } = sdk_1.Auth.config;
|
|
249
249
|
if (signInMethod === 'sso') {
|
|
250
250
|
const ssoClient = COGNITO_CONFIGS[(0, config_1.findEnvironmentName)(apiGateway)].sso;
|
package/dist/auth/login.spec.js
CHANGED
|
@@ -232,6 +232,7 @@ describe('signIn with SSO', () => {
|
|
|
232
232
|
delete process.env.CONTRAIL_CLI_PASSWORD;
|
|
233
233
|
config_1.getConfig.mockResolvedValue({ apiGateway: DEV_GATEWAY, orgSlug: 'adam-zone-1' });
|
|
234
234
|
sdk_1.getCurrentUser.mockResolvedValue({ id: 'user-1' });
|
|
235
|
+
mockAuthenticateUser.mockImplementation((_details, callbacks) => callbacks.onSuccess({ idToken: { jwtToken: 'cognito-id-token' } }));
|
|
235
236
|
promptSpy = jest.spyOn(inquirer_1.default, 'prompt');
|
|
236
237
|
pasteCodeFromPrintedSignInUrl();
|
|
237
238
|
fetchMock = jest.fn();
|
package/dist/auth/sso.js
CHANGED
|
@@ -66,10 +66,13 @@ function listenForLoopbackCode(expectedState) {
|
|
|
66
66
|
response.writeHead(404).end();
|
|
67
67
|
return;
|
|
68
68
|
}
|
|
69
|
+
if (url.searchParams.get('state') !== expectedState) {
|
|
70
|
+
response.writeHead(400, { 'Content-Type': 'text/plain' }).end('Unknown sign-in attempt.');
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
69
73
|
const error = url.searchParams.get('error_description') ?? url.searchParams.get('error');
|
|
70
74
|
const receivedCode = url.searchParams.get('code');
|
|
71
|
-
const
|
|
72
|
-
const signedIn = !error && receivedCode && isExpectedState;
|
|
75
|
+
const signedIn = !error && Boolean(receivedCode);
|
|
73
76
|
const page = signedIn
|
|
74
77
|
? 'Sign-in received. Return to your terminal.'
|
|
75
78
|
: 'Sign-in failed. Return to your terminal.';
|
|
@@ -127,7 +130,7 @@ function buildOpenBrowserCommand(url, platform) {
|
|
|
127
130
|
return ['open', [url]];
|
|
128
131
|
}
|
|
129
132
|
if (platform === 'win32') {
|
|
130
|
-
return ['
|
|
133
|
+
return ['rundll32', ['url.dll,FileProtocolHandler', url]];
|
|
131
134
|
}
|
|
132
135
|
return ['xdg-open', [url]];
|
|
133
136
|
}
|
|
@@ -157,8 +160,9 @@ async function postToTokenEndpoint(client, form) {
|
|
|
157
160
|
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
158
161
|
body: new URLSearchParams(form),
|
|
159
162
|
});
|
|
163
|
+
const body = await response.json();
|
|
160
164
|
if (!response.ok) {
|
|
161
|
-
throw new Error(`SSO token request failed (${response.status}).`);
|
|
165
|
+
throw new Error(`SSO token request failed (${response.status} ${body.error}).`);
|
|
162
166
|
}
|
|
163
|
-
return
|
|
167
|
+
return body;
|
|
164
168
|
}
|
package/dist/auth/sso.spec.js
CHANGED
|
@@ -62,11 +62,11 @@ describe('fetchSsoDomainCheck', () => {
|
|
|
62
62
|
afterEach(() => {
|
|
63
63
|
global.fetch = originalFetch;
|
|
64
64
|
});
|
|
65
|
-
function
|
|
65
|
+
function stubDomainCheckFetch(body, status = 200) {
|
|
66
66
|
global.fetch = jest.fn().mockResolvedValue(new Response(body, { status }));
|
|
67
67
|
}
|
|
68
68
|
it('should name the Cognito identity provider for an SSO domain', async () => {
|
|
69
|
-
|
|
69
|
+
stubDomainCheckFetch(JSON.stringify({ identityProvider: 'sso-vibeiq-com' }));
|
|
70
70
|
await expect((0, sso_1.fetchSsoDomainCheck)('Dev@VibeIQ.com', 'https://api')).resolves.toEqual({
|
|
71
71
|
kind: 'cognito',
|
|
72
72
|
identityProvider: 'sso-vibeiq-com',
|
|
@@ -74,19 +74,19 @@ describe('fetchSsoDomainCheck', () => {
|
|
|
74
74
|
expect(global.fetch).toHaveBeenCalledWith('https://api/sso-login/domain-check/vibeiq.com');
|
|
75
75
|
});
|
|
76
76
|
it('should report a legacy SSO domain', async () => {
|
|
77
|
-
|
|
77
|
+
stubDomainCheckFetch(JSON.stringify({ identityProvider: '', url: 'https://api/sso-login/login/acme.com' }));
|
|
78
78
|
await expect((0, sso_1.fetchSsoDomainCheck)('dev@acme.com', 'https://api')).resolves.toEqual({
|
|
79
79
|
kind: 'legacy',
|
|
80
80
|
});
|
|
81
81
|
});
|
|
82
82
|
it('should report no SSO for an empty response', async () => {
|
|
83
|
-
|
|
83
|
+
stubDomainCheckFetch('');
|
|
84
84
|
await expect((0, sso_1.fetchSsoDomainCheck)('dev@example.com', 'https://api')).resolves.toEqual({
|
|
85
85
|
kind: 'none',
|
|
86
86
|
});
|
|
87
87
|
});
|
|
88
88
|
it('should fail when the lookup fails', async () => {
|
|
89
|
-
|
|
89
|
+
stubDomainCheckFetch('{}', 502);
|
|
90
90
|
await expect((0, sso_1.fetchSsoDomainCheck)('dev@example.com', 'https://api')).rejects.toThrow('SSO lookup for example.com failed (502).');
|
|
91
91
|
});
|
|
92
92
|
});
|
|
@@ -97,17 +97,24 @@ describe('listenForLoopbackCode', () => {
|
|
|
97
97
|
expect(response.status).toBe(200);
|
|
98
98
|
await expect(listener.code).resolves.toBe('the-code');
|
|
99
99
|
});
|
|
100
|
-
it('should
|
|
100
|
+
it('should keep waiting for this attempt after a redirect from another attempt', async () => {
|
|
101
|
+
const listener = await (0, sso_1.listenForLoopbackCode)('the-state');
|
|
102
|
+
const staleResponse = await fetch(`${sso_1.LOOPBACK_CALLBACK_URL}?code=old-code&state=old-state`);
|
|
103
|
+
await fetch(`${sso_1.LOOPBACK_CALLBACK_URL}?code=the-code&state=the-state`);
|
|
104
|
+
expect(staleResponse.status).toBe(400);
|
|
105
|
+
await expect(listener.code).resolves.toBe('the-code');
|
|
106
|
+
});
|
|
107
|
+
it('should reject a redirect for this attempt that carries no code', async () => {
|
|
101
108
|
const listener = await (0, sso_1.listenForLoopbackCode)('the-state');
|
|
102
109
|
const rejection = expect(listener.code).rejects.toThrow('SSO sign-in returned an unexpected response.');
|
|
103
|
-
const response = await fetch(`${sso_1.LOOPBACK_CALLBACK_URL}?
|
|
110
|
+
const response = await fetch(`${sso_1.LOOPBACK_CALLBACK_URL}?state=the-state`);
|
|
104
111
|
expect(response.status).toBe(400);
|
|
105
112
|
await rejection;
|
|
106
113
|
});
|
|
107
114
|
it('should reject when the identity provider reports an error', async () => {
|
|
108
115
|
const listener = await (0, sso_1.listenForLoopbackCode)('the-state');
|
|
109
116
|
const rejection = expect(listener.code).rejects.toThrow('SSO sign-in failed: User cancelled');
|
|
110
|
-
await fetch(`${sso_1.LOOPBACK_CALLBACK_URL}?error=access_denied&error_description=User%20cancelled`);
|
|
117
|
+
await fetch(`${sso_1.LOOPBACK_CALLBACK_URL}?error=access_denied&error_description=User%20cancelled&state=the-state`);
|
|
111
118
|
await rejection;
|
|
112
119
|
});
|
|
113
120
|
it('should tell the user to paste a code instead when the port is taken', async () => {
|
|
@@ -117,3 +124,15 @@ describe('listenForLoopbackCode', () => {
|
|
|
117
124
|
await listener.code;
|
|
118
125
|
});
|
|
119
126
|
});
|
|
127
|
+
describe('exchangeCodeForTokens', () => {
|
|
128
|
+
const originalFetch = global.fetch;
|
|
129
|
+
afterEach(() => {
|
|
130
|
+
global.fetch = originalFetch;
|
|
131
|
+
});
|
|
132
|
+
it('should name the Cognito error when the exchange is refused', async () => {
|
|
133
|
+
global.fetch = jest
|
|
134
|
+
.fn()
|
|
135
|
+
.mockResolvedValue(new Response(JSON.stringify({ error: 'invalid_grant' }), { status: 400 }));
|
|
136
|
+
await expect((0, sso_1.exchangeCodeForTokens)(ssoClient, 'the-code', sso_1.LOOPBACK_CALLBACK_URL, 'verifier')).rejects.toThrow('SSO token request failed (400 invalid_grant).');
|
|
137
|
+
});
|
|
138
|
+
});
|
package/oclif.manifest.json
CHANGED