2024-03-21 09:30:47 -04:00
|
|
|
# SPDX-FileCopyrightText: 2024 Redict Contributors
|
|
|
|
# SPDX-FileCopyrightText: 2024 Salvatore Sanfilippo <antirez at gmail dot com>
|
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: BSD-3-Clause
|
2024-03-21 15:11:44 -04:00
|
|
|
# SPDX-License-Identifier: LGPL-3.0-only
|
2024-03-21 09:30:47 -04:00
|
|
|
|
2021-06-09 08:13:24 -04:00
|
|
|
start_server {tags {"auth external:skip"}} {
|
2011-10-10 16:21:17 -04:00
|
|
|
test {AUTH fails if there is no password configured server side} {
|
|
|
|
catch {r auth foo} err
|
|
|
|
set _ $err
|
2022-04-14 04:18:32 -04:00
|
|
|
} {ERR *any password*}
|
2022-02-09 15:09:20 -05:00
|
|
|
|
|
|
|
test {Arity check for auth command} {
|
|
|
|
catch {r auth a b c} err
|
|
|
|
set _ $err
|
|
|
|
} {*syntax error*}
|
2011-10-10 16:21:17 -04:00
|
|
|
}
|
|
|
|
|
2021-06-09 08:13:24 -04:00
|
|
|
start_server {tags {"auth external:skip"} overrides {requirepass foobar}} {
|
2010-05-14 11:31:11 -04:00
|
|
|
test {AUTH fails when a wrong password is given} {
|
|
|
|
catch {r auth wrong!} err
|
2011-10-10 16:21:17 -04:00
|
|
|
set _ $err
|
2019-01-17 12:30:23 -05:00
|
|
|
} {WRONGPASS*}
|
2014-07-31 14:39:49 -04:00
|
|
|
|
2010-05-14 11:31:11 -04:00
|
|
|
test {Arbitrary command gives an error when AUTH is required} {
|
|
|
|
catch {r set foo bar} err
|
2011-10-10 16:21:17 -04:00
|
|
|
set _ $err
|
2013-02-12 10:25:41 -05:00
|
|
|
} {NOAUTH*}
|
2010-05-14 11:31:11 -04:00
|
|
|
|
|
|
|
test {AUTH succeeds when the right password is given} {
|
|
|
|
r auth foobar
|
|
|
|
} {OK}
|
2011-10-10 16:21:17 -04:00
|
|
|
|
|
|
|
test {Once AUTH succeeded we can actually send commands to the server} {
|
|
|
|
r set foo 100
|
|
|
|
r incr foo
|
|
|
|
} {101}
|
2021-10-04 05:10:31 -04:00
|
|
|
|
|
|
|
test {For unauthenticated clients multibulk and bulk length are limited} {
|
2024-03-21 05:56:59 -04:00
|
|
|
set rr [redict [srv "host"] [srv "port"] 0 $::tls]
|
2021-10-04 05:10:31 -04:00
|
|
|
$rr write "*100\r\n"
|
|
|
|
$rr flush
|
|
|
|
catch {[$rr read]} e
|
|
|
|
assert_match {*unauthenticated multibulk length*} $e
|
|
|
|
$rr close
|
|
|
|
|
2024-03-21 05:56:59 -04:00
|
|
|
set rr [redict [srv "host"] [srv "port"] 0 $::tls]
|
2021-10-04 05:10:31 -04:00
|
|
|
$rr write "*1\r\n\$100000000\r\n"
|
|
|
|
$rr flush
|
|
|
|
catch {[$rr read]} e
|
|
|
|
assert_match {*unauthenticated bulk length*} $e
|
|
|
|
$rr close
|
|
|
|
}
|
2010-05-14 11:31:11 -04:00
|
|
|
}
|
2020-12-17 12:26:33 -05:00
|
|
|
|
2021-06-09 08:13:24 -04:00
|
|
|
start_server {tags {"auth_binary_password external:skip"}} {
|
2020-12-17 12:26:33 -05:00
|
|
|
test {AUTH fails when binary password is wrong} {
|
|
|
|
r config set requirepass "abc\x00def"
|
|
|
|
catch {r auth abc} err
|
|
|
|
set _ $err
|
|
|
|
} {WRONGPASS*}
|
|
|
|
|
|
|
|
test {AUTH succeeds when binary password is correct} {
|
|
|
|
r config set requirepass "abc\x00def"
|
|
|
|
r auth "abc\x00def"
|
|
|
|
} {OK}
|
|
|
|
|
|
|
|
start_server {tags {"masterauth"}} {
|
|
|
|
set master [srv -1 client]
|
|
|
|
set master_host [srv -1 host]
|
|
|
|
set master_port [srv -1 port]
|
|
|
|
set slave [srv 0 client]
|
|
|
|
|
|
|
|
test {MASTERAUTH test with binary password} {
|
|
|
|
$master config set requirepass "abc\x00def"
|
|
|
|
|
|
|
|
# Configure the replica with masterauth
|
|
|
|
set loglines [count_log_lines 0]
|
|
|
|
$slave config set masterauth "abc"
|
2023-08-01 11:03:33 -04:00
|
|
|
$slave slaveof $master_host $master_port
|
2020-12-17 12:26:33 -05:00
|
|
|
|
|
|
|
# Verify replica is not able to sync with master
|
|
|
|
wait_for_log_messages 0 {"*Unable to AUTH to MASTER*"} $loglines 1000 10
|
|
|
|
assert_equal {down} [s 0 master_link_status]
|
|
|
|
|
|
|
|
# Test replica with the correct masterauth
|
|
|
|
$slave config set masterauth "abc\x00def"
|
|
|
|
wait_for_condition 50 100 {
|
|
|
|
[s 0 master_link_status] eq {up}
|
|
|
|
} else {
|
|
|
|
fail "Can't turn the instance into a replica"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|