Slave/lifecycle #11
@@ -302,6 +302,24 @@ describe('UploadService', () => {
|
|||||||
await expect(service.getZkUploadCiphertext(fixedId)).rejects.toThrow(NotFoundException);
|
await expect(service.getZkUploadCiphertext(fixedId)).rejects.toThrow(NotFoundException);
|
||||||
expect(uploadRepository.increment).not.toHaveBeenCalled();
|
expect(uploadRepository.increment).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('throws NotFoundException when expiresAt is in the past', async () => {
|
||||||
|
uploadRepository.findOne.mockResolvedValue({
|
||||||
|
storagePath: fixedId,
|
||||||
|
iv: Buffer.alloc(12, 0x11),
|
||||||
|
expiresAt: new Date(Date.now() - 60_000),
|
||||||
|
zk: {
|
||||||
|
passwordProtected: false,
|
||||||
|
wrappedDek: null,
|
||||||
|
wrapIv: null,
|
||||||
|
salt: null
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
await expect(service.getZkUploadCiphertext(fixedId)).rejects.toThrow(NotFoundException);
|
||||||
|
expect(storageService.read).not.toHaveBeenCalled();
|
||||||
|
expect(uploadRepository.increment).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('getHotlinkImage', () => {
|
describe('getHotlinkImage', () => {
|
||||||
@@ -364,6 +382,19 @@ describe('UploadService', () => {
|
|||||||
await expect(service.getHotlinkImage(fixedId, secret)).rejects.toThrow(NotFoundException);
|
await expect(service.getHotlinkImage(fixedId, secret)).rejects.toThrow(NotFoundException);
|
||||||
expect(uploadRepository.increment).not.toHaveBeenCalled();
|
expect(uploadRepository.increment).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('throws NotFoundException when expiresAt is in the past', async () => {
|
||||||
|
uploadRepository.findOne.mockResolvedValue({
|
||||||
|
storagePath: fixedId,
|
||||||
|
iv,
|
||||||
|
expiresAt: new Date(Date.now() - 60_000),
|
||||||
|
hotlink: { mimeType: 'image/png' }
|
||||||
|
});
|
||||||
|
|
||||||
|
await expect(service.getHotlinkImage(fixedId, secret)).rejects.toThrow(NotFoundException);
|
||||||
|
expect(storageService.read).not.toHaveBeenCalled();
|
||||||
|
expect(uploadRepository.increment).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('deleteUpload', () => {
|
describe('deleteUpload', () => {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { BadRequestException, Injectable, NotFoundException } from '@nestjs/common';
|
import { BadRequestException, Injectable, NotFoundException } from '@nestjs/common';
|
||||||
import { InjectDataSource, InjectRepository } from '@nestjs/typeorm';
|
import { InjectDataSource, InjectRepository } from '@nestjs/typeorm';
|
||||||
|
import dayjs from 'dayjs';
|
||||||
import { fileTypeFromBuffer } from 'file-type';
|
import { fileTypeFromBuffer } from 'file-type';
|
||||||
import { createHash, randomBytes, randomUUID } from 'node:crypto';
|
import { createHash, randomBytes, randomUUID } from 'node:crypto';
|
||||||
import { DataSource, Repository } from 'typeorm';
|
import { DataSource, Repository } from 'typeorm';
|
||||||
@@ -127,6 +128,10 @@ export class UploadService {
|
|||||||
throw new NotFoundException();
|
throw new NotFoundException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (upload.expiresAt && dayjs(upload.expiresAt).isBefore(dayjs())) {
|
||||||
|
throw new NotFoundException();
|
||||||
|
}
|
||||||
|
|
||||||
let ciphertextBuffer: Buffer;
|
let ciphertextBuffer: Buffer;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -170,6 +175,10 @@ export class UploadService {
|
|||||||
throw new NotFoundException();
|
throw new NotFoundException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (upload.expiresAt && dayjs(upload.expiresAt).isBefore(dayjs())) {
|
||||||
|
throw new NotFoundException();
|
||||||
|
}
|
||||||
|
|
||||||
let ciphertextBuffer: Buffer;
|
let ciphertextBuffer: Buffer;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user