@@ -39,6 +39,9 @@ groups() ->
39
39
test_publish_v2 ,
40
40
test_gc_consumers ,
41
41
test_gc_publishers ,
42
+ test_update_secret ,
43
+ cannot_update_username_after_authenticated ,
44
+ cannot_use_another_authmechanism_when_updating_secret ,
42
45
unauthenticated_client_rejected_tcp_connected ,
43
46
timeout_tcp_connected ,
44
47
unauthenticated_client_rejected_peer_properties_exchanged ,
@@ -48,7 +51,8 @@ groups() ->
48
51
timeout_close_sent ,
49
52
max_segment_size_bytes_validation ,
50
53
close_connection_on_consumer_update_timeout ,
51
- set_filter_size ]},
54
+ set_filter_size
55
+ ]},
52
56
% % Run `test_global_counters` on its own so the global metrics are
53
57
% % initialised to 0 for each testcase
54
58
{single_node_1 , [], [test_global_counters ]},
@@ -132,6 +136,13 @@ end_per_group(_, Config) ->
132
136
rabbit_ct_helpers :run_steps (Config ,
133
137
rabbit_ct_broker_helpers :teardown_steps ()).
134
138
139
+ init_per_testcase (test_update_secret = TestCase , Config ) ->
140
+ rabbit_ct_helpers :testcase_started (Config , TestCase );
141
+
142
+ init_per_testcase (cannot_update_username_after_authenticated = TestCase , Config ) ->
143
+ ok = rabbit_ct_broker_helpers :add_user (Config , <<" other" >>),
144
+ rabbit_ct_helpers :testcase_started (Config , TestCase );
145
+
135
146
init_per_testcase (close_connection_on_consumer_update_timeout = TestCase , Config ) ->
136
147
ok = rabbit_ct_broker_helpers :rpc (Config ,
137
148
0 ,
@@ -142,6 +153,14 @@ init_per_testcase(close_connection_on_consumer_update_timeout = TestCase, Config
142
153
init_per_testcase (TestCase , Config ) ->
143
154
rabbit_ct_helpers :testcase_started (Config , TestCase ).
144
155
156
+ end_per_testcase (test_update_secret = TestCase , Config ) ->
157
+ ok = rabbit_ct_broker_helpers :change_password (Config , <<" guest" >>, <<" guest" >>),
158
+ rabbit_ct_helpers :testcase_finished (Config , TestCase );
159
+
160
+ end_per_testcase (cannot_update_username_after_authenticated = TestCase , Config ) ->
161
+ ok = rabbit_ct_broker_helpers :delete_user (Config , <<" other" >>),
162
+ rabbit_ct_helpers :testcase_finished (Config , TestCase );
163
+
145
164
end_per_testcase (filtering_ff = TestCase , Config ) ->
146
165
_ = rabbit_ct_broker_helpers :rpc (Config ,
147
166
0 ,
@@ -221,6 +240,34 @@ test_stream(Config) ->
221
240
test_server (gen_tcp , Stream , Config ),
222
241
ok .
223
242
243
+ test_update_secret (Config ) ->
244
+ Transport = gen_tcp ,
245
+ {S , C0 } = connect_and_authenticate (Transport , Config ),
246
+ rabbit_ct_broker_helpers :change_password (Config , <<" guest" >>, <<" password" >>),
247
+ C1 = expect_successful_authentication (
248
+ try_authenticate (Transport , S , C0 , <<" PLAIN" >>, <<" guest" >>, <<" password" >>)),
249
+ _C2 = test_close (Transport , S , C1 ),
250
+ closed = wait_for_socket_close (Transport , S , 10 ),
251
+ ok .
252
+
253
+ cannot_update_username_after_authenticated (Config ) ->
254
+ {S , C0 } = connect_and_authenticate (gen_tcp , Config ),
255
+ C1 = expect_unsuccessful_authentication (
256
+ try_authenticate (gen_tcp , S , C0 , <<" PLAIN" >>, <<" other" >>, <<" other" >>),
257
+ ? RESPONSE_SASL_CANNOT_CHANGE_USERNAME ),
258
+ _C2 = test_close (gen_tcp , S , C1 ),
259
+ closed = wait_for_socket_close (gen_tcp , S , 10 ),
260
+ ok .
261
+
262
+ cannot_use_another_authmechanism_when_updating_secret (Config ) ->
263
+ {S , C0 } = connect_and_authenticate (gen_tcp , Config ),
264
+ C1 = expect_unsuccessful_authentication (
265
+ try_authenticate (gen_tcp , S , C0 , <<" EXTERNAL" >>, <<" guest" >>, <<" new_password" >>),
266
+ ? RESPONSE_SASL_CANNOT_CHANGE_MECHANISM ),
267
+ _C2 = test_close (gen_tcp , S , C1 ),
268
+ closed = wait_for_socket_close (gen_tcp , S , 10 ),
269
+ ok .
270
+
224
271
test_stream_tls (Config ) ->
225
272
Stream = atom_to_binary (? FUNCTION_NAME , utf8 ),
226
273
test_server (ssl , Stream , Config ),
@@ -577,23 +624,43 @@ get_node_name(Config) ->
577
624
get_node_name (Config , Node ) ->
578
625
rabbit_ct_broker_helpers :get_node_config (Config , Node , nodename ).
579
626
627
+ get_port (Transport , Config ) ->
628
+ case Transport of
629
+ gen_tcp ->
630
+ get_stream_port (Config );
631
+ ssl ->
632
+ application :ensure_all_started (ssl ),
633
+ get_stream_port_tls (Config )
634
+ end .
635
+ get_opts (Transport ) ->
636
+ case Transport of
637
+ gen_tcp ->
638
+ [{active , false }, {mode , binary }];
639
+ ssl ->
640
+ [{active , false }, {mode , binary }, {verify , verify_none }]
641
+ end .
642
+
643
+ connect_and_authenticate (Transport , Config ) ->
644
+ Port = get_port (Transport , Config ),
645
+ Opts = get_opts (Transport ),
646
+ {ok , S } = Transport :connect (" localhost" , Port , Opts ),
647
+ C0 = rabbit_stream_core :init (0 ),
648
+ C1 = test_peer_properties (Transport , S , C0 ),
649
+ {S , test_authenticate (Transport , S , C1 )}.
650
+
651
+ try_authenticate (Transport , S , C , AuthMethod , Username , Password ) ->
652
+ case AuthMethod of
653
+ <<" PLAIN" >> ->
654
+ plain_sasl_authenticate (Transport , S , C , Username , Password );
655
+ _ ->
656
+ Null = 0 ,
657
+ sasl_authenticate (Transport , S , C , AuthMethod , <<Null :8 , Username /binary , Null :8 , Password /binary >>)
658
+ end .
659
+
580
660
test_server (Transport , Stream , Config ) ->
581
661
QName = rabbit_misc :r (<<" /" >>, queue , Stream ),
582
- Port =
583
- case Transport of
584
- gen_tcp ->
585
- get_stream_port (Config );
586
- ssl ->
587
- application :ensure_all_started (ssl ),
588
- get_stream_port_tls (Config )
589
- end ,
590
- Opts =
591
- case Transport of
592
- gen_tcp ->
593
- [{active , false }, {mode , binary }];
594
- ssl ->
595
- [{active , false }, {mode , binary }, {verify , verify_none }]
596
- end ,
662
+ Port = get_port (Transport , Config ),
663
+ Opts = get_opts (Transport ),
597
664
{ok , S } =
598
665
Transport :connect (" localhost" , Port , Opts ),
599
666
C0 = rabbit_stream_core :init (0 ),
@@ -652,6 +719,9 @@ test_peer_properties(Transport, S, C0) ->
652
719
C .
653
720
654
721
test_authenticate (Transport , S , C0 ) ->
722
+ tune (Transport , S , test_plain_sasl_authenticate (Transport , S , sasl_handshake (Transport , S , C0 ))).
723
+
724
+ sasl_handshake (Transport , S , C0 ) ->
655
725
SaslHandshakeFrame =
656
726
rabbit_stream_core :frame ({request , 1 , sasl_handshake }),
657
727
ok = Transport :send (S , SaslHandshakeFrame ),
@@ -664,18 +734,33 @@ test_authenticate(Transport, S, C0) ->
664
734
_ ->
665
735
ct :fail (" invalid cmd ~tp " , [Cmd ])
666
736
end ,
737
+ C1 .
738
+
739
+ test_plain_sasl_authenticate (Transport , S , C1 ) ->
740
+ expect_successful_authentication (plain_sasl_authenticate (Transport , S , C1 )).
667
741
668
- Username = <<" guest" >>,
669
- Password = <<" guest" >>,
742
+ plain_sasl_authenticate (Transport , S , C1 ) ->
743
+ plain_sasl_authenticate (Transport , S , C1 , <<" guest" >>, <<" guest" >>).
744
+
745
+ plain_sasl_authenticate (Transport , S , C1 , Username , Password ) ->
670
746
Null = 0 ,
671
- PlainSasl = <<Null :8 , Username /binary , Null :8 , Password /binary >>,
747
+ sasl_authenticate (Transport , S , C1 , <<" PLAIN" >>, <<Null :8 , Username /binary , Null :8 , Password /binary >>).
748
+
749
+ expect_successful_authentication ({SaslAuth , C2 } = _SaslReponse ) ->
750
+ {response , 2 , {sasl_authenticate , ? RESPONSE_CODE_OK }} = SaslAuth ,
751
+ C2 .
752
+ expect_unsuccessful_authentication ({SaslAuth , C2 } = _SaslReponse , ExpectedError ) ->
753
+ {response , 2 , {sasl_authenticate , ExpectedError }} = SaslAuth ,
754
+ C2 .
672
755
756
+ sasl_authenticate (Transport , S , C1 , AuthMethod , AuthBody ) ->
673
757
SaslAuthenticateFrame =
674
758
rabbit_stream_core :frame ({request , 2 ,
675
- {sasl_authenticate , Plain , PlainSasl }}),
759
+ {sasl_authenticate , AuthMethod , AuthBody }}),
676
760
ok = Transport :send (S , SaslAuthenticateFrame ),
677
- {SaslAuth , C2 } = receive_commands (Transport , S , C1 ),
678
- {response , 2 , {sasl_authenticate , ? RESPONSE_CODE_OK }} = SaslAuth ,
761
+ receive_commands (Transport , S , C1 ).
762
+
763
+ tune (Transport , S , C2 ) ->
679
764
{Tune , C3 } = receive_commands (Transport , S , C2 ),
680
765
{tune , ? DEFAULT_FRAME_MAX , ? DEFAULT_HEARTBEAT } = Tune ,
681
766
@@ -816,9 +901,9 @@ test_unsubscribe(Transport, Socket, SubscriptionId, C0) ->
816
901
C .
817
902
818
903
test_deliver (Transport , S , SubscriptionId , COffset , Body , C0 ) ->
819
- ct :pal (" test_deliver " , []),
820
904
{{deliver , SubscriptionId , Chunk }, C } =
821
905
receive_commands (Transport , S , C0 ),
906
+ ct :pal (" test_deliver ~p " , [Chunk ]),
822
907
<<5 :4 /unsigned ,
823
908
0 :4 /unsigned ,
824
909
0 :8 ,
@@ -838,9 +923,9 @@ test_deliver(Transport, S, SubscriptionId, COffset, Body, C0) ->
838
923
C .
839
924
840
925
test_deliver_v2 (Transport , S , SubscriptionId , COffset , Body , C0 ) ->
841
- ct :pal (" test_deliver " , []),
842
926
{{deliver_v2 , SubscriptionId , _CommittedOffset , Chunk }, C } =
843
927
receive_commands (Transport , S , C0 ),
928
+ ct :pal (" test_deliver_v2 ~p " , [Chunk ]),
844
929
<<5 :4 /unsigned ,
845
930
0 :4 /unsigned ,
846
931
0 :8 ,
0 commit comments