mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
refactor: Replace linting configurations
The previous package was outdated, preventing us from updating TS. This one also lints YAML and JSON, and applies many more rules to the test files, explaining all the changes in this PR.
This commit is contained in:
@@ -11,6 +11,7 @@ import {
|
||||
instantiateFromConfig,
|
||||
removeFolder,
|
||||
} from './Config';
|
||||
|
||||
const { namedNode, quad } = DataFactory;
|
||||
|
||||
const port = getPort('Conditions');
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
import {
|
||||
RepresentationMetadata,
|
||||
readableToString,
|
||||
ChainedConverter,
|
||||
guardedStreamFrom,
|
||||
RdfToQuadConverter,
|
||||
BasicRepresentation,
|
||||
ChainedConverter,
|
||||
getLoggerFor,
|
||||
guardedStreamFrom,
|
||||
INTERNAL_QUADS,
|
||||
RdfToQuadConverter,
|
||||
readableToString,
|
||||
RepresentationMetadata,
|
||||
} from '../../src';
|
||||
import type { Representation,
|
||||
RepresentationConverterArgs,
|
||||
Logger } from '../../src';
|
||||
import type { Logger,
|
||||
Representation,
|
||||
RepresentationConverterArgs } from '../../src';
|
||||
import { BaseTypedRepresentationConverter } from '../../src/storage/conversion/BaseTypedRepresentationConverter';
|
||||
|
||||
jest.mock('../../src/logging/LogUtil', (): any => {
|
||||
|
||||
@@ -237,7 +237,6 @@ describe.each(stores)('A Solid server with IDP using %s', (name, { config, teard
|
||||
describe('authenticating a client with a WebID', (): void => {
|
||||
const clientId = joinUrl(baseUrl, 'client-id');
|
||||
const badClientId = joinUrl(baseUrl, 'bad-client-id');
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
const clientJson = {
|
||||
'@context': 'https://www.w3.org/ns/solid/oidc-context.jsonld',
|
||||
|
||||
@@ -260,7 +259,7 @@ describe.each(stores)('A Solid server with IDP using %s', (name, { config, teard
|
||||
client_id: badClientId,
|
||||
redirect_uris: [],
|
||||
};
|
||||
/* eslint-enable @typescript-eslint/naming-convention */
|
||||
|
||||
let state: IdentityTestState;
|
||||
|
||||
beforeAll(async(): Promise<void> => {
|
||||
|
||||
@@ -53,7 +53,6 @@ export class IdentityTestState {
|
||||
for (const cookie of newCookies) {
|
||||
this.cookies.set(cookie.name, cookie);
|
||||
}
|
||||
// eslint-disable-next-line unicorn/prefer-spread
|
||||
this.cookie = Array.from(this.cookies, ([ , nom ]): string => `${nom.name}=${nom.value}`).join('; ');
|
||||
}
|
||||
return res;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { promises as fsPromises } from 'fs';
|
||||
import fetch from 'cross-fetch';
|
||||
import type { ResourceStore, App } from '../../src/';
|
||||
import type { App, ResourceStore } from '../../src/';
|
||||
import { BasicRepresentation, isSystemError, joinFilePath, joinUrl } from '../../src/';
|
||||
import { AclHelper } from '../util/AclHelper';
|
||||
import { deleteResource, getResource, postResource, putResource } from '../util/FetchUtil';
|
||||
|
||||
@@ -22,6 +22,7 @@ import {
|
||||
instantiateFromConfig,
|
||||
removeFolder,
|
||||
} from './Config';
|
||||
|
||||
const { literal, namedNode, quad } = DataFactory;
|
||||
|
||||
const port = getPort('LpdHandlerWithoutAuth');
|
||||
|
||||
@@ -51,14 +51,14 @@ describe('A server with the Solid WebSockets API behind a proxy', (): void => {
|
||||
await new Promise((resolve): any => client.on('open', resolve));
|
||||
});
|
||||
|
||||
afterAll((): void => {
|
||||
client.close();
|
||||
});
|
||||
|
||||
afterEach((): void => {
|
||||
messages.length = 0;
|
||||
});
|
||||
|
||||
afterAll((): void => {
|
||||
client.close();
|
||||
});
|
||||
|
||||
it('sends the protocol version.', (): void => {
|
||||
expect(messages).toEqual([
|
||||
'protocol solid-0.1',
|
||||
|
||||
@@ -44,7 +44,7 @@ const allModes = [ AM.read, AM.append, AM.create, AM.write, AM.delete ];
|
||||
// Columns: method, target, C/ permissions, C/R permissions, body, content-type, target exists, target does not exist
|
||||
// `undefined` implies C/R inherits the permissions of C/
|
||||
// For PUT/PATCH/DELETE we return 205 instead of 200/204
|
||||
/* eslint-disable no-multi-spaces */
|
||||
/* eslint-disable style/no-multi-spaces */
|
||||
const table: [string, string, AM[], AM[] | undefined, string, string, number, number][] = [
|
||||
// No authorization headers are sent in an OPTIONS request making it impossible to grant permission.
|
||||
// See https://github.com/CommunitySolidServer/CommunitySolidServer/issues/1246#issuecomment-1087325235
|
||||
@@ -118,7 +118,7 @@ const table: [string, string, AM[], AM[] | undefined, string, string, number, nu
|
||||
[ 'DELETE', 'C/', [ AM.write ], undefined, '', '', 401, 401 ],
|
||||
[ 'DELETE', 'C/', [ AM.read, AM.write ], undefined, '', '', 205, 404 ],
|
||||
];
|
||||
/* eslint-enable no-multi-spaces */
|
||||
/* eslint-enable style/no-multi-spaces */
|
||||
|
||||
function toPermission(modes: AM[]): AclPermissionSet {
|
||||
return Object.fromEntries(modes.map((mode): [AM, boolean] => [ mode, true ]));
|
||||
@@ -218,7 +218,7 @@ describe.each(stores)('A request on a server with %s authorization and %s', (aut
|
||||
await app.stop();
|
||||
});
|
||||
|
||||
describe.each(table)('%s %s with permissions C/: %s and C/R: %s.', (...entry): void => {
|
||||
describe.each(table)('%s %s with permissions C/: %s and C/R: %s', (...entry): void => {
|
||||
const [ method, target, cPerm, crPermTemp, body, contentType, existsCode, notExistsCode ] = entry;
|
||||
const crPerm = crPermTemp ?? cPerm;
|
||||
const id = v4();
|
||||
|
||||
@@ -7,6 +7,8 @@ import type { RedisReadWriteLock, RedisResourceLock } from '../../src/util/locki
|
||||
import { REDIS_LUA_SCRIPTS } from '../../src/util/locking/scripts/RedisLuaScripts';
|
||||
import { describeIf, getPort } from '../util/Util';
|
||||
import { getDefaultVariables, getTestConfigPath, instantiateFromConfig } from './Config';
|
||||
|
||||
/* eslint-disable jest/require-top-level-describe */
|
||||
/**
|
||||
* Test the general functionality of the server using a RedisLocker with Read-Write strategy.
|
||||
*/
|
||||
@@ -153,13 +155,13 @@ describeIf('docker')('A server with a RedisLocker', (): void => {
|
||||
it('can read a resource.', async(): Promise<void> => {
|
||||
const testFn = jest.fn();
|
||||
await expect(locker.withReadLock(identifier, (): any => testFn())).resolves.toBeUndefined();
|
||||
expect(testFn).toHaveBeenCalled();
|
||||
expect(testFn).toHaveBeenCalledWith();
|
||||
});
|
||||
|
||||
it('can write a resource.', async(): Promise<void> => {
|
||||
const testFn = jest.fn();
|
||||
await expect(locker.withWriteLock(identifier, (): any => testFn())).resolves.toBeUndefined();
|
||||
expect(testFn).toHaveBeenCalled();
|
||||
expect(testFn).toHaveBeenCalledWith();
|
||||
});
|
||||
|
||||
it('can read a resource twice again after it was unlocked.', async(): Promise<void> => {
|
||||
@@ -199,7 +201,7 @@ describeIf('docker')('A server with a RedisLocker', (): void => {
|
||||
[ 1, 0, 2 ].forEach((num): unknown => releaseSignal.emit(`release${num}`));
|
||||
}
|
||||
});
|
||||
const promises = [ 0, 1, 2 ].map((num): Promise<any> =>
|
||||
const promises = [ 0, 1, 2 ].map(async(num): Promise<any> =>
|
||||
locker.withReadLock(identifier, async(): Promise<void> => {
|
||||
res += `l${num}`;
|
||||
await new Promise<void>((resolve): any => {
|
||||
@@ -255,14 +257,14 @@ describeIf('docker')('A server with a RedisLocker', (): void => {
|
||||
await clearRedis();
|
||||
});
|
||||
|
||||
afterAll(async(): Promise<void> => {
|
||||
await redis.quit();
|
||||
});
|
||||
|
||||
beforeEach(async(): Promise<void> => {
|
||||
await clearRedis();
|
||||
});
|
||||
|
||||
afterAll(async(): Promise<void> => {
|
||||
await redis.quit();
|
||||
});
|
||||
|
||||
it('#acquireReadLock.', async(): Promise<void> => {
|
||||
const key1 = 'key1';
|
||||
const writeKey1 = `${key1}.wlock`;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import fetch from 'cross-fetch';
|
||||
import type { App, DataAccessorBasedStore, Initializable, ResourceLocker } from '../../src';
|
||||
import { readableToString, BasicRepresentation } from '../../src';
|
||||
import { BasicRepresentation, readableToString } from '../../src';
|
||||
import { describeIf, getPort } from '../util/Util';
|
||||
import { getDefaultVariables, getTestConfigPath, getTestFolder, instantiateFromConfig, removeFolder } from './Config';
|
||||
|
||||
@@ -24,6 +24,7 @@ const configs: [string, any][] = [
|
||||
}],
|
||||
];
|
||||
|
||||
/* eslint-disable jest/require-top-level-describe, jest/consistent-test-it */
|
||||
describeIf('docker').each(configs)('A server using %s locking', (id, { config, init, teardown }):
|
||||
void => {
|
||||
let app: App;
|
||||
|
||||
@@ -8,6 +8,7 @@ import { getDefaultVariables, getPresetConfigPath, getTestConfigPath, instantiat
|
||||
const port = getPort('SparqlStorage');
|
||||
const baseUrl = `http://localhost:${port}/`;
|
||||
|
||||
/* eslint-disable jest/require-top-level-describe, jest/consistent-test-it */
|
||||
describeIf('docker')('A server with a SPARQL endpoint as storage', (): void => {
|
||||
let app: App;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { createServer } from 'http';
|
||||
import type { Server, IncomingMessage, ServerResponse } from 'http';
|
||||
import type { IncomingMessage, Server, ServerResponse } from 'http';
|
||||
import { fetch } from 'cross-fetch';
|
||||
import { createRemoteJWKSet, jwtVerify } from 'jose';
|
||||
import type { NamedNode } from 'n3';
|
||||
|
||||
Reference in New Issue
Block a user