Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('authenticates successfully with valid token', async () => {
class InfoController {
constructor(
@inject(JWTAuthenticationStrategyBindings.TOKEN_SERVICE)
public tokenService: JWTService,
@inject(USER_REPO)
public users: UserRepository,
@inject(AuthenticationBindings.USER_PROFILE_FACTORY)
public userProfileFactory: UserProfileFactory,
) {}
@post('/login')
async logIn() {
//
// ...Other code for verifying a valid user (e.g. basic or local strategy)...
//
// Now with a valid userProfile, let's create a JSON web token
return this.tokenService.generateToken(
this.userProfileFactory(joeUser),
);
}
@get('/whoAmI')
@authenticate('jwt')
whoAmI(@inject(SecurityBindings.USER) userProfile: UserProfile) {
if (!userProfile) return 'userProfile is undefined';
if (!userProfile[securityId])
it('returns definitions inferred via app.controller()', () => {
@model()
class MyModel {
@property()
bar: string;
}
class MyController {
@post('/foo')
createFoo(@requestBody() foo: MyModel) {}
}
app.controller(MyController);
const spec = server.getApiSpec();
expect(spec.components && spec.components.schemas).to.deepEqual({
MyModel: {
title: 'MyModel',
properties: {
bar: {
type: 'string',
},
},
additionalProperties: false,
},
});
},
})
.withResponse(200, {
content: {
'application/json': {
schema: {
type: 'object',
},
},
},
description: '',
})
.build();
class MyController {
@post('/show-body', expectedOpSpec)
showBody(body: object) {
return body;
}
}
app.controller(MyController);
const spec = server.getApiSpec();
expect(spec.paths['/show-body'].post).to.containDeep(expectedOpSpec);
});