|
@@ -2,7 +2,7 @@ import { describe, it, expect, beforeEach, vi } from 'vitest';
|
|
|
import { testClient } from 'hono/testing';
|
|
import { testClient } from 'hono/testing';
|
|
|
import { IntegrationTestDatabase, setupIntegrationDatabaseHooksWithEntities } from '@d8d/shared-test-util';
|
|
import { IntegrationTestDatabase, setupIntegrationDatabaseHooksWithEntities } from '@d8d/shared-test-util';
|
|
|
import { JWTUtil } from '@d8d/shared-utils';
|
|
import { JWTUtil } from '@d8d/shared-utils';
|
|
|
-import { JWTPayload } from '@d8d/shared-types';
|
|
|
|
|
|
|
+import { JWTPayload, UserType } from '@d8d/shared-types';
|
|
|
import { UserEntity, Role } from '@d8d/user-module';
|
|
import { UserEntity, Role } from '@d8d/user-module';
|
|
|
import { File } from '@d8d/file-module';
|
|
import { File } from '@d8d/file-module';
|
|
|
import { DisabledPerson, DisabledBankCard, DisabledPhoto, DisabledRemark, DisabledVisit } from '@d8d/allin-disability-module';
|
|
import { DisabledPerson, DisabledBankCard, DisabledPhoto, DisabledRemark, DisabledVisit } from '@d8d/allin-disability-module';
|
|
@@ -1519,27 +1519,41 @@ describe('订单管理API集成测试', () => {
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- it('应该验证企业ID有效性', async () => {
|
|
|
|
|
|
|
+ it('应该拒绝无企业权限的用户访问 - 史诗012-15安全修复', async () => {
|
|
|
|
|
+ // 创建一个没有companyId的普通用户token
|
|
|
|
|
+ const dataSource = await IntegrationTestDatabase.getDataSource();
|
|
|
|
|
+ const userRepository = dataSource.getRepository(UserEntity);
|
|
|
|
|
+ const normalUser = userRepository.create({
|
|
|
|
|
+ username: `normal_user_${Date.now()}`,
|
|
|
|
|
+ password: 'test_password',
|
|
|
|
|
+ nickname: '普通用户',
|
|
|
|
|
+ userType: UserType.ADMIN,
|
|
|
|
|
+ registrationSource: 'web',
|
|
|
|
|
+ isDisabled: 0,
|
|
|
|
|
+ isDeleted: 0
|
|
|
|
|
+ });
|
|
|
|
|
+ await userRepository.save(normalUser);
|
|
|
|
|
+
|
|
|
|
|
+ const normalToken = JWTUtil.generateToken({
|
|
|
|
|
+ id: normalUser.id,
|
|
|
|
|
+ username: normalUser.username,
|
|
|
|
|
+ roles: [{ name: 'user' }]
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
const response = await enterpriseClient['company-videos'].$get({
|
|
const response = await enterpriseClient['company-videos'].$get({
|
|
|
- query: {
|
|
|
|
|
- companyId: '999999' // 不存在的企业ID
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ query: {}
|
|
|
}, {
|
|
}, {
|
|
|
headers: {
|
|
headers: {
|
|
|
- 'Authorization': `Bearer ${testToken}`
|
|
|
|
|
|
|
+ 'Authorization': `Bearer ${normalToken}`
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- // 注意:API可能会返回空列表而不是错误
|
|
|
|
|
- // 根据实际实现,可能返回200且空列表,或返回404
|
|
|
|
|
- // 这里我们假设返回200且空列表
|
|
|
|
|
- expect(response.status).toBe(200);
|
|
|
|
|
|
|
+ // 应该返回403,因为用户没有企业权限
|
|
|
|
|
+ expect(response.status).toBe(403);
|
|
|
|
|
|
|
|
- if (response.status === 200) {
|
|
|
|
|
- const data = await response.json();
|
|
|
|
|
- expect(data.data).toHaveLength(0);
|
|
|
|
|
- expect(data.total).toBe(0);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ const error = await response.json();
|
|
|
|
|
+ expect(error).toHaveProperty('message');
|
|
|
|
|
+ expect(error.message).toMatch(/enterprise/i);
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
|
|
|
|
@@ -1657,10 +1671,29 @@ describe('订单管理API集成测试', () => {
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- it('应该处理没有符合条件的视频文件', async () => {
|
|
|
|
|
|
|
+ it('应该拒绝无企业权限的用户批量下载 - 史诗012-15安全修复', async () => {
|
|
|
|
|
+ // 创建一个没有companyId的普通用户token
|
|
|
|
|
+ const dataSource = await IntegrationTestDatabase.getDataSource();
|
|
|
|
|
+ const userRepository = dataSource.getRepository(UserEntity);
|
|
|
|
|
+ const normalUser = userRepository.create({
|
|
|
|
|
+ username: `normal_user_dl_${Date.now()}`,
|
|
|
|
|
+ password: 'test_password',
|
|
|
|
|
+ nickname: '普通用户',
|
|
|
|
|
+ userType: UserType.ADMIN,
|
|
|
|
|
+ registrationSource: 'web',
|
|
|
|
|
+ isDisabled: 0,
|
|
|
|
|
+ isDeleted: 0
|
|
|
|
|
+ });
|
|
|
|
|
+ await userRepository.save(normalUser);
|
|
|
|
|
+
|
|
|
|
|
+ const normalToken = JWTUtil.generateToken({
|
|
|
|
|
+ id: normalUser.id,
|
|
|
|
|
+ username: normalUser.username,
|
|
|
|
|
+ roles: [{ name: 'user' }]
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
const requestData = {
|
|
const requestData = {
|
|
|
downloadScope: DownloadScope.COMPANY,
|
|
downloadScope: DownloadScope.COMPANY,
|
|
|
- companyId: 999999, // 不存在的企业
|
|
|
|
|
assetTypes: [AssetType.CHECKIN_VIDEO]
|
|
assetTypes: [AssetType.CHECKIN_VIDEO]
|
|
|
};
|
|
};
|
|
|
|
|
|
|
@@ -1668,19 +1701,16 @@ describe('订单管理API集成测试', () => {
|
|
|
json: requestData
|
|
json: requestData
|
|
|
}, {
|
|
}, {
|
|
|
headers: {
|
|
headers: {
|
|
|
- 'Authorization': `Bearer ${testToken}`
|
|
|
|
|
|
|
+ 'Authorization': `Bearer ${normalToken}`
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- expect(response.status).toBe(200);
|
|
|
|
|
|
|
+ // 应该返回403,因为用户没有企业权限
|
|
|
|
|
+ expect(response.status).toBe(403);
|
|
|
|
|
|
|
|
- if (response.status === 200) {
|
|
|
|
|
- const data = await response.json();
|
|
|
|
|
- expect(data.success).toBe(true);
|
|
|
|
|
- expect(data.files).toHaveLength(0);
|
|
|
|
|
- expect(data.totalFiles).toBe(0);
|
|
|
|
|
- expect(data.message).toContain('未找到符合条件的视频文件');
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ const error = await response.json();
|
|
|
|
|
+ expect(error).toHaveProperty('message');
|
|
|
|
|
+ expect(error.message).toMatch(/enterprise/i);
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
|
|
|