Skip to content

Commit 9f7e49c

Browse files
authored
Enhance orientdb module (#5974)
Starting with 3.2.x images, users are not created by default because of security reasons. Read more [here](https://orientdb.org/docs/3.2.x/release/3.2/Upgrading-to-OrientDB-3.2.html)
1 parent e013a65 commit 9f7e49c

File tree

4 files changed

+167
-8
lines changed

4 files changed

+167
-8
lines changed

modules/orientdb/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ description = "TestContainers :: Orientdb"
33
dependencies {
44
api project(":testcontainers")
55

6-
api "com.orientechnologies:orientdb-client:3.0.24"
6+
api "com.orientechnologies:orientdb-client:3.2.0"
77

88
testImplementation 'org.assertj:assertj-core:3.23.1'
9-
testImplementation 'org.apache.tinkerpop:gremlin-driver:3.3.4'
10-
testImplementation "com.orientechnologies:orientdb-gremlin:3.0.18"
9+
testImplementation 'org.apache.tinkerpop:gremlin-driver:3.6.1'
10+
testImplementation "com.orientechnologies:orientdb-gremlin:3.2.0"
1111
}

modules/orientdb/src/main/java/org/testcontainers/containers/OrientDBContainer.java

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@
1010
import org.slf4j.Logger;
1111
import org.slf4j.LoggerFactory;
1212
import org.testcontainers.containers.wait.strategy.LogMessageWaitStrategy;
13+
import org.testcontainers.utility.ComparableVersion;
1314
import org.testcontainers.utility.DockerImageName;
1415

1516
import java.io.IOException;
1617
import java.net.URL;
1718
import java.nio.charset.StandardCharsets;
19+
import java.util.Arrays;
1820
import java.util.Optional;
1921

2022
/**
@@ -69,7 +71,7 @@ public OrientDBContainer(final DockerImageName dockerImageName) {
6971
serverPassword = DEFAULT_SERVER_PASSWORD;
7072
databaseName = DEFAULT_DATABASE_NAME;
7173

72-
waitStrategy = new LogMessageWaitStrategy().withRegEx(".*Gremlin started correctly.*");
74+
waitStrategy = new LogMessageWaitStrategy().withRegEx(".*OrientDB Studio available.*");
7375

7476
addExposedPorts(DEFAULT_BINARY_PORT, DEFAULT_HTTP_PORT);
7577
}
@@ -107,6 +109,7 @@ protected void containerIsStarted(InspectContainerResponse containerInfo) {
107109
orientDB = new OrientDB(getServerUrl(), "root", serverPassword, OrientDBConfig.defaultConfig());
108110
}
109111

112+
@Deprecated
110113
public OrientDB getOrientDB() {
111114
return orientDB;
112115
}
@@ -119,13 +122,33 @@ public String getDbUrl() {
119122
return getServerUrl() + "/" + databaseName;
120123
}
121124

125+
@Deprecated
122126
public ODatabaseSession getSession() {
123127
return getSession(DEFAULT_USERNAME, DEFAULT_PASSWORD);
124128
}
125129

130+
@Deprecated
126131
public synchronized ODatabaseSession getSession(String username, String password) {
127-
orientDB.createIfNotExists(databaseName, ODatabaseType.PLOCAL);
128-
132+
String orientdbVersion = Arrays
133+
.stream(this.getContainerInfo().getConfig().getEnv())
134+
.filter(env -> env.startsWith("ORIENTDB_VERSION"))
135+
.map(env -> env.split("=")[1])
136+
.findFirst()
137+
.orElseThrow(() -> new IllegalStateException("no required env var"));
138+
boolean isGreaterThan32 = new ComparableVersion(orientdbVersion).isGreaterThanOrEqualTo("3.2.0");
139+
if (isGreaterThan32) {
140+
String script = String.format(
141+
"CREATE DATABASE %s plocal users(%s identified by '%s' role admin)",
142+
databaseName,
143+
username,
144+
password
145+
);
146+
if (!orientDB.exists(databaseName)) {
147+
orientDB.execute(script);
148+
}
149+
} else {
150+
orientDB.createIfNotExists(databaseName, ODatabaseType.PLOCAL);
151+
}
129152
if (session == null) {
130153
session = orientDB.open(databaseName, username, password);
131154

@@ -134,6 +157,7 @@ public synchronized ODatabaseSession getSession(String username, String password
134157
return session;
135158
}
136159

160+
@Deprecated
137161
private void loadScript(String path, ODatabaseSession session) {
138162
try {
139163
URL resource = getClass().getClassLoader().getResource(path);

modules/orientdb/src/test/java/org/testcontainers/containers/OrientDBContainerTest.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.orientechnologies.orient.core.db.ODatabaseSession;
44
import org.junit.Test;
55
import org.testcontainers.utility.DockerImageName;
6+
import org.testcontainers.utility.MountableFile;
67

78
import static org.assertj.core.api.Assertions.assertThat;
89

@@ -11,7 +12,7 @@
1112
*/
1213
public class OrientDBContainerTest {
1314

14-
private static final DockerImageName ORIENTDB_IMAGE = DockerImageName.parse("orientdb:3.0.24-tp3");
15+
private static final DockerImageName ORIENTDB_IMAGE = DockerImageName.parse("orientdb:3.2.0-tp3");
1516

1617
@Test
1718
public void shouldReturnTheSameSession() {
@@ -42,7 +43,13 @@ public void shouldInitializeWithCommands() {
4243

4344
@Test
4445
public void shouldQueryWithGremlin() {
45-
try (OrientDBContainer container = new OrientDBContainer(ORIENTDB_IMAGE)) {
46+
try (
47+
OrientDBContainer container = new OrientDBContainer(ORIENTDB_IMAGE)
48+
.withCopyFileToContainer(
49+
MountableFile.forClasspathResource("orientdb-server-config.xml"),
50+
"/orientdb/config/orientdb-server-config.xml"
51+
)
52+
) {
4653
container.start();
4754

4855
final ODatabaseSession session = container.getSession("admin", "admin");
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
<orient-server>
2+
<handlers>
3+
<!-- DISABLED-->
4+
<!--<handler class="com.orientechnologies.orient.graph.handler.OGraphServerHandler">-->
5+
<!--<parameters>-->
6+
<!--<parameter name="enabled" value="true"/>-->
7+
<!--<parameter name="graph.pool.max" value="50"/>-->
8+
<!--</parameters>-->
9+
<!--</handler>-->
10+
<!-- CLUSTER PLUGIN, TO TURN ON SET THE 'ENABLED' PARAMETER TO 'true' -->
11+
<handler class="com.orientechnologies.orient.server.hazelcast.OHazelcastPlugin">
12+
<parameters>
13+
<!-- <parameter name="nodeName" value="europe1" /> -->
14+
<parameter name="enabled" value="${distributed}"/>
15+
<parameter name="configuration.db.default"
16+
value="${ORIENTDB_HOME}/config/default-distributed-db-config.json"/>
17+
<parameter name="configuration.hazelcast" value="${ORIENTDB_HOME}/config/hazelcast.xml"/>
18+
</parameters>
19+
</handler>
20+
<!-- JMX SERVER, TO TURN ON SET THE 'ENABLED' PARAMETER TO 'true' -->
21+
<handler class="com.orientechnologies.orient.server.handler.OJMXPlugin">
22+
<parameters>
23+
<parameter name="enabled" value="false"/>
24+
<parameter name="profilerManaged" value="true"/>
25+
</parameters>
26+
</handler>
27+
<!-- AUTOMATIC BACKUP, TO TURN ON SET THE 'ENABLED' PARAMETER TO 'true' -->
28+
<handler class="com.orientechnologies.orient.server.handler.OAutomaticBackup">
29+
<parameters>
30+
<parameter name="enabled" value="false"/>
31+
<!-- LOCATION OF JSON CONFIGURATION FILE -->
32+
<parameter name="config" value="${ORIENTDB_HOME}/config/automatic-backup.json"/>
33+
</parameters>
34+
</handler>
35+
<!-- SERVER SIDE SCRIPT INTERPRETER. WARNING, THIS CAN BE A SECURITY HOLE BECAUSE MALICIOUS CODE COULD BE INJECTED.
36+
ENABLE IT ONLY IF CLIENTS ARE TRUSTED, TO TURN ON SET THE 'ENABLED' PARAMETER TO 'true' -->
37+
<handler
38+
class="com.orientechnologies.orient.server.handler.OServerSideScriptInterpreter">
39+
<parameters>
40+
<parameter name="enabled" value="true"/>
41+
<parameter name="allowedLanguages" value="SQL,GREMLIN"/>
42+
<!-- Comma separated packages allowed in JS scripts eg. java.math.*, java.util.ArrayList -->
43+
<parameter name="allowedPackages" value=""/>
44+
</parameters>
45+
</handler>
46+
<!-- CUSTOM SQL FUNCTIONS -->
47+
<handler class="com.orientechnologies.orient.server.handler.OCustomSQLFunctionPlugin">
48+
<parameters>
49+
<!-- LOCATION OF JSON CONFIGURATION FILE -->
50+
<parameter name="config" value="${ORIENTDB_HOME}/config/custom-sql-functions.json"/>
51+
</parameters>
52+
</handler>
53+
54+
</handlers>
55+
<network>
56+
<sockets>
57+
<socket implementation="com.orientechnologies.orient.server.network.OServerTLSSocketFactory" name="ssl">
58+
<parameters>
59+
<parameter value="false" name="network.ssl.clientAuth"/>
60+
<parameter value="config/cert/orientdb.ks" name="network.ssl.keyStore"/>
61+
<parameter value="password" name="network.ssl.keyStorePassword"/>
62+
<parameter value="config/cert/orientdb.ks" name="network.ssl.trustStore"/>
63+
<parameter value="password" name="network.ssl.trustStorePassword"/>
64+
</parameters>
65+
</socket>
66+
<socket implementation="com.orientechnologies.orient.server.network.OServerTLSSocketFactory" name="https">
67+
<parameters>
68+
<parameter value="false" name="network.ssl.clientAuth"/>
69+
<parameter value="config/cert/orientdb.ks" name="network.ssl.keyStore"/>
70+
<parameter value="password" name="network.ssl.keyStorePassword"/>
71+
<parameter value="config/cert/orientdb.ks" name="network.ssl.trustStore"/>
72+
<parameter value="password" name="network.ssl.trustStorePassword"/>
73+
</parameters>
74+
</socket>
75+
</sockets>
76+
<protocols>
77+
<!-- Default registered protocol. It reads commands using the HTTP protocol
78+
and write data locally -->
79+
<protocol name="binary"
80+
implementation="com.orientechnologies.orient.server.network.protocol.binary.ONetworkProtocolBinary"/>
81+
<protocol name="http"
82+
implementation="com.orientechnologies.orient.server.network.protocol.http.ONetworkProtocolHttpDb"/>
83+
</protocols>
84+
<listeners>
85+
<listener protocol="binary" ip-address="0.0.0.0" port-range="2424-2430" socket="default"/>
86+
<listener protocol="http" ip-address="0.0.0.0" port-range="2480-2490" socket="default">
87+
<parameters>
88+
<!-- Connection's custom parameters. If not specified the global configuration
89+
will be taken -->
90+
<parameter name="network.http.charset" value="utf-8"/>
91+
<parameter value="true" name="network.http.jsonResponseError"/>
92+
<parameter value="Content-Security-Policy: frame-ancestors 'none'" name="network.http.additionalResponseHeaders"></parameter>
93+
<!-- Define additional HTTP headers to always send as response -->
94+
<!-- Allow cross-site scripting -->
95+
<!-- parameter name="network.http.additionalResponseHeaders" value="Access-Control-Allow-Origin:
96+
*;Access-Control-Allow-Credentials: true" / -->
97+
</parameters>
98+
<commands>
99+
<command
100+
pattern="GET|www GET|studio/ GET| GET|*.htm GET|*.html GET|*.xml GET|*.jpeg GET|*.jpg GET|*.png GET|*.gif GET|*.js GET|*.css GET|*.swf GET|*.ico GET|*.txt GET|*.otf GET|*.pjs GET|*.svg GET|*.json GET|*.woff GET|*.woff2 GET|*.ttf GET|*.svgz"
101+
implementation="com.orientechnologies.orient.server.network.protocol.http.command.get.OServerCommandGetStaticContent">
102+
<parameters>
103+
<!-- Don't cache html resources in development mode -->
104+
<entry name="http.cache:*.htm *.html"
105+
value="Cache-Control: no-cache, no-store, max-age=0, must-revalidate\r\nPragma: no-cache"/>
106+
<!-- Default caching -->
107+
<entry name="http.cache:default" value="Cache-Control: max-age=120"/>
108+
</parameters>
109+
</command>
110+
<command pattern="GET|gephi/*"
111+
implementation="com.orientechnologies.orient.server.network.protocol.http.command.get.OServerCommandGetGephi"/>
112+
113+
</commands>
114+
</listener>
115+
</listeners>
116+
<cluster>
117+
</cluster>
118+
</network>
119+
<storages>
120+
</storages>
121+
<users>
122+
</users>
123+
<properties>
124+
<!-- PROFILER: configures the profiler as <seconds-for-snapshot>,<archive-snapshot-size>,<summary-size> -->
125+
<entry name="profiler.enabled" value="false"/>
126+
<!-- <entry name="profiler.config" value="30,10,10" /> -->
127+
</properties>
128+
</orient-server>

0 commit comments

Comments
 (0)