fix: make backend local verification safe

This commit is contained in:
2026-08-23 21:21:17 +03:00
parent fee4f8c8e6
commit 71d57d60bc
9 changed files with 70 additions and 12 deletions
+4 -1
View File
@@ -5,6 +5,7 @@ jest.mock('../prisma/prisma.service', () => ({
}));
import { TbankConnectionService } from './tbank-connection.service';
import type { TbankClient } from './tbank.client';
describe('TbankConnectionService', () => {
const prisma = {
@@ -17,7 +18,9 @@ describe('TbankConnectionService', () => {
const config = {
getOrThrow: jest.fn(() => 'MDEyMzQ1Njc4OWFiY2RlZjAxMjM0NTY3ODlhYmNkZWY='),
};
const tbank = { validateToken: jest.fn() };
const tbank: jest.Mocked<Pick<TbankClient, 'validateToken'>> = {
validateToken: jest.fn(),
};
const portfolio = { invalidate: jest.fn() };
const service = new TbankConnectionService(
prisma as never,
+4 -2
View File
@@ -1,4 +1,4 @@
import { BadRequestException, Injectable } from '@nestjs/common';
import { BadRequestException, Inject, Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { Environment } from '../config/env.validation';
import { PrismaService } from '../prisma/prisma.service';
@@ -6,6 +6,8 @@ import { TbankClient } from './tbank.client';
import { TbankCrypto } from './tbank.crypto';
import { PortfolioService } from './portfolio.service';
type TbankTokenValidator = Pick<TbankClient, 'validateToken'>;
@Injectable()
export class TbankConnectionService {
private readonly crypto: TbankCrypto;
@@ -13,7 +15,7 @@ export class TbankConnectionService {
constructor(
private readonly prisma: PrismaService,
config: ConfigService<Environment, true>,
private readonly tbank: TbankClient,
@Inject(TbankClient) private readonly tbank: TbankTokenValidator,
private readonly portfolio: PortfolioService,
) {
this.crypto = TbankCrypto.fromBase64(
+4 -1
View File
@@ -37,7 +37,10 @@ const instrumentCacheTtlMs = 24 * 60 * 60_000;
@Injectable()
export class UpcomingEventsService {
private readonly crypto: TbankCrypto;
private readonly dividendCache = new Map<string, CachedEntry<TbankDividend[]>>();
private readonly dividendCache = new Map<
string,
CachedEntry<TbankDividend[]>
>();
private readonly instrumentCache = new Map<
string,
CachedEntry<TbankInstrument | null>