Skip to content
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

Upgraded third-party dependencies to the latest versions and fixed CVE vulnerabilities #34409

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 5 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
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@
import org.apache.shardingsphere.encrypt.rewrite.token.generator.fixture.EncryptGeneratorFixtureBuilder;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.binder.context.statement.dml.InsertStatementContext;
import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.subquery.SubquerySegment;
import org.junit.jupiter.api.Test;

import java.util.Collections;
import java.util.Optional;

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertFalse;
Expand All @@ -38,7 +40,7 @@ class EncryptInsertSelectSupportedCheckerTest {
@Test
void assertIsCheck() {
InsertStatementContext sqlStatementContext = mock(InsertStatementContext.class, RETURNS_DEEP_STUBS);
when(sqlStatementContext.getSqlStatement().getInsertSelect().isPresent()).thenReturn(true);
when(sqlStatementContext.getSqlStatement().getInsertSelect()).thenReturn(Optional.of(mock(SubquerySegment.class)));
Copy link
Member

Choose a reason for hiding this comment

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

  • Why does updating some third-party dependencies cause a large number of unit tests to change? Where is the original issue?

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 new version of mock will prompt that the thenReturn type is wrong, and Optional.of(mock(SubquerySegment.class)) is required to return

Copy link
Member

Choose a reason for hiding this comment

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

This involves a problem. The new version of mockito does not support JDK8, so it makes no sense to do so.

assertTrue(new EncryptInsertSelectSupportedChecker().isCheck(sqlStatementContext));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.shardingsphere.encrypt.checker.sql.projection;

import org.apache.shardingsphere.encrypt.rule.EncryptRule;
import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
import org.apache.shardingsphere.infra.binder.context.segment.select.projection.impl.ColumnProjection;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.binder.context.statement.dml.SelectStatementContext;
Expand Down Expand Up @@ -76,8 +77,13 @@ void assertCheckWhenShorthandExpandContainsSubqueryTable() {

@Test
void assertCheckWhenCombineStatementContainsEncryptColumn() {
EncryptRule encryptRule = mock(EncryptRule.class, RETURNS_DEEP_STUBS);
when(encryptRule.findQueryEncryptor("foo_tbl", "foo_col_1")).thenReturn(Optional.of(mock(EncryptAlgorithm.class)));
when(encryptRule.findQueryEncryptor("foo_tbl", "foo_col_2")).thenReturn(Optional.of(mock(EncryptAlgorithm.class)));
when(encryptRule.findQueryEncryptor("bar_tbl", "bar_col_1")).thenReturn(Optional.of(mock(EncryptAlgorithm.class)));
when(encryptRule.findQueryEncryptor("bar_tbl", "bar_col_2")).thenReturn(Optional.of(mock(EncryptAlgorithm.class)));
SelectStatementContext sqlStatementContext = mockSelectStatementContext();
assertThrows(UnsupportedSQLOperationException.class, () -> new EncryptSelectProjectionSupportedChecker().check(mock(EncryptRule.class, RETURNS_DEEP_STUBS), null, null, sqlStatementContext));
assertThrows(UnsupportedSQLOperationException.class, () -> new EncryptSelectProjectionSupportedChecker().check(encryptRule, null, null, sqlStatementContext));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@
import org.apache.shardingsphere.encrypt.rewrite.token.generator.fixture.EncryptGeneratorFixtureBuilder;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.binder.context.statement.dml.SelectStatementContext;
import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.WithSegment;
import org.junit.jupiter.api.Test;

import java.util.Collections;
import java.util.Optional;

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertFalse;
Expand All @@ -38,7 +40,7 @@ class EncryptWithClauseSupportedCheckerTest {
@Test
void assertIsCheck() {
SelectStatementContext sqlStatementContext = mock(SelectStatementContext.class, RETURNS_DEEP_STUBS);
when(sqlStatementContext.getWith().isPresent()).thenReturn(true);
when(sqlStatementContext.getWith()).thenReturn(Optional.of(mock(WithSegment.class)));
assertTrue(new EncryptWithClauseSupportedChecker().isCheck(sqlStatementContext));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.apache.shardingsphere.encrypt.rule.column.EncryptColumn;
import org.apache.shardingsphere.encrypt.rule.table.EncryptTable;
import org.apache.shardingsphere.infra.binder.context.segment.table.TablesContext;
import org.apache.shardingsphere.infra.database.h2.type.H2DatabaseType;
import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.assignment.ColumnAssignmentSegment;
import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.assignment.SetAssignmentSegment;
import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.simple.LiteralExpressionSegment;
Expand Down Expand Up @@ -57,7 +58,7 @@ class EncryptAssignmentTokenGeneratorTest {

@BeforeEach
void setup() {
tokenGenerator = new EncryptAssignmentTokenGenerator(mockEncryptRule(), null, null);
tokenGenerator = new EncryptAssignmentTokenGenerator(mockEncryptRule(), "testDataBaseName", new H2DatabaseType());
when(tablesContext.getSimpleTables().iterator().next().getTableName().getIdentifier().getValue()).thenReturn("table");
when(assignmentSegment.getColumns().get(0).getIdentifier().getValue()).thenReturn("columns");
when(setAssignmentSegment.getAssignments()).thenReturn(Collections.singleton(assignmentSegment));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private EncryptRule mockEncryptRule() {
EncryptColumn encryptColumn = mock(EncryptColumn.class, RETURNS_DEEP_STUBS);
when(encryptColumn.getAssistedQuery()).thenReturn(Optional.empty());
when(encryptTable1.getEncryptColumn("mobile")).thenReturn(encryptColumn);
when(result.findEncryptTable("t_order").isPresent()).thenReturn(true);
when(result.findEncryptTable("t_order")).thenReturn(Optional.of(mock(EncryptTable.class)));
when(result.getEncryptTable("t_order").isEncryptColumn("order_id")).thenReturn(true);
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ void assertRetrieveWithColumnOwner() {
when(columnSegment.getColumnBoundInfo().getOriginalTable().getValue()).thenReturn("foo_tbl");
OwnerSegment ownerSegment = new OwnerSegment(0, 0, new IdentifierValue("foo"));
ownerSegment.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema")));
when(columnSegment.getOwner()).thenReturn(Optional.of(ownerSegment));
when(ColumnExtractor.extract(expressionSegment)).thenReturn(Collections.singleton(columnSegment));
when(ShadowExtractor.extractValues(expressionSegment, Collections.singletonList("foo"))).thenReturn(Optional.of(Collections.singleton("foo")));
when(sqlStatementContext.getTablesContext().getTableNames()).thenReturn(Collections.singleton("foo_tbl"));
Expand All @@ -81,7 +80,6 @@ void assertRetrieveWithoutColumnOwner() {
when(sqlStatementContext.getWhereSegments()).thenReturn(Arrays.asList(whereSegment, mock(WhereSegment.class, RETURNS_DEEP_STUBS)));
ColumnSegment columnSegment = mock(ColumnSegment.class, RETURNS_DEEP_STUBS);
when(columnSegment.getColumnBoundInfo().getOriginalTable().getValue()).thenReturn("foo_tbl");
when(columnSegment.getOwner()).thenReturn(Optional.empty());
when(ColumnExtractor.extract(expressionSegment)).thenReturn(Collections.singleton(columnSegment));
when(ShadowExtractor.extractValues(expressionSegment, Collections.singletonList("foo"))).thenReturn(Optional.of(Collections.singleton("foo")));
when(sqlStatementContext.getTablesContext().getTableNames()).thenReturn(Collections.singleton("foo_tbl"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ void assertRangeDoShardingByDays() {
"SQL Date values do not have a time component.");
assertThat(createAlgorithm("yyyy-MM-dd", "2021-06-01",
"2021-07-31", "yyyyMMdd", stepAmount, null)
.doSharding(availableTargetNames, shardingValueAsSqlDate).size(),
.doSharding(availableTargetNames, shardingValueAsSqlDate).size(),
is(expectSize));
final RangeShardingValue<Comparable<?>> shardingValueAsString = createShardingValue(
DateTimeFormatterFactory.getStandardFormatter().format(lower),
Expand All @@ -252,8 +252,8 @@ void assertRangeDoShardingByDaysInLocalDate() {
}
Collection<String> actualAsLocalDate = createAlgorithm("yyyy-MM-dd", "2021-06-01",
"2021-07-31", "yyyyMMdd", stepAmount, null)
.doSharding(availableTargetNames,
createShardingValue(LocalDate.of(2021, 6, 15), LocalDate.of(2021, 7, 31)));
.doSharding(availableTargetNames,
createShardingValue(LocalDate.of(2021, 6, 15), LocalDate.of(2021, 7, 31)));
assertThat(actualAsLocalDate.size(), is(24));
}

Expand Down Expand Up @@ -283,7 +283,7 @@ void assertRangeDoShardingByYears() {
}
Collection<String> actual = createAlgorithm("yyyy", "2000",
"2022", "yyyy", 2, "Years")
.doSharding(availableTargetNames, createShardingValue(Year.of(2001), Year.of(2013)));
.doSharding(availableTargetNames, createShardingValue(Year.of(2001), Year.of(2013)));
assertThat(actual.size(), is(7));
}

Expand All @@ -297,8 +297,8 @@ void assertRangeDoShardingByYearsInYearMonth() {
}
Collection<String> actualAsYearMonth = createAlgorithm("yyyy-MM", "2016-01",
"2021-12", "yyyyMM", 2, "Years")
.doSharding(availableTargetNames,
createShardingValue(YearMonth.of(2016, 1), YearMonth.of(2020, 1)));
.doSharding(availableTargetNames,
createShardingValue(YearMonth.of(2016, 1), YearMonth.of(2020, 1)));
assertThat(actualAsYearMonth.size(), is(3));
}

Expand Down Expand Up @@ -329,7 +329,7 @@ private IntervalShardingAlgorithm createAlgorithm(final String datetimePattern,
new Property("sharding-suffix-pattern", shardingSuffixPattern),
new Property("datetime-interval-amount", Integer.toString(datetimeIntervalAmount)));
if (null != datetimeIntervalUnit) {
props.put("datetime-interval-unit", datetimeIntervalUnit);
props.setProperty("datetime-interval-unit", datetimeIntervalUnit);
}
return (IntervalShardingAlgorithm) TypedSPILoader.getService(ShardingAlgorithm.class, "INTERVAL", props);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ class ShardingDALResultMergerTest {

@Test
void assertMergeForShowDatabasesStatement() throws SQLException {
SQLStatementContext sqlStatementContext = mockSQLStatementContext(new MySQLShowDatabasesStatement());
SQLStatementContext sqlStatementContext = mock(SQLStatementContext.class, withSettings().extraInterfaces(TableAvailable.class).defaultAnswer(RETURNS_DEEP_STUBS));
when(sqlStatementContext.getSqlStatement()).thenReturn(new MySQLShowDatabasesStatement());
when(sqlStatementContext.getDatabaseType()).thenReturn(databaseType);
assertThat(resultMerger.merge(queryResults, sqlStatementContext, mock(), mock()), instanceOf(LocalDataMergedResult.class));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.apache.shardingsphere.infra.binder.context.statement.CommonSQLStatementContext;
import org.apache.shardingsphere.infra.binder.context.statement.dml.InsertStatementContext;
import org.apache.shardingsphere.infra.binder.context.statement.dml.SelectStatementContext;
import org.apache.shardingsphere.infra.binder.context.type.TableAvailable;
import org.apache.shardingsphere.infra.hint.HintValueContext;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema;
Expand All @@ -39,6 +38,7 @@
import org.mockito.quality.Strictness;

import java.util.Collections;
import java.util.Optional;

import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.MatcherAssert.assertThat;
Expand Down Expand Up @@ -81,7 +81,7 @@ void setUp() {
@Test
void assertInsertStatementContext() {
InsertStatementContext statementContext = mock(InsertStatementContext.class, RETURNS_DEEP_STUBS);
when(((TableAvailable) statementContext).getTablesContext().getDatabaseName().isPresent()).thenReturn(false);
when(statementContext.getTablesContext().getDatabaseName()).thenReturn(Optional.empty());
when(statementContext.getInsertSelectContext()).thenReturn(null);
QueryContext queryContext = mock(QueryContext.class, RETURNS_DEEP_STUBS);
when(queryContext.getSqlStatementContext()).thenReturn(statementContext);
Expand All @@ -95,7 +95,7 @@ void assertInsertStatementContext() {
@Test
void assertNotInsertStatementContext() {
SelectStatementContext statementContext = mock(SelectStatementContext.class, RETURNS_DEEP_STUBS);
when(((TableAvailable) statementContext).getTablesContext().getDatabaseName().isPresent()).thenReturn(false);
when(statementContext.getTablesContext().getDatabaseName()).thenReturn(Optional.empty());
QueryContext queryContext = mock(QueryContext.class, RETURNS_DEEP_STUBS);
when(queryContext.getSqlStatementContext()).thenReturn(statementContext);
when(queryContext.getSql()).thenReturn("SELECT * FROM tbl WHERE id = ?");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.apache.shardingsphere.infra.binder.context.statement.CommonSQLStatementContext;
import org.apache.shardingsphere.infra.binder.context.statement.dml.InsertStatementContext;
import org.apache.shardingsphere.infra.binder.context.statement.dml.SelectStatementContext;
import org.apache.shardingsphere.infra.binder.context.type.TableAvailable;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.infra.datanode.DataNode;
import org.apache.shardingsphere.infra.hint.HintValueContext;
Expand All @@ -41,6 +40,7 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.Map;
import java.util.Optional;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
Expand Down Expand Up @@ -113,7 +113,7 @@ void assertRewriteWithStandardParameterBuilderWhenNeedAggregateRewrite() {
@Test
void assertRewriteWithGroupedParameterBuilderForBroadcast() {
InsertStatementContext statementContext = mock(InsertStatementContext.class, RETURNS_DEEP_STUBS);
when(((TableAvailable) statementContext).getTablesContext().getDatabaseName().isPresent()).thenReturn(false);
when(statementContext.getTablesContext().getDatabaseName()).thenReturn(Optional.of("testDataBaseName"));
when(statementContext.getInsertSelectContext()).thenReturn(null);
when(statementContext.getGroupedParameters()).thenReturn(Collections.singletonList(Collections.singletonList(1)));
when(statementContext.getOnDuplicateKeyUpdateParameters()).thenReturn(Collections.emptyList());
Expand All @@ -135,7 +135,7 @@ void assertRewriteWithGroupedParameterBuilderForBroadcast() {
@Test
void assertRewriteWithGroupedParameterBuilderForRouteWithSameDataNode() {
InsertStatementContext statementContext = mock(InsertStatementContext.class, RETURNS_DEEP_STUBS);
when(((TableAvailable) statementContext).getTablesContext().getDatabaseName().isPresent()).thenReturn(false);
when(statementContext.getTablesContext().getDatabaseName()).thenReturn(Optional.empty());
when(statementContext.getInsertSelectContext()).thenReturn(null);
when(statementContext.getGroupedParameters()).thenReturn(Collections.singletonList(Collections.singletonList(1)));
when(statementContext.getOnDuplicateKeyUpdateParameters()).thenReturn(Collections.emptyList());
Expand All @@ -159,7 +159,7 @@ void assertRewriteWithGroupedParameterBuilderForRouteWithSameDataNode() {
@Test
void assertRewriteWithGroupedParameterBuilderForRouteWithEmptyDataNode() {
InsertStatementContext statementContext = mock(InsertStatementContext.class, RETURNS_DEEP_STUBS);
when(((TableAvailable) statementContext).getTablesContext().getDatabaseName().isPresent()).thenReturn(false);
when(statementContext.getTablesContext().getDatabaseName()).thenReturn(Optional.empty());
when(statementContext.getInsertSelectContext()).thenReturn(null);
when(statementContext.getGroupedParameters()).thenReturn(Collections.singletonList(Collections.singletonList(1)));
when(statementContext.getOnDuplicateKeyUpdateParameters()).thenReturn(Collections.emptyList());
Expand All @@ -182,7 +182,7 @@ void assertRewriteWithGroupedParameterBuilderForRouteWithEmptyDataNode() {
@Test
void assertRewriteWithGroupedParameterBuilderForRouteWithNotSameDataNode() {
InsertStatementContext statementContext = mock(InsertStatementContext.class, RETURNS_DEEP_STUBS);
when(((TableAvailable) statementContext).getTablesContext().getDatabaseName().isPresent()).thenReturn(false);
when(statementContext.getTablesContext().getDatabaseName()).thenReturn(Optional.empty());
when(statementContext.getInsertSelectContext()).thenReturn(null);
when(statementContext.getGroupedParameters()).thenReturn(Collections.singletonList(Collections.singletonList(1)));
when(statementContext.getOnDuplicateKeyUpdateParameters()).thenReturn(Collections.emptyList());
Expand Down
Loading
Loading