acl.tcl 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  1. start_server {tags {"acl external:skip"}} {
  2. test {Connections start with the default user} {
  3. r ACL WHOAMI
  4. } {default}
  5. test {It is possible to create new users} {
  6. r ACL setuser newuser
  7. }
  8. test {New users start disabled} {
  9. r ACL setuser newuser >passwd1
  10. catch {r AUTH newuser passwd1} err
  11. set err
  12. } {*WRONGPASS*}
  13. test {Enabling the user allows the login} {
  14. r ACL setuser newuser on +acl
  15. r AUTH newuser passwd1
  16. r ACL WHOAMI
  17. } {newuser}
  18. test {Only the set of correct passwords work} {
  19. r ACL setuser newuser >passwd2
  20. catch {r AUTH newuser passwd1} e
  21. assert {$e eq "OK"}
  22. catch {r AUTH newuser passwd2} e
  23. assert {$e eq "OK"}
  24. catch {r AUTH newuser passwd3} e
  25. set e
  26. } {*WRONGPASS*}
  27. test {It is possible to remove passwords from the set of valid ones} {
  28. r ACL setuser newuser <passwd1
  29. catch {r AUTH newuser passwd1} e
  30. set e
  31. } {*WRONGPASS*}
  32. test {Test password hashes can be added} {
  33. r ACL setuser newuser #34344e4d60c2b6d639b7bd22e18f2b0b91bc34bf0ac5f9952744435093cfb4e6
  34. catch {r AUTH newuser passwd4} e
  35. assert {$e eq "OK"}
  36. }
  37. test {Test password hashes validate input} {
  38. # Validate Length
  39. catch {r ACL setuser newuser #34344e4d60c2b6d639b7bd22e18f2b0b91bc34bf0ac5f9952744435093cfb4e} e
  40. # Validate character outside set
  41. catch {r ACL setuser newuser #34344e4d60c2b6d639b7bd22e18f2b0b91bc34bf0ac5f9952744435093cfb4eq} e
  42. set e
  43. } {*Error in ACL SETUSER modifier*}
  44. test {ACL GETUSER returns the password hash instead of the actual password} {
  45. set passstr [dict get [r ACL getuser newuser] passwords]
  46. assert_match {*34344e4d60c2b6d639b7bd22e18f2b0b91bc34bf0ac5f9952744435093cfb4e6*} $passstr
  47. assert_no_match {*passwd4*} $passstr
  48. }
  49. test {Test hashed passwords removal} {
  50. r ACL setuser newuser !34344e4d60c2b6d639b7bd22e18f2b0b91bc34bf0ac5f9952744435093cfb4e6
  51. set passstr [dict get [r ACL getuser newuser] passwords]
  52. assert_no_match {*34344e4d60c2b6d639b7bd22e18f2b0b91bc34bf0ac5f9952744435093cfb4e6*} $passstr
  53. }
  54. test {By default users are not able to access any command} {
  55. catch {r SET foo bar} e
  56. set e
  57. } {*NOPERM*}
  58. test {By default users are not able to access any key} {
  59. r ACL setuser newuser +set
  60. catch {r SET foo bar} e
  61. set e
  62. } {*NOPERM*key*}
  63. test {It's possible to allow the access of a subset of keys} {
  64. r ACL setuser newuser allcommands ~foo:* ~bar:*
  65. r SET foo:1 a
  66. r SET bar:2 b
  67. catch {r SET zap:3 c} e
  68. r ACL setuser newuser allkeys; # Undo keys ACL
  69. set e
  70. } {*NOPERM*key*}
  71. test {By default users are able to publish to any channel} {
  72. r ACL setuser psuser on >pspass +acl +client +@pubsub
  73. r AUTH psuser pspass
  74. r PUBLISH foo bar
  75. } {0}
  76. test {By default users are able to subscribe to any channel} {
  77. set rd [redis_deferring_client]
  78. $rd AUTH psuser pspass
  79. $rd read
  80. $rd SUBSCRIBE foo
  81. assert_match {subscribe foo 1} [$rd read]
  82. $rd close
  83. } {0}
  84. test {By default users are able to subscribe to any pattern} {
  85. set rd [redis_deferring_client]
  86. $rd AUTH psuser pspass
  87. $rd read
  88. $rd PSUBSCRIBE bar*
  89. assert_match {psubscribe bar\* 1} [$rd read]
  90. $rd close
  91. } {0}
  92. test {It's possible to allow publishing to a subset of channels} {
  93. r ACL setuser psuser resetchannels &foo:1 &bar:*
  94. assert_equal {0} [r PUBLISH foo:1 somemessage]
  95. assert_equal {0} [r PUBLISH bar:2 anothermessage]
  96. catch {r PUBLISH zap:3 nosuchmessage} e
  97. set e
  98. } {*NOPERM*channel*}
  99. test {Validate subset of channels is prefixed with resetchannels flag} {
  100. r ACL setuser hpuser on nopass resetchannels &foo +@all
  101. # Verify resetchannels flag is prefixed before the channel name(s)
  102. set users [r ACL LIST]
  103. set curruser "hpuser"
  104. foreach user [lshuffle $users] {
  105. if {[string first $curruser $user] != -1} {
  106. assert_equal {user hpuser on nopass resetchannels &foo +@all} $user
  107. }
  108. }
  109. # authenticate as hpuser
  110. r AUTH hpuser pass
  111. assert_equal {0} [r PUBLISH foo bar]
  112. catch {r PUBLISH bar game} e
  113. # Falling back to psuser for the below tests
  114. r AUTH psuser pspass
  115. r ACL deluser hpuser
  116. set e
  117. } {*NOPERM*channel*}
  118. test {In transaction queue publish/subscribe/psubscribe to unauthorized channel will fail} {
  119. r ACL setuser psuser +multi +discard
  120. r MULTI
  121. catch {r PUBLISH notexits helloworld} e
  122. r DISCARD
  123. assert_match {*NOPERM*} $e
  124. r MULTI
  125. catch {r SUBSCRIBE notexits foo:1} e
  126. r DISCARD
  127. assert_match {*NOPERM*} $e
  128. r MULTI
  129. catch {r PSUBSCRIBE notexits:* bar:*} e
  130. r DISCARD
  131. assert_match {*NOPERM*} $e
  132. }
  133. test {It's possible to allow subscribing to a subset of channels} {
  134. set rd [redis_deferring_client]
  135. $rd AUTH psuser pspass
  136. $rd read
  137. $rd SUBSCRIBE foo:1
  138. assert_match {subscribe foo:1 1} [$rd read]
  139. $rd SUBSCRIBE bar:2
  140. assert_match {subscribe bar:2 2} [$rd read]
  141. $rd SUBSCRIBE zap:3
  142. catch {$rd read} e
  143. set e
  144. } {*NOPERM*channel*}
  145. test {It's possible to allow subscribing to a subset of channel patterns} {
  146. set rd [redis_deferring_client]
  147. $rd AUTH psuser pspass
  148. $rd read
  149. $rd PSUBSCRIBE foo:1
  150. assert_match {psubscribe foo:1 1} [$rd read]
  151. $rd PSUBSCRIBE bar:*
  152. assert_match {psubscribe bar:\* 2} [$rd read]
  153. $rd PSUBSCRIBE bar:baz
  154. catch {$rd read} e
  155. set e
  156. } {*NOPERM*channel*}
  157. test {Subscribers are killed when revoked of channel permission} {
  158. set rd [redis_deferring_client]
  159. r ACL setuser psuser resetchannels &foo:1
  160. $rd AUTH psuser pspass
  161. $rd read
  162. $rd CLIENT SETNAME deathrow
  163. $rd read
  164. $rd SUBSCRIBE foo:1
  165. $rd read
  166. r ACL setuser psuser resetchannels
  167. assert_no_match {*deathrow*} [r CLIENT LIST]
  168. $rd close
  169. } {0}
  170. test {Subscribers are killed when revoked of pattern permission} {
  171. set rd [redis_deferring_client]
  172. r ACL setuser psuser resetchannels &bar:*
  173. $rd AUTH psuser pspass
  174. $rd read
  175. $rd CLIENT SETNAME deathrow
  176. $rd read
  177. $rd PSUBSCRIBE bar:*
  178. $rd read
  179. r ACL setuser psuser resetchannels
  180. assert_no_match {*deathrow*} [r CLIENT LIST]
  181. $rd close
  182. } {0}
  183. test {Subscribers are pardoned if literal permissions are retained and/or gaining allchannels} {
  184. set rd [redis_deferring_client]
  185. r ACL setuser psuser resetchannels &foo:1 &bar:*
  186. $rd AUTH psuser pspass
  187. $rd read
  188. $rd CLIENT SETNAME pardoned
  189. $rd read
  190. $rd SUBSCRIBE foo:1
  191. $rd read
  192. $rd PSUBSCRIBE bar:*
  193. $rd read
  194. r ACL setuser psuser resetchannels &foo:1 &bar:* &baz:qaz &zoo:*
  195. assert_match {*pardoned*} [r CLIENT LIST]
  196. r ACL setuser psuser allchannels
  197. assert_match {*pardoned*} [r CLIENT LIST]
  198. $rd close
  199. } {0}
  200. test {Users can be configured to authenticate with any password} {
  201. r ACL setuser newuser nopass
  202. r AUTH newuser zipzapblabla
  203. } {OK}
  204. test {ACLs can exclude single commands} {
  205. r ACL setuser newuser -ping
  206. r INCR mycounter ; # Should not raise an error
  207. catch {r PING} e
  208. set e
  209. } {*NOPERM*}
  210. test {ACLs can include or exclude whole classes of commands} {
  211. r ACL setuser newuser -@all +@set +acl
  212. r SADD myset a b c; # Should not raise an error
  213. r ACL setuser newuser +@all -@string
  214. r SADD myset a b c; # Again should not raise an error
  215. # String commands instead should raise an error
  216. catch {r SET foo bar} e
  217. r ACL setuser newuser allcommands; # Undo commands ACL
  218. set e
  219. } {*NOPERM*}
  220. test {ACLs can include single subcommands} {
  221. r ACL setuser newuser +@all -client
  222. r ACL setuser newuser +client|id +client|setname
  223. r CLIENT ID; # Should not fail
  224. r CLIENT SETNAME foo ; # Should not fail
  225. catch {r CLIENT KILL type master} e
  226. set e
  227. } {*NOPERM*}
  228. test {ACLs set can include subcommands, if already full command exists} {
  229. r ACL setuser bob +memory|doctor
  230. set cmdstr [dict get [r ACL getuser bob] commands]
  231. assert_equal {-@all +memory|doctor} $cmdstr
  232. # Validate the commands have got engulfed to +memory.
  233. r ACL setuser bob +memory
  234. set cmdstr [dict get [r ACL getuser bob] commands]
  235. assert_equal {-@all +memory} $cmdstr
  236. # Appending to the existing access string of bob.
  237. r ACL setuser bob +@all +client|id
  238. # Validate the new commands has got engulfed to +@all.
  239. set cmdstr [dict get [r ACL getuser bob] commands]
  240. assert_equal {+@all} $cmdstr
  241. r CLIENT ID; # Should not fail
  242. r MEMORY DOCTOR; # Should not fail
  243. }
  244. # Note that the order of the generated ACL rules is not stable in Redis
  245. # so we need to match the different parts and not as a whole string.
  246. test {ACL GETUSER is able to translate back command permissions} {
  247. # Subtractive
  248. r ACL setuser newuser reset +@all ~* -@string +incr -debug +debug|digest
  249. set cmdstr [dict get [r ACL getuser newuser] commands]
  250. assert_match {*+@all*} $cmdstr
  251. assert_match {*-@string*} $cmdstr
  252. assert_match {*+incr*} $cmdstr
  253. assert_match {*-debug +debug|digest**} $cmdstr
  254. # Additive
  255. r ACL setuser newuser reset +@string -incr +acl +debug|digest +debug|segfault
  256. set cmdstr [dict get [r ACL getuser newuser] commands]
  257. assert_match {*-@all*} $cmdstr
  258. assert_match {*+@string*} $cmdstr
  259. assert_match {*-incr*} $cmdstr
  260. assert_match {*+debug|digest*} $cmdstr
  261. assert_match {*+debug|segfault*} $cmdstr
  262. assert_match {*+acl*} $cmdstr
  263. }
  264. # A regression test make sure that as long as there is a simple
  265. # category defining the commands, that it will be used as is.
  266. test {ACL GETUSER provides reasonable results} {
  267. set categories [r ACL CAT]
  268. # Test that adding each single category will
  269. # result in just that category with both +@all and -@all
  270. foreach category $categories {
  271. # Test for future commands where allowed
  272. r ACL setuser additive reset +@all "-@$category"
  273. set cmdstr [dict get [r ACL getuser additive] commands]
  274. assert_equal "+@all -@$category" $cmdstr
  275. # Test for future commands where disallowed
  276. r ACL setuser restrictive reset -@all "+@$category"
  277. set cmdstr [dict get [r ACL getuser restrictive] commands]
  278. assert_equal "-@all +@$category" $cmdstr
  279. }
  280. }
  281. test {ACL #5998 regression: memory leaks adding / removing subcommands} {
  282. r AUTH default ""
  283. r ACL setuser newuser reset -debug +debug|a +debug|b +debug|c
  284. r ACL setuser newuser -debug
  285. # The test framework will detect a leak if any.
  286. }
  287. test {ACL LOG shows failed command executions at toplevel} {
  288. r ACL LOG RESET
  289. r ACL setuser antirez >foo on +set ~object:1234
  290. r ACL setuser antirez +eval +multi +exec
  291. r ACL setuser antirez resetchannels +publish
  292. r AUTH antirez foo
  293. catch {r GET foo}
  294. r AUTH default ""
  295. set entry [lindex [r ACL LOG] 0]
  296. assert {[dict get $entry username] eq {antirez}}
  297. assert {[dict get $entry context] eq {toplevel}}
  298. assert {[dict get $entry reason] eq {command}}
  299. assert {[dict get $entry object] eq {get}}
  300. }
  301. test {ACL LOG is able to test similar events} {
  302. r AUTH antirez foo
  303. catch {r GET foo}
  304. catch {r GET foo}
  305. catch {r GET foo}
  306. r AUTH default ""
  307. set entry [lindex [r ACL LOG] 0]
  308. assert {[dict get $entry count] == 4}
  309. }
  310. test {ACL LOG is able to log keys access violations and key name} {
  311. r AUTH antirez foo
  312. catch {r SET somekeynotallowed 1234}
  313. r AUTH default ""
  314. set entry [lindex [r ACL LOG] 0]
  315. assert {[dict get $entry reason] eq {key}}
  316. assert {[dict get $entry object] eq {somekeynotallowed}}
  317. }
  318. test {ACL LOG is able to log channel access violations and channel name} {
  319. r AUTH antirez foo
  320. catch {r PUBLISH somechannelnotallowed nullmsg}
  321. r AUTH default ""
  322. set entry [lindex [r ACL LOG] 0]
  323. assert {[dict get $entry reason] eq {channel}}
  324. assert {[dict get $entry object] eq {somechannelnotallowed}}
  325. }
  326. test {ACL LOG RESET is able to flush the entries in the log} {
  327. r ACL LOG RESET
  328. assert {[llength [r ACL LOG]] == 0}
  329. }
  330. test {ACL LOG can distinguish the transaction context (1)} {
  331. r AUTH antirez foo
  332. r MULTI
  333. catch {r INCR foo}
  334. catch {r EXEC}
  335. r AUTH default ""
  336. set entry [lindex [r ACL LOG] 0]
  337. assert {[dict get $entry context] eq {multi}}
  338. assert {[dict get $entry object] eq {incr}}
  339. }
  340. test {ACL LOG can distinguish the transaction context (2)} {
  341. set rd1 [redis_deferring_client]
  342. r ACL SETUSER antirez +incr
  343. r AUTH antirez foo
  344. r MULTI
  345. r INCR object:1234
  346. $rd1 ACL SETUSER antirez -incr
  347. $rd1 read
  348. catch {r EXEC}
  349. $rd1 close
  350. r AUTH default ""
  351. set entry [lindex [r ACL LOG] 0]
  352. assert {[dict get $entry context] eq {multi}}
  353. assert {[dict get $entry object] eq {incr}}
  354. r ACL SETUSER antirez -incr
  355. }
  356. test {ACL can log errors in the context of Lua scripting} {
  357. r AUTH antirez foo
  358. catch {r EVAL {redis.call('incr','foo')} 0}
  359. r AUTH default ""
  360. set entry [lindex [r ACL LOG] 0]
  361. assert {[dict get $entry context] eq {lua}}
  362. assert {[dict get $entry object] eq {incr}}
  363. }
  364. test {ACL LOG can accept a numerical argument to show less entries} {
  365. r AUTH antirez foo
  366. catch {r INCR foo}
  367. catch {r INCR foo}
  368. catch {r INCR foo}
  369. catch {r INCR foo}
  370. r AUTH default ""
  371. assert {[llength [r ACL LOG]] > 1}
  372. assert {[llength [r ACL LOG 2]] == 2}
  373. }
  374. test {ACL LOG can log failed auth attempts} {
  375. catch {r AUTH antirez wrong-password}
  376. set entry [lindex [r ACL LOG] 0]
  377. assert {[dict get $entry context] eq {toplevel}}
  378. assert {[dict get $entry reason] eq {auth}}
  379. assert {[dict get $entry object] eq {AUTH}}
  380. assert {[dict get $entry username] eq {antirez}}
  381. }
  382. test {ACL LOG entries are limited to a maximum amount} {
  383. r ACL LOG RESET
  384. r CONFIG SET acllog-max-len 5
  385. r AUTH antirez foo
  386. for {set j 0} {$j < 10} {incr j} {
  387. catch {r SET obj:$j 123}
  388. }
  389. r AUTH default ""
  390. assert {[llength [r ACL LOG]] == 5}
  391. }
  392. test {When default user is off, new connections are not authenticated} {
  393. r ACL setuser default off
  394. catch {set rd1 [redis_deferring_client]} e
  395. r ACL setuser default on
  396. set e
  397. } {*NOAUTH*}
  398. test {When default user has no command permission, hello command still works for other users} {
  399. r ACL setuser secure-user >supass on +@all
  400. r ACL setuser default -@all
  401. r HELLO 2 AUTH secure-user supass
  402. r ACL setuser default nopass +@all
  403. r AUTH default ""
  404. }
  405. test {ACL HELP should not have unexpected options} {
  406. catch {r ACL help xxx} e
  407. assert_match "*Unknown subcommand or wrong number of arguments*" $e
  408. }
  409. test {Delete a user that the client doesn't use} {
  410. r ACL setuser not_used on >passwd
  411. assert {[r ACL deluser not_used] == 1}
  412. # The client is not closed
  413. assert {[r ping] eq {PONG}}
  414. }
  415. test {Delete a user that the client is using} {
  416. r ACL setuser using on +acl >passwd
  417. r AUTH using passwd
  418. # The client will receive reply normally
  419. assert {[r ACL deluser using] == 1}
  420. # The client is closed
  421. catch {[r ping]} e
  422. assert_match "*I/O error*" $e
  423. }
  424. }
  425. set server_path [tmpdir "server.acl"]
  426. exec cp -f tests/assets/user.acl $server_path
  427. start_server [list overrides [list "dir" $server_path "aclfile" "user.acl"] tags [list "external:skip"]] {
  428. # user alice on allcommands allkeys >alice
  429. # user bob on -@all +@set +acl ~set* >bob
  430. # user default on nopass ~* +@all
  431. test {default: load from include file, can access any channels} {
  432. r SUBSCRIBE foo
  433. r PSUBSCRIBE bar*
  434. r UNSUBSCRIBE
  435. r PUNSUBSCRIBE
  436. r PUBLISH hello world
  437. }
  438. test {default: with config acl-pubsub-default allchannels after reset, can access any channels} {
  439. r ACL setuser default reset on nopass ~* +@all
  440. r SUBSCRIBE foo
  441. r PSUBSCRIBE bar*
  442. r UNSUBSCRIBE
  443. r PUNSUBSCRIBE
  444. r PUBLISH hello world
  445. }
  446. test {default: with config acl-pubsub-default resetchannels after reset, can not access any channels} {
  447. r CONFIG SET acl-pubsub-default resetchannels
  448. r ACL setuser default reset on nopass ~* +@all
  449. catch {r SUBSCRIBE foo} e
  450. assert_match {*NOPERM*} $e
  451. catch {r PSUBSCRIBE bar*} e
  452. assert_match {*NOPERM*} $e
  453. catch {r PUBLISH hello world} e
  454. assert_match {*NOPERM*} $e
  455. r CONFIG SET acl-pubsub-default resetchannels
  456. }
  457. test {Alice: can execute all command} {
  458. r AUTH alice alice
  459. assert_equal "alice" [r acl whoami]
  460. r SET key value
  461. }
  462. test {Bob: just execute @set and acl command} {
  463. r AUTH bob bob
  464. assert_equal "bob" [r acl whoami]
  465. assert_equal "3" [r sadd set 1 2 3]
  466. catch {r SET key value} e
  467. set e
  468. } {*NOPERM*}
  469. test {ACL load and save} {
  470. r ACL setuser eve +get allkeys >eve on
  471. r ACL save
  472. # ACL load will free user and kill clients
  473. r ACL load
  474. catch {r ACL LIST} e
  475. assert_match {*I/O error*} $e
  476. reconnect
  477. r AUTH alice alice
  478. r SET key value
  479. r AUTH eve eve
  480. r GET key
  481. catch {r SET key value} e
  482. set e
  483. } {*NOPERM*}
  484. test {ACL load and save with restricted channels} {
  485. r AUTH alice alice
  486. r ACL setuser harry on nopass resetchannels &test +@all ~*
  487. r ACL save
  488. # ACL load will free user and kill clients
  489. r ACL load
  490. catch {r ACL LIST} e
  491. assert_match {*I/O error*} $e
  492. reconnect
  493. r AUTH harry anything
  494. r publish test bar
  495. catch {r publish test1 bar} e
  496. r ACL deluser harry
  497. set e
  498. } {*NOPERM*}
  499. }
  500. set server_path [tmpdir "resetchannels.acl"]
  501. exec cp -f tests/assets/nodefaultuser.acl $server_path
  502. exec cp -f tests/assets/default.conf $server_path
  503. start_server [list overrides [list "dir" $server_path "acl-pubsub-default" "resetchannels" "aclfile" "nodefaultuser.acl"] tags [list "external:skip"]] {
  504. test {Default user has access to all channels irrespective of flag} {
  505. set channelinfo [dict get [r ACL getuser default] channels]
  506. assert_equal "*" $channelinfo
  507. set channelinfo [dict get [r ACL getuser alice] channels]
  508. assert_equal "" $channelinfo
  509. }
  510. test {Update acl-pubsub-default, existing users shouldn't get affected} {
  511. set channelinfo [dict get [r ACL getuser default] channels]
  512. assert_equal "*" $channelinfo
  513. r CONFIG set acl-pubsub-default allchannels
  514. r ACL setuser mydefault
  515. set channelinfo [dict get [r ACL getuser mydefault] channels]
  516. assert_equal "*" $channelinfo
  517. r CONFIG set acl-pubsub-default resetchannels
  518. set channelinfo [dict get [r ACL getuser mydefault] channels]
  519. assert_equal "*" $channelinfo
  520. }
  521. test {Single channel is valid} {
  522. r ACL setuser onechannel &test
  523. set channelinfo [dict get [r ACL getuser onechannel] channels]
  524. assert_equal test $channelinfo
  525. r ACL deluser onechannel
  526. }
  527. test {Single channel is not valid with allchannels} {
  528. r CONFIG set acl-pubsub-default allchannels
  529. catch {r ACL setuser onechannel &test} err
  530. r CONFIG set acl-pubsub-default resetchannels
  531. set err
  532. } {*start with an empty list of channels*}
  533. }
  534. set server_path [tmpdir "resetchannels.acl"]
  535. exec cp -f tests/assets/nodefaultuser.acl $server_path
  536. exec cp -f tests/assets/default.conf $server_path
  537. start_server [list overrides [list "dir" $server_path "acl-pubsub-default" "resetchannels" "aclfile" "nodefaultuser.acl"] tags [list "external:skip"]] {
  538. test {Only default user has access to all channels irrespective of flag} {
  539. set channelinfo [dict get [r ACL getuser default] channels]
  540. assert_equal "*" $channelinfo
  541. set channelinfo [dict get [r ACL getuser alice] channels]
  542. assert_equal "" $channelinfo
  543. }
  544. }
  545. start_server {overrides {user "default on nopass ~* +@all"} tags {"external:skip"}} {
  546. test {default: load from config file, can access any channels} {
  547. r SUBSCRIBE foo
  548. r PSUBSCRIBE bar*
  549. r UNSUBSCRIBE
  550. r PUNSUBSCRIBE
  551. r PUBLISH hello world
  552. }
  553. }