Skip to content
Snippets Groups Projects
Verified Commit 9b7dfd68 authored by Konstantin Tsabolov's avatar Konstantin Tsabolov
Browse files

chore: remove attestation manager

parent ebb39da2
No related branches found
No related tags found
2 merge requests!32Remove attestation manager. Refs #9,!30Helm charts
Showing
with 0 additions and 2411 deletions
import credDefStub from '../stubs/credDef.stub.js';
const CredentialDefServiceMock = jest.fn().mockReturnValue({
createCredDef: jest.fn().mockReturnValue(credDefStub()),
findCredentialDef: jest.fn().mockReturnValue([1, [credDefStub()]]),
findCredentialDefById: jest.fn().mockReturnValue([1, [credDefStub()]]),
findCredentialDefBySchemaIdDesc: jest
.fn()
.mockReturnValue([1, [credDefStub()]]),
checkCredDefByNameAndSchemaID: jest
.fn()
.mockImplementation((cd) =>
cd.id === credDefStub().id ? [0, []] : [1, [credDefStub()]],
),
getAgentByParticipantId: jest.fn().mockReturnValue([1, [credDefStub()]]),
createCredDefOnLedger: jest.fn().mockReturnValue({ id: 'new-creddef-id' }),
});
export default CredentialDefServiceMock;
import type { TestingModule } from '@nestjs/testing';
import type { Response } from 'express';
import { HttpStatus } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { Test } from '@nestjs/testing';
import { createResponse } from 'node-mocks-http';
import CredentialDefController from '../controller/controller.js';
import CredentialDefService from '../services/service.js';
import CredentialDefServiceMock from './__mocks__/service.js';
import credDefStub from './stubs/credDef.stub.js';
describe('CredentialDefController', () => {
let credentialDefController: CredentialDefController;
let spyService: CredentialDefService;
beforeEach(async () => {
const CredentialDefServiceProvider = {
provide: CredentialDefService,
useFactory: CredentialDefServiceMock,
};
const module: TestingModule = await Test.createTestingModule({
imports: [],
controllers: [CredentialDefController],
providers: [CredentialDefServiceProvider, ConfigService],
}).compile();
credentialDefController = module.get<CredentialDefController>(
CredentialDefController,
);
spyService = module.get<CredentialDefService>(CredentialDefService);
jest.clearAllMocks();
});
it('should be defined', () => {
expect(credentialDefController).toBeDefined();
});
describe('findCredentialDef()', () => {
let query: {
pageSize: string;
page: string;
schemaID: string;
};
let credDefResponse: Response<string, Record<string, unknown>>;
beforeEach(async () => {
query = {
pageSize: '10',
page: '1',
schemaID: credDefStub().schemaID,
};
const response = createResponse();
credDefResponse = await credentialDefController.findCredentialDef(
query,
response,
);
});
it('should call findCredentialDef() from service', async () => {
expect(spyService.findCredentialDef).toHaveBeenCalled();
});
it('should retrieve CredDef for a correct ID', async () => {
expect(
spyService.findCredentialDef(
query.pageSize ? parseInt(query.pageSize, 10) : 10,
query.page ? parseInt(query.page, 10) : 0,
query.schemaID ? query.schemaID : '',
),
).toEqual([1, [credDefStub()]]);
});
it(`should retrieve HTTP status success(${HttpStatus.OK})`, async () => {
expect(credDefResponse?.statusCode).toEqual(HttpStatus.OK);
});
});
describe('findCredentialDefById()', () => {
let credDefID: string;
let credDef: Response<string, Record<string, unknown>>;
beforeEach(async () => {
credDefID = credDefStub().id;
const response = createResponse();
credDef = await credentialDefController.findCredentialDefById(
credDefID,
response,
);
});
it('should call findCredentialDefById() for a CredDef', async () => {
expect(spyService.findCredentialDefById).toHaveBeenCalled();
});
it('should retrieve CredDef for a correct ID', async () => {
expect(spyService.findCredentialDefById(credDefID)).toEqual([
1,
[credDefStub()],
]);
});
it(`should retrieve HTTP status success(${HttpStatus.OK})`, async () => {
expect(credDef?.statusCode).toEqual(HttpStatus.OK);
});
});
describe('createCredDef()', () => {
let credDef: Response<string, Record<string, unknown>>;
beforeEach(async () => {
const response = createResponse();
credDef = await credentialDefController.createCredentialDef(
credDefStub(),
response,
);
});
it('should call checkCredDefByNameAndSchemaID() from service', async () => {
expect(spyService.checkCredDefByNameAndSchemaID).toHaveBeenCalled();
});
it('should not retrieve CredDef for a given credDef', async () => {
expect(spyService.checkCredDefByNameAndSchemaID(credDefStub())).toContain(
0,
);
});
it('should call createCredDefOnLedger() from service', async () => {
expect(spyService.createCredDefOnLedger).toHaveBeenCalled();
});
it(`should retrieve HTTP status created(${HttpStatus.CREATED})`, async () => {
expect(credDef?.statusCode).toEqual(HttpStatus.CREATED);
});
});
});
import type { TestingModule } from '@nestjs/testing';
import { HttpModule } from '@nestjs/axios';
import { Test } from '@nestjs/testing';
import NatsClientService from '../../client/nats.client.js';
import RestClientService from '../../client/rest.client.js';
import NatsClientServiceMock from '../../client/tests/__mocks__/nats.client.js';
import RestClientServiceMock from '../../client/tests/__mocks__/rest.client.js';
import PrismaService from '../../prisma/prisma.service.js';
import PrismaServiceMock from '../../prisma/tests/__mocks__/prisma.service.js';
import CredentialDefModule from '../module.js';
import CredentialDefService from '../services/service.js';
import CredentialDefServiceMock from './__mocks__/service.js';
describe('CredentialDefModule', () => {
let credentialDefModule: CredentialDefModule;
const CredentialDefServiceProvider = {
provide: CredentialDefService,
useFactory: CredentialDefServiceMock,
};
const PrismaServiceProvider = {
provide: PrismaService,
useFactory: PrismaServiceMock,
};
const NatsClientServiceProvider = {
provide: NatsClientService,
useFactory: NatsClientServiceMock,
};
const RestClientServiceProvider = {
provide: RestClientService,
useFactory: RestClientServiceMock,
};
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
imports: [HttpModule],
providers: [
CredentialDefModule,
CredentialDefServiceProvider,
PrismaServiceProvider,
NatsClientServiceProvider,
RestClientServiceProvider,
],
}).compile();
credentialDefModule = module.get<CredentialDefModule>(CredentialDefModule);
});
it('should be defined', () => {
expect(credentialDefModule).toBeDefined();
});
});
import type { TestingModule } from '@nestjs/testing';
import type { CredentialDef } from '@prisma/client';
import { HttpModule } from '@nestjs/axios';
import { ConfigService } from '@nestjs/config';
import { Test } from '@nestjs/testing';
import NatsClientService from '../../client/nats.client.js';
import RestClientService from '../../client/rest.client.js';
import NatsClientServiceMock from '../../client/tests/__mocks__/nats.client.js';
import RestClientServiceMock from '../../client/tests/__mocks__/rest.client.js';
import PrismaService from '../../prisma/prisma.service.js';
import PrismaServiceMock from '../../prisma/tests/__mocks__/prisma.service.js';
import SchemasService from '../../schemas/services/service.js';
import SchemasServiceMock from '../../schemas/tests/__mocks__/service.js';
import CredentialDefService from '../services/service.js';
import credDefStub from './stubs/credDef.stub.js';
describe('CredentialDefService', () => {
let credDefService: CredentialDefService;
const PrismaServiceProvider = {
provide: PrismaService,
useFactory: PrismaServiceMock,
};
const NatsClientServiceProvider = {
provide: NatsClientService,
useFactory: NatsClientServiceMock,
};
const RestClientServiceProvider = {
provide: RestClientService,
useFactory: RestClientServiceMock,
};
const SchemasServiceProvider = {
provide: SchemasService,
useFactory: SchemasServiceMock,
};
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
imports: [HttpModule],
providers: [
CredentialDefService,
PrismaServiceProvider,
NatsClientServiceProvider,
RestClientServiceProvider,
ConfigService,
SchemasServiceProvider,
],
}).compile();
credDefService = module.get<CredentialDefService>(CredentialDefService);
});
it('should be defined', () => {
expect(credDefService).toBeDefined();
});
describe('createCredDef()', () => {
let credDefResponse: CredentialDef;
beforeEach(async () => {
credDefResponse = await credDefService.createCredDef(credDefStub());
});
it('should call create() from PrismaService', async () => {
expect(PrismaServiceMock().credentialDef.create).toHaveBeenCalled();
});
it('should retrieve credDef by participantId', async () => {
expect(credDefResponse).toEqual([credDefStub()]);
});
});
describe('findCredentialDef()', () => {
let credDefResponse: Array<number | CredentialDef[]>;
let id: string;
beforeEach(async () => {
const pageSize = 10;
const page = 10;
id = credDefStub().credDefId;
credDefResponse = await credDefService.findCredentialDef(
pageSize,
page,
id,
);
});
it('should call findMany() from PrismaService.credentialDef', async () => {
expect(PrismaServiceMock().credentialDef.findMany).toHaveBeenCalled();
});
it('should call count() from PrismaService.credentialDef', async () => {
expect(PrismaServiceMock().credentialDef.count).toHaveBeenCalled();
});
it('should call $transaction() from PrismaService', async () => {
expect(PrismaServiceMock().$transaction).toHaveBeenCalled();
});
it('should retrieve schema by ID', async () => {
expect(credDefResponse).toEqual([1, [credDefStub()]]);
});
});
describe('findCredentialDefById()', () => {
let credDefResponse: Array<number | CredentialDef[]>;
let id: string;
beforeEach(async () => {
id = credDefStub().credDefId;
credDefResponse = await credDefService.findCredentialDefById(id);
});
it('should call findMany() from PrismaService.credentialDef', async () => {
expect(PrismaServiceMock().credentialDef.findMany).toHaveBeenCalled();
});
it('should call count() from PrismaService.credentialDef', async () => {
expect(PrismaServiceMock().credentialDef.count).toHaveBeenCalled();
});
it('should call $transaction() from PrismaService', async () => {
expect(PrismaServiceMock().$transaction).toHaveBeenCalled();
});
it('should retrieve schema by ID', async () => {
expect(credDefResponse).toEqual([1, [credDefStub()]]);
});
});
describe('checkCredDefByNameAndSchemaID()', () => {
let credDefResponse: Array<number | CredentialDef[]>;
beforeEach(async () => {
credDefResponse =
await credDefService.checkCredDefByNameAndSchemaID(credDefStub());
});
it('should call findMany() from PrismaService.credentialDef', async () => {
expect(PrismaServiceMock().credentialDef.findMany).toHaveBeenCalled();
});
it('should call count() from PrismaService.credentialDef', async () => {
expect(PrismaServiceMock().credentialDef.count).toHaveBeenCalled();
});
it('should call $transaction() from PrismaService', async () => {
expect(PrismaServiceMock().$transaction).toHaveBeenCalled();
});
it('should retrieve credDef by Name and Schema ID', async () => {
expect(credDefResponse).toEqual([1, [credDefStub()]]);
});
});
describe('createCredDefOnLedger()', () => {
let credDefResponse: Array<number | CredentialDef[]>;
beforeEach(async () => {
credDefResponse = await credDefService.createCredDefOnLedger({
schemaId: credDefStub().schemaID,
supportRevocation: credDefStub().supportRevocation,
tag: credDefStub().tag,
});
});
it('should call post() from restClient', async () => {
expect(RestClientServiceMock().post).toHaveBeenCalled();
});
it('should get a response from AFJ', async () => {
expect(credDefResponse).not.toBe(null);
});
});
});
import type CredentialDefDto from '../../entities/credentialDef-entity.js';
const credDefStub = (): CredentialDefDto =>
({
id: 'cred-def-stub-id',
schemaID: 'cred-def-stub-schema-id',
name: 'cred-def-stub-name',
credDefId: 'cred-def-stub-cred-def-id',
supportRevocation: true,
isRevokable: true,
isAutoIssue: true,
expiryHours: '48',
createdBy: 'cred-def-stub-created-by-id',
createdDate: new Date(2022),
updatedBy: 'cred-def-stub-updated-by-id',
updatedDate: new Date(2022),
tag: 'cred-def-stub-tag',
}) as CredentialDefDto;
export default credDefStub;
import type { ResponseType } from '../common/response.js';
import { Controller, Get, HttpStatus, Version } from '@nestjs/common';
import { ApiOperation, ApiResponse } from '@nestjs/swagger';
@Controller('health')
export default class HealthController {
public res: ResponseType;
@Version(['1'])
@Get()
@ApiOperation({
summary: 'Health check',
description:
'This call provides the capability to check the service is working and up. The call returns 200 Status Code and current server time in json body',
})
@ApiResponse({
status: HttpStatus.OK,
description: 'Service is up and running.',
content: {
'application/json': {
schema: {},
examples: {
'Service is up and running.': {
value: {
statusCode: 200,
message:
'Thu Jan 01 1970 00:00:00 GMT+0000 (Coordinated Universal Time)',
},
},
},
},
},
})
public getHealth() {
this.res = {
statusCode: HttpStatus.OK,
message: `${new Date()}`,
};
return this.res;
}
}
import type { ResponseType } from '../../common/response.js';
import type { TestingModule } from '@nestjs/testing';
import { HttpStatus } from '@nestjs/common';
import { Test } from '@nestjs/testing';
import HealthController from '../health.controller.js';
describe('HealthController', () => {
let healthController: HealthController;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [HealthController],
}).compile();
healthController = module.get<HealthController>(HealthController);
jest.clearAllMocks();
});
it('should be defined', () => {
expect(healthController).toBeDefined();
});
describe('getHealth()', () => {
let health: ResponseType;
beforeEach(async () => {
health = healthController.getHealth();
});
it(`should retrieve HTTP status created(${HttpStatus.OK})`, async () => {
expect(health.statusCode).toEqual(HttpStatus.OK);
});
});
});
import { IsString, IsNotEmpty } from 'class-validator';
export default class CredentialDto {
@IsString()
@IsNotEmpty()
public credentialId: string;
@IsString()
@IsNotEmpty()
public credDefId: string;
@IsString()
public schemaId?: string;
@IsString()
@IsNotEmpty()
public participantId?: string;
@IsString()
@IsNotEmpty()
public principalDid?: string;
@IsString()
@IsNotEmpty()
public state: string;
@IsString()
@IsNotEmpty()
public threadId: string;
@IsString()
@IsNotEmpty()
public connectionId: string;
@IsString()
public expirationDate?: Date | null;
}
import { IsString, IsNotEmpty } from 'class-validator';
export default class CredentialStateDto {
@IsString()
@IsNotEmpty()
public id: string;
@IsNotEmpty()
public metadata: {
'_internal/indyCredential': {
credentialDefinitionId: string;
schemaId: string;
};
};
@IsString()
@IsNotEmpty()
public credDefId: string;
@IsString()
@IsNotEmpty()
public state: string;
@IsString()
@IsNotEmpty()
public threadId: string;
@IsString()
@IsNotEmpty()
public connectionId: string;
}
import { ApiProperty } from '@nestjs/swagger';
import { IsNotEmpty, IsString } from 'class-validator';
export default class CredentialTypeDto {
@IsString()
public id?: string;
@IsString()
@IsNotEmpty()
@ApiProperty()
public type: string;
@IsString()
@IsNotEmpty()
@ApiProperty()
public schemaId: string;
}
import { ApiProperty } from '@nestjs/swagger';
import { IsString, IsNotEmpty } from 'class-validator';
class CredentialPreviewAttributes {
@IsString()
@IsNotEmpty()
@ApiProperty()
public name: string;
@IsString()
@ApiProperty()
public value: string;
}
export default class OfferCredentialDto {
@IsString()
@IsNotEmpty()
@ApiProperty()
public connectionId: string;
@IsString()
@IsNotEmpty()
@ApiProperty()
public credentialDefinitionId: string;
@IsString()
@IsNotEmpty()
@ApiProperty()
public comment: string;
@ApiProperty({ type: [CredentialPreviewAttributes] })
public attributes: CredentialPreviewAttributes[];
@IsString()
@IsNotEmpty()
@ApiProperty()
public autoAcceptCredential: string;
}
import { IsString } from 'class-validator';
export default class GetIssueCredentialsDto {
@IsString()
public connectionId: string;
}
import { IsString } from 'class-validator';
export default class GetCredentialParams {
@IsString()
public id: string;
}
import { IsBoolean, IsString, IsDateString } from 'class-validator';
export default class GetCredentialQuery {
@IsString()
public page?: string;
@IsString()
public pageSize?: string;
@IsString()
public threadId?: string;
@IsBoolean()
public isReceived?: boolean | string;
@IsString()
public state?: string;
@IsString()
public credDefId?: string;
@IsDateString()
public createdDateStart?: string;
@IsDateString()
public createdDateEnd?: string;
@IsDateString()
public updatedDateStart?: string;
@IsDateString()
public updatedDateEnd?: string;
@IsDateString()
public expirationDateStart?: string;
@IsDateString()
public expirationDateEnd?: string;
@IsString()
public connectionId?: string;
@IsString()
public principalDid?: string;
}
import { ApiProperty } from '@nestjs/swagger';
import { IsString, IsNotEmpty } from 'class-validator';
export default class ProposeCredentialDto {
@IsString()
@IsNotEmpty()
@ApiProperty()
public connectionId: string;
@IsString()
@IsNotEmpty()
@ApiProperty()
public credentialDefinitionId: string;
@IsString()
@IsNotEmpty()
@ApiProperty()
public comment: string;
@IsString()
@IsNotEmpty()
@ApiProperty()
public credentialProposal: {
'@type': string;
attributes: {
name: string;
value: string;
}[];
};
@IsString()
@IsNotEmpty()
@ApiProperty()
public autoAcceptCredential: string;
}
import { ApiProperty } from '@nestjs/swagger';
import { IsString, IsNotEmpty } from 'class-validator';
export default class UpdateSchemaIdByTypeDto {
@IsString()
@IsNotEmpty()
@ApiProperty()
public schemaId: string;
}
import { HttpModule } from '@nestjs/axios';
import { Module } from '@nestjs/common';
import { ClientsModule, Transport } from '@nestjs/microservices';
import NatsClientService from '../client/nats.client.js';
import RestClientService from '../client/rest.client.js';
import TSAClientService from '../client/tsa.client.js';
import { NATSServices } from '../common/constants.js';
import config from '../config/config.js';
import CredentialDefService from '../credentialDef/services/service.js';
import PrismaService from '../prisma/prisma.service.js';
import SchemasService from '../schemas/services/service.js';
import UserInfoService from '../userInfo/services/service.js';
import AttestationController from './controller/controller.js';
import AttestationService from './services/service.js';
@Module({
imports: [
HttpModule,
ClientsModule.register([
{
name: NATSServices.SERVICE_NAME,
transport: Transport.NATS,
options: {
servers: [config().nats.url as string],
},
},
]),
],
controllers: [AttestationController],
providers: [
AttestationService,
PrismaService,
NatsClientService,
RestClientService,
CredentialDefService,
SchemasService,
TSAClientService,
UserInfoService,
],
})
export default class AttestationModule {}
import type { Prisma } from '@prisma/client';
import { Injectable } from '@nestjs/common';
import PrismaService from '../../prisma/prisma.service.js';
@Injectable()
export default class CredentialRepository {
public constructor(private readonly prismaService: PrismaService) {}
public async createCredential(data: Prisma.CredentialCreateInput) {
const credential = await this.prismaService.credential.create({ data });
const credDef = await this.prismaService.credentialDef.findFirst({
where: { credDefId: data.credDefId },
});
if (!credDef) {
return credential;
}
await this.prismaService.credentialDef.update({
where: {
credDefId: data.credDefId,
},
data: {
credentials: {
connect: {
id: credential.id,
},
},
},
});
return credential;
}
public async findUniqueCredential(params: {
where: Prisma.CredentialWhereUniqueInput;
}) {
const { where } = params;
return this.prismaService.credential.findUnique({
where,
});
}
public async updateCredential(params: {
where: Prisma.CredentialWhereUniqueInput;
data: Prisma.CredentialUpdateInput;
}) {
const { where, data } = params;
return this.prismaService.credential.update({
data,
where,
});
}
public async findCredential(params: {
skip?: number;
take?: number;
cursor?: Prisma.CredentialWhereUniqueInput;
where?: Prisma.CredentialWhereInput;
orderBy?: Prisma.CredentialOrderByWithRelationInput;
}) {
const { skip, take, cursor, where, orderBy } = params;
return this.prismaService.$transaction([
this.prismaService.credential.count({
where: {
...where,
},
}),
this.prismaService.credential.findMany({
skip,
take,
cursor,
where,
orderBy,
}),
]);
}
public async deleteCredential(params: {
where: Prisma.CredentialWhereUniqueInput;
}) {
const { where } = params;
return this.prismaService.credential.delete({
where,
});
}
}
import type { Prisma } from '@prisma/client';
import { Injectable } from '@nestjs/common';
import PrismaService from '../../prisma/prisma.service.js';
@Injectable()
export default class CredentialsTypeRepository {
public constructor(private readonly prismaService: PrismaService) {}
public async createCredentialsType(data: Prisma.CredentialsTypeCreateInput) {
return this.prismaService.credentialsType.create({ data });
}
public async createOrUpdateCredentialsType(
data: Prisma.CredentialsTypeCreateInput,
) {
const credentialType = await this.prismaService.credentialsType.findFirst({
where: {
type: {
equals: data.type,
mode: 'insensitive',
},
},
});
if (credentialType) {
return this.prismaService.credentialsType.update({
where: {
id: credentialType.id,
},
data,
});
}
const credentialTypeSchemaCheck =
await this.prismaService.credentialsType.findFirst({
where: {
schemaId: {
equals: data.schemaId,
},
},
});
if (credentialTypeSchemaCheck) {
return this.prismaService.credentialsType.update({
where: {
id: credentialTypeSchemaCheck.id,
},
data,
});
}
return this.prismaService.credentialsType.create({
data,
});
}
public async findUniqueCredentialsType(data: { type: string }) {
return this.prismaService.credentialsType.findFirst({
where: {
type: {
equals: data.type,
mode: 'insensitive',
},
},
});
}
// TODO check
public async updateCredentialsType(params: {
where: Prisma.CredentialsTypeWhereUniqueInput;
data: Prisma.CredentialsTypeUpdateInput;
}) {
const { where, data } = params;
return this.prismaService.credentialsType.update({
data,
where,
});
}
public async findCredentialsType(params: {
skip?: number;
take?: number;
cursor?: Prisma.CredentialsTypeWhereUniqueInput;
where?: Prisma.CredentialsTypeWhereInput;
orderBy?: Prisma.CredentialsTypeOrderByWithRelationInput;
}) {
const { skip, take, cursor, where, orderBy } = params;
return this.prismaService.$transaction([
this.prismaService.credentialsType.count({
where: {
...where,
},
}),
this.prismaService.credentialsType.findMany({
skip,
take,
cursor,
where,
orderBy,
}),
]);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment