summaryrefslogtreecommitdiff
path: root/tests/support
diff options
context:
space:
mode:
authorOran Agra <oran@redislabs.com>2022-08-22 15:53:56 +0800
committerOran Agra <oran@redislabs.com>2022-08-23 12:37:56 +0300
commit4faddf18ca8ca3adb93cf1e4e620be9eaf0f6bf4 (patch)
treec2b70793b7052e4464d92849a21d308600ae7767 /tests/support
parent89e11486880a59dad3857499e69e54c0b27be689 (diff)
downloadredis-4faddf18ca8ca3adb93cf1e4e620be9eaf0f6bf4.tar.gz
Build TLS as a loadable module
* Support BUILD_TLS=module to be loaded as a module via config file or command line. e.g. redis-server --loadmodule redis-tls.so * Updates to redismodule.h to allow it to be used side by side with server.h by defining REDISMODULE_CORE_MODULE * Changes to server.h, redismodule.h and module.c to avoid repeated type declarations (gcc 4.8 doesn't like these) * Add a mechanism for non-ABI neutral modules (ones who include server.h) to refuse loading if they detect not being built together with redis (release.c) * Fix wrong signature of RedisModuleDefragFunc, this could break compilation of a module, but not the ABI * Move initialization of listeners in server.c to be after loading the modules * Config TLS after initialization of listeners * Init cluster after initialization of listeners * Add TLS module to CI * Fix a test suite race conditions: Now that the listeners are initialized later, it's not sufficient to wait for the PID message in the log, we need to wait for the "Server Initialized" message. * Fix issues with moduleconfigs test as a result from start_server waiting for "Server Initialized" * Fix issues with modules/infra test as a result of an additional module present Notes about Sentinel: Sentinel can't really rely on the tls module, since it uses hiredis to initiate connections and depends on OpenSSL (won't be able to use any other connection modules for that), so it was decided that when TLS is built as a module, sentinel does not support TLS at all. This means that it keeps using redis_tls_ctx and redis_tls_client_ctx directly. Example code of config in redis-tls.so(may be use in the future): RedisModuleString *tls_cfg = NULL; void tlsInfo(RedisModuleInfoCtx *ctx, int for_crash_report) { UNUSED(for_crash_report); RedisModule_InfoAddSection(ctx, ""); RedisModule_InfoAddFieldLongLong(ctx, "var", 42); } int tlsCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) { if (argc != 2) return RedisModule_WrongArity(ctx); return RedisModule_ReplyWithString(ctx, argv[1]); } RedisModuleString *getStringConfigCommand(const char *name, void *privdata) { REDISMODULE_NOT_USED(name); REDISMODULE_NOT_USED(privdata); return tls_cfg; } int setStringConfigCommand(const char *name, RedisModuleString *new, void *privdata, RedisModuleString **err) { REDISMODULE_NOT_USED(name); REDISMODULE_NOT_USED(err); REDISMODULE_NOT_USED(privdata); if (tls_cfg) RedisModule_FreeString(NULL, tls_cfg); RedisModule_RetainString(NULL, new); tls_cfg = new; return REDISMODULE_OK; } int RedisModule_OnLoad(void *ctx, RedisModuleString **argv, int argc) { .... if (RedisModule_CreateCommand(ctx,"tls",tlsCommand,"",0,0,0) == REDISMODULE_ERR) return REDISMODULE_ERR; if (RedisModule_RegisterStringConfig(ctx, "cfg", "", REDISMODULE_CONFIG_DEFAULT, getStringConfigCommand, setStringConfigCommand, NULL, NULL) == REDISMODULE_ERR) return REDISMODULE_ERR; if (RedisModule_LoadConfigs(ctx) == REDISMODULE_ERR) { if (tls_cfg) { RedisModule_FreeString(ctx, tls_cfg); tls_cfg = NULL; } return REDISMODULE_ERR; } ... } Co-authored-by: zhenwei pi <pizhenwei@bytedance.com> Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
Diffstat (limited to 'tests/support')
-rw-r--r--tests/support/server.tcl5
-rw-r--r--tests/support/util.tcl22
2 files changed, 26 insertions, 1 deletions
diff --git a/tests/support/server.tcl b/tests/support/server.tcl
index b673b70ae..6cc846b97 100644
--- a/tests/support/server.tcl
+++ b/tests/support/server.tcl
@@ -300,7 +300,7 @@ proc wait_server_started {config_file stdout pid} {
set maxiter [expr {120*1000/$checkperiod}] ; # Wait up to 2 minutes.
set port_busy 0
while 1 {
- if {[regexp -- " PID: $pid" [exec cat $stdout]]} {
+ if {[regexp -- " PID: $pid.*Server initialized" [exec cat $stdout]]} {
break
}
after $checkperiod
@@ -464,6 +464,9 @@ proc start_server {options {code undefined}} {
set data [split [exec cat "tests/assets/$baseconfig"] "\n"]
set config {}
if {$::tls} {
+ if {$::tls_module} {
+ lappend config_lines [list "loadmodule" [format "%s/src/redis-tls.so" [pwd]]]
+ }
dict set config "tls-cert-file" [format "%s/tests/tls/server.crt" [pwd]]
dict set config "tls-key-file" [format "%s/tests/tls/server.key" [pwd]]
dict set config "tls-client-cert-file" [format "%s/tests/tls/client.crt" [pwd]]
diff --git a/tests/support/util.tcl b/tests/support/util.tcl
index 8153ad8bb..c7aef0f50 100644
--- a/tests/support/util.tcl
+++ b/tests/support/util.tcl
@@ -1039,3 +1039,25 @@ proc memory_usage {key} {
}
return $usage
}
+
+# forward compatibility, lmap missing in TCL 8.5
+proc lmap args {
+ set body [lindex $args end]
+ set args [lrange $args 0 end-1]
+ set n 0
+ set pairs [list]
+ foreach {varnames listval} $args {
+ set varlist [list]
+ foreach varname $varnames {
+ upvar 1 $varname var$n
+ lappend varlist var$n
+ incr n
+ }
+ lappend pairs $varlist $listval
+ }
+ set temp [list]
+ foreach {*}$pairs {
+ lappend temp [uplevel 1 $body]
+ }
+ set temp
+}