| | |
| | | import com.ruoyi.account.api.vo.AppUserWhitelistImportResultVO; |
| | | import com.ruoyi.account.api.vo.AppUserWhitelistMatchVO; |
| | | import com.ruoyi.account.mapper.TAppUserWhitelistMapper; |
| | | import com.ruoyi.account.service.PartnerAppUserAccessService; |
| | | import com.ruoyi.account.service.TAppUserService; |
| | | import com.ruoyi.account.service.TAppUserWhitelistSiteService; |
| | | import com.ruoyi.account.service.TCompanyAllocateRecordService; |
| | |
| | | import static org.mockito.ArgumentMatchers.eq; |
| | | import static org.mockito.ArgumentMatchers.isNull; |
| | | import static org.mockito.Mockito.doAnswer; |
| | | import static org.mockito.Mockito.doThrow; |
| | | import static org.mockito.Mockito.lenient; |
| | | import static org.mockito.Mockito.mock; |
| | | import static org.mockito.Mockito.never; |
| | |
| | | @Mock private GroupCompanyClient groupCompanyClient; |
| | | @Mock private RedissonClient redissonClient; |
| | | @Mock private TCompanyAllocateRecordService companyAllocateRecordService; |
| | | @Mock private PartnerAppUserAccessService partnerAppUserAccessService; |
| | | |
| | | private TAppUserWhitelistServiceImpl service; |
| | | |
| | |
| | | ReflectionTestUtils.setField(service, "groupCompanyClient", groupCompanyClient); |
| | | ReflectionTestUtils.setField(service, "redissonClient", redissonClient); |
| | | ReflectionTestUtils.setField(service, "companyAllocateRecordService", companyAllocateRecordService); |
| | | ReflectionTestUtils.setField(service, "partnerAppUserAccessService", partnerAppUserAccessService); |
| | | // 默认透传(模拟非公司账号),公司账号隔离场景由具体用例覆盖打桩 |
| | | lenient().when(partnerAppUserAccessService.resolveCompanyFilter(any())).thenAnswer(invocation -> invocation.getArgument(0)); |
| | | lenient().when(partnerAppUserAccessService.getCurrentCompanyId()).thenReturn(null); |
| | | RLock lock = mock(RLock.class); |
| | | // 并发锁仅在额度相关场景使用,宽松桩避免严格模式下未使用即报错 |
| | | lenient().when(redissonClient.getLock(any())).thenReturn(lock); |
| | |
| | | row.createCell(1).setCellValue(benefitType); |
| | | row.createCell(2).setCellValue(whitelistSite); |
| | | } |
| | | |
| | | // ==================== 公司账号数据隔离 ==================== |
| | | |
| | | @Test |
| | | void getAllocateOverviewForcesCompanyFilterForCompanyAccount() { |
| | | // 公司账号:额度概览的公司参数被强制覆盖为本公司 |
| | | when(partnerAppUserAccessService.resolveCompanyFilter(9)).thenReturn(2); |
| | | TGroupCompany company = new TGroupCompany(); |
| | | company.setId(2); |
| | | company.setName("本公司"); |
| | | company.setAccountMode(2); |
| | | company.setAvailableBalance(new BigDecimal("100.00")); |
| | | when(groupCompanyClient.getCompanyById(2)).thenReturn(R.ok(company)); |
| | | |
| | | AppUserWhitelistAllocateVO vo = service.getAllocateOverview(9); |
| | | |
| | | assertEquals(Integer.valueOf(2), vo.getCompanyId()); |
| | | verify(groupCompanyClient).getCompanyById(2); |
| | | } |
| | | |
| | | @Test |
| | | void updateStatusRejectsCrossCompanyRecord() { |
| | | // 公司账号:启停其他公司的白名单被越权校验拦截 |
| | | TAppUserWhitelist existing = new TAppUserWhitelist(); |
| | | existing.setId(1L); |
| | | existing.setStatus(1); |
| | | existing.setCompanyId(9); |
| | | when(mapper.selectById(1L)).thenReturn(existing); |
| | | doThrow(new ServiceException("无权操作其他公司的数据")).when(partnerAppUserAccessService).assertCompanyVisible(9); |
| | | AppUserWhitelistStatusDTO dto = new AppUserWhitelistStatusDTO(); |
| | | dto.setId(1L); |
| | | dto.setStatus(2); |
| | | |
| | | ServiceException exception = assertThrows(ServiceException.class, () -> service.updateStatus(dto)); |
| | | |
| | | assertEquals("无权操作其他公司的数据", exception.getMessage()); |
| | | verify(mapper, never()).update(isNull(), any(Wrapper.class)); |
| | | } |
| | | } |