Skip to content

Commit 721e8ab

Browse files
Fix unit test
1 parent 65d5536 commit 721e8ab

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

deps/rabbitmq_auth_backend_oauth2/src/rabbit_oauth2_resource_server.erl

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
-module(rabbit_oauth2_resource_server).
99

1010
-include("oauth2.hrl").
11+
-include_lib("kernel/include/logger.hrl").
1112

1213
-export([
1314
resolve_resource_server_from_audience/1,
@@ -166,12 +167,27 @@ find_audience(Audience, ResourceIdList) when is_binary(Audience) ->
166167
AudList = binary:split(Audience, <<" ">>, [global, trim_all]),
167168
find_audience(AudList, ResourceIdList);
168169
find_audience(AudList, ResourceIdList) when is_list(AudList) ->
169-
case intersection(AudList, ResourceIdList) of
170+
?LOG_DEBUG("find_audience ~p -> ~p vs ~p", [AudList,
171+
normalize_to_binary_list(AudList), ResourceIdList]),
172+
case intersection(normalize_to_binary_list(AudList), ResourceIdList) of
170173
[One] -> {ok, One};
171174
[_One|_Tail] -> {error, aud_matched_many_resource_servers_only_one_allowed};
172175
[] -> {error, no_matching_aud_found}
173176
end.
174177

178+
-spec normalize_to_binary_list(binary() | string() | [binary()]) -> [binary()].
179+
normalize_to_binary_list(Input) when is_list(Input) ->
180+
case Input of
181+
[H | _] when is_binary(H) ->
182+
Input;
183+
_ when is_list(Input) ->
184+
[unicode:characters_to_binary(Part) || Part <- string:tokens(Input, " ")];
185+
_ ->
186+
[]
187+
end;
188+
normalize_to_binary_list(Input) when is_binary(Input) ->
189+
binary:split(Input, <<" ">>, [global]).
190+
175191
-spec translate_error_if_any(
176192
{ok, resource_server()} |
177193
{error, not_found} |

deps/rabbitmq_auth_backend_oauth2/test/introspect_http_handler.erl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,16 @@ init(Req, State) ->
1212
<<"401">> ->
1313
{ok, cowboy_req:reply(401, #{}, [], Req), State};
1414
<<"active">> ->
15-
Body = rabbit_json:encode([{"active", true}, {"scope", "rabbitmq.configure:*/* rabbitmq.write:*/* rabbitmq.read:*/*"}]),
15+
Body = rabbit_json:encode([
16+
{"active", true},
17+
{"aud", <<"rabbitmq">>},
18+
{"scope", <<"rabbitmq.configure:*/* rabbitmq.write:*/* rabbitmq.read:*/*">>}]),
1619
{ok, cowboy_req:reply(200, #{<<"content-type">> => <<"application/json">>},
1720
Body, Req), State};
1821
<<"inactive">> ->
19-
Body = rabbit_json:encode([{"active", false}, {"scope", "rabbitmq.configure:*/* rabbitmq.write:*/* rabbitmq.read:*/*"}]),
22+
Body = rabbit_json:encode([
23+
{"active", false},
24+
{"scope", <<"rabbitmq.configure:*/* rabbitmq.write:*/* rabbitmq.read:*/*">>}]),
2025
{ok, cowboy_req:reply(200, #{<<"content-type">> => <<"application/json">>},
2126
Body, Req), State}
2227
end;

0 commit comments

Comments
 (0)