diff options
author | Yossi Gottlieb <yossigo@gmail.com> | 2020-10-11 17:11:42 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-11 17:11:42 +0300 |
commit | 0aec98dce2acbd280ad8ff4feac631e8afa833b1 (patch) | |
tree | aea73b0fa5b0f78108533384fa04604b5b82f637 /tests | |
parent | 907da0580b57013c9e5c38b27f351597c72e4e25 (diff) | |
download | redis-0aec98dce2acbd280ad8ff4feac631e8afa833b1.tar.gz |
Module API: Add RM_GetClientCertificate(). (#7866)
This API function makes it possible to retrieve the X.509 certificate
used by clients to authenticate TLS connections.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/modules/misc.c | 19 | ||||
-rw-r--r-- | tests/unit/moduleapi/misc.tcl | 10 |
2 files changed, 29 insertions, 0 deletions
diff --git a/tests/modules/misc.c b/tests/modules/misc.c index a43bb84ac..621b92b2d 100644 --- a/tests/modules/misc.c +++ b/tests/modules/misc.c @@ -195,6 +195,23 @@ int test_setlfu(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) return REDISMODULE_OK; } +int test_getclientcert(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) +{ + (void) argv; + (void) argc; + + RedisModuleString *cert = RedisModule_GetClientCertificate(ctx, + RedisModule_GetClientId(ctx)); + if (!cert) { + RedisModule_ReplyWithNull(ctx); + } else { + RedisModule_ReplyWithString(ctx, cert); + RedisModule_FreeString(ctx, cert); + } + + return REDISMODULE_OK; +} + int test_clientinfo(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) { (void) argv; @@ -283,6 +300,8 @@ int RedisModule_OnLoad(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) return REDISMODULE_ERR; if (RedisModule_CreateCommand(ctx,"test.clientinfo", test_clientinfo,"",0,0,0) == REDISMODULE_ERR) return REDISMODULE_ERR; + if (RedisModule_CreateCommand(ctx,"test.getclientcert", test_getclientcert,"",0,0,0) == REDISMODULE_ERR) + return REDISMODULE_ERR; if (RedisModule_CreateCommand(ctx,"test.log_tsctx", test_log_tsctx,"",0,0,0) == REDISMODULE_ERR) return REDISMODULE_ERR; diff --git a/tests/unit/moduleapi/misc.tcl b/tests/unit/moduleapi/misc.tcl index 2c9ac4fd0..e825f33ff 100644 --- a/tests/unit/moduleapi/misc.tcl +++ b/tests/unit/moduleapi/misc.tcl @@ -87,6 +87,16 @@ start_server {tags {"modules"}} { assert { [dict get $info flags] == "${ssl_flag}::tracking::" } } + test {test module getclientcert api} { + set cert [r test.getclientcert] + + if {$::tls} { + assert {$cert != ""} + } else { + assert {$cert == ""} + } + } + test {test detached thread safe cnotext} { r test.log_tsctx "info" "Test message" verify_log_message 0 "*<misc> Test message*" 0 |