mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-20 10:15:17 -04:00
auth: Add tests for AuthService
Move AuthTokens to auth folder Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
parent
c9751404f7
commit
508ad26771
30 changed files with 329 additions and 186 deletions
|
@ -5,12 +5,13 @@
|
|||
*/
|
||||
|
||||
import { Module } from '@nestjs/common';
|
||||
import { UsersModule } from '../../users/users.module';
|
||||
import { TokensController } from './tokens/tokens.controller';
|
||||
import { LoggerModule } from '../../logger/logger.module';
|
||||
import { UsersModule } from '../../users/users.module';
|
||||
import { AuthModule } from '../../auth/auth.module';
|
||||
|
||||
@Module({
|
||||
imports: [UsersModule, LoggerModule],
|
||||
imports: [LoggerModule, UsersModule, AuthModule],
|
||||
controllers: [TokensController],
|
||||
})
|
||||
export class PrivateApiModule {}
|
||||
|
|
|
@ -7,11 +7,11 @@
|
|||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { TokensController } from './tokens.controller';
|
||||
import { LoggerModule } from '../../../logger/logger.module';
|
||||
import { UsersModule } from '../../../users/users.module';
|
||||
import { getRepositoryToken } from '@nestjs/typeorm';
|
||||
import { Identity } from '../../../users/identity.entity';
|
||||
import { User } from '../../../users/user.entity';
|
||||
import { AuthToken } from '../../../users/auth-token.entity';
|
||||
import { AuthToken } from '../../../auth/auth-token.entity';
|
||||
import { AuthModule } from '../../../auth/auth.module';
|
||||
|
||||
describe('TokensController', () => {
|
||||
let controller: TokensController;
|
||||
|
@ -19,7 +19,7 @@ describe('TokensController', () => {
|
|||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
controllers: [TokensController],
|
||||
imports: [LoggerModule, UsersModule],
|
||||
imports: [LoggerModule, AuthModule],
|
||||
})
|
||||
.overrideProvider(getRepositoryToken(User))
|
||||
.useValue({})
|
||||
|
|
|
@ -14,15 +14,15 @@ import {
|
|||
Post,
|
||||
} from '@nestjs/common';
|
||||
import { ConsoleLoggerService } from '../../../logger/console-logger.service';
|
||||
import { UsersService } from '../../../users/users.service';
|
||||
import { AuthTokenDto } from '../../../users/auth-token.dto';
|
||||
import { AuthTokenWithSecretDto } from '../../../users/auth-token-with-secret.dto';
|
||||
import { AuthTokenDto } from '../../../auth/auth-token.dto';
|
||||
import { AuthTokenWithSecretDto } from '../../../auth/auth-token-with-secret.dto';
|
||||
import { AuthService } from '../../../auth/auth.service';
|
||||
|
||||
@Controller('tokens')
|
||||
export class TokensController {
|
||||
constructor(
|
||||
private readonly logger: ConsoleLoggerService,
|
||||
private usersService: UsersService,
|
||||
private authService: AuthService,
|
||||
) {
|
||||
this.logger.setContext(TokensController.name);
|
||||
}
|
||||
|
@ -31,8 +31,8 @@ export class TokensController {
|
|||
async getUserTokens(): Promise<AuthTokenDto[]> {
|
||||
// ToDo: Get real userName
|
||||
return (
|
||||
await this.usersService.getTokensByUsername('hardcoded')
|
||||
).map((token) => this.usersService.toAuthTokenDto(token));
|
||||
await this.authService.getTokensByUsername('hardcoded')
|
||||
).map((token) => this.authService.toAuthTokenDto(token));
|
||||
}
|
||||
|
||||
@Post()
|
||||
|
@ -41,18 +41,13 @@ export class TokensController {
|
|||
@Body('until') until: number,
|
||||
): Promise<AuthTokenWithSecretDto> {
|
||||
// ToDo: Get real userName
|
||||
const authToken = await this.usersService.createTokenForUser(
|
||||
'hardcoded',
|
||||
label,
|
||||
until,
|
||||
);
|
||||
return this.usersService.toAuthTokenWithSecretDto(authToken);
|
||||
return this.authService.createTokenForUser('hardcoded', label, until);
|
||||
}
|
||||
|
||||
@Delete('/:keyId')
|
||||
@HttpCode(204)
|
||||
async deleteToken(@Param('keyId') keyId: string) {
|
||||
// ToDo: Get real userName
|
||||
return this.usersService.removeToken('hardcoded', keyId);
|
||||
return this.authService.removeToken('hardcoded', keyId);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ import { NotesModule } from '../../../notes/notes.module';
|
|||
import { Tag } from '../../../notes/tag.entity';
|
||||
import { Authorship } from '../../../revisions/authorship.entity';
|
||||
import { Revision } from '../../../revisions/revision.entity';
|
||||
import { AuthToken } from '../../../users/auth-token.entity';
|
||||
import { AuthToken } from '../../../auth/auth-token.entity';
|
||||
import { Identity } from '../../../users/identity.entity';
|
||||
import { User } from '../../../users/user.entity';
|
||||
import { UsersModule } from '../../../users/users.module';
|
||||
|
|
|
@ -18,7 +18,7 @@ import { NotesModule } from '../../../notes/notes.module';
|
|||
import { Tag } from '../../../notes/tag.entity';
|
||||
import { Authorship } from '../../../revisions/authorship.entity';
|
||||
import { Revision } from '../../../revisions/revision.entity';
|
||||
import { AuthToken } from '../../../users/auth-token.entity';
|
||||
import { AuthToken } from '../../../auth/auth-token.entity';
|
||||
import { Identity } from '../../../users/identity.entity';
|
||||
import { User } from '../../../users/user.entity';
|
||||
import { MediaController } from './media.controller';
|
||||
|
|
|
@ -14,7 +14,7 @@ import { Tag } from '../../../notes/tag.entity';
|
|||
import { Authorship } from '../../../revisions/authorship.entity';
|
||||
import { Revision } from '../../../revisions/revision.entity';
|
||||
import { RevisionsModule } from '../../../revisions/revisions.module';
|
||||
import { AuthToken } from '../../../users/auth-token.entity';
|
||||
import { AuthToken } from '../../../auth/auth-token.entity';
|
||||
import { Identity } from '../../../users/identity.entity';
|
||||
import { User } from '../../../users/user.entity';
|
||||
import { UsersModule } from '../../../users/users.module';
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue