@contrail/cli 3.5.6-alpha.ba21aa2 → 3.5.7-alpha.30ba14d
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 +8 -4
- package/dist/auth/login.spec.js +12 -5
- 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.5.
|
|
20
|
+
@contrail/cli/3.5.7-alpha.30ba14d linux-x64 node-v24.22.1
|
|
21
21
|
$ contrail --help [COMMAND]
|
|
22
22
|
USAGE
|
|
23
23
|
$ contrail COMMAND
|
package/dist/auth/login.js
CHANGED
|
@@ -37,9 +37,10 @@ async function authUser() {
|
|
|
37
37
|
};
|
|
38
38
|
(0, sdk_1.setConfig)(sdk_1.Auth.config);
|
|
39
39
|
try {
|
|
40
|
-
return await
|
|
40
|
+
return await signInWithStoredTokens();
|
|
41
41
|
}
|
|
42
42
|
catch (e) {
|
|
43
|
+
logger_1.default.debug(`stored tokens rejected: ${e?.message}`);
|
|
43
44
|
if (isNetworkConnectionError(e)) {
|
|
44
45
|
logger_1.default.error("Encountered a network connection issue. Please ensure you're connected to the internet and try again");
|
|
45
46
|
process.exit(1);
|
|
@@ -161,8 +162,7 @@ async function setAuthContext(user, params) {
|
|
|
161
162
|
(0, sdk_1.setConfig)(sdk_1.Auth.config);
|
|
162
163
|
return refreshCurrentUserOrg();
|
|
163
164
|
}
|
|
164
|
-
async function
|
|
165
|
-
logger_1.default.debug('refreshing current user org...');
|
|
165
|
+
async function signInWithStoredTokens() {
|
|
166
166
|
try {
|
|
167
167
|
await (0, sdk_1.getCurrentUser)();
|
|
168
168
|
}
|
|
@@ -172,8 +172,12 @@ async function refreshCurrentUserOrg() {
|
|
|
172
172
|
}
|
|
173
173
|
logger_1.default.debug('access token rejected, refreshing it...');
|
|
174
174
|
await refreshAccessToken();
|
|
175
|
-
await (0, sdk_1.getCurrentUser)();
|
|
176
175
|
}
|
|
176
|
+
return refreshCurrentUserOrg();
|
|
177
|
+
}
|
|
178
|
+
async function refreshCurrentUserOrg() {
|
|
179
|
+
logger_1.default.debug('refreshing current user org...');
|
|
180
|
+
await (0, sdk_1.getCurrentUser)();
|
|
177
181
|
// TODO: To uncomment when telemetry backend is developed.
|
|
178
182
|
// const current_Version = getVersionFromPackageJson();
|
|
179
183
|
// await checkTelemetry(current_Version);
|
package/dist/auth/login.spec.js
CHANGED
|
@@ -137,6 +137,7 @@ describe('authUser with stored tokens', () => {
|
|
|
137
137
|
};
|
|
138
138
|
let acceptedTokens;
|
|
139
139
|
let fetchMock;
|
|
140
|
+
let exitSpy;
|
|
140
141
|
function acceptOnlyTokensGivenToTheSdk() {
|
|
141
142
|
sdk_1.getCurrentUser.mockImplementation(async () => {
|
|
142
143
|
const token = sdk_1.setConfig.mock.calls.at(-1)?.[0]?.apiUserToken;
|
|
@@ -158,6 +159,7 @@ describe('authUser with stored tokens', () => {
|
|
|
158
159
|
global.fetch = fetchMock;
|
|
159
160
|
});
|
|
160
161
|
afterEach(() => {
|
|
162
|
+
exitSpy?.mockRestore();
|
|
161
163
|
global.fetch = originalFetch;
|
|
162
164
|
restoreEnv('CONTRAIL_CLI_EMAIL', originalEmail);
|
|
163
165
|
restoreEnv('CONTRAIL_CLI_PASSWORD', originalPassword);
|
|
@@ -166,14 +168,12 @@ describe('authUser with stored tokens', () => {
|
|
|
166
168
|
fetchMock.mockResolvedValueOnce(jsonResponse(200, { accessToken: 'refreshed-access' }));
|
|
167
169
|
const context = await (0, login_1.authUser)();
|
|
168
170
|
expect(fetchMock).toHaveBeenCalledWith(`${DEV_GATEWAY}/auth/jwt_refresh/`, expect.objectContaining({ body: JSON.stringify({ refreshToken: 'stored-refresh' }) }));
|
|
169
|
-
expect(mockAuthenticateUser).not.toHaveBeenCalled();
|
|
170
171
|
expect(context).toEqual({ ...storedConfig, apiUserToken: 'refreshed-access' });
|
|
171
172
|
expect(config_1.storeConfig).toHaveBeenCalledWith(context);
|
|
172
173
|
});
|
|
173
174
|
it('should keep a still-valid access token without refreshing it', async () => {
|
|
174
175
|
acceptedTokens = ['expired-access'];
|
|
175
176
|
const context = await (0, login_1.authUser)();
|
|
176
|
-
expect(fetchMock).not.toHaveBeenCalled();
|
|
177
177
|
expect(context).toEqual(storedConfig);
|
|
178
178
|
});
|
|
179
179
|
it('should fall back to the password sign-in when the refresh token is rejected', async () => {
|
|
@@ -181,25 +181,32 @@ describe('authUser with stored tokens', () => {
|
|
|
181
181
|
.mockResolvedValueOnce(jsonResponse(401, { message: 'Unauthorized' }))
|
|
182
182
|
.mockResolvedValueOnce(jsonResponse(200, { accessToken: 'vibe-access', refreshToken: 'vibe-refresh' }));
|
|
183
183
|
const context = await (0, login_1.authUser)();
|
|
184
|
-
expect(mockAuthenticateUser).toHaveBeenCalledTimes(1);
|
|
185
184
|
expect(context).toEqual({
|
|
186
185
|
...storedConfig,
|
|
187
186
|
apiUserToken: 'vibe-access',
|
|
188
187
|
apiRefreshToken: 'vibe-refresh',
|
|
189
188
|
});
|
|
190
189
|
});
|
|
190
|
+
it('should report a rejected password sign-in without refreshing the token it was just issued', async () => {
|
|
191
|
+
config_1.getConfig.mockResolvedValue({ apiGateway: DEV_GATEWAY, orgSlug: 'adam-zone-1' });
|
|
192
|
+
acceptedTokens = [];
|
|
193
|
+
fetchMock
|
|
194
|
+
.mockResolvedValueOnce(jsonResponse(200, { accessToken: 'vibe-access', refreshToken: 'vibe-refresh' }))
|
|
195
|
+
.mockResolvedValueOnce(jsonResponse(400, { message: 'Bad Request' }));
|
|
196
|
+
await expect((0, login_1.authUser)()).rejects.toThrow('Failed to fetch current user. Unauthorized');
|
|
197
|
+
expect(config_1.storeConfig).not.toHaveBeenCalled();
|
|
198
|
+
});
|
|
191
199
|
it('should exit with a connection error instead of prompting when the network is down', async () => {
|
|
192
200
|
const networkError = Object.assign(new TypeError('fetch failed'), {
|
|
193
201
|
cause: { code: 'ENOTFOUND' },
|
|
194
202
|
});
|
|
195
203
|
sdk_1.getCurrentUser.mockRejectedValue(networkError);
|
|
196
|
-
|
|
204
|
+
exitSpy = jest.spyOn(process, 'exit').mockImplementation((code) => {
|
|
197
205
|
throw new Error(`exit ${code}`);
|
|
198
206
|
});
|
|
199
207
|
await expect((0, login_1.authUser)()).rejects.toThrow('exit 1');
|
|
200
208
|
expect(fetchMock).not.toHaveBeenCalled();
|
|
201
209
|
expect(mockAuthenticateUser).not.toHaveBeenCalled();
|
|
202
|
-
exit.mockRestore();
|
|
203
210
|
});
|
|
204
211
|
});
|
|
205
212
|
describe('getVersionFromPackageJson', () => {
|
package/oclif.manifest.json
CHANGED