1 package com.omnisci.jdbc;
3 import static org.junit.Assert.*;
5 import org.apache.thrift.transport.TTransportException;
6 import org.junit.BeforeClass;
10 import java.io.FileInputStream;
11 import java.io.InputStream;
13 import java.sql.SQLException;
14 import java.util.Properties;
16 import javax.net.ssl.SSLPeerUnverifiedException;
21 static final String
user = PROPERTIES.getProperty(
"default_super_user");
22 static final String
password = PROPERTIES.getProperty(
"default_user_password");
27 String fileName = System.getProperty(
"propertiesFileName");
29 if (fileName == null || fileName.equals(
"")) {
32 File initialFile =
new File(fileName);
33 InputStream inputStream =
new FileInputStream(initialFile);
34 base_properties.load(inputStream);
39 String
url = PROPERTIES.getProperty(
"binary_connection_url") +
":"
42 assertNotEquals(null, conn);
44 boolean closed = conn.isClosed();
45 assertEquals(
true, closed);
46 }
catch (SQLException sq) {
47 String err =
"Connection test failed " + sq.toString();
54 String
url = PROPERTIES.getProperty(
"http_connection_url") +
":"
55 +
PROPERTIES.getProperty(
"default_db") +
":http";
57 assertNotEquals(null, conn);
59 boolean closed = conn.isClosed();
60 assertEquals(
true, closed);
61 }
catch (SQLException sq) {
62 String err =
"Connection test failed " + sq.toString();
69 String
url = PROPERTIES.getProperty(
"failed_connection_url") +
":"
71 Properties pt =
new Properties();
72 pt.setProperty(
"user",
user);
73 pt.setProperty(
"password",
password);
74 Connection conn = DriverManager.getConnection(
url, pt);
75 }
catch (SQLException sq) {
76 assertEquals(sq.getMessage(),
77 "No suitable driver found for jdbc:NOT_omnisci:localhost:6274:omnisci");
80 String err =
"Connection should have thrown";
87 String
url = PROPERTIES.getProperty(
"default_mapd_connection_url") +
":"
89 Properties pt =
new Properties();
90 pt.setProperty(
"user",
user);
91 pt.setProperty(
"password",
password);
92 pt.setProperty(
"db_name",
"SomeOtherDB");
94 Connection conn = DriverManager.getConnection(
url, pt);
95 }
catch (SQLException sq) {
96 fail(sq.getMessage());
103 String
url =
"jdbc:omnisci:" + base_properties.getProperty(
"host_name");
105 assertNotEquals(null, conn);
107 boolean closed = conn.isClosed();
108 assertEquals(
true, closed);
109 }
catch (SQLException sq) {
110 String err =
"Connection test failed " + sq.toString();
118 String
url = PROPERTIES.getProperty(
"binary_connection_url") +
":"
119 +
PROPERTIES.getProperty(
"default_db") +
":binary_tls";
121 Properties pt =
new Properties();
122 pt.setProperty(
"user",
user);
123 pt.setProperty(
"password",
password);
124 Connection conn = DriverManager.getConnection(
url, pt);
125 assertNotEquals(null, conn);
127 boolean closed = conn.isClosed();
128 assertEquals(
true, closed);
129 }
catch (SQLException sq) {
130 String err =
"Connection test failed " + sq.toString();
138 Properties pt =
new Properties();
139 String
url = PROPERTIES.getProperty(
"binary_connection_url") +
":"
140 +
PROPERTIES.getProperty(
"default_db") +
":binary_tls";
142 ClassLoader cl = getClass().getClassLoader();
143 String trust_store = PROPERTIES.getProperty(
"server_trust_store");
144 trust_store = cl.getResource(trust_store).getPath();
145 pt.setProperty(
"server_trust_store", trust_store);
147 String sslcert_cl1 = PROPERTIES.getProperty(
"sslcert_cl1_pkcs12");
148 sslcert_cl1 = cl.getResource(sslcert_cl1).getPath();
149 pt.setProperty(
"sslcert", sslcert_cl1);
151 pt.setProperty(
"sslkey_password", PROPERTIES.getProperty(
"sslkey_password_cl1"));
153 pt.setProperty(
"user",
"pki");
154 pt.setProperty(
"password",
"");
155 pt.setProperty(
"server_trust_store_pwd",
156 PROPERTIES.getProperty(
"server_trust_store_password"));
157 pt.setProperty(
"pkiauth", PROPERTIES.getProperty(
"pkiauth"));
159 Connection conn = DriverManager.getConnection(
url, pt);
160 assertNotEquals(null, conn);
162 Statement statement = conn.createStatement();
163 statement.executeUpdate(
"drop table if exists test_jdbc_tm_tble");
166 boolean closed = conn.isClosed();
167 assertEquals(
true, closed);
168 }
catch (SQLException sq) {
169 String err =
"Connection test failed " + sq.toString();
177 Properties pt =
new Properties();
178 String
url = PROPERTIES.getProperty(
"binary_connection_url") +
":"
179 +
PROPERTIES.getProperty(
"default_db") +
":binary_tls";
181 ClassLoader cl = getClass().getClassLoader();
182 String trust_store = PROPERTIES.getProperty(
"server_trust_store");
183 trust_store = cl.getResource(trust_store).getPath();
184 pt.setProperty(
"server_trust_store", trust_store);
187 String sslcert_cl2 = PROPERTIES.getProperty(
"sslcert_cl2");
188 sslcert_cl2 = cl.getResource(sslcert_cl2).getPath();
189 pt.setProperty(
"sslcert", sslcert_cl2);
191 String sslkey_cl2 = PROPERTIES.getProperty(
"sslkey_cl2");
192 sslkey_cl2 = cl.getResource(sslkey_cl2).getPath();
193 pt.setProperty(
"sslkey", sslkey_cl2);
195 pt.setProperty(
"user",
"pki");
196 pt.setProperty(
"password",
"");
197 pt.setProperty(
"server_trust_store_pwd",
198 PROPERTIES.getProperty(
"server_trust_store_password"));
199 pt.setProperty(
"pkiauth", PROPERTIES.getProperty(
"pkiauth"));
201 Connection conn = DriverManager.getConnection(
url, pt);
202 assertNotEquals(null, conn);
204 boolean closed = conn.isClosed();
205 fail(
"Credential should not have been accepted");
206 }
catch (SQLException sq) {
207 String err =
"Connection test failed " + sq.toString();
208 assertTrue(err.contains(
"Invalid credentials"));
215 Properties pt =
new Properties();
216 pt.setProperty(
"user",
user);
217 pt.setProperty(
"password",
password);
218 pt.setProperty(
"protocol",
"https_insecure");
219 String
url = PROPERTIES.getProperty(
"https_connection_url") +
":"
221 Connection conn = DriverManager.getConnection(
url, pt);
222 assertNotEquals(null, conn);
224 boolean closed = conn.isClosed();
225 assertEquals(
true, closed);
226 }
catch (SQLException sq) {
227 String err =
"Connection test failed " + sq.toString();
235 ClassLoader cl = getClass().getClassLoader();
236 String trust_store = PROPERTIES.getProperty(
"server_trust_store");
237 trust_store = cl.getResource(trust_store).getPath();
239 Properties pt =
new Properties();
240 pt.setProperty(
"server_trust_store", trust_store);
241 pt.setProperty(
"server_trust_store_pwd",
242 PROPERTIES.getProperty(
"server_trust_store_password"));
244 pt.setProperty(
"user",
user);
245 pt.setProperty(
"password",
password);
246 pt.setProperty(
"protocol",
"https_insecure");
248 String
url = PROPERTIES.getProperty(
"https_connection_url") +
":"
250 Connection conn = DriverManager.getConnection(
url, pt);
251 assertNotEquals(null, conn);
253 boolean closed = conn.isClosed();
254 assertEquals(
true, closed);
255 }
catch (SQLException sq) {
256 String err =
"Connection test failed " + sq.toString();
264 Properties pt =
new Properties();
265 pt.setProperty(
"user",
user);
266 pt.setProperty(
"password",
password);
267 pt.setProperty(
"protocol",
"https");
268 String
url = PROPERTIES.getProperty(
"https_connection_url") +
":"
270 Connection conn = DriverManager.getConnection(
url, pt);
271 assertNotEquals(null, conn);
273 boolean closed = conn.isClosed();
274 assertEquals(
true, closed);
275 }
catch (SQLException sq) {
276 String err =
"Connection test failed " + sq.toString();
284 ClassLoader cl = getClass().getClassLoader();
285 String trust_store = PROPERTIES.getProperty(
"ca_primary_trust_store");
286 trust_store = cl.getResource(trust_store).getPath();
287 Properties pt =
new Properties();
288 pt.setProperty(
"server_trust_store", trust_store);
289 pt.setProperty(
"server_trust_store_pwd",
290 PROPERTIES.getProperty(
"server_trust_store_password"));
292 pt.setProperty(
"user",
user);
293 pt.setProperty(
"password",
password);
294 pt.setProperty(
"protocol",
"https");
296 String
url = PROPERTIES.getProperty(
"https_connection_url") +
":"
299 Connection conn = DriverManager.getConnection(
url, pt);
301 assertNotEquals(null, conn);
302 boolean closed = conn.isClosed();
303 assertEquals(
true, closed);
305 assertNotEquals(null, conn);
306 }
catch (SQLException sq) {
307 String err =
"Connection test failed " + sq.toString();
314 Properties pt =
new Properties();
315 String
url = PROPERTIES.getProperty(
"https_connection_url") +
":"
316 +
PROPERTIES.getProperty(
"default_db") +
":https_insecure";
318 ClassLoader cl = getClass().getClassLoader();
319 String trust_store = PROPERTIES.getProperty(
"server_trust_store");
320 trust_store = cl.getResource(trust_store).getPath();
321 pt.setProperty(
"server_trust_store", trust_store);
323 String sslcert_cl1 = PROPERTIES.getProperty(
"sslcert_cl1_pkcs12");
324 sslcert_cl1 = cl.getResource(sslcert_cl1).getPath();
325 pt.setProperty(
"sslcert", sslcert_cl1);
327 pt.setProperty(
"sslkey_password", PROPERTIES.getProperty(
"sslkey_password_cl1"));
329 pt.setProperty(
"user",
"pki");
330 pt.setProperty(
"password",
"");
331 pt.setProperty(
"server_trust_store_pwd",
332 PROPERTIES.getProperty(
"server_trust_store_password"));
333 pt.setProperty(
"pkiauth", PROPERTIES.getProperty(
"pkiauth"));
335 Connection conn = DriverManager.getConnection(
url, pt);
336 Statement statement = conn.createStatement();
337 statement.executeUpdate(
"drop table if exists test_jdbc_tm_tble");
338 assertNotEquals(null, conn);
340 boolean closed = conn.isClosed();
341 assertEquals(
true, closed);
342 }
catch (SQLException sq) {
343 String err =
"Connection test failed " + sq.toString();
static Properties PROPERTIES
void tst5_properties_connection()
void tst3b_https_encrypted_without_server_validation_supplied_truststore()
static Properties base_properties
void tst1_binary_unencrypted()
void tst1b_binary_encrypted_default()
void tst3c_https_encrypted_server_validation_default_truststore()
static void setUpBeforeClass()
void tst3e_https_insecure_encrypted_supplied_truststore_pkiauth_valid()
void tst1c_binary_encrypted_supplied_truststore_pkiauth_valid()
void tst3a_https_encrypted_without_server_validation_default_truststore()
void tst4_connect_url_override()
void tst1e_binary_encrypted_supplied_truststore_pkiauth_invalid()
static final String password
void tst3d_https_encrypted_with_server_validation_supplied_truststore()
void tst2_http_unencrypted()