Search in sources :

Example 6 with SecurityManagerSetup

use of org.apache.derbyTesting.junit.SecurityManagerSetup in project derby by apache.

the class SystemPrivilegesPermissionTest method suite.

/**
 * Return a suite with all tests in this class (default suite)
 */
public static Test suite() {
    // this suite cannot be constructed with automatic test extraction
    // (by passing a class argument); instead, the tests need to be added
    // manually since some of them require their own policy file
    BaseTestSuite suite = new BaseTestSuite("SystemPrivilegesPermissionTest");
    // add API tests for the basic security framework classes
    suite.addTest(new SystemPrivilegesPermissionTest("testSystemPrincipal"));
    suite.addTest(new SystemPrivilegesPermissionTest("testSystemPermission"));
    suite.addTest(new SystemPrivilegesPermissionTest("testSystemPermissionCollections"));
    // the DatabasePermission test attempts to canonicalize various
    // directory path names and requires an all-files-read-permission,
    // which is not granted by default derby_tests.policy
    suite.addTest(new SecurityManagerSetup(new SystemPrivilegesPermissionTest("testDatabasePermission"), POLICY_FILE_NAME1));
    // on all JVM platforms
    if (SecurityManagerSetup.JVM_HAS_SUBJECT_AUTHORIZATION) {
        suite.addTest(new SecurityManagerSetup(new SystemPrivilegesPermissionTest("policyTestSystemPermissionGrants"), POLICY_FILE_NAME));
        suite.addTest(new SecurityManagerSetup(new SystemPrivilegesPermissionTest("policyTestDatabasePermissionGrants"), POLICY_FILE_NAME));
    }
    // Only run this test on Java 8.
    if (isJava8()) {
        suite.addTest(SecurityManagerSetup.noSecurityManager(new SystemPrivilegesPermissionTest("testSerialization")));
    }
    return suite;
}
Also used : BaseTestSuite(org.apache.derbyTesting.junit.BaseTestSuite) SecurityManagerSetup(org.apache.derbyTesting.junit.SecurityManagerSetup)

Example 7 with SecurityManagerSetup

use of org.apache.derbyTesting.junit.SecurityManagerSetup in project derby by apache.

the class ProtocolTest method suite.

/**
 * Creates a suite of tests dynamically from a file describing protocol
 * tests.
 *
 * @return A suite of tests.
 * @throws Exception if creating the suite fails for some reason
 */
public static Test suite() throws Exception {
    BaseTestSuite suite = new BaseTestSuite("Derby DRDA protocol tests");
    // Process the list of files and create test cases for the sub-tests.
    // NOTE: We cannot assume anything about the order in which the tests
    // are executed.
    final String testFile = PREFIX + "protocol.tests";
    final URL testFileURL = BaseTestCase.getTestResource(testFile);
    BufferedReader bIn = new BufferedReader(new InputStreamReader(openTestResource(testFileURL), Charset.forName("UTF-8")));
    // Split the tests into individual tests.
    final String END_TEST = ProtocolTestGrammar.END_TEST.toCmdString();
    int currentLine = 1;
    // First line is line number one.
    int startLine = 1;
    ArrayList<String> cmdLines = new ArrayList<String>();
    StringBuilder str = new StringBuilder();
    String line;
    // Iterate until the end of test token is reached.
    while ((line = bIn.readLine()) != null) {
        cmdLines.add(line);
        str.append(line).append(NL);
        if (line.toLowerCase(Locale.ENGLISH).startsWith(END_TEST)) {
            // Create a new test case.
            suite.addTest(new ProtocolTest("protocol.tests", str.toString(), startLine, currentLine - startLine));
            cmdLines.clear();
            str.setLength(0);
            startLine = currentLine + 1;
        }
        currentLine++;
    }
    bIn.close();
    // Install a security policy and copy the required include files.
    final String resourcePath = "functionTests/tests/derbynet";
    return new SecurityManagerSetup(TestConfiguration.clientServerDecorator(new SupportFilesSetup(suite, new String[] { resourcePath + "/connect.inc", resourcePath + "/excsat_accsecrd1.inc", resourcePath + "/excsat_accsecrd2.inc", resourcePath + "/excsat_accsecrd_nordb.inc", resourcePath + "/excsat_secchk_nordbonaccsec.inc", resourcePath + "/excsat_secchk.inc", resourcePath + "/values1.inc", resourcePath + "/values64kblksz.inc" })), PREFIX + "ProtocolTest.policy", true);
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) ArrayList(java.util.ArrayList) BaseTestSuite(org.apache.derbyTesting.junit.BaseTestSuite) SecurityManagerSetup(org.apache.derbyTesting.junit.SecurityManagerSetup) SupportFilesSetup(org.apache.derbyTesting.junit.SupportFilesSetup) URL(java.net.URL)

Example 8 with SecurityManagerSetup

use of org.apache.derbyTesting.junit.SecurityManagerSetup in project derby by apache.

the class GetCurrentPropertiesTest method suite.

public static Test suite() {
    Test test = new BaseTestSuite(GetCurrentPropertiesTest.class);
    test = TestConfiguration.clientServerDecorator(test);
    // Install a security manager using the special policy file.
    // Grant ALL FILES execute, and getPolicy permissions,
    // as well as write for the trace files.
    test = new SecurityManagerSetup(test, POLICY_FILE_NAME);
    // properties, wrap in singleUseDatabaseDecorator
    return TestConfiguration.singleUseDatabaseDecorator(test);
}
Also used : Test(junit.framework.Test) BaseTestSuite(org.apache.derbyTesting.junit.BaseTestSuite) SecurityManagerSetup(org.apache.derbyTesting.junit.SecurityManagerSetup)

Example 9 with SecurityManagerSetup

use of org.apache.derbyTesting.junit.SecurityManagerSetup in project derby by apache.

the class Derby5582AutomaticIndexStatisticsTest method suite.

public static Test suite() {
    // Run just the one fixture with the custom SecurityManager
    Test t = new Derby5582AutomaticIndexStatisticsTest("testDerby5582");
    Derby5582SecurityManager sm = new Derby5582SecurityManager();
    return TestConfiguration.additionalDatabaseDecorator(new SecurityManagerSetup(t, null, sm), MASTERDB);
}
Also used : Test(junit.framework.Test) SecurityManagerSetup(org.apache.derbyTesting.junit.SecurityManagerSetup)

Example 10 with SecurityManagerSetup

use of org.apache.derbyTesting.junit.SecurityManagerSetup in project derby by apache.

the class CacheManagerMBeanTest method suite.

public static Test suite() {
    BaseTestSuite suite = new BaseTestSuite();
    suite.addTest(MBeanTest.suite(CacheManagerMBeanTest.class, "CacheManagerMBeanTest"));
    // files, so skip these test cases when running from classes.
    if (TestConfiguration.loadingFromJars()) {
        Test negative = new CacheManagerMBeanTest("withoutPermsTest");
        negative = JMXConnectionDecorator.platformMBeanServer(negative);
        negative = new SecurityManagerSetup(negative, "org/apache/derbyTesting/functionTests/tests/management/" + "CacheManagerMBeanTest.withoutPerm.policy");
        suite.addTest(negative);
        Test positive = new CacheManagerMBeanTest("withPermsTest");
        positive = JMXConnectionDecorator.platformMBeanServer(positive);
        positive = new SecurityManagerSetup(positive, "org/apache/derbyTesting/functionTests/tests/management/" + "CacheManagerMBeanTest.withPerm.policy");
        suite.addTest(positive);
    }
    return suite;
}
Also used : Test(junit.framework.Test) BaseTestSuite(org.apache.derbyTesting.junit.BaseTestSuite) SecurityManagerSetup(org.apache.derbyTesting.junit.SecurityManagerSetup)

Aggregations

SecurityManagerSetup (org.apache.derbyTesting.junit.SecurityManagerSetup)20 Test (junit.framework.Test)13 BaseTestSuite (org.apache.derbyTesting.junit.BaseTestSuite)13 SupportFilesSetup (org.apache.derbyTesting.junit.SupportFilesSetup)4 Properties (java.util.Properties)2 LocaleTestSetup (org.apache.derbyTesting.junit.LocaleTestSetup)2 SystemPropertyTestSetup (org.apache.derbyTesting.junit.SystemPropertyTestSetup)2 BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)1 URL (java.net.URL)1 PreparedStatement (java.sql.PreparedStatement)1 Statement (java.sql.Statement)1 ArrayList (java.util.ArrayList)1 Locale (java.util.Locale)1 ClassLoaderTestSetup (org.apache.derbyTesting.junit.ClassLoaderTestSetup)1 CleanDatabaseTestSetup (org.apache.derbyTesting.junit.CleanDatabaseTestSetup)1 ServerSetup (org.apache.derbyTesting.junit.ServerSetup)1 TestConfiguration (org.apache.derbyTesting.junit.TestConfiguration)1