This is an automated email from the ASF dual-hosted git repository.
lizhimins pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/rocketmq-dashboard.git
The following commit(s) were added to refs/heads/master by this push:
new 3b157f680 fix(consumer): reject an import batch above the backend
group cap (#6829)
3b157f680 is described below
commit 3b157f6801397c24e2d292fb3737cc4915bef64d
Author: Apulupie <[email protected]>
AuthorDate: Fri Nov 27 12:42:44 2026 +0800
fix(consumer): reject an import batch above the backend group cap (#6829)
---
web/src/services/consumerService.test.ts | 33 ++++++++++++++++++++++++++++++++
web/src/services/consumerService.ts | 7 +++++++
2 files changed, 40 insertions(+)
diff --git a/web/src/services/consumerService.test.ts
b/web/src/services/consumerService.test.ts
index aee2c601e..147298789 100644
--- a/web/src/services/consumerService.test.ts
+++ b/web/src/services/consumerService.test.ts
@@ -27,6 +27,7 @@ import {
getConsumerProgress,
getConsumerStack,
getConsumerSubscriptions,
+ importConsumerGroups,
listAllConsumerGroups,
listConsumerGroupPage,
listConsumerGroups,
@@ -660,3 +661,35 @@ describe('consumer group page mock pagination contract',
() => {
);
});
});
+
+describe('consumer group import batch contract', () => {
+ const batchOf = (prefix: string, count: number) =>
+ Array.from({ length: count }, (_, index) => ({ name: `${prefix}-${index}`
}));
+
+ it('rejects an import above the backend batch cap', async () => {
+ // MetadataService.importConsumerGroups answers 400 "At most 100 consumer
groups are allowed
+ // per import" for more than 100 groups; the CSV import path has no cap of
its own
+ // (resourceCsvImport.validateConsumerGroupCsvImport), so the mock must
not import a longer
+ // list row by row.
+ const batch = batchOf('mock-import-over-cap', 101);
+ await expect(importConsumerGroups('instance-direct-1',
batch)).rejects.toThrow(
+ 'At most 100 consumer groups are allowed per import',
+ );
+
+ const stored = await listConsumerGroups({ instanceId: 'instance-direct-1'
});
+ expect(stored.some((group) =>
group.name.startsWith('mock-import-over-cap'))).toBe(false);
+ });
+
+ it('imports a batch at the backend cap', async () => {
+ const batch = batchOf('mock-import-at-cap', 100);
+ try {
+ const result = await importConsumerGroups('instance-direct-1', batch);
+ expect(result.imported).toBe(100);
+ expect(result.failed).toBe(0);
+ } finally {
+ for (const group of batch) {
+ await deleteConsumerGroup(group.name, 'instance-direct-1');
+ }
+ }
+ });
+});
diff --git a/web/src/services/consumerService.ts
b/web/src/services/consumerService.ts
index 11bafe9d0..e21c43516 100644
--- a/web/src/services/consumerService.ts
+++ b/web/src/services/consumerService.ts
@@ -56,6 +56,7 @@ function hasActiveFixtureGroup(name: string, instanceId?:
string): boolean {
}
const EXPORT_PAGE_SIZE = 100;
const MAX_EXPORT_PAGES = 100;
+const MAX_IMPORT_GROUPS = 100;
const GROUP_EXPORT_COLUMNS: CsvColumn<ConsumerGroup>[] = [
{ header: 'Name', value: (group) => group.name },
{ header: 'Namespace', value: (group) => group.namespace },
@@ -363,6 +364,12 @@ export async function importConsumerGroups(
groups: Partial<ConsumerGroup>[],
): Promise<ImportConsumerGroupsResult> {
if (isMockMode()) {
+ // MetadataService.importConsumerGroups answers 400 "At most 100 consumer
groups are allowed
+ // per import" for more than 100 groups; the CSV import path sends every
pending row, so a
+ // longer list must fail here instead of being created row by row.
+ if (groups.length > MAX_IMPORT_GROUPS) {
+ throw new Error('At most 100 consumer groups are allowed per import');
+ }
const imported: ConsumerGroup[] = [];
const failures: ImportConsumerGroupsResult['failures'] = [];
for (const [index, group] of groups.entries()) {