Fixed tests, fixed wide char name in keystore struct

This commit is contained in:
David Puglielli 2018-05-16 15:14:47 -07:00
Родитель 2239511f80
Коммит 079c4ea0fe
6 изменённых файлов: 124 добавлений и 115 удалений

Просмотреть файл

@ -971,25 +971,49 @@ void configure_azure_key_vault( sqlsrv_conn* conn, BYTE config_attr, const DWORD
{
BYTE akv_data[sizeof( CEKEYSTOREDATA ) + sizeof(DWORD) + 1 ];
CEKEYSTOREDATA *pData = reinterpret_cast<CEKEYSTOREDATA*>( akv_data );
pData->name = L"AZURE_KEY_VAULT";
char akv_name[] = "AZURE_KEY_VAULT";
unsigned int name_len = 15;
unsigned int wname_len = 0;
sqlsrv_malloc_auto_ptr<SQLWCHAR> wakv_name;
wakv_name = utf16_string_from_mbcs_string( SQLSRV_ENCODING_UTF8, akv_name, name_len, &wname_len );
CHECK_CUSTOM_ERROR( wakv_name == 0, conn, SQLSRV_ERROR_CONNECT_STRING_ENCODING_TRANSLATE ) {
throw core::CoreException();
}
pData->name = (wchar_t *) wakv_name.get();
pData->data[0] = config_attr;
pData->dataSize = sizeof(config_attr) + sizeof(config_value);
*reinterpret_cast<DWORD*>(&pData->data[1]) = config_value;
int r = ::SQLSetConnectAttr( conn, SQL_COPT_SS_CEKEYSTOREDATA, reinterpret_cast<SQLPOINTER>(pData), SQL_IS_POINTER );
core::SQLSetConnectAttr( conn, SQL_COPT_SS_CEKEYSTOREDATA, reinterpret_cast<SQLPOINTER>(pData), SQL_IS_POINTER );
}
void configure_azure_key_vault( sqlsrv_conn* conn, BYTE config_attr, const char* config_value, size_t key_size )
{
BYTE akv_data[sizeof( CEKEYSTOREDATA ) + 2048 ];
CEKEYSTOREDATA *pData = reinterpret_cast<CEKEYSTOREDATA*>( akv_data );
pData->name = L"AZURE_KEY_VAULT";
char akv_name[] = "AZURE_KEY_VAULT";
unsigned int name_len = 15;
unsigned int wname_len = 0;
sqlsrv_malloc_auto_ptr<SQLWCHAR> wakv_name;
wakv_name = utf16_string_from_mbcs_string( SQLSRV_ENCODING_UTF8, akv_name, name_len, &wname_len );
CHECK_CUSTOM_ERROR( wakv_name == 0, conn, SQLSRV_ERROR_CONNECT_STRING_ENCODING_TRANSLATE ) {
throw core::CoreException();
}
pData->name = (wchar_t *) wakv_name.get();
pData->data[0] = config_attr;
pData->dataSize = 1+key_size;
memcpy_s( pData->data+1, key_size * sizeof( char ) , config_value, key_size );
int r = ::SQLSetConnectAttr( conn, SQL_COPT_SS_CEKEYSTOREDATA, reinterpret_cast<SQLPOINTER>(pData), SQL_IS_POINTER );
core::SQLSetConnectAttr( conn, SQL_COPT_SS_CEKEYSTOREDATA, reinterpret_cast<SQLPOINTER>(pData), SQL_IS_POINTER );
}
void common_conn_str_append_func( _In_z_ const char* odbc_name, _In_reads_(val_len) const char* val, _Inout_ size_t val_len, _Inout_ std::string& conn_str TSRMLS_DC )

Просмотреть файл

@ -2256,15 +2256,15 @@ namespace core {
}
// inline void SQLSetConnectAttr( _Inout_ sqlsrv_context& ctx, _In_ SQLINTEGER attr, _In_reads_bytes_opt_(str_len) SQLPOINTER value_ptr, _In_ SQLINTEGER str_len TSRMLS_DC )
// {
// SQLRETURN r;
// r = ::SQLSetConnectAttr( ctx.handle(), attr, value_ptr, str_len );
inline void SQLSetConnectAttr( _Inout_ sqlsrv_context& ctx, _In_ SQLINTEGER attr, _In_reads_bytes_opt_(str_len) SQLPOINTER value_ptr, _In_ SQLINTEGER str_len TSRMLS_DC )
{
SQLRETURN r;
r = ::SQLSetConnectAttr( ctx.handle(), attr, value_ptr, str_len );
// CHECK_SQL_ERROR_OR_WARNING( r, ctx ) {
// throw CoreException();
// }
// }
CHECK_SQL_ERROR_OR_WARNING( r, ctx ) {
throw CoreException();
}
}
inline void SQLSetDescField( _Inout_ sqlsrv_stmt* stmt, _In_ SQLSMALLINT rec_num, _In_ SQLSMALLINT fld_id, _In_reads_bytes_opt_( str_len ) SQLPOINTER value_ptr, _In_ SQLINTEGER str_len TSRMLS_DC )
{

Просмотреть файл

@ -1,7 +1,7 @@
--TEST--
Test connection keywords and credentials for Azure Key Vault for Always Encrypted.
--SKIPIF--
<?php require('skipif_mid-refactor.inc'); ?>
<?php require('skipif.inc'); ?>
--FILE--
<?php
require_once("MsCommon_mid-refactor.inc");
@ -14,41 +14,32 @@ $keyStoreAuthentication = ['KeyVaultPassword', 'KeyVaultClientSecret', 'KeyVault
$keyStorePrincipalId = [$AKVPrincipalName, $AKVClientID, 'notaname', ''];
$keyStoreSecret = [$AKVPassword, $AKVSecret, 'notasecret', ''];
// Verify that the error is in the list of expected errors
function checkErrors($errors, ...$codes)
{
$errSize = empty($errors) ? 0 : sizeof($errors);
if (2*$errSize < sizeof($codes)) fatalError("Errors and input codes do not match.\n");
$codeFound = false;
$i=0;
foreach($codes as $code)
{
if ($i%2==0) {
if ($errors[0] != $code)
{
echo "Error: ";
print_r($errors[0]);
echo "\nExpected: ";
print_r($code);
echo "\n";
fatalError("Error codes do not match.\n");
}
} else if ($i%2==1) {
if ($errors[1] != $code)
{
echo "Error: ";
print_r($errors[1]);
echo "\nExpected: ";
print_r($code);
echo "\n";
fatalError("Error codes do not match.\n");
}
}
++$i;
if ($code[0]==$errors[0] and $code[1]==$errors[1])
$codeFound = true;
}
if ($codeFound == false)
{
echo "Error: ";
print_r($errors);
echo "\nExpected: ";
print_r($codes);
echo "\n";
fatalError("Error code not found.\n");
}
}
// Set up the columns and build the insert query. Each data type has an
// AE-encrypted and a non-encrypted column side by side in the table.
// If column encryption is not set in MsSetup.inc, this function simply
// creates two non-encrypted columns side-by-side for each type.
function FormulateSetupQuery($tableName, &$dataTypes, &$columns, &$insertQuery)
{
$columns = array();
@ -111,7 +102,8 @@ for ($i=0; $i < sizeof($columnEncryption); ++$i) {
$connectionOptions .= ";";
try {
try
{
// Connect to the AE-enabled database
$conn = new PDO($connectionOptions, $uid, $pwd);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
@ -154,28 +146,35 @@ for ($i=0; $i < sizeof($columnEncryption); ++$i) {
// Free the statement and close the connection
$stmt = null;
$conn = null;
} catch(Exception $e) {
}
catch(Exception $e)
{
$errors = $e->errorInfo;
if ($i==0 and $j==3 and $k==3 and $m==3)
checkErrors($errors, 'CE258', '0');
else if ($j==2)
checkErrors($errors, 'IMSSP', '-85');
else if ($i==2)
checkErrors($errors, '08001', '0');
else if ($i==1 or $i==3)
checkErrors($errors, '22018', '206');
else if ($j==3)
checkErrors($errors, 'IMSSP', '-86');
else if ($k==3)
checkErrors($errors, 'IMSSP', '-87');
else if ($m==3)
checkErrors($errors, 'IMSSP', '-88');
if (!isColEncrypted())
{
checkErrors($errors, array('CE258', '0'),
array('CE275', '0'),
array('IMSSP', '-85'),
array('IMSSP', '-86'),
array('IMSSP', '-87'),
array('IMSSP', '-88'),
array('08001', '0'),
array('08001', '-1')); // SSL error occurs in Ubuntu
}
else
{
echo "i=$i j=$j k=$k m=$m failed connection\n";
checkErrors($errors, 'CE275', '0');
checkErrors($errors, array('CE258', '0'),
array('CE275', '0'),
array('IMSSP', '-85'),
array('IMSSP', '-86'),
array('IMSSP', '-87'),
array('IMSSP', '-88'),
array('08001', '0'),
array('08001', '-1'), // SSL error occurs in Ubuntu
array('22018', '206'));
}
}
}
}
}
}

Просмотреть файл

@ -1,7 +1,7 @@
--TEST--
Test connection keywords and credentials for Azure Key Vault for Always Encrypted.
--SKIPIF--
<?php require('skipif_mid-refactor.inc'); ?>
<?php require('skipif.inc'); ?>
--FILE--
<?php
require_once("MsCommon_mid-refactor.inc");

Просмотреть файл

@ -1,11 +1,10 @@
--TEST--
Test connection keywords nad credentials for Azure Key Vault for Always Encrypted.
Test connection keywords and credentials for Azure Key Vault for Always Encrypted.
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
require_once('MsCommon.inc');
require_once('tools.inc');
require_once('values.php');
// We will test the direct product (set of all possible combinations) of the following
@ -14,36 +13,26 @@ $keyStoreAuthentication = ['KeyVaultPassword', 'KeyVaultClientSecret', 'KeyVault
$keyStorePrincipalId = [$AKVPrincipalName, $AKVClientID, 'notaname', ''];
$keyStoreSecret = [$AKVPassword, $AKVSecret, 'notasecret', ''];
$is_win = (strtoupper(substr(php_uname('s'), 0, 3)) === 'WIN');
function checkErrors($errors, ...$codes)
{
$errSize = empty($errors) ? 0 : sizeof($errors);
if (2*$errSize < sizeof($codes)) fatalError("Errors and input codes do not match.\n");
{
$codeFound = false;
$i=0;
foreach($codes as $code)
{
if ($i%2==0) {
if ($errors[$i/2][0] != $code)
{
echo "Error: ";
print_r($errors[$i/2][0]);
echo "\nExpected: ";
print_r($code);
echo "\n";
fatalError("Error codes do not match.\n");
}
} else if ($i%2==1) {
if ($errors[$i/2][1] != $code)
{
echo "Error: ";
print_r($errors[$i/2][1]);
echo "\nExpected: ";
print_r($code);
echo "\n";
fatalError("Error codes do not match.\n");
}
}
++$i;
if ($code[0]==$errors[0][0] and $code[1]==$errors[0][1])
$codeFound = true;
}
if ($codeFound == false)
{
echo "Error: ";
print_r($errors);
echo "\nExpected: ";
print_r($codes);
echo "\n";
fatalError("Error code not found.\n");
}
}
@ -106,7 +95,7 @@ for ($i=0; $i < sizeof($columnEncryption); ++$i) {
$connectionOptions['KeyStorePrincipalId'] = $keyStorePrincipalId[$k];
if (!empty($keyStoreSecret[$m]))
$connectionOptions['KeyStoreSecret'] = $keyStoreSecret[$m];
// Valid credentials getting skipped
if (($i==0 and $j==0 and $k==0 and $m==0) or
($i==0 and $j==1 and $k==1 and $m==1)) {
@ -116,26 +105,19 @@ for ($i=0; $i < sizeof($columnEncryption); ++$i) {
// Connect to the AE-enabled database
// Failure is expected when the keyword combination is wrong
$conn = sqlsrv_connect($server, $connectionOptions);
if (!$conn) {
if (!$conn)
{
$errors = sqlsrv_errors();
if ($j==2)
checkErrors($errors, 'IMSSP', '-110');
else if ($i==2)
checkErrors($errors, '08001', '0');
else if ($j==3)
checkErrors($errors, 'IMSSP', '-111');
else if ($k==3)
checkErrors($errors, 'IMSSP', '-112');
else if ($m==3)
checkErrors($errors, 'IMSSP', '-113');
else
{
echo "i=$i j=$j k=$k m=$m failed connection\n";
print_r(sqlsrv_errors());
fatalError("Connection failed, unexpected connection string.\n");
}
} else {
checkErrors($errors, array('08001','0'),
array('08001','-1'), // SSL error occurs in Ubuntu
array('IMSSP','-110'),
array('IMSSP','-111'),
array('IMSSP','-112'),
array('IMSSP','-113'));
}
else
{
$columns = array();
$insertQuery = "";
@ -167,17 +149,22 @@ for ($i=0; $i < sizeof($columnEncryption); ++$i) {
if (sqlsrv_execute($stmt) == false) {
$errors = sqlsrv_errors();
if ($i==0 and $j==3 and $k==3 and $m==3)
checkErrors($errors, 'CE258', '0', 'CE202', '0');
if ($i==0 and $j==3)
checkErrors($errors, 'CE258', '0', 'CE202', '0');
else if ($i==1 or $i==3)
checkErrors($errors, '22018', '206', '42000', '33514','42000', '8180');
if (!AE\isColEncrypted())
{
checkErrors($errors, array('CE258', '0'),
array('CE275', '0'));
}
else
checkErrors($errors, 'CE275', '0', 'CE275', '0', 'CE258', '0', 'CE202', '0');
{
checkErrors($errors, array('CE258', '0'),
array('CE275', '0'),
array('22018', '206'));
}
sqlsrv_free_stmt($stmt);
} else {
}
else
{
// The INSERT query succeeded with bad credentials, which
// should only happen when encryption is not enabled.
if (AE\isColEncrypted())

Просмотреть файл

@ -1,11 +1,10 @@
--TEST--
Test connection keywords nad credentials for Azure Key Vault for Always Encrypted.
Test connection keywords and credentials for Azure Key Vault for Always Encrypted.
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
require_once('MsCommon.inc');
require_once('tools.inc');
require_once('values.php');
// Set up the columns and build the insert query. Each data type has an