Skip to content
This repository has been archived by the owner on Mar 31, 2021. It is now read-only.

Connection string refactoring and registry updates #2

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added libraries/VisualLeakDetector/lib/vld.lib
Binary file not shown.
Binary file added libraries/VisualLeakDetector/lib64/vld.lib
Binary file not shown.
17 changes: 17 additions & 0 deletions src/IntegrationTests/ITODBCAwsAuth/test_aws_auth_dsn.reg
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBCINST.INI\ODBC Drivers]
"ElasticsearchODBC"="Installed"

[HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBCINST.INI\ElasticsearchODBC]
"Driver"="<project-root>\\bin64\\Release\\elasticodbc.dll"
"Setup"="<project-root>\\bin64\\Release\\elasticodbc.dll"

[HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources]
"test_aws_auth_dsn"="ElasticsearchODBC"

[HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\test_aws_auth_dsn]
"host"="https://search-sept-cdg-david-test-domain-gouok3seqeupz64smuvfxyddui.eu-west-3.es.amazonaws.com"
"auth"="AWS_SIGV4"
"region"="eu-west-3"
"useSSL"="0"
8 changes: 8 additions & 0 deletions src/IntegrationTests/ITODBCAwsAuth/test_odbc.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[ODBC Data Sources]
test_aws_auth_dsn = ElasticsearchODBC

[test_aws_auth_dsn]
host = https://search-sept-cdg-david-test-domain-gouok3seqeupz64smuvfxyddui.eu-west-3.es.amazonaws.com
auth = AWS_SIGV4
region = eu-west-3
useSSL = 0
2 changes: 1 addition & 1 deletion src/IntegrationTests/ITODBCAwsAuth/test_odbc_aws_auth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include "it_odbc_helper.h"
// clang-format on

std::wstring dsn_name = L"test_dsn";
std::wstring dsn_name = L"test_aws_auth_dsn";
std::wstring aws_auth_conn_string =
L"Driver={Elasticsearch};DataBase=database_name;"
L"Server=https://"
Expand Down
6 changes: 6 additions & 0 deletions src/IntegrationTests/ITODBCAwsAuth/test_odbcinst.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[ODBC Drivers]
ElasticsearchODBC = Installed

[ElasticsearchODBC]
Driver = <project-root>/lib64/libelasticodbc.dylib
Setup = <project-root>/lib64/libelasticodbc.dylib
12 changes: 8 additions & 4 deletions src/IntegrationTests/ITODBCConnection/test_dsn.reg
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ Windows Registry Editor Version 5.00
"test_dsn"="ElasticsearchODBC"

[HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\test_dsn]
"Host"="localhost"
"Port"="9200"
"Username"="admin"
"Password"="admin"
"host"="localhost"
"port"="9200"
"user"="admin"
"password"="admin"
"auth"="BASIC"
"useSSL"="0"
"responseTimeout"="10"

13 changes: 8 additions & 5 deletions src/IntegrationTests/ITODBCConnection/test_odbc.ini
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
[ODBC Data Sources]
test_dsn = ElasticsearchODBC
test_dsn = ElasticsearchODBC

[test_dsn]
Host = localhost
Port = 9200
Username = admin
Password = admin
host = localhost
port = 9200
user = admin
password = admin
auth = BASIC
useSSL = 0
responseTimeout = 10
88 changes: 65 additions & 23 deletions src/IntegrationTests/ITODBCConnection/test_odbc_connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ TEST(TestSqlDriverConnect, SqlDriverNoprompt) {
// std::wstring invalid_driver_conn_string =
// L"Driver=xxxx;DataBase=database_name;"
// L"Server=localhost;port=9200;"
// L"Uid=admin;Pwd=admin;";
// L"username=admin;password=admin;";

// SQLRETURN ret;
// ExecuteSqlDriverConnect((SQLTCHAR*)invalid_driver_conn_string.c_str(),
Expand All @@ -156,10 +156,17 @@ TEST(TestSqlDriverConnect, SqlDriverNoprompt) {
// }

TEST(TestSqlDriverConnect, InvalidHost) {
std::wstring invalid_host_conn_string =
L"Driver={SQL Server};DataBase=database_name;"
L"Host=8.8.8.8;Port=9200;"
L"Username=admin;Password=admin;AuthenticationMode=BASIC";
std::wstring invalid_host_conn_string =
use_ssl ? L"Driver={Elasticsearch ODBC};"
L"host=https://8.8.8.8;port=9200;"
L"user=admin;password=admin;auth=BASIC;useSSL="
L"1;hostnameVerification=0;logLevel=0;logOutput=C:\\;"
L"responseTimeout=10;"
: L"Driver={Elasticsearch ODBC};"
L"host=8.8.8.8;port=9200;"
L"user=admin;password=admin;auth=BASIC;useSSL="
L"0;hostnameVerification=0;logLevel=0;logOutput=C:\\;"
L"responseTimeout=10;";

SQLRETURN ret;
ExecuteSqlDriverConnect((SQLTCHAR*)invalid_host_conn_string.c_str(),
Expand All @@ -169,9 +176,16 @@ TEST(TestSqlDriverConnect, InvalidHost) {

TEST(TestSqlDriverConnect, InvalidPort) {
std::wstring invalid_port_conn_string =
L"Driver={SQL Server};DataBase=database_name;"
L"Host=localhost;Port=5432;"
L"Username=admin;Password=admin;";
use_ssl ? L"Driver={Elasticsearch ODBC};"
L"host=https://localhost;port=5432;"
L"user=admin;password=admin;auth=BASIC;useSSL="
L"1;hostnameVerification=0;logLevel=0;logOutput=C:\\;"
L"responseTimeout=10;"
: L"Driver={Elasticsearch ODBC};"
L"host=localhost;port=5432;"
L"user=admin;password=admin;auth=BASIC;useSSL="
L"0;hostnameVerification=0;logLevel=0;logOutput=C:\\;"
L"responseTimeout=10;";

SQLRETURN ret;
ExecuteSqlDriverConnect((SQLTCHAR*)invalid_port_conn_string.c_str(),
Expand All @@ -184,9 +198,16 @@ TEST(TestSqlDriverConnect, InvalidPort) {
// string attribute)
TEST(TestSqlDriverConnect, UnsupportedKeyword) {
std::wstring unsupported_keyword_conn_string =
L"Driver={SQL Server};DataBase=database_name;"
L"Host=localhost;Port=5432;"
L"Username=admin;Password=admin;extra=1;";
use_ssl ? L"Driver={Elasticsearch ODBC};"
L"host=https://localhost;port=5432;"
L"user=admin;password=admin;auth=BASIC;useSSL="
L"1;hostnameVerification=0;logLevel=0;logOutput=C:\\;"
L"responseTimeout=10;extra=1"
: L"Driver={Elasticsearch ODBC};"
L"host=localhost;port=5432;"
L"user=admin;password=admin;auth=BASIC;useSSL="
L"0;hostnameVerification=0;logLevel=0;logOutput=C:\\;"
L"responseTimeout=10;extra=1";

SQLRETURN ret;
ExecuteSqlDriverConnect((SQLTCHAR*)unsupported_keyword_conn_string.c_str(),
Expand All @@ -195,10 +216,17 @@ TEST(TestSqlDriverConnect, UnsupportedKeyword) {
}

TEST(TestSqlDriverConnect, Timeout1Second) {
std::wstring one_second_timeout =
L"Driver={SQL Server};DataBase=elasticsearch;"
L"Host=8.8.8.8;Port=9200;"
L"Username=admin;Password=admin;ResponseTimeout=1;";
std::wstring one_second_timeout =
use_ssl ? L"Driver={Elasticsearch ODBC};"
L"host=https://8.8.8.8;port=9200;"
L"user=admin;password=admin;auth=BASIC;useSSL="
L"1;hostnameVerification=0;logLevel=0;logOutput=C:\\;"
L"responseTimeout=1;"
: L"Driver={Elasticsearch ODBC};"
L"host=8.8.8.8;port=9200;"
L"user=admin;password=admin;auth=BASIC;useSSL="
L"0;hostnameVerification=0;logLevel=0;logOutput=C:\\;"
L"responseTimeout=1;";

SQLRETURN ret;
auto start = std::chrono::steady_clock::now();
Expand All @@ -223,10 +251,17 @@ TEST(TestSqlDriverConnect, Timeout1Second) {
}

TEST(TestSqlDriverConnect, Timeout3Second) {
std::wstring one_second_timeout =
L"Driver={SQL Server};DataBase=elasticsearch;"
L"Host=8.8.8.8;Port=9200;"
L"Username=admin;Password=admin;ResponseTimeout=3;";
std::wstring one_second_timeout =
use_ssl ? L"Driver={Elasticsearch ODBC};"
L"host=https://8.8.8.8;port=9200;"
L"user=admin;password=admin;auth=BASIC;useSSL="
L"1;hostnameVerification=0;logLevel=0;logOutput=C:\\;"
L"responseTimeout=3;"
: L"Driver={Elasticsearch ODBC};"
L"host=8.8.8.8;port=9200;"
L"user=admin;password=admin;auth=BASIC;useSSL="
L"0;hostnameVerification=0;logLevel=0;logOutput=C:\\;"
L"responseTimeout=3;";

SQLRETURN ret;
auto start = std::chrono::steady_clock::now();
Expand All @@ -251,10 +286,17 @@ TEST(TestSqlDriverConnect, Timeout3Second) {
}

TEST(TestSqlDriverConnect, Timeout7Second) {
std::wstring seven_second_timeout =
L"Driver={SQL Server};DataBase=elasticsearch;"
L"Host=8.8.8.8;Port=9200;"
L"Username=admin;Password=admin;ResponseTimeout=7;";
std::wstring seven_second_timeout =
use_ssl ? L"Driver={Elasticsearch ODBC};"
L"host=https://8.8.8.8;port=9200;"
L"user=admin;password=admin;auth=BASIC;useSSL="
L"1;hostnameVerification=0;logLevel=0;logOutput=C:\\;"
L"responseTimeout=7;"
: L"Driver={Elasticsearch ODBC};"
L"host=8.8.8.8;port=9200;"
L"user=admin;password=admin;auth=BASIC;useSSL="
L"0;hostnameVerification=0;logLevel=0;logOutput=C:\\;"
L"responseTimeout=7;";

SQLRETURN ret;
auto start = std::chrono::steady_clock::now();
Expand Down
5 changes: 0 additions & 5 deletions src/IntegrationTests/ITODBCHelper/it_odbc_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,6 @@ void AllocConnection(SQLTCHAR* connection_string, SQLHDBC* db_connection,
SQLTCHAR out_conn_string[1024];
SQLSMALLINT out_conn_string_length;

// TODO: Integration tests hanging for tests with no SQL_ERROR test case
// (AE-114)
SQLDriverConnect(*db_connection, NULL, (SQLTCHAR*)L"", SQL_NTS,
out_conn_string, IT_SIZEOF(out_conn_string),
&out_conn_string_length, SQL_DRIVER_COMPLETE);
EXECUTION_HANDLER(
throw_on_error, log_diag, SQL_HANDLE_DBC, *db_connection, ret_code,
SQLDriverConnect(*db_connection, NULL, connection_string, SQL_NTS,
Expand Down
21 changes: 13 additions & 8 deletions src/IntegrationTests/ITODBCHelper/it_odbc_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@
#endif
#include <sql.h>
#include <sqlext.h>
#include "unit_test_helper.h"

#include <iostream>

#include "unit_test_helper.h"

// SQLSTATEs
#define SQLSTATE_STRING_DATA_RIGHT_TRUNCATED (SQLWCHAR*)L"01004"
#define SQLSTATE_INVALID_DESCRIPTOR_INDEX (SQLWCHAR*)L"07009"
Expand All @@ -34,13 +36,16 @@
#define IT_SIZEOF(x) (NULL == (x) ? 0 : (sizeof((x)) / sizeof((x)[0])))

std::wstring conn_string =
use_ssl ? L"Driver={SQL Server};DataBase=database_name;"
L"Server=https://localhost;port=9200;"
L"Username=admin;Password=admin;AuthenticationMode=BASIC;SSLUse="
L"1;SSLVerifyServer=0;"
: L"Driver={SQL Server};DataBase=database_name;"
L"Server=localhost;port=9200;SSLUse=0;SSLVerifyServer=0;"
L"Username=admin;Password=admin;AuthenticationMode=BASIC;";
use_ssl ? L"Driver={Elasticsearch ODBC};"
L"host=https://localhost;port=9200;"
L"user=admin;password=admin;auth=BASIC;useSSL="
L"1;hostnameVerification=0;logLevel=0;logOutput=C:\\;"
L"responseTimeout=10;"
: L"Driver={Elasticsearch ODBC};"
L"host=localhost;port=9200;"
L"user=admin;password=admin;auth=BASIC;useSSL="
L"0;hostnameVerification=0;logLevel=0;logOutput=C:\\;"
L"responseTimeout=10;";

void AllocConnection(SQLTCHAR* connection_string, SQLHDBC* db_connection,
bool throw_on_error, bool log_diag);
Expand Down
6 changes: 3 additions & 3 deletions src/UnitTests/UTConn/test_conn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ const std::string invalid_host = "10.1.1.189";
const std::string invalid_port = "920";
const std::string invalid_user = "amin";
const std::string invalid_pw = "amin";
runtime_options valid_opt_val = {{valid_host, valid_port, "elasticsearch", "1"},
runtime_options valid_opt_val = {{valid_host, valid_port, "1"},
{"BASIC", valid_user, valid_pw},
{use_ssl, false, "", "", "", ""}};
runtime_options invalid_opt_val = {
{invalid_host, invalid_port, "elasticsearch", "1"},
{invalid_host, invalid_port, "1"},
{"BASIC", invalid_user, invalid_pw},
{use_ssl, false, "", "", "", ""}};
runtime_options missing_opt_val = {{"", "", "elasticsearch", "1"},
runtime_options missing_opt_val = {{"", "", "1"},
{"BASIC", "", invalid_pw},
{use_ssl, false, "", "", "", ""}};

Expand Down
2 changes: 1 addition & 1 deletion src/UnitTests/UTConn/test_query_execution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const int EXECUTION_ERROR = -1;
const int all_columns_flights_count = 25;
const int some_columns_flights_count = 2;
runtime_options valid_conn_opt_val = {
{valid_host, valid_port, "elasticsearch", "1"},
{valid_host, valid_port, "1"},
{"BASIC", valid_user, valid_pw},
{use_ssl, false, "", "", "", ""}};

Expand Down
53 changes: 5 additions & 48 deletions src/elasticodbc/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ RETCODE SQL_API ESAPI_Connect(HDBC hdbc, const SQLCHAR *szDSN,
/* get the values for the DSN from the registry */
getDSNinfo(ci, NULL);

logs_on_off(1, ci->drivers.debug, ci->drivers.commlog);
logs_on_off(1, ci->drivers.loglevel, ci->drivers.loglevel);
/* initialize es_version from connInfo.protocol */
CC_initialize_es_version(conn);

Expand Down Expand Up @@ -186,8 +186,8 @@ RETCODE SQL_API ESAPI_Disconnect(HDBC hdbc) {
return SQL_ERROR;
}

logs_on_off(-1, conn->connInfo.drivers.debug,
conn->connInfo.drivers.commlog);
logs_on_off(-1, conn->connInfo.drivers.loglevel,
conn->connInfo.drivers.loglevel);
MYLOG(0, "about to CC_cleanup\n");

/* Close the connection and free statements */
Expand Down Expand Up @@ -495,43 +495,6 @@ CC_cleanup(ConnectionClass *self, BOOL keepCommunication) {
return ret;
}

int CC_set_translation(ConnectionClass *self) {
UNUSED(self);
#ifdef WIN32
CSTR func = "CC_set_translation";

if (self->translation_handle != NULL) {
FreeLibrary(self->translation_handle);
self->translation_handle = NULL;
}

if (self->connInfo.translation_dll[0] == 0)
return TRUE;

self->translation_option = atoi(self->connInfo.translation_option);
self->translation_handle = LoadLibrary(self->connInfo.translation_dll);

if (self->translation_handle == NULL) {
CC_set_error(self, CONN_UNABLE_TO_LOAD_DLL,
"Could not load the translation DLL.", func);
return FALSE;
}

self->DataSourceToDriver = (DataSourceToDriverProc)GetProcAddress(
self->translation_handle, "SQLDataSourceToDriver");

self->DriverToDataSource = (DriverToDataSourceProc)GetProcAddress(
self->translation_handle, "SQLDriverToDataSource");

if (self->DataSourceToDriver == NULL || self->DriverToDataSource == NULL) {
CC_set_error(self, CONN_UNABLE_TO_LOAD_DLL,
"Could not find translation DLL functions.", func);
return FALSE;
}
#endif
return TRUE;
}

#ifndef ES_DIAG_SEVERITY_NONLOCALIZED
#define ES_DIAG_SEVERITY_NONLOCALIZED 'V'
#endif
Expand Down Expand Up @@ -692,14 +655,8 @@ void CC_log_error(const char *func, const char *desc,
}

const char *CurrCat(const ConnectionClass *conn) {
/*
* Returning the database name causes problems in MS Query. It
* generates query like: "SELECT DISTINCT a FROM byronnbad3
* bad3"
*/
if (isMsQuery()) /* MS Query */
return NULL;
return conn->connInfo.database;
UNUSED(conn);
return NULL;
}

const char *CurrCatString(const ConnectionClass *conn) {
Expand Down
Loading