@fixedwidthtable/fixedwidthtable 0.0.1-security → 0.0.3
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.
Potentially problematic release.
This version of @fixedwidthtable/fixedwidthtable might be problematic. Click here for more details.
- package/.eslintignore +2 -0
- package/.eslintrc.js +8 -0
- package/.github/dependabot.yml +24 -0
- package/.github/workflows/audit.yml +14 -0
- package/.github/workflows/ci.yml +53 -0
- package/.github/workflows/release.yml +31 -0
- package/.github/workflows/reusable-audit.yml +41 -0
- package/.github/workflows/reusable-lint.yml +33 -0
- package/CODEOWNERS +1 -0
- package/LICENSE.md +18 -0
- package/README.md +12 -3
- package/e2e/browser/test/e2e.playwright.ts +67 -0
- package/e2e/browser/test/globalSetup.ts +30 -0
- package/e2e/browser/test-app/.eslintrc.js +6 -0
- package/e2e/browser/test-app/README.md +46 -0
- package/e2e/browser/test-app/components/appContainer/index.tsx +109 -0
- package/e2e/browser/test-app/components/solidClient/index.tsx +149 -0
- package/e2e/browser/test-app/next-env.d.ts +5 -0
- package/e2e/browser/test-app/next.config.js +6 -0
- package/e2e/browser/test-app/package-lock.json +1982 -0
- package/e2e/browser/test-app/package.json +25 -0
- package/e2e/browser/test-app/pages/_app.tsx +28 -0
- package/e2e/browser/test-app/pages/index.tsx +36 -0
- package/e2e/browser/test-app/tsconfig.json +20 -0
- package/eslint-configs/README.md +75 -0
- package/eslint-configs/eslint-config-base/README.md +29 -0
- package/eslint-configs/eslint-config-base/index.js +159 -0
- package/eslint-configs/eslint-config-base/license-header.js +20 -0
- package/eslint-configs/eslint-config-base/package.json +41 -0
- package/eslint-configs/eslint-config-lib/README.md +51 -0
- package/eslint-configs/eslint-config-lib/index.js +83 -0
- package/eslint-configs/eslint-config-lib/package.json +29 -0
- package/eslint-configs/eslint-config-react/README.md +97 -0
- package/eslint-configs/eslint-config-react/index.js +75 -0
- package/eslint-configs/eslint-config-react/package.json +32 -0
- package/lerna.json +4 -0
- package/package.json +45 -3
- package/packages/base-rollup-config/README.md +22 -0
- package/packages/base-rollup-config/index.mjs +59 -0
- package/packages/base-rollup-config/package.json +25 -0
- package/packages/internal-playwright-helpers/README.md +30 -0
- package/packages/internal-playwright-helpers/package.json +29 -0
- package/packages/internal-playwright-helpers/rollup.config.mjs +57 -0
- package/packages/internal-playwright-helpers/src/fixtures.ts +51 -0
- package/packages/internal-playwright-helpers/src/flows/auth.ts +93 -0
- package/packages/internal-playwright-helpers/src/index.ts +26 -0
- package/packages/internal-playwright-helpers/src/pages/cognito.ts +48 -0
- package/packages/internal-playwright-helpers/src/pages/open-id.ts +56 -0
- package/packages/internal-playwright-helpers/src/pages/testPage.ts +74 -0
- package/packages/internal-playwright-helpers/tsconfig.json +8 -0
- package/packages/internal-playwright-testids/package.json +22 -0
- package/packages/internal-playwright-testids/rollup.config.mjs +56 -0
- package/packages/internal-playwright-testids/src/index.ts +35 -0
- package/packages/internal-playwright-testids/tsconfig.json +8 -0
- package/packages/internal-test-env/README.md +44 -0
- package/packages/internal-test-env/env/.env.example +36 -0
- package/packages/internal-test-env/index.ts +474 -0
- package/packages/internal-test-env/package.json +30 -0
- package/packages/internal-test-env/rollup.config.mjs +80 -0
- package/packages/internal-test-env/tsconfig.json +20 -0
- package/packages/internal-test-env/utils.ts +31 -0
- package/packages/jest-jsdom-polyfills/README.md +21 -0
- package/packages/jest-jsdom-polyfills/index.js +80 -0
- package/packages/jest-jsdom-polyfills/package.json +36 -0
- package/playwright.config.ts +76 -0
- package/scripts/index.js +1 -0
- package/scripts/prepare-release.sh +32 -0
- package/scripts/release.sh +36 -0
- package/tsconfig.base.json +17 -0
|
@@ -0,0 +1,474 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright Inrupt Inc.
|
|
3
|
+
//
|
|
4
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
// of this software and associated documentation files (the "Software"), to deal in
|
|
6
|
+
// the Software without restriction, including without limitation the rights to use,
|
|
7
|
+
// copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
|
|
8
|
+
// Software, and to permit persons to whom the Software is furnished to do so,
|
|
9
|
+
// subject to the following conditions:
|
|
10
|
+
//
|
|
11
|
+
// The above copyright notice and this permission notice shall be included in
|
|
12
|
+
// all copies or substantial portions of the Software.
|
|
13
|
+
//
|
|
14
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
|
15
|
+
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
|
16
|
+
// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
17
|
+
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
18
|
+
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
19
|
+
// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
20
|
+
//
|
|
21
|
+
import { join } from "path";
|
|
22
|
+
import { config } from "dotenv";
|
|
23
|
+
import { Session } from "@inrupt/solid-client-authn-node";
|
|
24
|
+
import { getAuthenticatedFetch } from "@jeswr/css-auth-utils";
|
|
25
|
+
import merge from "deepmerge-json";
|
|
26
|
+
import {
|
|
27
|
+
createContainerInContainer,
|
|
28
|
+
createSolidDataset,
|
|
29
|
+
deleteSolidDataset,
|
|
30
|
+
getPodUrlAll,
|
|
31
|
+
getSourceIri,
|
|
32
|
+
saveSolidDatasetInContainer,
|
|
33
|
+
getSolidDataset,
|
|
34
|
+
setThing,
|
|
35
|
+
getThing,
|
|
36
|
+
setIri,
|
|
37
|
+
saveSolidDatasetAt,
|
|
38
|
+
} from "@inrupt/solid-client";
|
|
39
|
+
import { isValidUrl } from "./utils";
|
|
40
|
+
|
|
41
|
+
export const availableEnvironments = [
|
|
42
|
+
"ESS Dev-2-2" as const,
|
|
43
|
+
"ESS Dev-Next" as const,
|
|
44
|
+
"ESS PodSpaces" as const,
|
|
45
|
+
"NSS" as const,
|
|
46
|
+
"CSS" as const,
|
|
47
|
+
];
|
|
48
|
+
|
|
49
|
+
export type AvailableEnvironments = typeof availableEnvironments extends Array<
|
|
50
|
+
infer E
|
|
51
|
+
>
|
|
52
|
+
? E
|
|
53
|
+
: never;
|
|
54
|
+
|
|
55
|
+
export interface TestingEnvironmentNode extends TestingEnvironmentBase {
|
|
56
|
+
clientCredentials: {
|
|
57
|
+
owner:
|
|
58
|
+
| {
|
|
59
|
+
type: "ESS Client Credentials";
|
|
60
|
+
id: string;
|
|
61
|
+
secret: string;
|
|
62
|
+
}
|
|
63
|
+
| {
|
|
64
|
+
type: "CSS Client Credentials";
|
|
65
|
+
login: string;
|
|
66
|
+
password: string;
|
|
67
|
+
email: string;
|
|
68
|
+
};
|
|
69
|
+
requestor?: {
|
|
70
|
+
id?: string;
|
|
71
|
+
secret?: string;
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
export interface TestingEnvironmentBrowser extends TestingEnvironmentBase {
|
|
76
|
+
clientCredentials: {
|
|
77
|
+
owner: {
|
|
78
|
+
login: string;
|
|
79
|
+
password: string;
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export interface TestingEnvironmentBase {
|
|
85
|
+
environment: AvailableEnvironments;
|
|
86
|
+
idp: string;
|
|
87
|
+
features: FeatureFlags | undefined;
|
|
88
|
+
notificationGateway?: string;
|
|
89
|
+
notificationProtocol?: string;
|
|
90
|
+
vcProvider?: string;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
type FeatureFlags = {
|
|
94
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
95
|
+
[key: string]: any;
|
|
96
|
+
};
|
|
97
|
+
const ENV_FEATURE_PREFIX = "E2E_TEST_FEATURE_";
|
|
98
|
+
|
|
99
|
+
let envLoaded = false;
|
|
100
|
+
export interface EnvVariables {
|
|
101
|
+
// Common Envs
|
|
102
|
+
E2E_TEST_ENVIRONMENT: AvailableEnvironments;
|
|
103
|
+
E2E_TEST_IDP: string;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export function setupEnv() {
|
|
107
|
+
// If we're in CI, the environment is already configured. Otherwise, it is
|
|
108
|
+
// loaded once.
|
|
109
|
+
if (process.env.CI || envLoaded) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
const envPath = join(process.cwd(), "e2e/env/.env.local");
|
|
113
|
+
|
|
114
|
+
// Load dotenv configuration
|
|
115
|
+
config({
|
|
116
|
+
path: envPath,
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
if (!process.env.E2E_TEST_ENVIRONMENT) {
|
|
120
|
+
// eslint-disable-next-line no-console
|
|
121
|
+
console.error(
|
|
122
|
+
`We didn't find the given environment variable E2E_TEST_ENVIRONMENT, tried looking in the following directory for '.env.local': ${envPath}`,
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
envLoaded = true;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export interface LibraryVariables {
|
|
129
|
+
notificationGateway?: boolean;
|
|
130
|
+
notificationProtocol?: boolean;
|
|
131
|
+
vcProvider?: boolean;
|
|
132
|
+
clientCredentials?: {
|
|
133
|
+
owner?: {
|
|
134
|
+
id?: boolean;
|
|
135
|
+
secret?: boolean;
|
|
136
|
+
login?: boolean;
|
|
137
|
+
password?: boolean;
|
|
138
|
+
};
|
|
139
|
+
requestor?: {
|
|
140
|
+
id?: boolean;
|
|
141
|
+
secret?: boolean;
|
|
142
|
+
};
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export interface BrowserVariables extends LibraryVariables {
|
|
147
|
+
clientCredentials?: {
|
|
148
|
+
owner: {
|
|
149
|
+
login: true;
|
|
150
|
+
password: true;
|
|
151
|
+
};
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export interface NodeVariables extends LibraryVariables {
|
|
156
|
+
clientCredentials?: {
|
|
157
|
+
owner: {
|
|
158
|
+
id: true;
|
|
159
|
+
secret: true;
|
|
160
|
+
};
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function validateLibVars(varsToValidate: LibraryVariables): object {
|
|
165
|
+
// Notifications-related environment variables.
|
|
166
|
+
if (varsToValidate.notificationGateway) {
|
|
167
|
+
if (typeof process.env.E2E_TEST_NOTIFICATION_GATEWAY !== "string") {
|
|
168
|
+
throw new Error(
|
|
169
|
+
"Missing the E2E_TEST_NOTIFICATION_GATEWAY environment variable",
|
|
170
|
+
);
|
|
171
|
+
} else if (!isValidUrl(process.env.E2E_TEST_NOTIFICATION_GATEWAY)) {
|
|
172
|
+
throw new Error(
|
|
173
|
+
`Expected E2E_TEST_NOTIFICATION_GATEWAY environment variable to be an IRI, found: ${process.env.E2E_TEST_NOTIFICATION_GATEWAY}`,
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
if (varsToValidate.notificationProtocol) {
|
|
179
|
+
if (typeof process.env.E2E_TEST_NOTIFICATION_PROTOCOL !== "string") {
|
|
180
|
+
throw new Error(
|
|
181
|
+
"Missing the E2E_TEST_NOTIFICATION_PROTOCOL environment variable",
|
|
182
|
+
);
|
|
183
|
+
} else if (!isValidUrl(process.env.E2E_TEST_NOTIFICATION_PROTOCOL)) {
|
|
184
|
+
throw new Error(
|
|
185
|
+
`Expected E2E_TEST_NOTIFICATION_PROTOCOL environment variable to be an IRI, found: ${process.env.E2E_TEST_NOTIFICATION_PROTOCOL}`,
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// VC-related environment variables.
|
|
191
|
+
if (varsToValidate.vcProvider) {
|
|
192
|
+
if (typeof process.env.E2E_TEST_VC_PROVIDER !== "string") {
|
|
193
|
+
throw new Error("Missing the E2E_TEST_VC_PROVIDER environment variable");
|
|
194
|
+
} else if (!isValidUrl(process.env.E2E_TEST_VC_PROVIDER)) {
|
|
195
|
+
throw new Error(
|
|
196
|
+
`Expected E2E_TEST_VC_PROVIDER environment variable to be an IRI, found: ${process.env.E2E_TEST_VC_PROVIDER}`,
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// Resource owner static credentials.
|
|
202
|
+
if (
|
|
203
|
+
varsToValidate.clientCredentials?.owner?.id &&
|
|
204
|
+
typeof process.env.E2E_TEST_OWNER_CLIENT_ID !== "string" &&
|
|
205
|
+
process.env.E2E_TEST_OWNER_CLIENT_ID !== "" &&
|
|
206
|
+
process.env.E2E_TEST_ENVIRONMENT !== "CSS"
|
|
207
|
+
) {
|
|
208
|
+
throw new Error(
|
|
209
|
+
"Missing the E2E_TEST_OWNER_CLIENT_ID environment variable",
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
if (
|
|
213
|
+
varsToValidate.clientCredentials?.owner?.secret &&
|
|
214
|
+
typeof process.env.E2E_TEST_OWNER_CLIENT_SECRET !== "string" &&
|
|
215
|
+
process.env.E2E_TEST_OWNER_CLIENT_SECRET !== "" &&
|
|
216
|
+
process.env.E2E_TEST_ENVIRONMENT !== "CSS"
|
|
217
|
+
) {
|
|
218
|
+
throw new Error(
|
|
219
|
+
"Missing the E2E_TEST_OWNER_CLIENT_SECRET environment variable",
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
// Resource requestor static credentials.
|
|
223
|
+
if (
|
|
224
|
+
varsToValidate.clientCredentials?.requestor?.id &&
|
|
225
|
+
typeof process.env.E2E_TEST_REQUESTOR_CLIENT_ID !== "string" &&
|
|
226
|
+
process.env.E2E_TEST_REQUESTOR_CLIENT_ID !== ""
|
|
227
|
+
) {
|
|
228
|
+
throw new Error(
|
|
229
|
+
"Missing the E2E_TEST_REQUESTOR_CLIENT_ID environment variable",
|
|
230
|
+
);
|
|
231
|
+
}
|
|
232
|
+
if (
|
|
233
|
+
varsToValidate.clientCredentials?.requestor?.secret &&
|
|
234
|
+
typeof process.env.E2E_TEST_REQUESTOR_CLIENT_SECRET !== "string" &&
|
|
235
|
+
process.env.E2E_TEST_REQUESTOR_CLIENT_SECRET !== ""
|
|
236
|
+
) {
|
|
237
|
+
throw new Error(
|
|
238
|
+
"Missing the E2E_TEST_REQUESTOR_CLIENT_SECRET environment variable",
|
|
239
|
+
);
|
|
240
|
+
}
|
|
241
|
+
// Resource owner username/password.
|
|
242
|
+
if (
|
|
243
|
+
varsToValidate.clientCredentials?.owner?.login &&
|
|
244
|
+
typeof process.env.E2E_TEST_USER !== "string" &&
|
|
245
|
+
process.env.E2E_TEST_USER !== ""
|
|
246
|
+
) {
|
|
247
|
+
throw new Error("The environment variable E2E_TEST_USER is undefined.");
|
|
248
|
+
}
|
|
249
|
+
if (
|
|
250
|
+
varsToValidate.clientCredentials?.owner?.password &&
|
|
251
|
+
typeof process.env.E2E_TEST_PASSWORD !== "string" &&
|
|
252
|
+
process.env.E2E_TEST_PASSWORD !== ""
|
|
253
|
+
) {
|
|
254
|
+
throw new Error("The environment variable E2E_TEST_PASSWORD is undefined.");
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
return {
|
|
258
|
+
notificationGateway: process.env.E2E_TEST_NOTIFICATION_GATEWAY,
|
|
259
|
+
notificationProtocol: process.env.E2E_TEST_NOTIFICATION_PROTOCOL,
|
|
260
|
+
vcProvider: process.env.E2E_TEST_VC_PROVIDER,
|
|
261
|
+
clientCredentials: {
|
|
262
|
+
owner:
|
|
263
|
+
process.env.E2E_TEST_ENVIRONMENT !== "CSS"
|
|
264
|
+
? {
|
|
265
|
+
type: "ESS Client Credentials",
|
|
266
|
+
id: process.env.E2E_TEST_OWNER_CLIENT_ID,
|
|
267
|
+
secret: process.env.E2E_TEST_OWNER_CLIENT_SECRET,
|
|
268
|
+
login: process.env.E2E_TEST_USER,
|
|
269
|
+
password: process.env.E2E_TEST_PASSWORD,
|
|
270
|
+
}
|
|
271
|
+
: {
|
|
272
|
+
type: "CSS Client Credentials",
|
|
273
|
+
login: process.env.E2E_TEST_USER,
|
|
274
|
+
password: process.env.E2E_TEST_PASSWORD,
|
|
275
|
+
email: process.env.E2E_TEST_EMAIL,
|
|
276
|
+
},
|
|
277
|
+
requestor: {
|
|
278
|
+
id: process.env.E2E_TEST_REQUESTOR_CLIENT_ID,
|
|
279
|
+
secret: process.env.E2E_TEST_REQUESTOR_CLIENT_SECRET,
|
|
280
|
+
},
|
|
281
|
+
},
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
function getBaseTestingEnvironment<T extends LibraryVariables>(
|
|
286
|
+
libVars?: T,
|
|
287
|
+
): T extends NodeVariables
|
|
288
|
+
? TestingEnvironmentNode
|
|
289
|
+
: TestingEnvironmentBrowser {
|
|
290
|
+
setupEnv();
|
|
291
|
+
|
|
292
|
+
// Load and validate target environment name.
|
|
293
|
+
const targetEnvName = process.env.E2E_TEST_ENVIRONMENT;
|
|
294
|
+
if (!availableEnvironments.includes(targetEnvName as AvailableEnvironments)) {
|
|
295
|
+
throw new Error(
|
|
296
|
+
`Unknown environment: [${targetEnvName}]\n\nAvailable environments are ${availableEnvironments
|
|
297
|
+
.map((env) => `[${env}]`)
|
|
298
|
+
.join(", ")}`,
|
|
299
|
+
);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
// Load and validate target OpenID Provider.
|
|
303
|
+
const targetIdp = process.env.E2E_TEST_IDP;
|
|
304
|
+
if (typeof targetIdp !== "string" || !isValidUrl(targetIdp)) {
|
|
305
|
+
throw new Error(
|
|
306
|
+
`The environment variable E2E_TEST_IDP is not a valid URL: found ${targetIdp}.`,
|
|
307
|
+
);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
// Creating feature flag object if there are feature flags
|
|
311
|
+
const features = Object.keys(process.env)
|
|
312
|
+
.filter((envVar) => envVar.startsWith(ENV_FEATURE_PREFIX))
|
|
313
|
+
.reduce((featureFlags, envVar) => {
|
|
314
|
+
// Trim the prefix from the environment variable name.
|
|
315
|
+
const flagName = envVar.substring(ENV_FEATURE_PREFIX.length);
|
|
316
|
+
const flagValue = process.env[envVar];
|
|
317
|
+
return { ...featureFlags, [`${flagName}`]: flagValue };
|
|
318
|
+
}, {});
|
|
319
|
+
|
|
320
|
+
const base = {
|
|
321
|
+
idp: targetIdp,
|
|
322
|
+
environment: targetEnvName,
|
|
323
|
+
features,
|
|
324
|
+
};
|
|
325
|
+
|
|
326
|
+
return libVars ? merge(base, validateLibVars(libVars)) : base;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
export function getNodeTestingEnvironment(
|
|
330
|
+
varsToValidate?: LibraryVariables,
|
|
331
|
+
): TestingEnvironmentNode {
|
|
332
|
+
return getBaseTestingEnvironment<NodeVariables>(
|
|
333
|
+
merge(varsToValidate, {
|
|
334
|
+
// Enforce client credentials are present for the resource owner.
|
|
335
|
+
clientCredentials: { owner: { id: true, secret: true } },
|
|
336
|
+
}),
|
|
337
|
+
);
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
export function getBrowserTestingEnvironment(
|
|
341
|
+
varsToValidate?: LibraryVariables,
|
|
342
|
+
): TestingEnvironmentBrowser {
|
|
343
|
+
return getBaseTestingEnvironment<BrowserVariables>(
|
|
344
|
+
merge(varsToValidate, {
|
|
345
|
+
// Enforce login/password are present for the resource owner.
|
|
346
|
+
clientCredentials: { owner: { login: true, password: true } },
|
|
347
|
+
}),
|
|
348
|
+
);
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
export async function getAuthenticatedSession(
|
|
352
|
+
authDetails: TestingEnvironmentNode,
|
|
353
|
+
): Promise<Session> {
|
|
354
|
+
const { owner } = authDetails.clientCredentials;
|
|
355
|
+
|
|
356
|
+
if (owner.type === "CSS Client Credentials") {
|
|
357
|
+
return {
|
|
358
|
+
info: {
|
|
359
|
+
isLoggedIn: true,
|
|
360
|
+
// CSS WebIds are always minted in this format
|
|
361
|
+
// with the configs that are currently available
|
|
362
|
+
webId: `${authDetails.idp + owner.login}/profile/card#me`,
|
|
363
|
+
sessionId: "",
|
|
364
|
+
},
|
|
365
|
+
fetch: await getAuthenticatedFetch({
|
|
366
|
+
podName: owner.login,
|
|
367
|
+
password: owner.password,
|
|
368
|
+
url: authDetails.idp,
|
|
369
|
+
email: owner.email,
|
|
370
|
+
}),
|
|
371
|
+
logout() {
|
|
372
|
+
this.info.isLoggedIn = false;
|
|
373
|
+
this.fetch = globalThis.fetch;
|
|
374
|
+
},
|
|
375
|
+
} as Session;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
const session = new Session();
|
|
379
|
+
|
|
380
|
+
await session.login({
|
|
381
|
+
oidcIssuer: authDetails.idp,
|
|
382
|
+
clientId: owner.id,
|
|
383
|
+
clientSecret: owner.secret,
|
|
384
|
+
});
|
|
385
|
+
|
|
386
|
+
if (!session.info.isLoggedIn) {
|
|
387
|
+
throw new Error("Logging the test agent in failed.");
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
return session;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
// Adds the `pim:storage` triple to a CSS WebId profile document
|
|
394
|
+
// as it is not made available by default
|
|
395
|
+
export async function addCssPimStorage(
|
|
396
|
+
authDetails: TestingEnvironmentNode,
|
|
397
|
+
): Promise<void> {
|
|
398
|
+
const session = await getAuthenticatedSession(authDetails);
|
|
399
|
+
const { webId } = session.info;
|
|
400
|
+
|
|
401
|
+
if (!webId) throw new Error("WebId cannot be found in session");
|
|
402
|
+
|
|
403
|
+
let dataset = await getSolidDataset(webId, { fetch: session.fetch });
|
|
404
|
+
const thing = getThing(dataset, webId);
|
|
405
|
+
|
|
406
|
+
if (!thing)
|
|
407
|
+
throw new Error("WebId cannot be found in WebId profile document");
|
|
408
|
+
|
|
409
|
+
dataset = setThing(
|
|
410
|
+
dataset,
|
|
411
|
+
setIri(
|
|
412
|
+
thing,
|
|
413
|
+
"http://www.w3.org/ns/pim/space#storage",
|
|
414
|
+
webId.replace("profile/card#me", ""),
|
|
415
|
+
),
|
|
416
|
+
);
|
|
417
|
+
|
|
418
|
+
await saveSolidDatasetAt(webId, dataset, { fetch: session.fetch });
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
export async function getPodRoot(session: Session) {
|
|
422
|
+
if (!(typeof session.info.webId === "string")) {
|
|
423
|
+
throw new Error("Missing our webid, unable to find PodRoot");
|
|
424
|
+
}
|
|
425
|
+
const podRootAll = await getPodUrlAll(session.info.webId as string);
|
|
426
|
+
if (podRootAll.length === 0) {
|
|
427
|
+
throw new Error(
|
|
428
|
+
`No Pod root were found in the profile associated to [${session.info.webId}]`,
|
|
429
|
+
);
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
// Arbitrarily pick one available Pod root.
|
|
433
|
+
return podRootAll[0];
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
export function createFetch(session: Session, userAgent: string): typeof fetch {
|
|
437
|
+
return (url, options?) => {
|
|
438
|
+
return session.fetch(url, {
|
|
439
|
+
...options,
|
|
440
|
+
headers: {
|
|
441
|
+
...options?.headers,
|
|
442
|
+
"User-Agent": userAgent,
|
|
443
|
+
},
|
|
444
|
+
});
|
|
445
|
+
};
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
export async function setupTestResources(
|
|
449
|
+
podRoot: string,
|
|
450
|
+
fetchOptions: { fetch: typeof fetch },
|
|
451
|
+
) {
|
|
452
|
+
const containerUrl = getSourceIri(
|
|
453
|
+
await createContainerInContainer(podRoot, fetchOptions),
|
|
454
|
+
);
|
|
455
|
+
const resourceUrl = getSourceIri(
|
|
456
|
+
await saveSolidDatasetInContainer(
|
|
457
|
+
containerUrl,
|
|
458
|
+
createSolidDataset(),
|
|
459
|
+
fetchOptions,
|
|
460
|
+
),
|
|
461
|
+
);
|
|
462
|
+
return { containerUrl, resourceUrl };
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
export async function teardownTestResources(
|
|
466
|
+
session: Session,
|
|
467
|
+
containerUrl: string,
|
|
468
|
+
resourceUrl: string,
|
|
469
|
+
fetchOptions: { fetch: typeof fetch },
|
|
470
|
+
) {
|
|
471
|
+
await deleteSolidDataset(resourceUrl, fetchOptions);
|
|
472
|
+
await deleteSolidDataset(containerUrl, fetchOptions);
|
|
473
|
+
await session.logout();
|
|
474
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@inrupt/internal-test-env",
|
|
3
|
+
"version": "2.4.0",
|
|
4
|
+
"description": "This package provides various test environment utilities needed for jest when using the Inrupt SDKs",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.es.js",
|
|
7
|
+
"publishConfig": {
|
|
8
|
+
"access": "public"
|
|
9
|
+
},
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "rollup -c rollup.config.mjs",
|
|
12
|
+
"clean": "rimraf dist"
|
|
13
|
+
},
|
|
14
|
+
"author": "Inrupt <devtools-team@inrupt.com>",
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"require": "./dist/index.js",
|
|
19
|
+
"import": "./dist/index.mjs"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@inrupt/solid-client": "^1.30.0",
|
|
24
|
+
"@inrupt/solid-client-authn-browser": "^1.17.1",
|
|
25
|
+
"@inrupt/solid-client-authn-node": "^1.17.1",
|
|
26
|
+
"@jeswr/css-auth-utils": "^1.4.0",
|
|
27
|
+
"deepmerge-json": "^1.5.0",
|
|
28
|
+
"dotenv": "^16.3.1"
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// The following is only possible from Node 18 onwards
|
|
2
|
+
// import pkg from "./package.json" assert { type: "json" };
|
|
3
|
+
|
|
4
|
+
// Until we only support Node 18+, this should be used instead
|
|
5
|
+
// (see https://rollupjs.org/guide/en/#importing-packagejson)
|
|
6
|
+
import { createRequire } from "node:module";
|
|
7
|
+
const require = createRequire(import.meta.url);
|
|
8
|
+
const pkg = require("./package.json");
|
|
9
|
+
|
|
10
|
+
import typescript from "rollup-plugin-typescript2";
|
|
11
|
+
|
|
12
|
+
const external = [
|
|
13
|
+
...Object.keys(pkg.dependencies || {}),
|
|
14
|
+
"@inrupt/solid-client-authn-node",
|
|
15
|
+
"@inrupt/solid-client",
|
|
16
|
+
];
|
|
17
|
+
|
|
18
|
+
const plugins = [
|
|
19
|
+
typescript({
|
|
20
|
+
// Use our own version of TypeScript, rather than the one bundled with the plugin:
|
|
21
|
+
typescript: require("typescript"),
|
|
22
|
+
tsconfigOverride: {
|
|
23
|
+
compilerOptions: {
|
|
24
|
+
module: "esnext",
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
}),
|
|
28
|
+
];
|
|
29
|
+
|
|
30
|
+
const rollupDefaultConfig = { external, plugins };
|
|
31
|
+
|
|
32
|
+
export default [
|
|
33
|
+
{
|
|
34
|
+
...rollupDefaultConfig,
|
|
35
|
+
external: [
|
|
36
|
+
"dotenv",
|
|
37
|
+
"path",
|
|
38
|
+
"deepmerge-json",
|
|
39
|
+
"@inrupt/solid-client-authn-node",
|
|
40
|
+
"@inrupt/solid-client",
|
|
41
|
+
],
|
|
42
|
+
input: "index.ts",
|
|
43
|
+
output: [
|
|
44
|
+
{
|
|
45
|
+
file: pkg.main,
|
|
46
|
+
format: "cjs",
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
file: pkg.module,
|
|
50
|
+
entryFileNames: "[name].es.js",
|
|
51
|
+
format: "esm",
|
|
52
|
+
},
|
|
53
|
+
],
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
...rollupDefaultConfig,
|
|
57
|
+
external: [
|
|
58
|
+
"dotenv",
|
|
59
|
+
"path",
|
|
60
|
+
"deepmerge-json",
|
|
61
|
+
"@inrupt/solid-client-authn-node",
|
|
62
|
+
"@inrupt/solid-client",
|
|
63
|
+
],
|
|
64
|
+
input: ["index.ts"],
|
|
65
|
+
output: [
|
|
66
|
+
{
|
|
67
|
+
dir: "dist",
|
|
68
|
+
entryFileNames: "[name].d.ts",
|
|
69
|
+
format: "esm",
|
|
70
|
+
preserveModules: true,
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
dir: "dist",
|
|
74
|
+
entryFileNames: "[name].mjs",
|
|
75
|
+
format: "esm",
|
|
76
|
+
preserveModules: true,
|
|
77
|
+
},
|
|
78
|
+
],
|
|
79
|
+
},
|
|
80
|
+
];
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
/* Basic Options */
|
|
4
|
+
"target": "ES2017",
|
|
5
|
+
"module": "commonjs",
|
|
6
|
+
// "moduleResolution": "node",
|
|
7
|
+
"lib": ["es2017", "dom"],
|
|
8
|
+
"declaration": true,
|
|
9
|
+
"outDir": "dist",
|
|
10
|
+
"rootDir": "./",
|
|
11
|
+
"strict": true,
|
|
12
|
+
"esModuleInterop": true,
|
|
13
|
+
// Prevent developers on different OSes from running into problems:
|
|
14
|
+
"forceConsistentCasingInFileNames": true,
|
|
15
|
+
/* Advanced Options */
|
|
16
|
+
"stripInternal": true,
|
|
17
|
+
"allowJs": false
|
|
18
|
+
},
|
|
19
|
+
"include": ["index.ts"]
|
|
20
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright Inrupt Inc.
|
|
3
|
+
//
|
|
4
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
// of this software and associated documentation files (the "Software"), to deal in
|
|
6
|
+
// the Software without restriction, including without limitation the rights to use,
|
|
7
|
+
// copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
|
|
8
|
+
// Software, and to permit persons to whom the Software is furnished to do so,
|
|
9
|
+
// subject to the following conditions:
|
|
10
|
+
//
|
|
11
|
+
// The above copyright notice and this permission notice shall be included in
|
|
12
|
+
// all copies or substantial portions of the Software.
|
|
13
|
+
//
|
|
14
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
|
15
|
+
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
|
16
|
+
// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
17
|
+
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
18
|
+
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
19
|
+
// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
20
|
+
//
|
|
21
|
+
|
|
22
|
+
export function isValidUrl(url: string): boolean {
|
|
23
|
+
try {
|
|
24
|
+
// Use URL constructor for validation
|
|
25
|
+
// eslint-disable-next-line no-new
|
|
26
|
+
new URL(url);
|
|
27
|
+
return true;
|
|
28
|
+
} catch {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# @inrupt/jest-jsdom-polyfills
|
|
2
|
+
|
|
3
|
+
This package contains polyfills for Web APIs that we use from the Inrupt SDKs that don't currently exist in jsdom which is used by Jest.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
1. `npm install --save-dev @inrupt/jest-jsdom-polyfills`
|
|
8
|
+
|
|
9
|
+
## Usage:
|
|
10
|
+
|
|
11
|
+
Add the following line to your [Jest Test Setup file](https://jestjs.io/docs/configuration#setupfilesafterenv-array), usually you'll have this configured as `jest.setup.ts` or something similar.
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
import "@inrupt/jest-jsdom-polyfills"
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Done, the SDKs should now have everything they need to be tested via jest / jsdom.
|
|
18
|
+
|
|
19
|
+
## ESM / CJS Compatibility
|
|
20
|
+
|
|
21
|
+
The Inrupt SDKs currently rely on some modules that require ESM, in order to load those with Jest, you need to opt into using ESM and configure your environment appropriately.
|