# "unable to install test security manager" when using ESTestCase

**URL:** <https://discuss.elastic.co/t/unable-to-install-test-security-manager-when-using-estestcase/150031>\
**Category:** Elasticsearch\
**Created:** [September 26, 2018, 2:36pm UTC](https://discuss.elastic.co/t/unable-to-install-test-security-manager-when-using-estestcase/150031 "2018-09-26T14:36:10Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![uwieuwe4](https://avatars.discourse-cdn.com/v4/letter/u/eb9ed0/32.png) [@uwieuwe4](https://discuss.elastic.co/u/uwieuwe4)\
**Post date:** [September 26, 2018, 2:36pm UTC](https://discuss.elastic.co/t/unable-to-install-test-security-manager-when-using-estestcase/150031/1 "2018-09-26T14:36:10Z")

</div>

I am testing my code using ESTestCase. When running the test I get the following error:

```
java.lang.RuntimeException: unable to install test security manager

	at org.elasticsearch.bootstrap.BootstrapForTesting.<clinit>(BootstrapForTesting.java:168)
	at org.elasticsearch.test.ESTestCase.<clinit>(ESTestCase.java:228)
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Class.java:348)
	at com.carrotsearch.randomizedtesting.RandomizedRunner$2.run(RandomizedRunner.java:620)
Caused by: java.lang.IllegalStateException: codebase property already set: codebase.elasticsearch-secure-sm -> file:/C:/Users/noel.dinger/.m2/repository/org/elasticsearch/elasticsearch-secure-sm/6.4.0/elasticsearch-secure-sm-6.4.0.jar, cannot set to file:/C:/Users/noel.dinger/.m2/repository/org/elasticsearch/elasticsearch-secure-sm/6.4.0/elasticsearch-secure-sm-6.4.0.jar
	at org.elasticsearch.bootstrap.Security.readPolicy(Security.java:234)
	at org.elasticsearch.bootstrap.BootstrapForTesting.<clinit>(BootstrapForTesting.java:143)
Test ignored.
Exception in thread "Thread-1" java.lang.NoClassDefFoundError: Could not initialize class org.elasticsearch.test.ESTestCase
	at java.lang.Thread.run(Thread.java:748)
	Suppressed: java.lang.IllegalStateException: No context information for thread: Thread[id=12, name=Thread-1, state=RUNNABLE, group=TGRP-ElasticsearchStorageBackendTestNew]. Is this thread running under a class com.carrotsearch.randomizedtesting.RandomizedRunner runner context? Add @RunWith(class com.carrotsearch.randomizedtesting.RandomizedRunner.class) to your test class. Make sure your code accesses random contexts within @BeforeClass and @AfterClass boundary (for example, static test class initializers are not permitted to access random contexts).
		at com.carrotsearch.randomizedtesting.RandomizedContext.context(RandomizedContext.java:249)
		at com.carrotsearch.randomizedtesting.RandomizedContext.current(RandomizedContext.java:134)
		at com.carrotsearch.randomizedtesting.RandomizedRunner.augmentStackTrace(RandomizedRunner.java:1872)
		at com.carrotsearch.randomizedtesting.RunnerThreadGroup.uncaughtException(RunnerThreadGroup.java:20)
		at java.lang.Thread.dispatchUncaughtException(Thread.java:1959)

```

Those are my dependencies:

```
  <dependencies>
    <dependency>
        <groupId>org.elasticsearch.client</groupId>
        <artifactId>elasticsearch-rest-high-level-client</artifactId>
        <version>6.4.0</version>
    </dependency>

    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-api</artifactId>
        <version>${org.apache.logging.log4j.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-core</artifactId>
        <version>${org.apache.logging.log4j.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-slf4j-impl</artifactId>
        <version>${org.apache.logging.log4j.version}</version>
    </dependency>
    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <version>${org.projectlombok.version}</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
        <version>2.6.2</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <version>2.9.6</version>
    </dependency>
        <dependency>
            <groupId>org.apache.lucene</groupId>
            <artifactId>lucene-test-framework</artifactId>
            <version>7.4.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.elasticsearch.test</groupId>
            <artifactId>framework</artifactId>
            <version>6.4.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>21.0</version>
        </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.11</version>
        <scope>test</scope>
        <exclusions>
            <exclusion>
                <artifactId>hamcrest-core</artifactId>
                <groupId>org.hamcrest</groupId>
            </exclusion>
        </exclusions>
    </dependency>
</dependencies>
```

---

<div class="post-metadata">

**Author:** ![rjernst](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rjernst/32/6363_2.png) [@rjernst](https://discuss.elastic.co/u/rjernst)\
**Post date:** [September 26, 2018, 10:10pm UTC](https://discuss.elastic.co/t/unable-to-install-test-security-manager-when-using-estestcase/150031/2 "2018-09-26T22:10:51Z")

</div>

How are you running the test? A similar problem was fixed recently: [https://github.com/elastic/elasticsearch/issues/33045](https://github.com/elastic/elasticsearch/issues/33045)

---

<div class="post-metadata">

**Author:** ![uwieuwe4](https://avatars.discourse-cdn.com/v4/letter/u/eb9ed0/32.png) [@uwieuwe4](https://discuss.elastic.co/u/uwieuwe4)\
**Post date:** [September 27, 2018, 7:25am UTC](https://discuss.elastic.co/t/unable-to-install-test-security-manager-when-using-estestcase/150031/3 "2018-09-27T07:25:16Z")

</div>

Thanks for your answer. I dont really get what was done in this github post. Which file did he edit?  
I use junit in IntelliJ IDEA and for running it I use right Click "Run ...".

```
import org.elasticsearch.client.Client;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.node.Node;
import org.elasticsearch.test.ESIntegTestCase;
import org.elasticsearch.test.ESTestCase;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.io.Files;
import java.io.File;
import java.io.IOException;
import java.util.Optional;
import java.util.UUID;

    public class ElasticsearchStorageBackendTestNew extends ESTestCase {

        private static String index = "clusters";
        private static String docType = "elasticsearch";
        IndexResponse indexResponse;
        private DatabaseCustomerClusterConfig config;
        ElasticsearchStorageBackend elasticsearchStorageBackend;
        DatabaseEceClusterConfig databaseEceClusterConfig;
        String clusterId;
        private static final Logger logger = LoggerFactory.getLogger(ElasticsearchStorageBackendTestNew.class);

        private ElasticsearchStorageBackend createBackend() {
            elasticsearchStorageBackend = new ElasticsearchStorageBackend("localhost", "9200", "...", "user", "pw", "http");
            return elasticsearchStorageBackend;
        }

        private DatabaseCustomerClusterConfig createClusterConfigValid() {
            UUID clusterID = UUID.randomUUID();
            config = new DatabaseCustomerClusterConfig("d.fiedler@example.com", 5, databaseEceClusterConfig, clusterId, "mySecondCluster", "kibanaid123");
            return config;
        }

        private DatabaseEceClusterConfig createEceConfig(){
            databaseEceClusterConfig = new DatabaseEceClusterConfig("DEV", 1000, 3, 1, "1.0", 1000, 2, 1, "1.11" );
            return databaseEceClusterConfig;
        }

        @Test
        public void testCreateCustomerClusterConfigEntryValid() {
            config = createClusterConfigValid();
            elasticsearchStorageBackend.createCustomerClusterConfigEntry(config, index);
        }
```

---

<div class="post-metadata">

**Author:** ![rjernst](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rjernst/32/6363_2.png) [@rjernst](https://discuss.elastic.co/u/rjernst)\
**Post date:** [September 29, 2018, 8:54pm UTC](https://discuss.elastic.co/t/unable-to-install-test-security-manager-when-using-estestcase/150031/4 "2018-09-29T20:54:50Z")

</div>

There is no edit to make. This will be fixed in 6.5.0. See this PR: [https://github.com/elastic/elasticsearch/pull/33066](https://github.com/elastic/elasticsearch/pull/33066)

---

<div class="post-metadata">

**Author:** ![paulkeogh](https://avatars.discourse-cdn.com/v4/letter/p/8dc957/32.png) [@paulkeogh](https://discuss.elastic.co/u/paulkeogh)\
**Post date:** [October 15, 2018, 2:16pm UTC](https://discuss.elastic.co/t/unable-to-install-test-security-manager-when-using-estestcase/150031/5 "2018-10-15T14:16:44Z")

</div>

Is there any known workaround for 6.4.2 ?

Seeing the same thing in Red Hat JBoss Developer Studio Version: 11.3.0.GA.

---

<div class="post-metadata">

**Author:** ![rjernst](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rjernst/32/6363_2.png) [@rjernst](https://discuss.elastic.co/u/rjernst)\
**Post date:** [October 15, 2018, 4:11pm UTC](https://discuss.elastic.co/t/unable-to-install-test-security-manager-when-using-estestcase/150031/7 "2018-10-15T16:11:56Z")

</div>

Sorry @paulkeogh I don't know of any workarounds for 6.4.x.

---

<div class="post-metadata">

**Author:** ![Sven\_Woltmann](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sven_woltmann/32/21380_2.png) [@Sven\_Woltmann](https://discuss.elastic.co/u/Sven_Woltmann)\
**Post date:** [November 5, 2018, 8:36pm UTC](https://discuss.elastic.co/t/unable-to-install-test-security-manager-when-using-estestcase/150031/8 "2018-11-05T20:36:52Z")

</div>

@uwieuwe4, @paulkeogh:  
A workaround is to disable the security manager during test by adding the following VM option

```auto
 -Dtests.security.manager=false

```

When running your tests with Maven, you can add the following to your pom.xml:

```auto
<build>
	<pluginManagement>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-surefire-plugin</artifactId>
				<configuration>
					<!-- for disabling security manager in tests -->
					<systemPropertyVariables>
						<tests.security.manager>false</tests.security.manager>
					</systemPropertyVariables>
				</configuration>
			</plugin>
		</plugins>
	</pluginManagement>
</build>

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [December 3, 2018, 8:37pm UTC](https://discuss.elastic.co/t/unable-to-install-test-security-manager-when-using-estestcase/150031/9 "2018-12-03T20:37:01Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
