Skip to content

Commit 5a49020

Browse files
committed
Add tests for authentication schema, improve code coverage
1 parent 5b2a20a commit 5a49020

File tree

5 files changed

+32
-12
lines changed

5 files changed

+32
-12
lines changed

packages/authentication/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
},
6666
"devDependencies": {
6767
"@feathersjs/memory": "^5.0.0-pre.17",
68+
"@feathersjs/schema": "^5.0.0-pre.17",
6869
"@types/lodash": "^4.14.178",
6970
"@types/mocha": "^9.1.0",
7071
"@types/node": "^17.0.15",

packages/authentication/src/options.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,17 @@ export const authenticationSettingsSchema = {
4848
},
4949
jwt: {
5050
type: 'object',
51-
header: {
52-
type: 'string',
53-
default: 'Authorization',
54-
description: 'The HTTP header containing the JWT'
55-
},
56-
schemes: {
57-
type: 'array',
58-
items: { type: 'string' },
59-
description: 'An array of schemes to support'
51+
properties: {
52+
header: {
53+
type: 'string',
54+
default: 'Authorization',
55+
description: 'The HTTP header containing the JWT'
56+
},
57+
schemes: {
58+
type: 'array',
59+
items: { type: 'string' },
60+
description: 'An array of schemes to support'
61+
}
6062
}
6163
},
6264
local: {

packages/authentication/test/core.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import assert from 'assert';
22
import { feathers, Application } from '@feathersjs/feathers';
33
import jwt from 'jsonwebtoken';
4+
import { Infer, schema } from '@feathersjs/schema';
45

56
import { AuthenticationBase, AuthenticationRequest } from '../src/core';
7+
import { authenticationSettingsSchema } from '../src/options';
68
import { Strategy1, Strategy2, MockRequest } from './fixtures';
79
import { ServerResponse } from 'http';
810

@@ -31,6 +33,21 @@ describe('authentication/core', () => {
3133
});
3234

3335
describe('configuration', () => {
36+
it('infers configuration from settings schema', async () => {
37+
const settingsSchema = schema({
38+
$id: 'AuthSettingsSchema',
39+
...authenticationSettingsSchema
40+
} as const);
41+
type Settings = Infer<typeof settingsSchema>;
42+
const config: Settings = {
43+
entity: 'user',
44+
secret: 'supersecret',
45+
authStrategies: [ 'some', 'thing' ]
46+
}
47+
48+
await settingsSchema.validate(config);
49+
});
50+
3451
it('throws an error when app is not provided', () => {
3552
try {
3653
// @ts-ignore

packages/schema/src/resolver.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ export type PropertyResolverMap<T, C> = {
1313
}
1414

1515
export interface ResolverConfig<T, C> {
16-
// TODO this should be `Schema<any>` but has recently produced an error, see
17-
// https://github.com/ThomasAribart/json-schema-to-ts/issues/53
1816
schema?: Schema<T>,
1917
validate?: 'before'|'after'|false,
2018
properties: PropertyResolverMap<T, C>

packages/schema/test/fixture.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { GeneralError } from '@feathersjs/errors';
66

77
import {
88
schema, resolve, Infer, resolveResult,
9-
queryProperty, resolveQuery, resolveData
9+
queryProperty, resolveQuery, resolveData, validateData, validateQuery
1010
} from '../src';
1111

1212
export const userSchema = schema({
@@ -148,6 +148,7 @@ const app = feathers<ServiceTypes>()
148148
.use('messages', memory());
149149

150150
app.service('messages').hooks([
151+
validateQuery(messageQuerySchema),
151152
resolveQuery(messageQueryResolver),
152153
resolveResult(messageResultResolver)
153154
]);
@@ -158,6 +159,7 @@ app.service('users').hooks([
158159

159160
app.service('users').hooks({
160161
create: [
162+
validateData(userSchema),
161163
resolveData(userDataResolver)
162164
]
163165
});

0 commit comments

Comments
 (0)