fix(redis): validate database number
This commit is contained in:
parent
2cc0ba1217
commit
9701c3f7a1
|
@ -157,22 +157,32 @@ t_create_with_config_values_wont_work(_Config) ->
|
||||||
).
|
).
|
||||||
|
|
||||||
t_create_invalid_config(_Config) ->
|
t_create_invalid_config(_Config) ->
|
||||||
Config0 = raw_redis_auth_config(),
|
BaseAuthConfig = raw_redis_auth_config(),
|
||||||
Config = maps:without([<<"server">>], Config0),
|
|
||||||
|
test_create_invalid_config(
|
||||||
|
maps:without([<<"server">>], BaseAuthConfig),
|
||||||
|
"authentication.1.server"
|
||||||
|
),
|
||||||
|
test_create_invalid_config(
|
||||||
|
BaseAuthConfig#{<<"database">> => <<"-1">>},
|
||||||
|
"authentication.1.database"
|
||||||
|
).
|
||||||
|
|
||||||
|
test_create_invalid_config(InvalidAuthConfig, Path) ->
|
||||||
?assertMatch(
|
?assertMatch(
|
||||||
{error, #{
|
{error, #{
|
||||||
kind := validation_error,
|
kind := validation_error,
|
||||||
matched_type := "authn:redis_single",
|
matched_type := "authn:redis_single",
|
||||||
path := "authentication.1.server",
|
path := Path
|
||||||
reason := required_field
|
|
||||||
}},
|
}},
|
||||||
emqx:update_config(?PATH, {create_authenticator, ?GLOBAL, Config})
|
emqx:update_config(?PATH, {create_authenticator, ?GLOBAL, InvalidAuthConfig})
|
||||||
),
|
),
|
||||||
?assertMatch([], emqx_config:get_raw([authentication])),
|
?assertMatch([], emqx_config:get_raw([authentication])),
|
||||||
?assertEqual(
|
?assertEqual(
|
||||||
{error, {not_found, {chain, ?GLOBAL}}},
|
{error, {not_found, {chain, ?GLOBAL}}},
|
||||||
emqx_authentication:list_authenticators(?GLOBAL)
|
emqx_authentication:list_authenticators(?GLOBAL)
|
||||||
).
|
),
|
||||||
|
ok.
|
||||||
|
|
||||||
t_authenticate(_Config) ->
|
t_authenticate(_Config) ->
|
||||||
ok = lists:foreach(
|
ok = lists:foreach(
|
||||||
|
|
|
@ -294,7 +294,7 @@ redis_fields() ->
|
||||||
{pool_size, fun emqx_connector_schema_lib:pool_size/1},
|
{pool_size, fun emqx_connector_schema_lib:pool_size/1},
|
||||||
{password, fun emqx_connector_schema_lib:password/1},
|
{password, fun emqx_connector_schema_lib:password/1},
|
||||||
{database, #{
|
{database, #{
|
||||||
type => integer(),
|
type => non_neg_integer(),
|
||||||
default => 0,
|
default => 0,
|
||||||
desc => ?DESC("database")
|
desc => ?DESC("database")
|
||||||
}},
|
}},
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Fixed database number validation for Redis connector. Previously negative numbers were accepted as valid database numbers.
|
Loading…
Reference in New Issue