@osdk/oauth 1.8.0-beta.4 → 1.8.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/CHANGELOG.md +16 -0
- package/build/browser/Logger.js +2 -0
- package/build/browser/Logger.js.map +1 -0
- package/build/browser/createPublicOauthClient.js +5 -5
- package/build/browser/createPublicOauthClient.js.map +1 -1
- package/build/browser/index.js.map +1 -1
- package/build/browser/utils.js +2 -1
- package/build/browser/utils.js.map +1 -1
- package/build/cjs/index.cjs +7 -4
- package/build/cjs/index.cjs.map +1 -1
- package/build/cjs/index.d.cts +10 -1
- package/build/esm/Logger.js +2 -0
- package/build/esm/Logger.js.map +1 -0
- package/build/esm/createPublicOauthClient.js +5 -5
- package/build/esm/createPublicOauthClient.js.map +1 -1
- package/build/esm/index.js.map +1 -1
- package/build/esm/utils.js +2 -1
- package/build/esm/utils.js.map +1 -1
- package/build/types/Logger.d.ts +3 -0
- package/build/types/Logger.d.ts.map +1 -0
- package/build/types/createPublicOauthClient.d.ts +6 -0
- package/build/types/createPublicOauthClient.d.ts.map +1 -1
- package/build/types/index.d.ts +1 -0
- package/build/types/index.d.ts.map +1 -1
- package/build/types/utils.d.ts +3 -1
- package/build/types/utils.d.ts.map +1 -1
- package/package.json +3 -3
- package/build/browser/AuthorizationServer.test.js +0 -53
- package/build/browser/AuthorizationServer.test.js.map +0 -1
- package/build/browser/__tests__/createPublicOauthClient.test.js +0 -59
- package/build/browser/__tests__/createPublicOauthClient.test.js.map +0 -1
- package/build/browser/common.test.js +0 -68
- package/build/browser/common.test.js.map +0 -1
- package/build/browser/createAuthlessClient.test.js +0 -31
- package/build/browser/createAuthlessClient.test.js.map +0 -1
- package/build/browser/publicOauth.test.js +0 -430
- package/build/browser/publicOauth.test.js.map +0 -1
- package/build/esm/AuthorizationServer.test.js +0 -53
- package/build/esm/AuthorizationServer.test.js.map +0 -1
- package/build/esm/__tests__/createPublicOauthClient.test.js +0 -59
- package/build/esm/__tests__/createPublicOauthClient.test.js.map +0 -1
- package/build/esm/common.test.js +0 -68
- package/build/esm/common.test.js.map +0 -1
- package/build/esm/createAuthlessClient.test.js +0 -31
- package/build/esm/createAuthlessClient.test.js.map +0 -1
- package/build/esm/publicOauth.test.js +0 -430
- package/build/esm/publicOauth.test.js.map +0 -1
- package/build/types/AuthorizationServer.test.d.ts +0 -1
- package/build/types/AuthorizationServer.test.d.ts.map +0 -1
- package/build/types/__tests__/createPublicOauthClient.test.d.ts +0 -1
- package/build/types/__tests__/createPublicOauthClient.test.d.ts.map +0 -1
- package/build/types/common.test.d.ts +0 -1
- package/build/types/common.test.d.ts.map +0 -1
- package/build/types/createAuthlessClient.test.d.ts +0 -1
- package/build/types/createAuthlessClient.test.d.ts.map +0 -1
- package/build/types/publicOauth.test.d.ts +0 -1
- package/build/types/publicOauth.test.d.ts.map +0 -1
|
@@ -1,430 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2024 Palantir Technologies, Inc. All rights reserved.
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
* you may not use this file except in compliance with the License.
|
|
6
|
-
* You may obtain a copy of the License at
|
|
7
|
-
*
|
|
8
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
*
|
|
10
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
* See the License for the specific language governing permissions and
|
|
14
|
-
* limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
/* eslint-disable @typescript-eslint/consistent-type-imports */
|
|
18
|
-
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
|
19
|
-
import * as commonJs from "./common.js";
|
|
20
|
-
import { createPublicOauthClient } from "./createPublicOauthClient.js";
|
|
21
|
-
const hoistedMocks = vi.hoisted(() => {
|
|
22
|
-
return {
|
|
23
|
-
makeTokenAndSaveRefresh: vi.fn()
|
|
24
|
-
};
|
|
25
|
-
});
|
|
26
|
-
vi.mock("./delay.js", () => ({
|
|
27
|
-
delay: vi.fn(ms => new Promise(resolve => setTimeout(resolve, ms / 100)))
|
|
28
|
-
}));
|
|
29
|
-
vi.mock("./common.js", async importOriginal => {
|
|
30
|
-
const original = await importOriginal();
|
|
31
|
-
return {
|
|
32
|
-
...original,
|
|
33
|
-
common: vi.fn((...args) => {
|
|
34
|
-
const result = original.common(...args);
|
|
35
|
-
return {
|
|
36
|
-
...result,
|
|
37
|
-
makeTokenAndSaveRefresh: hoistedMocks.makeTokenAndSaveRefresh
|
|
38
|
-
};
|
|
39
|
-
}),
|
|
40
|
-
readLocal: vi.spyOn(original, "readLocal"),
|
|
41
|
-
readSession: vi.spyOn(original, "readSession")
|
|
42
|
-
// vi.fn(original.readLocal),
|
|
43
|
-
};
|
|
44
|
-
});
|
|
45
|
-
vi.mock("oauth4webapi");
|
|
46
|
-
describe(createPublicOauthClient, () => {
|
|
47
|
-
const DEFAULT_CUR_URL = new URL("https://fauxurl");
|
|
48
|
-
const fetchFn = vi.fn();
|
|
49
|
-
const mockWindow = {
|
|
50
|
-
location: {
|
|
51
|
-
toString: vi.fn(() => DEFAULT_CUR_URL),
|
|
52
|
-
assign: vi.fn(),
|
|
53
|
-
href: DEFAULT_CUR_URL.href,
|
|
54
|
-
pathname: DEFAULT_CUR_URL.pathname
|
|
55
|
-
},
|
|
56
|
-
history: {
|
|
57
|
-
replaceState: vi.fn()
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
const mockLocalStorage = {
|
|
61
|
-
setItem: vi.fn(),
|
|
62
|
-
getItem: vi.fn(),
|
|
63
|
-
removeItem: vi.fn()
|
|
64
|
-
};
|
|
65
|
-
const mockSessionStorage = {
|
|
66
|
-
setItem: vi.fn(),
|
|
67
|
-
getItem: vi.fn(),
|
|
68
|
-
removeItem: vi.fn()
|
|
69
|
-
};
|
|
70
|
-
beforeEach(() => {
|
|
71
|
-
vi.restoreAllMocks();
|
|
72
|
-
fetchFn.mockRestore();
|
|
73
|
-
});
|
|
74
|
-
afterEach(() => {
|
|
75
|
-
vi.clearAllMocks();
|
|
76
|
-
fetchFn.mockReset();
|
|
77
|
-
});
|
|
78
|
-
beforeAll(() => {
|
|
79
|
-
vi.stubGlobal("window", mockWindow);
|
|
80
|
-
vi.stubGlobal("localStorage", mockLocalStorage);
|
|
81
|
-
vi.stubGlobal("sessionStorage", mockSessionStorage);
|
|
82
|
-
});
|
|
83
|
-
afterAll(() => {
|
|
84
|
-
vi.unstubAllGlobals();
|
|
85
|
-
});
|
|
86
|
-
const BASE_CLIENT_ARGS = {
|
|
87
|
-
clientId: "this-would-be-client-id",
|
|
88
|
-
foundryUrl: "https://a.foundry.url.local",
|
|
89
|
-
redirectUrl: "https://my.redirect.url.local",
|
|
90
|
-
fetchFn
|
|
91
|
-
};
|
|
92
|
-
const fullLoginUrl = new URL("/loginPage", DEFAULT_CUR_URL);
|
|
93
|
-
function setupWindowLocation(currentUrl) {
|
|
94
|
-
mockWindow.location.href = new URL(currentUrl).href;
|
|
95
|
-
mockWindow.location.pathname = new URL(currentUrl).pathname;
|
|
96
|
-
}
|
|
97
|
-
function setupLocalState(initialLocalState) {
|
|
98
|
-
vi.mocked(commonJs.readLocal).mockImplementation(() => initialLocalState);
|
|
99
|
-
}
|
|
100
|
-
let client;
|
|
101
|
-
let clientArgs;
|
|
102
|
-
function setupClient(clientArgs_) {
|
|
103
|
-
clientArgs = clientArgs_;
|
|
104
|
-
if (clientArgs.refreshTokenMarker) {
|
|
105
|
-
client = createPublicOauthClient(clientArgs.clientId, clientArgs.foundryUrl, clientArgs.redirectUrl, clientArgs);
|
|
106
|
-
} else {
|
|
107
|
-
client = createPublicOauthClient(clientArgs.clientId, clientArgs.foundryUrl, clientArgs.redirectUrl, clientArgs.useHistory, clientArgs.loginPage, clientArgs.postLoginPage, clientArgs.scopes, clientArgs.fetchFn, clientArgs.ctxPath);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
beforeEach(() => {
|
|
111
|
-
// prevents mistakes like forgetting to initialize the client with an
|
|
112
|
-
// old value around
|
|
113
|
-
client = undefined;
|
|
114
|
-
clientArgs = undefined;
|
|
115
|
-
});
|
|
116
|
-
async function expectRedirectToMultipass(tokenPromise) {
|
|
117
|
-
// we assume window.location.assign will take you away therefore we
|
|
118
|
-
// also have to expect in this scenario that the thrown error happens
|
|
119
|
-
await expect(tokenPromise).rejects.toThrowError(new Error("Unable to redirect"));
|
|
120
|
-
expect(mockWindow.location.assign).toHaveBeenCalledOnce();
|
|
121
|
-
const url = new URL(mockWindow.location.assign.mock.calls[0][0]);
|
|
122
|
-
expect(url.origin).toEqual(clientArgs.foundryUrl);
|
|
123
|
-
expect(url.pathname).toEqual("/multipass/api/oauth2/authorize");
|
|
124
|
-
expect(Object.fromEntries(url.searchParams.entries())).toEqual(expect.objectContaining({
|
|
125
|
-
client_id: clientArgs.clientId,
|
|
126
|
-
code_challenge: expect.any(String),
|
|
127
|
-
redirect_uri: clientArgs.redirectUrl,
|
|
128
|
-
response_type: "code",
|
|
129
|
-
code_challenge_method: "S256",
|
|
130
|
-
scope: ["offline_access", ...(clientArgs.scopes ?? ["api:read-data", "api:write-data", "api:use-ontologies-read", "api:use-ontologies-write"].sort())].join(" "),
|
|
131
|
-
state: expect.any(String)
|
|
132
|
-
}));
|
|
133
|
-
}
|
|
134
|
-
describe("refresh token marker and scopes", () => {
|
|
135
|
-
beforeEach(() => {
|
|
136
|
-
setupWindowLocation("https://foundry.local");
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
// Backwards compatibility from when we didn't store scopes
|
|
140
|
-
it("should not allow refresh if scopes in local storage is undefined", async () => {
|
|
141
|
-
setupLocalState({
|
|
142
|
-
refresh_token: "refreshToken"
|
|
143
|
-
});
|
|
144
|
-
setupClient({
|
|
145
|
-
...BASE_CLIENT_ARGS
|
|
146
|
-
// Testing with default scopes
|
|
147
|
-
});
|
|
148
|
-
await expectRedirectToMultipass(client());
|
|
149
|
-
});
|
|
150
|
-
it("should not allow refresh if requested scopes are different", async () => {
|
|
151
|
-
setupLocalState({
|
|
152
|
-
refresh_token: "refreshToken",
|
|
153
|
-
requestedScopes: "api:read-data"
|
|
154
|
-
});
|
|
155
|
-
setupClient({
|
|
156
|
-
...BASE_CLIENT_ARGS,
|
|
157
|
-
scopes: ["api:write-data"]
|
|
158
|
-
});
|
|
159
|
-
await expectRedirectToMultipass(client());
|
|
160
|
-
});
|
|
161
|
-
it("should not allow refresh if the refresh markers do not match", async () => {
|
|
162
|
-
setupLocalState({
|
|
163
|
-
refresh_token: "refreshToken",
|
|
164
|
-
refreshTokenMarker: "not-the-right-marker",
|
|
165
|
-
requestedScopes: "api:read-data"
|
|
166
|
-
});
|
|
167
|
-
setupClient({
|
|
168
|
-
...BASE_CLIENT_ARGS,
|
|
169
|
-
refreshTokenMarker: "marker",
|
|
170
|
-
scopes: ["api:read-data"]
|
|
171
|
-
});
|
|
172
|
-
await expectRedirectToMultipass(client());
|
|
173
|
-
});
|
|
174
|
-
it("should try to refresh if refresh markers match and requested scopes are equal", async () => {
|
|
175
|
-
setupLocalState({
|
|
176
|
-
refresh_token: "refreshToken",
|
|
177
|
-
refreshTokenMarker: "marker",
|
|
178
|
-
requestedScopes: "api:admin-read api:datasets-read"
|
|
179
|
-
});
|
|
180
|
-
setupClient({
|
|
181
|
-
...BASE_CLIENT_ARGS,
|
|
182
|
-
refreshTokenMarker: "marker",
|
|
183
|
-
scopes: ["api:datasets-read", "api:admin-read"]
|
|
184
|
-
});
|
|
185
|
-
hoistedMocks.makeTokenAndSaveRefresh.mockImplementationOnce(() => ({
|
|
186
|
-
access_token: "some token",
|
|
187
|
-
expires_at: Date.now(),
|
|
188
|
-
expires_in: 10000
|
|
189
|
-
}));
|
|
190
|
-
const tokenPromise = client();
|
|
191
|
-
await expect(tokenPromise).resolves.toEqual("some token");
|
|
192
|
-
expect(hoistedMocks.makeTokenAndSaveRefresh).toBeCalledTimes(1);
|
|
193
|
-
});
|
|
194
|
-
});
|
|
195
|
-
describe.each([{
|
|
196
|
-
name: "Basic Usage",
|
|
197
|
-
currentUrl: DEFAULT_CUR_URL,
|
|
198
|
-
clientArgs: {
|
|
199
|
-
...BASE_CLIENT_ARGS
|
|
200
|
-
},
|
|
201
|
-
should: {
|
|
202
|
-
redirectToLoginPage: false
|
|
203
|
-
}
|
|
204
|
-
}, {
|
|
205
|
-
name: "Base w/ full loginPage and curUrl is root",
|
|
206
|
-
currentUrl: DEFAULT_CUR_URL,
|
|
207
|
-
clientArgs: {
|
|
208
|
-
...BASE_CLIENT_ARGS,
|
|
209
|
-
loginPage: fullLoginUrl.toString()
|
|
210
|
-
},
|
|
211
|
-
should: {
|
|
212
|
-
redirectToLoginPage: true
|
|
213
|
-
}
|
|
214
|
-
}, {
|
|
215
|
-
name: "Base w/ full loginPage and curUrl is login page",
|
|
216
|
-
currentUrl: fullLoginUrl,
|
|
217
|
-
clientArgs: {
|
|
218
|
-
...BASE_CLIENT_ARGS,
|
|
219
|
-
loginPage: fullLoginUrl.toString()
|
|
220
|
-
},
|
|
221
|
-
should: {
|
|
222
|
-
redirectToLoginPage: false
|
|
223
|
-
}
|
|
224
|
-
}, {
|
|
225
|
-
name: "Base w/ short loginPage and curUrl is root",
|
|
226
|
-
currentUrl: DEFAULT_CUR_URL,
|
|
227
|
-
clientArgs: {
|
|
228
|
-
...BASE_CLIENT_ARGS,
|
|
229
|
-
loginPage: "/loginPage"
|
|
230
|
-
},
|
|
231
|
-
should: {
|
|
232
|
-
redirectToLoginPage: true
|
|
233
|
-
}
|
|
234
|
-
}, {
|
|
235
|
-
name: "Base w/ short loginPage and curUrl is loginPage",
|
|
236
|
-
currentUrl: new URL("/loginPage", DEFAULT_CUR_URL),
|
|
237
|
-
clientArgs: {
|
|
238
|
-
...BASE_CLIENT_ARGS,
|
|
239
|
-
loginPage: "/loginPage"
|
|
240
|
-
},
|
|
241
|
-
should: {
|
|
242
|
-
redirectToLoginPage: false
|
|
243
|
-
}
|
|
244
|
-
}])("$name", ({
|
|
245
|
-
clientArgs,
|
|
246
|
-
currentUrl,
|
|
247
|
-
should
|
|
248
|
-
}) => {
|
|
249
|
-
beforeEach(() => {
|
|
250
|
-
setupClient(clientArgs);
|
|
251
|
-
setupWindowLocation(currentUrl.toString());
|
|
252
|
-
});
|
|
253
|
-
it("calls common with expected values", () => {
|
|
254
|
-
expect(vi.mocked(commonJs.common)).toHaveBeenCalledWith(expect.objectContaining({
|
|
255
|
-
client_id: clientArgs.clientId,
|
|
256
|
-
token_endpoint_auth_method: "none"
|
|
257
|
-
}), commonJs.createAuthorizationServer(clientArgs.ctxPath ?? "/multipass", clientArgs.foundryUrl), expect.any(Function), expect.anything(), expect.any(Function), undefined, (clientArgs.scopes ?? ["api:read-data", "api:write-data", "api:use-ontologies-read", "api:use-ontologies-write"]).sort().join(" "), undefined);
|
|
258
|
-
});
|
|
259
|
-
describe.each([{
|
|
260
|
-
localStorage: {
|
|
261
|
-
refresh_token: "a-refresh-token",
|
|
262
|
-
requestedScopes: (clientArgs.scopes ?? ["api:read-data", "api:write-data", "api:use-ontologies-read", "api:use-ontologies-write"]).sort().join(" ")
|
|
263
|
-
},
|
|
264
|
-
sessionStorage: {}
|
|
265
|
-
}, {
|
|
266
|
-
localStorage: {},
|
|
267
|
-
sessionStorage: {
|
|
268
|
-
codeVerifier: "hi",
|
|
269
|
-
state: "mom",
|
|
270
|
-
oldUrl: "https://someoldurl.local"
|
|
271
|
-
}
|
|
272
|
-
}, {
|
|
273
|
-
localStorage: {},
|
|
274
|
-
sessionStorage: {}
|
|
275
|
-
}])("Initial Local State: %s", initialState => {
|
|
276
|
-
const ACCESS_TOKEN = (Math.random() + 1).toString(36).substring(7);
|
|
277
|
-
beforeEach(() => {
|
|
278
|
-
vi.mocked(commonJs.readLocal).mockImplementation(() => initialState.localStorage);
|
|
279
|
-
vi.mocked(commonJs.readSession).mockImplementation(() => initialState.sessionStorage);
|
|
280
|
-
hoistedMocks.makeTokenAndSaveRefresh.mockImplementation(() => ({
|
|
281
|
-
access_token: ACCESS_TOKEN,
|
|
282
|
-
expires_at: Date.now(),
|
|
283
|
-
expires_in: 10000
|
|
284
|
-
}));
|
|
285
|
-
});
|
|
286
|
-
if (Object.keys(initialState.localStorage).length === 0 && Object.keys(initialState.sessionStorage).length === 0) {
|
|
287
|
-
if (should.redirectToLoginPage) {
|
|
288
|
-
it("redirects to login page", async () => {
|
|
289
|
-
const tokenPromise = client();
|
|
290
|
-
expect(vi.mocked(commonJs.common)).toBeCalledTimes(1);
|
|
291
|
-
if (should.redirectToLoginPage) {
|
|
292
|
-
// expect save local
|
|
293
|
-
await expect(tokenPromise).resolves.toBeUndefined();
|
|
294
|
-
expect(mockSessionStorage.setItem).toBeCalledWith(`@osdk/oauth : refresh : ${clientArgs.clientId}`, JSON.stringify({
|
|
295
|
-
oldUrl: window.location.toString()
|
|
296
|
-
}));
|
|
297
|
-
expect(mockWindow.history.replaceState).toHaveBeenCalledWith({}, "", clientArgs.loginPage);
|
|
298
|
-
}
|
|
299
|
-
});
|
|
300
|
-
} else {
|
|
301
|
-
it("redirects to multipass", async () => {
|
|
302
|
-
const tokenPromise = client();
|
|
303
|
-
expect(vi.mocked(commonJs.common)).toBeCalledTimes(1);
|
|
304
|
-
if (should.redirectToLoginPage) {
|
|
305
|
-
// expect save local
|
|
306
|
-
await expect(tokenPromise).resolves.toBeUndefined();
|
|
307
|
-
expect(mockSessionStorage.setItem).toBeCalledWith(`@osdk/oauth : refresh : ${clientArgs.clientId}`, JSON.stringify({
|
|
308
|
-
oldUrl: window.location.toString()
|
|
309
|
-
}));
|
|
310
|
-
expect(mockWindow.history.replaceState).toHaveBeenCalledWith({}, "", clientArgs.loginPage);
|
|
311
|
-
return;
|
|
312
|
-
}
|
|
313
|
-
await expectRedirectToMultipass(tokenPromise);
|
|
314
|
-
});
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
if (initialState.sessionStorage.codeVerifier) {
|
|
318
|
-
it("tries to auth with return results", async () => {
|
|
319
|
-
await expect(client()).resolves.toEqual(ACCESS_TOKEN);
|
|
320
|
-
expect(hoistedMocks.makeTokenAndSaveRefresh).toHaveBeenCalledTimes(1);
|
|
321
|
-
expect(hoistedMocks.makeTokenAndSaveRefresh).toHaveBeenCalledWith(undefined,
|
|
322
|
-
// this is only because we didn't mock out the internals
|
|
323
|
-
"signIn");
|
|
324
|
-
expect(mockWindow.history.replaceState).toHaveBeenCalledTimes(1);
|
|
325
|
-
expect(mockWindow.history.replaceState).toBeCalledWith(expect.anything(), expect.anything(), initialState.sessionStorage.oldUrl);
|
|
326
|
-
});
|
|
327
|
-
}
|
|
328
|
-
if (initialState.localStorage.refresh_token) {
|
|
329
|
-
it("refreshes", async () => {
|
|
330
|
-
await expect(client()).resolves.toEqual(ACCESS_TOKEN);
|
|
331
|
-
expect(hoistedMocks.makeTokenAndSaveRefresh).toHaveBeenCalledTimes(1);
|
|
332
|
-
expect(hoistedMocks.makeTokenAndSaveRefresh).toHaveBeenCalledWith(undefined,
|
|
333
|
-
// this is only because we didn't mock out the internals
|
|
334
|
-
"refresh");
|
|
335
|
-
});
|
|
336
|
-
}
|
|
337
|
-
});
|
|
338
|
-
});
|
|
339
|
-
describe("tokenStorage option", () => {
|
|
340
|
-
beforeEach(() => {
|
|
341
|
-
setupWindowLocation("https://foundry.local");
|
|
342
|
-
setupLocalState({});
|
|
343
|
-
vi.mocked(commonJs.readSession).mockImplementation(() => ({}));
|
|
344
|
-
// getStorage() checks process.env.TARGET to determine if we're in a browser
|
|
345
|
-
vi.stubGlobal("process", {
|
|
346
|
-
env: {
|
|
347
|
-
TARGET: "browser"
|
|
348
|
-
}
|
|
349
|
-
});
|
|
350
|
-
});
|
|
351
|
-
afterEach(() => {
|
|
352
|
-
vi.unstubAllGlobals();
|
|
353
|
-
// Re-stub the globals that the outer describe needs
|
|
354
|
-
vi.stubGlobal("window", mockWindow);
|
|
355
|
-
vi.stubGlobal("localStorage", mockLocalStorage);
|
|
356
|
-
vi.stubGlobal("sessionStorage", mockSessionStorage);
|
|
357
|
-
});
|
|
358
|
-
it("should pass localStorage to common when tokenStorage is 'localStorage'", () => {
|
|
359
|
-
createPublicOauthClient(BASE_CLIENT_ARGS.clientId, BASE_CLIENT_ARGS.foundryUrl, BASE_CLIENT_ARGS.redirectUrl, {
|
|
360
|
-
tokenStorage: "localStorage"
|
|
361
|
-
});
|
|
362
|
-
|
|
363
|
-
// common() is called with 8 args, the last one being the storage
|
|
364
|
-
const lastArg = vi.mocked(commonJs.common).mock.calls[0][7];
|
|
365
|
-
expect(lastArg).toBe(mockLocalStorage);
|
|
366
|
-
});
|
|
367
|
-
it("should pass sessionStorage to common when tokenStorage is 'sessionStorage'", () => {
|
|
368
|
-
createPublicOauthClient(BASE_CLIENT_ARGS.clientId, BASE_CLIENT_ARGS.foundryUrl, BASE_CLIENT_ARGS.redirectUrl, {
|
|
369
|
-
tokenStorage: "sessionStorage"
|
|
370
|
-
});
|
|
371
|
-
const lastArg = vi.mocked(commonJs.common).mock.calls[0][7];
|
|
372
|
-
expect(lastArg).toBe(mockSessionStorage);
|
|
373
|
-
});
|
|
374
|
-
it("should pass undefined to common when tokenStorage is 'none'", () => {
|
|
375
|
-
createPublicOauthClient(BASE_CLIENT_ARGS.clientId, BASE_CLIENT_ARGS.foundryUrl, BASE_CLIENT_ARGS.redirectUrl, {
|
|
376
|
-
tokenStorage: "none"
|
|
377
|
-
});
|
|
378
|
-
const lastArg = vi.mocked(commonJs.common).mock.calls[0][7];
|
|
379
|
-
expect(lastArg).toBeUndefined();
|
|
380
|
-
});
|
|
381
|
-
it("should not include offline_access scope when tokenStorage is 'none'", async () => {
|
|
382
|
-
const client = createPublicOauthClient(BASE_CLIENT_ARGS.clientId, BASE_CLIENT_ARGS.foundryUrl, BASE_CLIENT_ARGS.redirectUrl, {
|
|
383
|
-
tokenStorage: "none"
|
|
384
|
-
});
|
|
385
|
-
|
|
386
|
-
// Trigger the auth flow - this should redirect to multipass
|
|
387
|
-
await expect(client()).rejects.toThrowError("Unable to redirect");
|
|
388
|
-
expect(mockWindow.location.assign).toHaveBeenCalledOnce();
|
|
389
|
-
const url = new URL(mockWindow.location.assign.mock.calls[0][0]);
|
|
390
|
-
const scope = url.searchParams.get("scope");
|
|
391
|
-
|
|
392
|
-
// Should NOT include offline_access
|
|
393
|
-
expect(scope).not.toContain("offline_access");
|
|
394
|
-
// Should still include the regular scopes
|
|
395
|
-
expect(scope).toContain("api:read-data");
|
|
396
|
-
});
|
|
397
|
-
it("should pass localStorage to common when tokenStorage is not provided", () => {
|
|
398
|
-
createPublicOauthClient(BASE_CLIENT_ARGS.clientId, BASE_CLIENT_ARGS.foundryUrl, BASE_CLIENT_ARGS.redirectUrl);
|
|
399
|
-
const lastArg = vi.mocked(commonJs.common).mock.calls[0][7];
|
|
400
|
-
expect(lastArg).toBe(mockLocalStorage);
|
|
401
|
-
});
|
|
402
|
-
it("should include offline_access scope when tokenStorage is 'localStorage'", async () => {
|
|
403
|
-
const client = createPublicOauthClient(BASE_CLIENT_ARGS.clientId, BASE_CLIENT_ARGS.foundryUrl, BASE_CLIENT_ARGS.redirectUrl, {
|
|
404
|
-
tokenStorage: "localStorage"
|
|
405
|
-
});
|
|
406
|
-
await expect(client()).rejects.toThrowError("Unable to redirect");
|
|
407
|
-
const url = new URL(mockWindow.location.assign.mock.calls[0][0]);
|
|
408
|
-
const scope = url.searchParams.get("scope");
|
|
409
|
-
expect(scope).toContain("offline_access");
|
|
410
|
-
});
|
|
411
|
-
it("should include offline_access scope when tokenStorage is 'sessionStorage'", async () => {
|
|
412
|
-
const client = createPublicOauthClient(BASE_CLIENT_ARGS.clientId, BASE_CLIENT_ARGS.foundryUrl, BASE_CLIENT_ARGS.redirectUrl, {
|
|
413
|
-
tokenStorage: "sessionStorage"
|
|
414
|
-
});
|
|
415
|
-
await expect(client()).rejects.toThrowError("Unable to redirect");
|
|
416
|
-
const url = new URL(mockWindow.location.assign.mock.calls[0][0]);
|
|
417
|
-
const scope = url.searchParams.get("scope");
|
|
418
|
-
expect(scope).toContain("offline_access");
|
|
419
|
-
});
|
|
420
|
-
it("should not attempt to read from storage when tokenStorage is 'none'", async () => {
|
|
421
|
-
vi.mocked(commonJs.readLocal).mockClear();
|
|
422
|
-
const client = createPublicOauthClient(BASE_CLIENT_ARGS.clientId, BASE_CLIENT_ARGS.foundryUrl, BASE_CLIENT_ARGS.redirectUrl, {
|
|
423
|
-
tokenStorage: "none"
|
|
424
|
-
});
|
|
425
|
-
await expect(client()).rejects.toThrowError("Unable to redirect");
|
|
426
|
-
expect(vi.mocked(commonJs.readLocal)).not.toHaveBeenCalled();
|
|
427
|
-
});
|
|
428
|
-
});
|
|
429
|
-
});
|
|
430
|
-
//# sourceMappingURL=publicOauth.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"publicOauth.test.js","names":["afterAll","afterEach","beforeAll","beforeEach","describe","expect","it","vi","commonJs","createPublicOauthClient","hoistedMocks","hoisted","makeTokenAndSaveRefresh","fn","mock","delay","ms","Promise","resolve","setTimeout","importOriginal","original","common","args","result","readLocal","spyOn","readSession","DEFAULT_CUR_URL","URL","fetchFn","mockWindow","location","toString","assign","href","pathname","history","replaceState","mockLocalStorage","setItem","getItem","removeItem","mockSessionStorage","restoreAllMocks","mockRestore","clearAllMocks","mockReset","stubGlobal","unstubAllGlobals","BASE_CLIENT_ARGS","clientId","foundryUrl","redirectUrl","fullLoginUrl","setupWindowLocation","currentUrl","setupLocalState","initialLocalState","mocked","mockImplementation","client","clientArgs","setupClient","clientArgs_","refreshTokenMarker","useHistory","loginPage","postLoginPage","scopes","ctxPath","undefined","expectRedirectToMultipass","tokenPromise","rejects","toThrowError","Error","toHaveBeenCalledOnce","url","calls","origin","toEqual","Object","fromEntries","searchParams","entries","objectContaining","client_id","code_challenge","any","String","redirect_uri","response_type","code_challenge_method","scope","sort","join","state","refresh_token","requestedScopes","mockImplementationOnce","access_token","expires_at","Date","now","expires_in","resolves","toBeCalledTimes","each","name","should","redirectToLoginPage","toHaveBeenCalledWith","token_endpoint_auth_method","createAuthorizationServer","Function","anything","localStorage","sessionStorage","codeVerifier","oldUrl","initialState","ACCESS_TOKEN","Math","random","substring","keys","length","toBeUndefined","toBeCalledWith","JSON","stringify","window","toHaveBeenCalledTimes","env","TARGET","tokenStorage","lastArg","toBe","get","not","toContain","mockClear","toHaveBeenCalled"],"sources":["publicOauth.test.ts"],"sourcesContent":["/*\n * Copyright 2024 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/* eslint-disable @typescript-eslint/consistent-type-imports */\nimport {\n afterAll,\n afterEach,\n beforeAll,\n beforeEach,\n describe,\n expect,\n it,\n vi,\n} from \"vitest\";\n\nimport * as commonJs from \"./common.js\";\nimport { LocalStorageState, SessionStorageState } from \"./common.js\";\nimport { createPublicOauthClient } from \"./createPublicOauthClient.js\";\nimport { PublicOauthClient } from \"./PublicOauthClient.js\";\n\nconst hoistedMocks = vi.hoisted(() => {\n return {\n makeTokenAndSaveRefresh: vi.fn(),\n };\n});\n\nvi.mock(\"./delay.js\", () => ({\n delay: vi.fn((ms: number) =>\n new Promise<void>(resolve => setTimeout(resolve, ms / 100))\n ),\n}));\n\nvi.mock(\"./common.js\", async (importOriginal) => {\n const original = await importOriginal<typeof import(\"./common.js\")>();\n return {\n ...original,\n common: vi.fn<typeof commonJs.common>((...args) => {\n const result = original.common(...args);\n return {\n ...result,\n makeTokenAndSaveRefresh: hoistedMocks.makeTokenAndSaveRefresh,\n };\n }),\n readLocal: vi.spyOn(original, \"readLocal\"),\n readSession: vi.spyOn(original, \"readSession\"),\n // vi.fn(original.readLocal),\n };\n});\n\nvi.mock(\"oauth4webapi\");\n\ninterface BaseClientArgs {\n clientId: string;\n foundryUrl: string;\n redirectUrl: string;\n fetchFn?: typeof globalThis.fetch;\n}\n\ninterface ClientArgs extends BaseClientArgs {\n useHistory?: boolean;\n loginPage?: string;\n postLoginPage?: string;\n scopes?: string[];\n ctxPath?: string;\n refreshTokenMarker?: string;\n}\n\ndescribe(createPublicOauthClient, () => {\n const DEFAULT_CUR_URL = new URL(\"https://fauxurl\");\n const fetchFn = vi.fn<typeof fetch>();\n\n const mockWindow = {\n location: {\n toString: vi.fn(() => DEFAULT_CUR_URL),\n assign: vi.fn(),\n href: DEFAULT_CUR_URL.href,\n pathname: DEFAULT_CUR_URL.pathname,\n },\n history: {\n replaceState: vi.fn<typeof window.history.replaceState>(),\n },\n };\n\n const mockLocalStorage = {\n setItem: vi.fn(),\n getItem: vi.fn(),\n removeItem: vi.fn(),\n };\n\n const mockSessionStorage = {\n setItem: vi.fn(),\n getItem: vi.fn(),\n removeItem: vi.fn(),\n };\n\n beforeEach((context) => {\n vi.restoreAllMocks();\n fetchFn.mockRestore();\n });\n\n afterEach((context) => {\n vi.clearAllMocks();\n fetchFn.mockReset();\n });\n\n beforeAll(() => {\n vi.stubGlobal(\"window\", mockWindow);\n vi.stubGlobal(\"localStorage\", mockLocalStorage);\n vi.stubGlobal(\"sessionStorage\", mockSessionStorage);\n });\n\n afterAll(() => {\n vi.unstubAllGlobals();\n });\n\n const BASE_CLIENT_ARGS: BaseClientArgs = {\n clientId: \"this-would-be-client-id\",\n foundryUrl: \"https://a.foundry.url.local\",\n redirectUrl: \"https://my.redirect.url.local\",\n fetchFn,\n };\n\n const fullLoginUrl = new URL(\"/loginPage\", DEFAULT_CUR_URL);\n\n function setupWindowLocation(currentUrl: string) {\n mockWindow.location.href = new URL(currentUrl).href;\n mockWindow.location.pathname = new URL(currentUrl).pathname;\n }\n\n function setupLocalState(initialLocalState: LocalStorageState) {\n vi.mocked(commonJs.readLocal).mockImplementation(() => initialLocalState);\n }\n\n let client: PublicOauthClient;\n let clientArgs: ClientArgs;\n function setupClient(clientArgs_: ClientArgs) {\n clientArgs = clientArgs_;\n if (clientArgs.refreshTokenMarker) {\n client = createPublicOauthClient(\n clientArgs.clientId,\n clientArgs.foundryUrl,\n clientArgs.redirectUrl,\n clientArgs,\n );\n } else {\n client = createPublicOauthClient(\n clientArgs.clientId,\n clientArgs.foundryUrl,\n clientArgs.redirectUrl,\n clientArgs.useHistory,\n clientArgs.loginPage,\n clientArgs.postLoginPage,\n clientArgs.scopes,\n clientArgs.fetchFn,\n clientArgs.ctxPath,\n );\n }\n }\n beforeEach((context) => {\n // prevents mistakes like forgetting to initialize the client with an\n // old value around\n client = undefined!;\n clientArgs = undefined!;\n });\n\n async function expectRedirectToMultipass(\n tokenPromise: Promise<string>,\n ) {\n // we assume window.location.assign will take you away therefore we\n // also have to expect in this scenario that the thrown error happens\n await expect(tokenPromise)\n .rejects.toThrowError(new Error(\"Unable to redirect\"));\n\n expect(mockWindow.location.assign).toHaveBeenCalledOnce();\n\n const url = new URL(\n mockWindow.location.assign.mock.calls[0][0],\n );\n expect(url.origin).toEqual(clientArgs.foundryUrl);\n expect(url.pathname).toEqual(\"/multipass/api/oauth2/authorize\");\n expect(Object.fromEntries(url.searchParams.entries())).toEqual(\n expect.objectContaining({\n client_id: clientArgs.clientId,\n code_challenge: expect.any(String),\n redirect_uri: clientArgs.redirectUrl,\n response_type: \"code\",\n code_challenge_method: \"S256\",\n scope: [\n \"offline_access\",\n ...(clientArgs.scopes\n ?? [\n \"api:read-data\",\n \"api:write-data\",\n \"api:use-ontologies-read\",\n \"api:use-ontologies-write\",\n ].sort()),\n ].join(\" \"),\n state: expect.any(String),\n }),\n );\n }\n\n describe(\"refresh token marker and scopes\", () => {\n beforeEach(() => {\n setupWindowLocation(\"https://foundry.local\");\n });\n\n // Backwards compatibility from when we didn't store scopes\n it(\"should not allow refresh if scopes in local storage is undefined\", async () => {\n setupLocalState({\n refresh_token: \"refreshToken\",\n });\n\n setupClient({\n ...BASE_CLIENT_ARGS,\n // Testing with default scopes\n });\n\n await expectRedirectToMultipass(\n client(),\n );\n });\n\n it(\"should not allow refresh if requested scopes are different\", async () => {\n setupLocalState({\n refresh_token: \"refreshToken\",\n requestedScopes: \"api:read-data\",\n });\n\n setupClient({\n ...BASE_CLIENT_ARGS,\n scopes: [\"api:write-data\"],\n });\n\n await expectRedirectToMultipass(\n client(),\n );\n });\n\n it(\"should not allow refresh if the refresh markers do not match\", async () => {\n setupLocalState({\n refresh_token: \"refreshToken\",\n refreshTokenMarker: \"not-the-right-marker\",\n requestedScopes: \"api:read-data\",\n });\n\n setupClient({\n ...BASE_CLIENT_ARGS,\n refreshTokenMarker: \"marker\",\n scopes: [\"api:read-data\"],\n });\n\n await expectRedirectToMultipass(\n client(),\n );\n });\n\n it(\"should try to refresh if refresh markers match and requested scopes are equal\", async () => {\n setupLocalState({\n refresh_token: \"refreshToken\",\n refreshTokenMarker: \"marker\",\n requestedScopes: \"api:admin-read api:datasets-read\",\n });\n\n setupClient({\n ...BASE_CLIENT_ARGS,\n refreshTokenMarker: \"marker\",\n scopes: [\"api:datasets-read\", \"api:admin-read\"],\n });\n\n hoistedMocks.makeTokenAndSaveRefresh.mockImplementationOnce(\n () => ({\n access_token: \"some token\",\n expires_at: Date.now(),\n expires_in: 10000,\n }),\n );\n\n const tokenPromise = client();\n\n await expect(tokenPromise).resolves.toEqual(\"some token\");\n\n expect(hoistedMocks.makeTokenAndSaveRefresh).toBeCalledTimes(1);\n });\n });\n\n describe.each<{\n name: string;\n currentUrl: URL;\n clientArgs: BaseClientArgs & {\n useHistory?: boolean;\n loginPage?: string;\n postLoginPage?: string;\n scopes?: string[];\n ctxPath?: string;\n };\n should: {\n redirectToLoginPage: boolean;\n };\n }>([\n {\n name: \"Basic Usage\",\n currentUrl: DEFAULT_CUR_URL,\n clientArgs: {\n ...BASE_CLIENT_ARGS,\n },\n should: {\n redirectToLoginPage: false,\n },\n },\n {\n name: \"Base w/ full loginPage and curUrl is root\",\n currentUrl: DEFAULT_CUR_URL,\n clientArgs: {\n ...BASE_CLIENT_ARGS,\n loginPage: fullLoginUrl.toString(),\n },\n should: {\n redirectToLoginPage: true,\n },\n },\n {\n name: \"Base w/ full loginPage and curUrl is login page\",\n currentUrl: fullLoginUrl,\n clientArgs: {\n ...BASE_CLIENT_ARGS,\n loginPage: fullLoginUrl.toString(),\n },\n should: {\n redirectToLoginPage: false,\n },\n },\n {\n name: \"Base w/ short loginPage and curUrl is root\",\n currentUrl: DEFAULT_CUR_URL,\n clientArgs: {\n ...BASE_CLIENT_ARGS,\n loginPage: \"/loginPage\",\n },\n should: {\n redirectToLoginPage: true,\n },\n },\n {\n name: \"Base w/ short loginPage and curUrl is loginPage\",\n currentUrl: new URL(\"/loginPage\", DEFAULT_CUR_URL),\n clientArgs: {\n ...BASE_CLIENT_ARGS,\n loginPage: \"/loginPage\",\n },\n should: {\n redirectToLoginPage: false,\n },\n },\n ])(\"$name\", ({ clientArgs, currentUrl, should }) => {\n beforeEach(() => {\n setupClient(clientArgs);\n setupWindowLocation(currentUrl.toString());\n });\n\n it(\"calls common with expected values\", () => {\n expect(vi.mocked(commonJs.common)).toHaveBeenCalledWith(\n expect.objectContaining({\n client_id: clientArgs.clientId,\n token_endpoint_auth_method: \"none\",\n }),\n commonJs.createAuthorizationServer(\n clientArgs.ctxPath ?? \"/multipass\",\n clientArgs.foundryUrl,\n ),\n expect.any(Function),\n expect.anything(),\n expect.any(Function),\n undefined,\n (clientArgs.scopes\n ?? [\n \"api:read-data\",\n \"api:write-data\",\n \"api:use-ontologies-read\",\n \"api:use-ontologies-write\",\n ]).sort().join(\" \"),\n undefined,\n );\n });\n\n describe.each<\n { localStorage: LocalStorageState; sessionStorage: SessionStorageState }\n >([\n {\n localStorage: {\n refresh_token: \"a-refresh-token\",\n requestedScopes: (clientArgs.scopes\n ?? [\n \"api:read-data\",\n \"api:write-data\",\n \"api:use-ontologies-read\",\n \"api:use-ontologies-write\",\n ]).sort().join(\" \"),\n },\n sessionStorage: {},\n },\n {\n localStorage: {},\n sessionStorage: {\n codeVerifier: \"hi\",\n state: \"mom\",\n oldUrl: \"https://someoldurl.local\",\n },\n },\n { localStorage: {}, sessionStorage: {} },\n ])(\"Initial Local State: %s\", (initialState) => {\n const ACCESS_TOKEN = (Math.random() + 1).toString(36).substring(7);\n\n beforeEach(() => {\n vi.mocked(commonJs.readLocal).mockImplementation(() =>\n initialState.localStorage\n );\n\n vi.mocked(commonJs.readSession).mockImplementation(() =>\n initialState.sessionStorage\n );\n\n hoistedMocks.makeTokenAndSaveRefresh.mockImplementation(\n () => ({\n access_token: ACCESS_TOKEN,\n expires_at: Date.now(),\n expires_in: 10000,\n }),\n );\n });\n\n if (\n Object.keys(initialState.localStorage).length === 0\n && Object.keys(initialState.sessionStorage).length === 0\n ) {\n if (should.redirectToLoginPage) {\n it(\"redirects to login page\", async () => {\n const tokenPromise = client!();\n expect(vi.mocked(commonJs.common)).toBeCalledTimes(1);\n\n if (should.redirectToLoginPage) {\n // expect save local\n await expect(tokenPromise).resolves.toBeUndefined();\n expect(mockSessionStorage.setItem).toBeCalledWith(\n `@osdk/oauth : refresh : ${clientArgs.clientId}`,\n JSON.stringify({ oldUrl: window.location.toString() }),\n );\n expect(mockWindow.history.replaceState).toHaveBeenCalledWith(\n {},\n \"\",\n clientArgs.loginPage,\n );\n return;\n }\n });\n } else {\n it(\"redirects to multipass\", async () => {\n const tokenPromise = client!();\n expect(vi.mocked(commonJs.common)).toBeCalledTimes(1);\n\n if (should.redirectToLoginPage) {\n // expect save local\n await expect(tokenPromise).resolves.toBeUndefined();\n expect(mockSessionStorage.setItem).toBeCalledWith(\n `@osdk/oauth : refresh : ${clientArgs.clientId}`,\n JSON.stringify({ oldUrl: window.location.toString() }),\n );\n\n expect(mockWindow.history.replaceState).toHaveBeenCalledWith(\n {},\n \"\",\n clientArgs.loginPage,\n );\n return;\n }\n\n await expectRedirectToMultipass(\n tokenPromise,\n );\n });\n }\n }\n\n if (initialState.sessionStorage.codeVerifier) {\n it(\"tries to auth with return results\", async () => {\n await expect(client()).resolves.toEqual(ACCESS_TOKEN);\n expect(hoistedMocks.makeTokenAndSaveRefresh).toHaveBeenCalledTimes(\n 1,\n );\n expect(hoistedMocks.makeTokenAndSaveRefresh).toHaveBeenCalledWith(\n undefined, // this is only because we didn't mock out the internals\n \"signIn\",\n );\n\n expect(mockWindow.history.replaceState).toHaveBeenCalledTimes(1);\n expect(mockWindow.history.replaceState).toBeCalledWith(\n expect.anything(),\n expect.anything(),\n initialState.sessionStorage.oldUrl,\n );\n });\n }\n\n if (initialState.localStorage.refresh_token) {\n it(\"refreshes\", async () => {\n await expect(client()).resolves.toEqual(ACCESS_TOKEN);\n\n expect(hoistedMocks.makeTokenAndSaveRefresh).toHaveBeenCalledTimes(\n 1,\n );\n expect(hoistedMocks.makeTokenAndSaveRefresh).toHaveBeenCalledWith(\n undefined, // this is only because we didn't mock out the internals\n \"refresh\",\n );\n });\n }\n });\n });\n\n describe(\"tokenStorage option\", () => {\n beforeEach(() => {\n setupWindowLocation(\"https://foundry.local\");\n setupLocalState({});\n vi.mocked(commonJs.readSession).mockImplementation(() => ({}));\n // getStorage() checks process.env.TARGET to determine if we're in a browser\n vi.stubGlobal(\"process\", { env: { TARGET: \"browser\" } });\n });\n\n afterEach(() => {\n vi.unstubAllGlobals();\n // Re-stub the globals that the outer describe needs\n vi.stubGlobal(\"window\", mockWindow);\n vi.stubGlobal(\"localStorage\", mockLocalStorage);\n vi.stubGlobal(\"sessionStorage\", mockSessionStorage);\n });\n\n it(\"should pass localStorage to common when tokenStorage is 'localStorage'\", () => {\n createPublicOauthClient(\n BASE_CLIENT_ARGS.clientId,\n BASE_CLIENT_ARGS.foundryUrl,\n BASE_CLIENT_ARGS.redirectUrl,\n { tokenStorage: \"localStorage\" },\n );\n\n // common() is called with 8 args, the last one being the storage\n const lastArg = vi.mocked(commonJs.common).mock.calls[0][7];\n expect(lastArg).toBe(mockLocalStorage);\n });\n\n it(\"should pass sessionStorage to common when tokenStorage is 'sessionStorage'\", () => {\n createPublicOauthClient(\n BASE_CLIENT_ARGS.clientId,\n BASE_CLIENT_ARGS.foundryUrl,\n BASE_CLIENT_ARGS.redirectUrl,\n { tokenStorage: \"sessionStorage\" },\n );\n\n const lastArg = vi.mocked(commonJs.common).mock.calls[0][7];\n expect(lastArg).toBe(mockSessionStorage);\n });\n\n it(\"should pass undefined to common when tokenStorage is 'none'\", () => {\n createPublicOauthClient(\n BASE_CLIENT_ARGS.clientId,\n BASE_CLIENT_ARGS.foundryUrl,\n BASE_CLIENT_ARGS.redirectUrl,\n { tokenStorage: \"none\" },\n );\n\n const lastArg = vi.mocked(commonJs.common).mock.calls[0][7];\n expect(lastArg).toBeUndefined();\n });\n\n it(\"should not include offline_access scope when tokenStorage is 'none'\", async () => {\n const client = createPublicOauthClient(\n BASE_CLIENT_ARGS.clientId,\n BASE_CLIENT_ARGS.foundryUrl,\n BASE_CLIENT_ARGS.redirectUrl,\n { tokenStorage: \"none\" },\n );\n\n // Trigger the auth flow - this should redirect to multipass\n await expect(client()).rejects.toThrowError(\"Unable to redirect\");\n\n expect(mockWindow.location.assign).toHaveBeenCalledOnce();\n\n const url = new URL(mockWindow.location.assign.mock.calls[0][0]);\n const scope = url.searchParams.get(\"scope\");\n\n // Should NOT include offline_access\n expect(scope).not.toContain(\"offline_access\");\n // Should still include the regular scopes\n expect(scope).toContain(\"api:read-data\");\n });\n\n it(\"should pass localStorage to common when tokenStorage is not provided\", () => {\n createPublicOauthClient(\n BASE_CLIENT_ARGS.clientId,\n BASE_CLIENT_ARGS.foundryUrl,\n BASE_CLIENT_ARGS.redirectUrl,\n );\n const lastArg = vi.mocked(commonJs.common).mock.calls[0][7];\n expect(lastArg).toBe(mockLocalStorage);\n });\n\n it(\"should include offline_access scope when tokenStorage is 'localStorage'\", async () => {\n const client = createPublicOauthClient(\n BASE_CLIENT_ARGS.clientId,\n BASE_CLIENT_ARGS.foundryUrl,\n BASE_CLIENT_ARGS.redirectUrl,\n { tokenStorage: \"localStorage\" },\n );\n\n await expect(client()).rejects.toThrowError(\"Unable to redirect\");\n\n const url = new URL(mockWindow.location.assign.mock.calls[0][0]);\n const scope = url.searchParams.get(\"scope\");\n\n expect(scope).toContain(\"offline_access\");\n });\n\n it(\"should include offline_access scope when tokenStorage is 'sessionStorage'\", async () => {\n const client = createPublicOauthClient(\n BASE_CLIENT_ARGS.clientId,\n BASE_CLIENT_ARGS.foundryUrl,\n BASE_CLIENT_ARGS.redirectUrl,\n { tokenStorage: \"sessionStorage\" },\n );\n\n await expect(client()).rejects.toThrowError(\"Unable to redirect\");\n\n const url = new URL(mockWindow.location.assign.mock.calls[0][0]);\n const scope = url.searchParams.get(\"scope\");\n\n expect(scope).toContain(\"offline_access\");\n });\n\n it(\"should not attempt to read from storage when tokenStorage is 'none'\", async () => {\n vi.mocked(commonJs.readLocal).mockClear();\n\n const client = createPublicOauthClient(\n BASE_CLIENT_ARGS.clientId,\n BASE_CLIENT_ARGS.foundryUrl,\n BASE_CLIENT_ARGS.redirectUrl,\n { tokenStorage: \"none\" },\n );\n\n await expect(client()).rejects.toThrowError(\"Unable to redirect\");\n\n expect(vi.mocked(commonJs.readLocal)).not.toHaveBeenCalled();\n });\n });\n});\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,SACEA,QAAQ,EACRC,SAAS,EACTC,SAAS,EACTC,UAAU,EACVC,QAAQ,EACRC,MAAM,EACNC,EAAE,EACFC,EAAE,QACG,QAAQ;AAEf,OAAO,KAAKC,QAAQ,MAAM,aAAa;AAEvC,SAASC,uBAAuB,QAAQ,8BAA8B;AAGtE,MA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E,EAAE,CAACoD,MAAM,CAACnD,QAAQ,CAACiB,SAAS,CAAC,CAAC,CAACmH,GAAG,CAACG,gBAAgB,CAAC,CAAC;IAC9D,CAAC,CAAC;EACJ,CAAC,CAAC;AACJ,CAAC,CAAC","ignoreList":[]}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2024 Palantir Technologies, Inc. All rights reserved.
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
* you may not use this file except in compliance with the License.
|
|
6
|
-
* You may obtain a copy of the License at
|
|
7
|
-
*
|
|
8
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
*
|
|
10
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
* See the License for the specific language governing permissions and
|
|
14
|
-
* limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
import { describe, expect, it } from "vitest";
|
|
18
|
-
import { createAuthorizationServer } from "./common.js";
|
|
19
|
-
describe("Create authorization server", () => {
|
|
20
|
-
it("works with old multipass ctx path", () => {
|
|
21
|
-
const authServer = createAuthorizationServer("/multipass", "https://stack.palantir.com");
|
|
22
|
-
expect(authServer).toEqual({
|
|
23
|
-
token_endpoint: "https://stack.palantir.com/multipass/api/oauth2/token",
|
|
24
|
-
authorization_endpoint: "https://stack.palantir.com/multipass/api/oauth2/authorize",
|
|
25
|
-
revocation_endpoint: "https://stack.palantir.com/multipass/api/oauth2/revoke_token",
|
|
26
|
-
issuer: "https://stack.palantir.com/multipass"
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
|
-
it("works with new multipass ctx path", () => {
|
|
30
|
-
const authServer = createAuthorizationServer("multipass", "https://stack.palantir.com");
|
|
31
|
-
expect(authServer).toEqual({
|
|
32
|
-
token_endpoint: "https://stack.palantir.com/multipass/api/oauth2/token",
|
|
33
|
-
authorization_endpoint: "https://stack.palantir.com/multipass/api/oauth2/authorize",
|
|
34
|
-
revocation_endpoint: "https://stack.palantir.com/multipass/api/oauth2/revoke_token",
|
|
35
|
-
issuer: "https://stack.palantir.com/multipass"
|
|
36
|
-
});
|
|
37
|
-
const authServerCustom = createAuthorizationServer("multipass", "https://stack.palantir.com/foo/first/someStuff");
|
|
38
|
-
expect(authServerCustom).toEqual({
|
|
39
|
-
token_endpoint: "https://stack.palantir.com/foo/first/someStuff/multipass/api/oauth2/token",
|
|
40
|
-
authorization_endpoint: "https://stack.palantir.com/foo/first/someStuff/multipass/api/oauth2/authorize",
|
|
41
|
-
revocation_endpoint: "https://stack.palantir.com/foo/first/someStuff/multipass/api/oauth2/revoke_token",
|
|
42
|
-
issuer: "https://stack.palantir.com/foo/first/someStuff/multipass"
|
|
43
|
-
});
|
|
44
|
-
const authServerCustomWithTrailingSlash = createAuthorizationServer("multipass", "https://stack.palantir.com/foo/first/someStuff/");
|
|
45
|
-
expect(authServerCustomWithTrailingSlash).toEqual({
|
|
46
|
-
token_endpoint: "https://stack.palantir.com/foo/first/someStuff/multipass/api/oauth2/token",
|
|
47
|
-
authorization_endpoint: "https://stack.palantir.com/foo/first/someStuff/multipass/api/oauth2/authorize",
|
|
48
|
-
revocation_endpoint: "https://stack.palantir.com/foo/first/someStuff/multipass/api/oauth2/revoke_token",
|
|
49
|
-
issuer: "https://stack.palantir.com/foo/first/someStuff/multipass"
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
//# sourceMappingURL=AuthorizationServer.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AuthorizationServer.test.js","names":["describe","expect","it","createAuthorizationServer","authServer","toEqual","token_endpoint","authorization_endpoint","revocation_endpoint","issuer","authServerCustom","authServerCustomWithTrailingSlash"],"sources":["AuthorizationServer.test.ts"],"sourcesContent":["/*\n * Copyright 2024 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { describe, expect, it } from \"vitest\";\n\nimport { createAuthorizationServer } from \"./common.js\";\n\ndescribe(\"Create authorization server\", () => {\n it(\"works with old multipass ctx path\", () => {\n const authServer = createAuthorizationServer(\n \"/multipass\",\n \"https://stack.palantir.com\",\n );\n expect(authServer).toEqual({\n token_endpoint: \"https://stack.palantir.com/multipass/api/oauth2/token\",\n authorization_endpoint:\n \"https://stack.palantir.com/multipass/api/oauth2/authorize\",\n revocation_endpoint:\n \"https://stack.palantir.com/multipass/api/oauth2/revoke_token\",\n issuer: \"https://stack.palantir.com/multipass\",\n });\n });\n\n it(\"works with new multipass ctx path\", () => {\n const authServer = createAuthorizationServer(\n \"multipass\",\n \"https://stack.palantir.com\",\n );\n expect(authServer).toEqual({\n token_endpoint: \"https://stack.palantir.com/multipass/api/oauth2/token\",\n authorization_endpoint:\n \"https://stack.palantir.com/multipass/api/oauth2/authorize\",\n revocation_endpoint:\n \"https://stack.palantir.com/multipass/api/oauth2/revoke_token\",\n issuer: \"https://stack.palantir.com/multipass\",\n });\n\n const authServerCustom = createAuthorizationServer(\n \"multipass\",\n \"https://stack.palantir.com/foo/first/someStuff\",\n );\n expect(authServerCustom).toEqual({\n token_endpoint:\n \"https://stack.palantir.com/foo/first/someStuff/multipass/api/oauth2/token\",\n authorization_endpoint:\n \"https://stack.palantir.com/foo/first/someStuff/multipass/api/oauth2/authorize\",\n revocation_endpoint:\n \"https://stack.palantir.com/foo/first/someStuff/multipass/api/oauth2/revoke_token\",\n issuer: \"https://stack.palantir.com/foo/first/someStuff/multipass\",\n });\n const authServerCustomWithTrailingSlash = createAuthorizationServer(\n \"multipass\",\n \"https://stack.palantir.com/foo/first/someStuff/\",\n );\n expect(authServerCustomWithTrailingSlash).toEqual({\n token_endpoint:\n \"https://stack.palantir.com/foo/first/someStuff/multipass/api/oauth2/token\",\n authorization_endpoint:\n \"https://stack.palantir.com/foo/first/someStuff/multipass/api/oauth2/authorize\",\n revocation_endpoint:\n \"https://stack.palantir.com/foo/first/someStuff/multipass/api/oauth2/revoke_token\",\n issuer: \"https://stack.palantir.com/foo/first/someStuff/multipass\",\n });\n });\n});\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,QAAQ,EAAEC,MAAM,EAAEC,EAAE,QAAQ,QAAQ;AAE7C,SAASC,yBAAyB,QAAQ,aAAa;AAEvDH,QAAQ,CAAC,6BAA6B,EAAE,MAAM;EAC5CE,EAAE,CAAC,mCAAmC,EAAE,MAAM;IAC5C,MAAME,UAAU,GAAGD,yBAAyB,CAC1C,YAAY,EACZ,4BACF,CAAC;IACDF,MAAM,CAACG,UAAU,CAAC,CAACC,OAAO,CAAC;MACzBC,cAAc,EAAE,uDAAuD;MACvEC,sBAAsB,EACpB,2DAA2D;MAC7DC,mBAAmB,EACjB,8DAA8D;MAChEC,MAAM,EAAE;IACV,CAAC,CAAC;EACJ,CAAC,CAAC;EAEFP,EAAE,CAAC,mCAAmC,EAAE,MAAM;IAC5C,MAAME,UAAU,GAAGD,yBAAyB,CAC1C,WAAW,EACX,4BACF,CAAC;IACDF,MAAM,CAACG,UAAU,CAAC,CAACC,OAAO,CAAC;MACzBC,cAAc,EAAE,uDAAuD;MACvEC,sBAAsB,EACpB,2DAA2D;MAC7DC,mBAAmB,EACjB,8DAA8D;MAChEC,MAAM,EAAE;IACV,CAAC,CAAC;IAEF,MAAMC,gBAAgB,GAAGP,yBAAyB,CAChD,WAAW,EACX,gDACF,CAAC;IACDF,MAAM,CAACS,gBAAgB,CAAC,CAACL,OAAO,CAAC;MAC/BC,cAAc,EACZ,2EAA2E;MAC7EC,sBAAsB,EACpB,+EAA+E;MACjFC,mBAAmB,EACjB,kFAAkF;MACpFC,MAAM,EAAE;IACV,CAAC,CAAC;IACF,MAAME,iCAAiC,GAAGR,yBAAyB,CACjE,WAAW,EACX,iDACF,CAAC;IACDF,MAAM,CAACU,iCAAiC,CAAC,CAACN,OAAO,CAAC;MAChDC,cAAc,EACZ,2EAA2E;MAC7EC,sBAAsB,EACpB,+EAA+E;MACjFC,mBAAmB,EACjB,kFAAkF;MACpFC,MAAM,EAAE;IACV,CAAC,CAAC;EACJ,CAAC,CAAC;AACJ,CAAC,CAAC","ignoreList":[]}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2024 Palantir Technologies, Inc. All rights reserved.
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
* you may not use this file except in compliance with the License.
|
|
6
|
-
* You may obtain a copy of the License at
|
|
7
|
-
*
|
|
8
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
*
|
|
10
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
* See the License for the specific language governing permissions and
|
|
14
|
-
* limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
import { createPublicOauthClient } from "@osdk/oauth";
|
|
18
|
-
import * as oauthModule from "@osdk/oauth";
|
|
19
|
-
import { describe, expect, it, vi } from "vitest";
|
|
20
|
-
import * as utilsModule from "../utils.js";
|
|
21
|
-
const originalCreatePublicOauthClient = oauthModule.createPublicOauthClient;
|
|
22
|
-
const FOUNDRY_CLIENT_ID = "example-foundry-client-id";
|
|
23
|
-
const FOUNDRY_URL = "http://example-foundry-url.com";
|
|
24
|
-
const REDIRECT_URI = "http://localhost:8080/auth/callback";
|
|
25
|
-
vi.stubGlobal("window", {
|
|
26
|
-
location: {
|
|
27
|
-
toString: vi.fn().mockReturnValue("http://example.com")
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
describe("createPublicOauthClient", () => {
|
|
31
|
-
it("should return the same processed options for both client creation methods", async () => {
|
|
32
|
-
const mockProcessOptionsAndAssignDefaults = vi.fn();
|
|
33
|
-
|
|
34
|
-
// Mock processOptionsAndAssignDefaults to call the mock function
|
|
35
|
-
vi.spyOn(utilsModule, "processOptionsAndAssignDefaults").mockImplementation((...args) => {
|
|
36
|
-
mockProcessOptionsAndAssignDefaults(...args);
|
|
37
|
-
return utilsModule.processOptionsAndAssignDefaults(...args);
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
// Mock createPublicOauthClient to call both the mock and the original function
|
|
41
|
-
vi.spyOn(oauthModule, "createPublicOauthClient").mockImplementation((...args) => {
|
|
42
|
-
const [_client_id, ...rest] = args;
|
|
43
|
-
mockProcessOptionsAndAssignDefaults(...rest);
|
|
44
|
-
return originalCreatePublicOauthClient(...args);
|
|
45
|
-
});
|
|
46
|
-
const authClient = createPublicOauthClient(FOUNDRY_CLIENT_ID, FOUNDRY_URL, REDIRECT_URI, true, undefined, undefined, undefined, fetch, undefined);
|
|
47
|
-
expect(authClient).toBeDefined();
|
|
48
|
-
expect(mockProcessOptionsAndAssignDefaults).toHaveBeenCalledTimes(1);
|
|
49
|
-
const authClientWithOptions = createPublicOauthClient(FOUNDRY_CLIENT_ID, FOUNDRY_URL, REDIRECT_URI, {
|
|
50
|
-
useHistory: true,
|
|
51
|
-
fetchFn: fetch
|
|
52
|
-
});
|
|
53
|
-
expect(authClientWithOptions).toBeDefined();
|
|
54
|
-
expect(mockProcessOptionsAndAssignDefaults).toHaveBeenCalledTimes(2);
|
|
55
|
-
const [result1, result2] = mockProcessOptionsAndAssignDefaults.mock.results;
|
|
56
|
-
expect(result1.value).toEqual(result2.value);
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
//# sourceMappingURL=createPublicOauthClient.test.js.map
|