auth.tcl 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. start_server {tags {"auth external:skip"}} {
  2. test {AUTH fails if there is no password configured server side} {
  3. catch {r auth foo} err
  4. set _ $err
  5. } {ERR*any password*}
  6. }
  7. start_server {tags {"auth external:skip"} overrides {requirepass foobar}} {
  8. test {AUTH fails when a wrong password is given} {
  9. catch {r auth wrong!} err
  10. set _ $err
  11. } {WRONGPASS*}
  12. test {Arbitrary command gives an error when AUTH is required} {
  13. catch {r set foo bar} err
  14. set _ $err
  15. } {NOAUTH*}
  16. test {AUTH succeeds when the right password is given} {
  17. r auth foobar
  18. } {OK}
  19. test {Once AUTH succeeded we can actually send commands to the server} {
  20. r set foo 100
  21. r incr foo
  22. } {101}
  23. test {For unauthenticated clients multibulk and bulk length are limited} {
  24. set rr [redis [srv "host"] [srv "port"] 0 $::tls]
  25. $rr write "*100\r\n"
  26. $rr flush
  27. catch {[$rr read]} e
  28. assert_match {*unauthenticated multibulk length*} $e
  29. $rr close
  30. set rr [redis [srv "host"] [srv "port"] 0 $::tls]
  31. $rr write "*1\r\n\$100000000\r\n"
  32. $rr flush
  33. catch {[$rr read]} e
  34. assert_match {*unauthenticated bulk length*} $e
  35. $rr close
  36. }
  37. }
  38. start_server {tags {"auth_binary_password external:skip"}} {
  39. test {AUTH fails when binary password is wrong} {
  40. r config set requirepass "abc\x00def"
  41. catch {r auth abc} err
  42. set _ $err
  43. } {WRONGPASS*}
  44. test {AUTH succeeds when binary password is correct} {
  45. r config set requirepass "abc\x00def"
  46. r auth "abc\x00def"
  47. } {OK}
  48. start_server {tags {"masterauth"}} {
  49. set master [srv -1 client]
  50. set master_host [srv -1 host]
  51. set master_port [srv -1 port]
  52. set slave [srv 0 client]
  53. test {MASTERAUTH test with binary password} {
  54. $master config set requirepass "abc\x00def"
  55. # Configure the replica with masterauth
  56. set loglines [count_log_lines 0]
  57. $slave slaveof $master_host $master_port
  58. $slave config set masterauth "abc"
  59. # Verify replica is not able to sync with master
  60. wait_for_log_messages 0 {"*Unable to AUTH to MASTER*"} $loglines 1000 10
  61. assert_equal {down} [s 0 master_link_status]
  62. # Test replica with the correct masterauth
  63. $slave config set masterauth "abc\x00def"
  64. wait_for_condition 50 100 {
  65. [s 0 master_link_status] eq {up}
  66. } else {
  67. fail "Can't turn the instance into a replica"
  68. }
  69. }
  70. }
  71. }