Skip to content

Commit

Permalink
Fixed test failures introduced by sonarqube cleanup (#2014)
Browse files Browse the repository at this point in the history
  • Loading branch information
lilgreenbird authored Dec 23, 2022
1 parent 0780337 commit 27f6680
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -333,12 +333,12 @@ void validateStatementSignature() throws SQLServerException, GeneralSecurityExce
* Signature Blob - signatureSize bytes
*/
ByteBuffer enclaveReportPackageBuffer = ByteBuffer.wrap(enclaveReportPackage).order(ByteOrder.LITTLE_ENDIAN);
// packageSize
// version
// signatureScheme
enclaveReportPackageBuffer.getInt(); // packageSize
enclaveReportPackageBuffer.getInt(); // version
enclaveReportPackageBuffer.getInt(); // signatureScheme
int signedStatementSize = enclaveReportPackageBuffer.getInt();
int signatureSize = enclaveReportPackageBuffer.getInt();
// reserved
enclaveReportPackageBuffer.getInt(); // reserved

byte[] signedStatement = new byte[signedStatementSize];
enclaveReportPackageBuffer.get(signedStatement, 0, signedStatementSize);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.sql.SQLException;
import java.sql.Statement;

Expand Down Expand Up @@ -88,17 +89,25 @@ public void testParameterMetaDataCache() throws Exception {
@Tag(Constants.xSQLv14)
@Tag(Constants.reqExternalSetup)
public void testParameterMetaDataCacheTrim() throws Exception {
Field cacheSize = Class.forName("com.microsoft.sqlserver.jdbc.ParameterMetaDataCache")
.getDeclaredField("CACHE_SIZE");
Field maximumWeightedCapacity = Class.forName("com.microsoft.sqlserver.jdbc.ParameterMetaDataCache")
.getDeclaredField("MAX_WEIGHTED_CAPACITY");

cacheSize.setAccessible(true);
maximumWeightedCapacity.setAccessible(true);

cacheSize.set(cacheSize.get(Class.forName("com.microsoft.sqlserver.jdbc.ParameterMetaDataCache")), 0);
maximumWeightedCapacity.set(
maximumWeightedCapacity.get(Class.forName("com.microsoft.sqlserver.jdbc.ParameterMetaDataCache")), 0);
// changing static final values does not work after java 17
try {
Field modifiers = Field.class.getDeclaredField("modifiers");
modifiers.setAccessible(true);

Field cacheSize = Class.forName("com.microsoft.sqlserver.jdbc.ParameterMetaDataCache")
.getDeclaredField("CACHE_SIZE");
modifiers.setInt(cacheSize, cacheSize.getModifiers() & ~Modifier.FINAL);
cacheSize.setAccessible(true);
cacheSize.set(cacheSize.get(Class.forName("com.microsoft.sqlserver.jdbc.ParameterMetaDataCache")), 0);

Field maximumWeightedCapacity = Class.forName("com.microsoft.sqlserver.jdbc.ParameterMetaDataCache")
.getDeclaredField("MAX_WEIGHTED_CAPACITY");
modifiers.setInt(maximumWeightedCapacity, maximumWeightedCapacity.getModifiers() & ~Modifier.FINAL);
maximumWeightedCapacity.setAccessible(true);
maximumWeightedCapacity.set(
maximumWeightedCapacity.get(Class.forName("com.microsoft.sqlserver.jdbc.ParameterMetaDataCache")),
0);
} catch (Exception NoSuchFieldException) {}

try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString);
Statement stmt = con.createStatement()) {
Expand Down

0 comments on commit 27f6680

Please sign in to comment.