云
21 小时以前 704265308b1227dbada5a36b2027b588c062ded2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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());
  }
}