@openmrs/esm-api 9.0.3-pre.4643 → 9.0.3-pre.4665
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/.turbo/turbo-build.log +1 -1
- package/package.json +5 -5
- package/src/openmrs-fetch.test.ts +63 -1
package/.turbo/turbo-build.log
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openmrs/esm-api",
|
|
3
|
-
"version": "9.0.3-pre.
|
|
3
|
+
"version": "9.0.3-pre.4665",
|
|
4
4
|
"license": "MPL-2.0",
|
|
5
5
|
"description": "The javascript module for interacting with the OpenMRS API",
|
|
6
6
|
"type": "module",
|
|
@@ -62,10 +62,10 @@
|
|
|
62
62
|
"@openmrs/esm-navigation": "9.x"
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
|
-
"@openmrs/esm-config": "9.0.3-pre.
|
|
66
|
-
"@openmrs/esm-error-handling": "9.0.3-pre.
|
|
67
|
-
"@openmrs/esm-globals": "9.0.3-pre.
|
|
68
|
-
"@openmrs/esm-navigation": "9.0.3-pre.
|
|
65
|
+
"@openmrs/esm-config": "9.0.3-pre.4665",
|
|
66
|
+
"@openmrs/esm-error-handling": "9.0.3-pre.4665",
|
|
67
|
+
"@openmrs/esm-globals": "9.0.3-pre.4665",
|
|
68
|
+
"@openmrs/esm-navigation": "9.0.3-pre.4665",
|
|
69
69
|
"@swc/cli": "0.8.1",
|
|
70
70
|
"@swc/core": "1.15.21",
|
|
71
71
|
"@vitest/coverage-v8": "^4.1.2",
|
|
@@ -210,6 +210,68 @@ describe('openmrsFetch', () => {
|
|
|
210
210
|
}
|
|
211
211
|
});
|
|
212
212
|
|
|
213
|
+
it('redirects to the Location header URL when a 401 response contains a Location header (auth-module challenge)', async () => {
|
|
214
|
+
mockGetConfig.mockResolvedValueOnce({
|
|
215
|
+
redirectAuthFailure: {
|
|
216
|
+
enabled: true,
|
|
217
|
+
url: '',
|
|
218
|
+
errors: [401],
|
|
219
|
+
resolvePromise: true,
|
|
220
|
+
},
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
// @ts-expect-error
|
|
224
|
+
window.fetch.mockReturnValue(
|
|
225
|
+
Promise.resolve({
|
|
226
|
+
ok: false,
|
|
227
|
+
status: 401,
|
|
228
|
+
statusText: 'Unauthorized',
|
|
229
|
+
headers: {
|
|
230
|
+
has: (name: string) => name.toLowerCase() === 'location',
|
|
231
|
+
get: (name: string) => (name.toLowerCase() === 'location' ? '/module/authentication/login.form' : null),
|
|
232
|
+
},
|
|
233
|
+
text: () => Promise.resolve(''),
|
|
234
|
+
}),
|
|
235
|
+
);
|
|
236
|
+
|
|
237
|
+
await openmrsFetch('/ws/rest/v1/session');
|
|
238
|
+
|
|
239
|
+
expect(mockNavigate.mock.calls[0][0]).toStrictEqual({
|
|
240
|
+
to: '/module/authentication/login.form',
|
|
241
|
+
});
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
it('redirects to the default login URL when a 401 response has no Location header (genuine auth failure)', async () => {
|
|
245
|
+
mockGetConfig.mockResolvedValueOnce({
|
|
246
|
+
redirectAuthFailure: {
|
|
247
|
+
enabled: true,
|
|
248
|
+
url: '',
|
|
249
|
+
errors: [401],
|
|
250
|
+
resolvePromise: true,
|
|
251
|
+
},
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
// @ts-expect-error
|
|
255
|
+
window.fetch.mockReturnValue(
|
|
256
|
+
Promise.resolve({
|
|
257
|
+
ok: false,
|
|
258
|
+
status: 401,
|
|
259
|
+
statusText: 'Unauthorized',
|
|
260
|
+
headers: {
|
|
261
|
+
has: (name: string) => false,
|
|
262
|
+
get: (name: string) => null,
|
|
263
|
+
},
|
|
264
|
+
text: () => Promise.resolve(''),
|
|
265
|
+
}),
|
|
266
|
+
);
|
|
267
|
+
|
|
268
|
+
await openmrsFetch('/ws/rest/v1/session');
|
|
269
|
+
|
|
270
|
+
expect(mockNavigate.mock.calls[0][0]).toStrictEqual({
|
|
271
|
+
to: '${openmrsSpaBase}/login',
|
|
272
|
+
});
|
|
273
|
+
});
|
|
274
|
+
|
|
213
275
|
it('navigates to spa login page when the server responds with a 401', async () => {
|
|
214
276
|
mockGetConfig.mockResolvedValueOnce({
|
|
215
277
|
redirectAuthFailure: {
|
|
@@ -220,7 +282,7 @@ describe('openmrsFetch', () => {
|
|
|
220
282
|
},
|
|
221
283
|
});
|
|
222
284
|
|
|
223
|
-
// @ts-
|
|
285
|
+
// @ts-expect-error
|
|
224
286
|
window.fetch.mockReturnValue(
|
|
225
287
|
Promise.resolve({
|
|
226
288
|
ok: false,
|