2020-07-14 00:39:36 +08:00
|
|
|
%% This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
%% License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
%% file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
2019-06-06 19:16:14 +08:00
|
|
|
%%
|
2024-02-06 00:53:36 +08:00
|
|
|
%% Copyright (c) 2007-2025 Broadcom. All Rights Reserved. The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. All rights reserved.
|
2019-06-06 19:16:14 +08:00
|
|
|
%%
|
|
|
|
|
|
|
|
%% A mock authn/authz that records information during calls. For testing purposes only.
|
|
|
|
|
|
|
|
-module(rabbit_auth_backend_mqtt_mock).
|
|
|
|
-include_lib("rabbit_common/include/rabbit.hrl").
|
|
|
|
|
|
|
|
-behaviour(rabbit_authn_backend).
|
|
|
|
-behaviour(rabbit_authz_backend).
|
|
|
|
|
2021-01-13 21:41:03 +08:00
|
|
|
-export([setup/1,
|
2020-12-02 21:52:56 +08:00
|
|
|
user_login_authentication/2, user_login_authorization/2,
|
2019-06-06 19:16:14 +08:00
|
|
|
check_vhost_access/3, check_resource_access/4, check_topic_access/4,
|
2024-01-23 17:40:24 +08:00
|
|
|
expiry_timestamp/1,
|
2019-06-06 19:16:14 +08:00
|
|
|
get/1]).
|
|
|
|
|
2021-01-13 21:41:03 +08:00
|
|
|
setup(CallerPid) ->
|
2019-06-06 19:16:14 +08:00
|
|
|
ets:new(?MODULE, [set, public, named_table]),
|
2024-07-17 21:36:20 +08:00
|
|
|
CallerPid ! {ok, self()},
|
2020-12-02 21:52:56 +08:00
|
|
|
receive
|
|
|
|
stop -> ok
|
|
|
|
end.
|
|
|
|
|
2023-01-28 02:25:57 +08:00
|
|
|
|
2023-02-01 16:55:40 +08:00
|
|
|
user_login_authentication(_Username, AuthProps) ->
|
2019-06-06 19:16:14 +08:00
|
|
|
ets:insert(?MODULE, {authentication, AuthProps}),
|
|
|
|
{ok, #auth_user{username = <<"dummy">>,
|
|
|
|
tags = [],
|
|
|
|
impl = none}}.
|
|
|
|
|
|
|
|
user_login_authorization(_, _) ->
|
|
|
|
io:format("login authorization"),
|
|
|
|
{ok, does_not_matter}.
|
|
|
|
|
2019-07-02 22:27:10 +08:00
|
|
|
check_vhost_access(#auth_user{}, _VHostPath, AuthzData) ->
|
2019-06-06 19:16:14 +08:00
|
|
|
ets:insert(?MODULE, {vhost_access, AuthzData}),
|
|
|
|
true.
|
2019-07-02 22:27:10 +08:00
|
|
|
check_resource_access(#auth_user{}, #resource{}, _Permission, AuthzContext) ->
|
2019-06-06 19:16:14 +08:00
|
|
|
ets:insert(?MODULE, {resource_access, AuthzContext}),
|
|
|
|
true.
|
2019-07-02 22:27:10 +08:00
|
|
|
check_topic_access(#auth_user{}, #resource{}, _Permission, TopicContext) ->
|
2019-06-06 19:16:14 +08:00
|
|
|
ets:insert(?MODULE, {topic_access, TopicContext}),
|
|
|
|
true.
|
|
|
|
|
2024-01-23 17:40:24 +08:00
|
|
|
expiry_timestamp(_) ->
|
|
|
|
never.
|
2019-07-02 21:50:12 +08:00
|
|
|
|
2019-06-06 19:16:14 +08:00
|
|
|
get(K) ->
|
2019-07-02 22:27:10 +08:00
|
|
|
ets:lookup(?MODULE, K).
|