20
20
{vhost_path , " http://localhost:" ++ integer_to_list (? AUTH_PORT ) ++ " /auth/vhost" },
21
21
{resource_path , " http://localhost:" ++ integer_to_list (? AUTH_PORT ) ++ " /auth/resource" },
22
22
{topic_path , " http://localhost:" ++ integer_to_list (? AUTH_PORT ) ++ " /auth/topic" }]).
23
- -define (ALLOWED_USER , #{username => <<" Ala " >>,
23
+ -define (ALLOWED_USER , #{username => <<" Ala1 " >>,
24
24
password => <<" Kocur" >>,
25
+ expected_credentials => [username , password ],
25
26
tags => [policymaker , monitoring ]}).
26
- -define (DENIED_USER , #{username => <<" Alice" >>, password => <<" Cat" >>}).
27
+ -define (ALLOWED_USER_WITH_EXTRA_CREDENTIALS , #{username => <<" Ala2" >>,
28
+ password => <<" Kocur" >>,
29
+ client_id => <<" some_id" >>,
30
+ expected_credentials => [username , password , client_id ],
31
+ tags => [policymaker , monitoring ]}).
32
+ -define (DENIED_USER , #{username => <<" Alice" >>,
33
+ password => <<" Cat" >>
34
+ }).
27
35
28
- all () -> [grants_access_to_user , denies_access_to_user ].
36
+ all () -> [grants_access_to_user ,
37
+ denies_access_to_user ,
38
+ grants_access_to_user_passing_additional_required_authprops ,
39
+ grants_access_to_user_skipping_internal_authprops ].
29
40
30
41
init_per_suite (Config ) ->
31
42
configure_http_auth_backend (),
32
- #{username := Username , password := Password , tags := Tags } = ? ALLOWED_USER ,
33
- start_http_auth_server (? AUTH_PORT , ? USER_PATH , #{Username => {Password , Tags }}),
34
- [{allowed_user , ? ALLOWED_USER }, {denied_user , ? DENIED_USER } | Config ].
43
+ {User1 , Tuple1 } = extractUserTuple (? ALLOWED_USER ),
44
+ {User2 , Tuple2 } = extractUserTuple (? ALLOWED_USER_WITH_EXTRA_CREDENTIALS ),
45
+ start_http_auth_server (? AUTH_PORT , ? USER_PATH , #{User1 => Tuple1 , User2 => Tuple2 }),
46
+ [{allowed_user , ? ALLOWED_USER },
47
+ {allowed_user_with_extra_credentials , ? ALLOWED_USER_WITH_EXTRA_CREDENTIALS },
48
+ {denied_user , ? DENIED_USER } | Config ].
49
+ extractUserTuple (User ) ->
50
+ #{username := Username , password := Password , tags := Tags , expected_credentials := ExpectedCredentials } = User ,
51
+ {Username , {Password , Tags , ExpectedCredentials }}.
35
52
36
53
end_per_suite (_Config ) ->
37
54
stop_http_auth_server ().
@@ -47,6 +64,20 @@ denies_access_to_user(Config) ->
47
64
? assertMatch ({refused , " Denied by the backing HTTP service" , []},
48
65
rabbit_auth_backend_http :user_login_authentication (U , [{password , P }])).
49
66
67
+
68
+ grants_access_to_user_passing_additional_required_authprops (Config ) ->
69
+ #{username := U , password := P , tags := T , client_id := ClientId } = ? config (allowed_user_with_extra_credentials , Config ),
70
+ {ok , User } = rabbit_auth_backend_http :user_login_authentication (U , [{password , P }, {client_id , ClientId }]),
71
+ ? assertMatch ({U , T , P },
72
+ {User # auth_user .username , User # auth_user .tags , (User # auth_user .impl )()}).
73
+
74
+ grants_access_to_user_skipping_internal_authprops (Config ) ->
75
+ #{username := U , password := P , tags := T , client_id := ClientId } = ? config (allowed_user_with_extra_credentials , Config ),
76
+ {ok , User } = rabbit_auth_backend_http :user_login_authentication (U ,
77
+ [{password , P }, {client_id , ClientId }, {rabbit_any_internal_property , <<" some value" >>}]),
78
+ ? assertMatch ({U , T , P },
79
+ {User # auth_user .username , User # auth_user .tags , (User # auth_user .impl )()}).
80
+
50
81
% %% HELPERS
51
82
52
83
configure_http_auth_backend () ->
0 commit comments