# ------------------------------------------------------------------- # task.check – Redis configuration validator # ------------------------------------------------------------------- # Soft checks scan for specific config keywords and hand over captured # values to Python generators that print assert: conditions. # ------------------------------------------------------------------- # ------------------------------------------------------------------- # 1. bind directive # ------------------------------------------------------------------- note: bind – the server should listen on loopback only regexp: ^^ \s* bind \s+ (.+) \s* $$ generator: <= 8 state = get_state() state['requirepass_set'] = True update_state(state) print(f"assert: {1 if ok else 0} requirepass length >= 8, got {len(pwd)} chars") CODE # ------------------------------------------------------------------- # 6. dir (working directory) # ------------------------------------------------------------------- note: dir – working directory must be specified regexp: ^^ \s* dir \s+ (.+) \s* $$ generator: < 0 print(f"assert: {1 if ok else 0} dir must be non-empty, got '{path}'") CODE # ------------------------------------------------------------------- # 7. dbfilename # ------------------------------------------------------------------- note: dbfilename – RDB filename should be set regexp: ^^ \s* dbfilename \s+ (.+) \s* $$ generator: < 0 print(f"assert: {1 if ok else 0} dbfilename must be non-empty, got '{name}'") CODE # ------------------------------------------------------------------- # 8. save (RDB snapshot policy) # ------------------------------------------------------------------- note: save – RDB save policy should be defined regexp: ^^ \s* save \s+ (.+) \s* $$ generator: < 0 print(f"assert: {1 if ok else 0} save policy defined, got '{args}'") CODE # ------------------------------------------------------------------- # 9. maxmemory # ------------------------------------------------------------------- note: maxmemory – a memory limit should be set regexp: ^^ \s* maxmemory \s+ (.+) \s* $$ generator: < 0 print(f"assert: {1 if ok else 0} maxmemory set, got '{val}'") CODE # ------------------------------------------------------------------- # 10. maxmemory-policy # ------------------------------------------------------------------- note: maxmemory-policy – must be a recognised eviction policy regexp: ^^ \s* maxmemory\-policy \s+ ([\w\-]+) \s* $$ generator: < 0 print(f"assert: {1 if ok else 0} logfile must be non-empty, got '{path}'") CODE # ------------------------------------------------------------------- # 12. tcp-keepalive # ------------------------------------------------------------------- note: tcp-keepalive – should be a positive number regexp: ^^ \s* tcp\-keepalive \s+ (\d+) \s* $$ generator: < 0 print(f"assert: {1 if ok else 0} tcp-keepalive > 0, got {val}") CODE # ------------------------------------------------------------------- # 13. include directive # ------------------------------------------------------------------- note: include – optional, but paths must be non-empty regexp: ^^ \s* include \s+ (.+) \s* $$ generator: < 0 print(f"assert: {1 if ok else 0} include path valid, got '{path}'") CODE # ------------------------------------------------------------------- # 14. loadmodule directive # ------------------------------------------------------------------- note: loadmodule – optional, but path must be non-empty regexp: ^^ \s* loadmodule \s+ (.+) \s* $$ generator: < 0 print(f"assert: {1 if ok else 0} loadmodule path valid, got '{path}'") CODE # ------------------------------------------------------------------- # 15. replicaof directive # ------------------------------------------------------------------- note: replicaof – if present, must supply master host and port regexp: ^^ \s* replicaof \s+ (.+) \s+ (\d+) \s* $$ generator: < 0 and 1 <= port <= 65535 print(f"assert: {1 if ok else 0} replicaof {host}:{port} valid") CODE # ------------------------------------------------------------------- # 16. masterauth directive # ------------------------------------------------------------------- note: masterauth – if replicaof is used, masterauth should be set regexp: ^^ \s* masterauth \s+ (.+) \s* $$ generator: < 0 print(f"assert: {1 if ok else 0} masterauth set, got {len(auth)} chars") CODE # ------------------------------------------------------------------- # 17. ACL file directive # ------------------------------------------------------------------- note: aclfile – if ACLs are enabled, path must be valid regexp: ^^ \s* aclfile \s+ (.+) \s* $$ generator: < 0 print(f"assert: {1 if ok else 0} aclfile path valid, got '{path}'") CODE # ------------------------------------------------------------------- # 18. ACL user definitions (simplified check) # ------------------------------------------------------------------- note: user – ACL user definitions must have a valid status (on|off) regexp: ^^ \s* user \s+ \S+ \s+ (on|off) \s* $$ generator: < 0 print(f"assert: {1 if ok else 0} databases > 0, got {num}") CODE # ------------------------------------------------------------------- # 20. timeout directive # ------------------------------------------------------------------- note: timeout – client idle timeout should be a non-negative integer regexp: ^^ \s* timeout \s+ (\d+) \s* $$ generator: <= 0 print(f"assert: {1 if ok else 0} timeout >= 0, got {val}") CODE # ------------------------------------------------------------------- # 21. stop-writes-on-bgsave-error # ------------------------------------------------------------------- note: stop-writes-on-bgsave-error – should normally be yes regexp: ^^ \s* stop\-writes\-on\-bgsave\-error \s+ (yes|no) \s* $$ generator: <