Skip to content

Commit

Permalink
Fixed typos in #2274 and also some minor code cleanup and test fixes (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
lilgreenbird authored Jan 13, 2024
1 parent 8289086 commit e980590
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -391,21 +391,4 @@ private byte[] getLittleEndianBytesFromShort(short value) {
byteBuffer.order(ByteOrder.LITTLE_ENDIAN);
return byteBuffer.putShort(value).array();
}

/*
* Verify signature against certificate
*/
private boolean rsaVerifySignature(byte[] dataToVerify, byte[] signature,
CertificateDetails certificateDetails) throws InvalidKeyException, NoSuchAlgorithmException, SignatureException {
Signature sig = Signature.getInstance("SHA256withRSA");

sig.initSign((PrivateKey) certificateDetails.privateKey);
sig.update(dataToVerify);

byte[] signedHash = sig.sign();

sig.initVerify(certificateDetails.certificate.getPublicKey());
sig.update(dataToVerify);
return sig.verify(signature);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,9 @@ public String toString() {

/**
* Generate a 6 byte random array for netAddress
* As per TDS spec this is a unique clientID (MAC address) used to identify the client.
* A random number is used instead of the actual MAC address to avoid PII issues.
* As per spec this is informational only server does not process this so there is no need to use SecureRandom.
*
* @return byte[]
*/
Expand Down Expand Up @@ -2137,9 +2140,9 @@ void validateConnectionRetry() throws SQLServerException {

// Set to larger default value for Azure connections to greatly improve recovery
if (isAzureSynapseOnDemandEndpoint()) {
connectRetryCount = AZURE_SERVER_ENDPOINT_RETRY_COUNT_DEFAULT;
} else if (isAzureSqlServerEndpoint()) {
connectRetryCount = AZURE_SYNAPSE_ONDEMAND_ENDPOINT_RETRY_COUNT_DEFAFULT;
} else if (isAzureSqlServerEndpoint()) {
connectRetryCount = AZURE_SERVER_ENDPOINT_RETRY_COUNT_DEFAULT;
}
}
}
Expand Down Expand Up @@ -8382,7 +8385,7 @@ boolean isAzureSynapseOnDemandEndpoint() {
int px = serverName.indexOf('\\');
String parsedServerName = (px >= 0) ? serverName.substring(0, px) : serverName;

return AzureSQLServerEndpoints.isAzureSqlServerEndpoint(parsedServerName);
return AzureSQLServerEndpoints.isAzureSynapseOnDemandEndpoint(parsedServerName);
}

return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,10 +269,11 @@ public void testAzureEndpointRetry() {
if (f.getName() == "connectRetryCount") {
f.setAccessible(true);
int retryCount = f.getInt(con);
if (TestUtils.isAzure(con)) {
assertTrue(retryCount == 2); // AZURE_SERVER_ENDPOINT_RETRY_COUNT_DEFAFULT
} else if (TestUtils.isAzureDW(con)) {

if (TestUtils.isAzureDW(con)) {
assertTrue(retryCount == 5); // AZURE_SYNAPSE_ONDEMAND_ENDPOINT_RETRY_COUNT_DEFAFULT
} else if (TestUtils.isAzure(con)) {
assertTrue(retryCount == 2); // AZURE_SERVER_ENDPOINT_RETRY_COUNT_DEFAFULT
} else {
assertTrue(retryCount == 1); // default connectRetryCount
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -819,8 +819,8 @@ public void testNoSpaceInsert() throws Exception {
f1.setAccessible(true);
f1.set(connection, true);

TestUtils.dropTableIfExists(testNoSpaceInsertTableName, stmt);
String createTable = "create table " + testNoSpaceInsertTableName
TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(testNoSpaceInsertTableName), stmt);
String createTable = "create table " + AbstractSQLGenerator.escapeIdentifier(testNoSpaceInsertTableName)
+ " (id nvarchar(100) not null, json nvarchar(max) not null,"
+ " vcol1 as json_value([json], '$.vcol1'), vcol2 as json_value([json], '$.vcol2'))";
stmt.execute(createTable);
Expand All @@ -832,6 +832,8 @@ public void testNoSpaceInsert() throws Exception {
pstmt.setString(2, jsonValue);
pstmt.addBatch();
pstmt.executeBatch();
} catch (Exception e) {
fail(testNoSpaceInsertTableName + ": " + e.getMessage());
} finally {
try (Statement stmt = connection.createStatement()) {
TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(testNoSpaceInsertTableName), stmt);
Expand Down

0 comments on commit e980590

Please sign in to comment.