All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.opencms.ugc.TestFormSessionSecurityLimits Maven / Gradle / Ivy

Go to download

OpenCms is an enterprise-ready, easy to use website content management system based on Java and XML technology. Offering a complete set of features, OpenCms helps content managers worldwide to create and maintain beautiful websites fast and efficiently.

There is a newer version: 18.0
Show newest version
/*
 * This library is part of OpenCms -
 * the Open Source Content Management System
 *
 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * For further information about Alkacon Software, please see the
 * company website: http://www.alkacon.com
 *
 * For further information about OpenCms, please see the
 * project website: http://www.opencms.org
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package org.opencms.ugc;

import org.opencms.file.CmsGroup;
import org.opencms.file.CmsObject;
import org.opencms.file.CmsResource;
import org.opencms.file.CmsUser;
import org.opencms.test.OpenCmsTestCase;
import org.opencms.test.OpenCmsTestProperties;
import org.opencms.ugc.shared.CmsUgcException;
import org.opencms.util.CmsUUID;

import java.util.Arrays;
import java.util.List;
import java.util.Locale;

import com.google.common.base.Optional;

import junit.framework.Test;

/**
 * Test cases for the org.opencms.editors.usergenerated package.
 */
public class TestFormSessionSecurityLimits extends OpenCmsTestCase {

    /**
     * Creates a new test instance.
     *
     * @return the test suite
     */
    public static Test suite() {

        OpenCmsTestProperties.initialize(org.opencms.test.AllTests.TEST_PROPERTIES_PATH);
        return generateSetupTestWrapper(TestFormSessionSecurityLimits.class, "systemtest", "/");
    }

    /**
     * Tests that an error occurs when trying to upload without a configured upload folder.

* * @throws Exception - */ public void testErrorNoUploadsAllowed() throws Exception { CmsObject cms = getCmsObject(); CmsUser admin = cms.readUser("Admin"); CmsResource rootFolder = cms.readResource("/"); CmsGroup administrators = cms.readGroup("Administrators"); CmsUgcConfiguration config = new CmsUgcConfiguration( new CmsUUID(), Optional.of(admin), administrators, "plain", rootFolder, "n_%(number)", Locale.ENGLISH, Optional. absent(), Optional. absent(), Optional.of(Integer.valueOf(100)), Optional. absent(), Optional. absent(), false, Optional.of(Arrays.asList(".jpg", ".PNG"))); try { CmsUgcSessionSecurityUtil.checkCreateUpload(cms, config, "foo.png", 100L); fail("Exception should have been thrown!"); } catch (CmsUgcException e) { // empty } } /** * Tests that errors are thrown when the configured upload / content limits in the configuration are violated.

* * @throws Exception - */ public void testLimits() throws Exception { CmsObject cms = getCmsObject(); CmsUser admin = cms.readUser("Admin"); CmsResource uploadFolder = cms.createResource("/uploads", 0); CmsResource rootFolder = cms.readResource("/"); CmsGroup administrators = cms.readGroup("Administrators"); CmsUgcConfiguration config = new CmsUgcConfiguration( new CmsUUID(), Optional.of(admin), administrators, "plain", rootFolder, "n_%(number)", Locale.ENGLISH, Optional.of(uploadFolder), Optional.of(Long.valueOf(10000)), Optional.of(Integer.valueOf(0)), Optional. absent(), Optional. absent(), false, Optional.of(Arrays.asList(".jpg", ".PNG"))); try { CmsUgcSessionSecurityUtil.checkCreateUpload(cms, config, "foo.png", 50000); fail("Exception should have been thrown!"); } catch (CmsUgcException e) { // empty } try { CmsUgcSessionSecurityUtil.checkCreateUpload(cms, config, "foo.png", 3); } catch (CmsUgcException e) { fail("Exception was thrown: " + e.getLocalizedMessage()); } try { CmsUgcSessionSecurityUtil.checkCreateUpload(cms, config, "foo.doc", 100L); fail("Exception should have been thrown!"); } catch (CmsUgcException e) { // empty } try { CmsUgcSessionSecurityUtil.checkCreateUpload(cms, config, "foo.JPG", 100L); } catch (CmsUgcException e) { fail("Exceptikon was thrown: " + e.getLocalizedMessage()); } try { CmsUgcSessionSecurityUtil.checkCreateContent(cms, config); fail("Exception should have been thrown!"); } catch (CmsUgcException e) { // empty } config = new CmsUgcConfiguration( new CmsUUID(), Optional.of(admin), administrators, "plain", rootFolder, "n_%(number)", Locale.ENGLISH, Optional.of(uploadFolder), Optional. absent(), Optional.of(Integer.valueOf(100)), Optional. absent(), Optional. absent(), false, Optional.of(Arrays.asList(".jpg", ".PNG"))); try { CmsUgcSessionSecurityUtil.checkCreateContent(cms, config); } catch (CmsUgcException e) { fail("Exception was thrown: " + e.getLocalizedMessage()); } } /** * Tests that errors are not thrown if no limits are configured in the form configuration.

* * @throws Exception - */ public void testNoLimits() throws Exception { CmsObject cms = getCmsObject(); CmsUser admin = cms.readUser("Admin"); CmsResource uploadFolder = cms.createResource("/uploads2", 0); CmsResource rootFolder = cms.readResource("/"); CmsGroup administrators = cms.readGroup("Administrators"); CmsUgcConfiguration config = new CmsUgcConfiguration( new CmsUUID(), Optional.of(admin), administrators, "plain", rootFolder, "n_%(number)", Locale.ENGLISH, Optional.of(uploadFolder), Optional. absent(), Optional. absent(), Optional. absent(), Optional. absent(), false, Optional.> absent()); try { CmsUgcSessionSecurityUtil.checkCreateUpload(cms, config, "foo.aasdfasdfasdf", 99999999L); } catch (CmsUgcException e) { fail("Exception was thrown: " + e); } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy