Skip to content

Ae v2 extended tests #1077

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Feb 3, 2020

Conversation

david-puglielli
Copy link
Contributor

No description provided.

@coveralls
Copy link

coveralls commented Jan 15, 2020

Coverage Status

Coverage increased (+0.03%) to 73.693% when pulling 2fe0250 on david-puglielli:ae-v2-extended-tests into e7b5a88 on microsoft:dev.

Copy link
Contributor

@yitam yitam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Beginning with php 7.4, nested ternary operations must explicitly use parentheses to dictate the order of the operations. Even though you may not have operations nested, add parentheses to ensure no ambiguity. FYI, see https://www.php.net/manual/en/migration74.deprecated.php

Also, before accessing any array values, do check if the array is empty first. Will continue reviewing after you have fixed all these.

} elseif ($attestationType == 'invalid') {
die("Connection should have failed for invalid protocol\n");
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please indicate the conditions under which connection should have failed or should not have failed in the error messages such that if this happens we know which combination it is.

}
} elseif ($targetAttestationType == 'invalid') {
continue;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add an else case as well to catch all.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The else case is just to connect successfully and proceed with the rest of the test - the continue and die statements ensure that it won't proceed with the code below when it shouldn't.

}
} elseif ($attestationType == 'invalid') {
die("Connection should have failed for invalid protocol\n");
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, add the else case

}

$ceDisabled = $attestationType == 'disabled' ? true : false;
insertValues($conn, $insertQuery, $dataTypes, $testValues, $ceDisabled);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add parentheses around the if condition.

$sameKeyAndType = false;
if ($key == $targetKey and $encryptionType == $targetType and $isEncrypted) {
$sameKeyAndType = true;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, add parentheses around testing if conditions

// Connect and clear the procedure cache
function connect($attestation_info)
{
include("MsSetup.inc");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use require

{
include("MsSetup.inc");
$options = "sqlsrv:Server=$server;Database=$databaseName;ColumnEncryption=$attestation_info";

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, be consistent with your variable names. Stick with camel case please

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I vaguely recall there were others. Please double check and fix those as well.

$stmt = $conn->query($query);
$info = $stmt->fetch();
if ($info['value'] != 1 or $info['value_in_use'] != 1) {
die("Error: enclave computations are not enabled on the server!");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add parentheses and check $stmt and $info is null or false


function insertValues($conn, $insertQuery, $dataTypes, $testValues, $ceDisabled=false)
{
for ($v = 0; $v < sizeof($testValues['bigint']); ++$v) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test if $testValues is empty or null first

$stmt->bindParam($i, $val, $PDOType, 0, PDO::SQLSRV_ENCODING_BINARY);
$stmt->bindParam($i+1, $val, $PDOType, 0, PDO::SQLSRV_ENCODING_BINARY);
}
$i+=2;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put curly braces to the end of line for if, foreach or else

Copy link
Contributor

@yitam yitam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some other minor issues and please ensure the tests / checks will pass.

@@ -307,22 +307,30 @@ function connect($attestation_info)
return false;
}

$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
$conn->setAttribute(PDO::SQLSRV_ATTR_FETCHES_DATETIME_TYPE, true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please justify why ERRMODE_WARNING is used rather than ERRMODE_EXCEPTION here (I know it will be set to using the latter mode later but add a comment to ease future maintenance)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's from an earlier version - we can set ERRMODE_EXCEPTION immediately. Will fix.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please note later in this test you reset to ERRMODE_EXCEPTION I was asking you to justify this in a comment

{
include("MsSetup.inc");
$options = "sqlsrv:Server=$server;Database=$databaseName;ColumnEncryption=$attestation_info";

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I vaguely recall there were others. Please double check and fix those as well.

die("Error: enclave computations are not enabled on the server!");
if (!$stmt) {
print_r($conn->errorInfo());
die("Error when checking if enclave computations are enabled. This should never happen!\n");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a simple comment to explain why this should never happen. e.g. the right sql server, etc.

$info = sqlsrv_fetch_array($stmt);
if (empty($info) or ($info['value'] != 1) or ($info['value_in_use'] != 1)) {
die("Error: enclave computations are not enabled on the server!");
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering if this should have been verified in a skipif instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather check it here, so that the test clearly fails if enclave computations are not enabled (the skipif checks that the server is a HGS enabled VM - if it is, then these tests should proceed and work as expected).

# populate these tables
populateTables(conn_options, args.DBNAME)
print("About to set up encryption...\n")
# setup AE (certificate, column master key and column encryption key)
setupAE(conn_options, args.DBNAME)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This reminds me. This setup_dbs.py can be used to set up an Azure database as well. Do we need special handling with the AE part when it's Azure?

@david-puglielli david-puglielli merged commit 71b9d40 into microsoft:dev Feb 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants