diff options
author | Oran Agra <oran@redislabs.com> | 2022-04-27 16:32:17 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-27 16:32:17 +0300 |
commit | d375595d5e3ae2e5c29e6c00a2dc3d60578fd9fc (patch) | |
tree | c4d753d3ee0109e3513a879af8c5487e002d10a3 /tests/unit/cluster-scripting.tcl | |
parent | fb4e0d400ff82117104bde5296c477ad95f8dd41 (diff) | |
parent | c1f3020631ea8640f2b6aa666a245dd76635a807 (diff) | |
download | redis-7.0.0.tar.gz |
Merge pull request #10652 from oranagra/redis-7.0.07.0.0
Redis 7.0.0
Diffstat (limited to 'tests/unit/cluster-scripting.tcl')
-rw-r--r-- | tests/unit/cluster-scripting.tcl | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/tests/unit/cluster-scripting.tcl b/tests/unit/cluster-scripting.tcl new file mode 100644 index 000000000..72fc028c3 --- /dev/null +++ b/tests/unit/cluster-scripting.tcl @@ -0,0 +1,64 @@ +# make sure the test infra won't use SELECT +set old_singledb $::singledb +set ::singledb 1 + +start_server {overrides {cluster-enabled yes} tags {external:skip cluster}} { + r 0 cluster addslotsrange 0 16383 + wait_for_condition 50 100 { + [csi 0 cluster_state] eq "ok" + } else { + fail "Cluster never became 'ok'" + } + + test {Eval scripts with shebangs and functions default to no cross slots} { + # Test that scripts with shebang block cross slot operations + assert_error "ERR Script attempted to access keys that do not hash to the same slot*" { + r 0 eval {#!lua + redis.call('set', 'foo', 'bar') + redis.call('set', 'bar', 'foo') + return 'OK' + } 0} + + # Test the functions by default block cross slot operations + r 0 function load REPLACE {#!lua name=crossslot + local function test_cross_slot(keys, args) + redis.call('set', 'foo', 'bar') + redis.call('set', 'bar', 'foo') + return 'OK' + end + + redis.register_function('test_cross_slot', test_cross_slot)} + assert_error "ERR Script attempted to access keys that do not hash to the same slot*" {r FCALL test_cross_slot 0} + } + + test {Cross slot commands are allowed by default for eval scripts and with allow-cross-slot-keys flag} { + # Old style lua scripts are allowed to access cross slot operations + r 0 eval "redis.call('set', 'foo', 'bar'); redis.call('set', 'bar', 'foo')" 0 + + # scripts with allow-cross-slot-keys flag are allowed + r 0 eval {#!lua flags=allow-cross-slot-keys + redis.call('set', 'foo', 'bar'); redis.call('set', 'bar', 'foo') + } 0 + + # Functions with allow-cross-slot-keys flag are allowed + r 0 function load REPLACE {#!lua name=crossslot + local function test_cross_slot(keys, args) + redis.call('set', 'foo', 'bar') + redis.call('set', 'bar', 'foo') + return 'OK' + end + + redis.register_function{function_name='test_cross_slot', callback=test_cross_slot, flags={ 'allow-cross-slot-keys' }}} + r FCALL test_cross_slot 0 + } + + test {Cross slot commands are also blocked if they disagree with pre-declared keys} { + assert_error "ERR Script attempted to access keys that do not hash to the same slot*" { + r 0 eval {#!lua + redis.call('set', 'foo', 'bar') + return 'OK' + } 1 bar} + } +} + +set ::singledb $old_singledb |