From f93c22045d2b61c5b968b06162f720cb2efa3ae5 Mon Sep 17 00:00:00 2001 From: "Zaiming (Stone) Shi" Date: Sat, 24 Dec 2022 11:39:27 +0100 Subject: [PATCH] fix: non-empty field should not be undefined --- apps/emqx_authz/test/emqx_authz_redis_SUITE.erl | 14 ++++++++++++-- apps/emqx_resource/src/emqx_resource_validator.erl | 1 + 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/apps/emqx_authz/test/emqx_authz_redis_SUITE.erl b/apps/emqx_authz/test/emqx_authz_redis_SUITE.erl index ebf2b4d06..54d7a406c 100644 --- a/apps/emqx_authz/test/emqx_authz_redis_SUITE.erl +++ b/apps/emqx_authz/test/emqx_authz_redis_SUITE.erl @@ -161,12 +161,13 @@ t_lookups(_Config) -> ] ). -t_create_invalid(_Config) -> +%% should still succeed to create even if the config will not work, +%% because it's not a part of the schema check +t_create_with_config_values_wont_works(_Config) -> AuthzConfig = raw_redis_authz_config(), InvalidConfigs = [ - maps:without([<<"server">>], AuthzConfig), AuthzConfig#{<<"server">> => <<"unknownhost:3333">>}, AuthzConfig#{<<"password">> => <<"wrongpass">>}, AuthzConfig#{<<"database">> => <<"5678">>} @@ -180,6 +181,15 @@ t_create_invalid(_Config) -> InvalidConfigs ). +%% creating without a require filed should return error +t_create_invalid_schema(_Config) -> + AuthzConfig = raw_redis_authz_config(), + C = maps:without([<<"server">>], AuthzConfig), + ?assertMatch( + {error, {emqx_conf_schema, _}}, + emqx_authz:update(?CMD_REPLACE, [C]) + ). + t_redis_error(_Config) -> ok = setup_config(#{<<"cmd">> => <<"INVALID COMMAND">>}), diff --git a/apps/emqx_resource/src/emqx_resource_validator.erl b/apps/emqx_resource/src/emqx_resource_validator.erl index 7623ae7fa..a5404a65e 100644 --- a/apps/emqx_resource/src/emqx_resource_validator.erl +++ b/apps/emqx_resource/src/emqx_resource_validator.erl @@ -30,6 +30,7 @@ min(Type, Min) -> not_empty(ErrMsg) -> fun + (undefined) -> {error, ErrMsg}; (<<>>) -> {error, ErrMsg}; (_) -> ok end.