package cn.iocoder.yudao.module.mes.controller.admin.pro.scan; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.security.core.LoginUser; import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils; import cn.iocoder.yudao.module.mes.controller.admin.pro.scan.vo.MesProScanEventPageReqVO; import cn.iocoder.yudao.module.mes.dal.dataobject.pro.scan.MesProScanEventDO; import cn.iocoder.yudao.module.mes.service.pro.scan.MesProScanEventService; import org.junit.jupiter.api.*; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.test.util.ReflectionTestUtils; import java.util.List; import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.*; class MobileScanAccessTest { private final MesProScanEventService service=mock(MesProScanEventService.class); private final MesProScanEventController controller=new MesProScanEventController(); @BeforeEach void setup(){ SecurityFrameworkUtils.setLoginUser(new LoginUser().setId(7L),new org.springframework.mock.web.MockHttpServletRequest()); ReflectionTestUtils.setField(controller,"service",service); } @AfterEach void cleanup(){SecurityContextHolder.clearContext();} @Test void overridesForgedCreatorOnOwnPage(){ MesProScanEventPageReqVO req=new MesProScanEventPageReqVO();req.setCreator("8"); when(service.getPage(req)).thenReturn(new PageResult<>(List.of(),0L)); controller.myPage(req); assertEquals("7",req.getCreator());verify(service).getPage(req); } @Test void doesNotExposeAnotherUsersEvent(){ MesProScanEventDO event=new MesProScanEventDO();event.setCreator("8"); when(service.getByEventId("other")).thenReturn(event); assertNull(controller.myEvent("other").getData()); event.setCreator("7");event.setEventId("other"); assertEquals("other",controller.myEvent("other").getData().getEventId()); } }