Exemplo n.º 1
0
  @Test
  public void request_content_image_with_no_access() throws Exception {
    byte[] bytes = loadImage("Arn.JPG");
    ContentKey contentKey =
        createImageContent(
            "MyImage.jpg", 2, bytes, "ImageCategory", new DateTime(2011, 6, 27, 10, 0, 0, 0), null);

    fixture.createAndStoreUserAndUserGroup(
        "user-with-no-access", "testuser fullname", UserType.NORMAL, "testuserstore");
    loginUserInPortal(fixture.findUserByName("user-with-no-access").getKey());

    String imageRequestPath = "_image/" + contentKey + ".jpg";
    setPathInfoAndRequestURI(httpServletRequest, imageRequestPath);
    httpServletRequest.setParameter("_background", "0xffffff");
    httpServletRequest.setParameter("_quality", "100");
    try {
      imageController.handleRequestInternal(httpServletRequest, httpServletResponse);
      fail("Expected exception");
    } catch (Exception e) {
      assertTrue(e instanceof ImageRequestException);
      ImageRequestException imageRequestException = (ImageRequestException) e;
      assertTrue(
          imageRequestException
              .getMessage()
              .contains("Resource '/_image/" + contentKey + ".jpg' not found"));
    }
  }
Exemplo n.º 2
0
  @Before
  public void before() {
    fixture = new DomainFixture(hibernateTemplate);
    factory = new DomainFactory(fixture);

    fixture.initSystemData();
    fixture.createAndStoreUserAndUserGroup(
        "testuser", "testuser fullname", UserType.NORMAL, "testuserstore");

    httpServletRequest.setCharacterEncoding("UTF-8");
    ServletRequestAccessor.setRequest(httpServletRequest);
    loginUserInPortal(fixture.findUserByName("testuser").getKey());

    previewService = Mockito.mock(PreviewService.class);
    Mockito.when(previewService.isInPreview()).thenReturn(false);
    Mockito.when(previewService.getPreviewContext()).thenReturn(PreviewContext.NO_PREVIEW);
    imageController.setPreviewService(previewService);

    MockTimeService timeService = new MockTimeService(new DateTime(2011, 6, 27, 12, 0, 0, 0));
    imageController.setTimeService(timeService);

    site1 = factory.createSite("MySite", new Date(), null, "en");
    fixture.save(site1);
    MenuItemEntity firstPage = createPage("Firstpage", null, "MySite");
    fixture.save(firstPage);

    site1.setFirstPage(firstPage);

    fixture.flushAndClearHibernateSesssion();

    fixture.save(
        factory.createContentHandler(
            "Image content", ContentHandlerName.IMAGE.getHandlerClassShortName()));
    fixture.save(
        factory.createContentType(
            "ImageContentType", ContentHandlerName.IMAGE.getHandlerClassShortName()));
    fixture.save(factory.createUnit("ImageUnit"));
    fixture.save(
        factory.createCategory(
            "ImageCategory", "ImageContentType", "ImageUnit", "testuser", "testuser"));
    fixture.save(
        factory.createCategoryAccessForUser("ImageCategory", "testuser", "read, create, approve"));

    fixture.flushAndClearHibernateSesssion();
  }