1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-09 00:22:08 +03:00

DOC-4423: add TCEs for various command pages (#2885)

* DOC-4423: add TCEs for various command pages

* fix problematic doctest

from redis docs for ACL DELUSER:
Delete all the specified ACL users and terminate all the connections
 that are authenticated with such users

Nodejs complains: Warning: Detected unsettled top-level await
which in turn gives the error code 13 in the workflow

await client.auth({ username: 'test-user' ...});
// deleting the user that is currently logged in -> bad
await client.sendCommand(['ACL', 'DELUSER', 'test-user']);
await client.quit()

fix: authenticate with the default user before deleting the test-user

---------

Co-authored-by: Nikolay Karadzhov <nkaradzhov89@gmail.com>
This commit is contained in:
David Dougherty
2025-04-22 07:50:35 -07:00
committed by GitHub
parent 001087f520
commit cb26059e5d
5 changed files with 306 additions and 1 deletions

49
doctests/cmds-cnxmgmt.js Normal file
View File

@@ -0,0 +1,49 @@
// EXAMPLE: cmds_cnxmgmt
// REMOVE_START
import assert from "node:assert";
// REMOVE_END
// HIDE_START
import { createClient } from 'redis';
const client = createClient();
await client.connect().catch(console.error);
// HIDE_END
// STEP_START auth1
// REMOVE_START
await client.sendCommand(['CONFIG', 'SET', 'requirepass', 'temp_pass']);
// REMOVE_END
const res1 = await client.auth({ password: 'temp_pass' });
console.log(res1); // OK
const res2 = await client.auth({ username: 'default', password: 'temp_pass' });
console.log(res2); // OK
// REMOVE_START
assert.equal(res1, "OK");
assert.equal(res2, "OK");
await client.sendCommand(['CONFIG', 'SET', 'requirepass', '']);
// REMOVE_END
// STEP_END
// STEP_START auth2
// REMOVE_START
await client.sendCommand([
'ACL', 'SETUSER', 'test-user',
'on', '>strong_password', '+acl'
]);
// REMOVE_END
const res3 = await client.auth({ username: 'test-user', password: 'strong_password' });
console.log(res3); // OK
// REMOVE_START
assert.equal(res3, "OK");
await client.auth({ username: 'default', password: '' })
await client.sendCommand(['ACL', 'DELUSER', 'test-user']);
// REMOVE_END
// STEP_END
// HIDE_START
await client.quit();
// HIDE_END