Skip to content

Commit c6a0122

Browse files
authored
Merge pull request #2386 from RedisInsight/be/bugfix/RI-4699_dangerous_rule_not_connected
#RI-4699 - 500 error on connecting to user with -@dangerous rule
2 parents 90c9fe0 + 677e01b commit c6a0122

File tree

2 files changed

+40
-24
lines changed

2 files changed

+40
-24
lines changed

redisinsight/api/src/modules/database/providers/database-info.provider.spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,18 @@ describe('DatabaseInfoProvider', () => {
370370
nodes: [mockRedisGeneralInfo, mockRedisGeneralInfo],
371371
});
372372
});
373+
it('should throw an error if no permission to run \'info\' command', async () => {
374+
mockIORedisClient.info.mockRejectedValue({
375+
message: 'NOPERM this user has no permissions to run the \'info\' command'
376+
});
377+
378+
try {
379+
await service.getRedisGeneralInfo(mockIORedisClient);
380+
fail('Should throw an error');
381+
} catch (err) {
382+
expect(err).toBeInstanceOf(ForbiddenException);
383+
}
384+
});
373385
});
374386

375387
describe('getMasterEndpoints', () => {

redisinsight/api/src/modules/database/providers/database-info.provider.ts

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -216,30 +216,34 @@ export class DatabaseInfoProvider {
216216
private async getRedisNodeGeneralInfo(
217217
client: IORedis.Redis,
218218
): Promise<RedisDatabaseInfoResponse> {
219-
const info = convertRedisInfoReplyToObject(
220-
await client.info(),
221-
);
222-
const serverInfo = info['server'];
223-
const memoryInfo = info['memory'];
224-
const keyspaceInfo = info['keyspace'];
225-
const clientsInfo = info['clients'];
226-
const statsInfo = info['stats'];
227-
const replicationInfo = info['replication'];
228-
const databases = await this.getDatabasesCount(client, keyspaceInfo);
229-
return {
230-
version: serverInfo?.redis_version,
231-
databases,
232-
role: get(replicationInfo, 'role') || undefined,
233-
totalKeys: this.getRedisNodeTotalKeysCount(keyspaceInfo),
234-
usedMemory: parseInt(get(memoryInfo, 'used_memory'), 10) || undefined,
235-
connectedClients:
236-
parseInt(get(clientsInfo, 'connected_clients'), 10) || undefined,
237-
uptimeInSeconds:
238-
parseInt(get(serverInfo, 'uptime_in_seconds'), 10) || undefined,
239-
hitRatio: this.getRedisHitRatio(statsInfo),
240-
cashedScripts: parseInt(get(memoryInfo, 'number_of_cached_scripts'), 10) || undefined,
241-
server: serverInfo,
242-
};
219+
try {
220+
const info = convertRedisInfoReplyToObject(
221+
await client.info(),
222+
);
223+
const serverInfo = info['server'];
224+
const memoryInfo = info['memory'];
225+
const keyspaceInfo = info['keyspace'];
226+
const clientsInfo = info['clients'];
227+
const statsInfo = info['stats'];
228+
const replicationInfo = info['replication'];
229+
const databases = await this.getDatabasesCount(client, keyspaceInfo);
230+
return {
231+
version: serverInfo?.redis_version,
232+
databases,
233+
role: get(replicationInfo, 'role') || undefined,
234+
totalKeys: this.getRedisNodeTotalKeysCount(keyspaceInfo),
235+
usedMemory: parseInt(get(memoryInfo, 'used_memory'), 10) || undefined,
236+
connectedClients:
237+
parseInt(get(clientsInfo, 'connected_clients'), 10) || undefined,
238+
uptimeInSeconds:
239+
parseInt(get(serverInfo, 'uptime_in_seconds'), 10) || undefined,
240+
hitRatio: this.getRedisHitRatio(statsInfo),
241+
cashedScripts: parseInt(get(memoryInfo, 'number_of_cached_scripts'), 10) || undefined,
242+
server: serverInfo,
243+
};
244+
} catch (error) {
245+
throw catchAclError(error);
246+
}
243247
}
244248

245249
private async getRedisMasterNodesGeneralInfo(

0 commit comments

Comments
 (0)