Просмотр исходного кода

Merge pull request #12037 from zhongwencool/license-watermark-check

fix: validate error when set license's watermark to 100%
zhongwencool 2 лет назад
Родитель
Сommit
6e6e68c902

+ 10 - 4
apps/emqx_license/src/emqx_license_schema.erl

@@ -72,10 +72,16 @@ check_license_watermark(Conf) ->
         undefined ->
             true;
         Low ->
-            High = hocon_maps:get("license.connection_high_watermark", Conf),
-            case High =/= undefined andalso High > Low of
-                true -> true;
-                false -> {bad_license_watermark, #{high => High, low => Low}}
+            case hocon_maps:get("license.connection_high_watermark", Conf) of
+                undefined ->
+                    {bad_license_watermark, #{high => undefined, low => Low}};
+                High ->
+                    {ok, HighFloat} = emqx_schema:to_percent(High),
+                    {ok, LowFloat} = emqx_schema:to_percent(Low),
+                    case HighFloat > LowFloat of
+                        true -> true;
+                        false -> {bad_license_watermark, #{high => High, low => Low}}
+                    end
             end
     end.
 

+ 11 - 0
apps/emqx_license/test/emqx_license_http_api_SUITE.erl

@@ -194,6 +194,17 @@ t_license_setting(_Config) ->
     ?assertEqual(0.5, emqx_config:get([license, connection_low_watermark])),
     ?assertEqual(0.55, emqx_config:get([license, connection_high_watermark])),
 
+    %% update
+    Low1 = <<"50%">>,
+    High1 = <<"100%">>,
+    UpdateRes1 = request(put, uri(["license", "setting"]), #{
+        <<"connection_low_watermark">> => Low1,
+        <<"connection_high_watermark">> => High1
+    }),
+    validate_setting(UpdateRes1, Low1, High1),
+    ?assertEqual(0.5, emqx_config:get([license, connection_low_watermark])),
+    ?assertEqual(1.0, emqx_config:get([license, connection_high_watermark])),
+
     %% update bad setting low >= high
     ?assertMatch(
         {ok, 400, _},