Skip to content

Commit

Permalink
IP Restriction plugin: support mask format
Browse files Browse the repository at this point in the history
  • Loading branch information
gmile committed Sep 19, 2017
1 parent a575737 commit 6ce6128
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/annon_api/plugins/ip_restriction/settings_validator.ex
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ defmodule Annon.Plugins.IPRestriction.SettingsValidator do
"items" => %{
"type" => "string",
"oneOf" => [
%{"pattern" => "^(\\*|\\d+)\.(\\*|\\d+)\.(\\*|\\d+)\.(\\*|\\d+)$"}
%{"pattern" => "^(\\*|\\d+)\.(\\*|\\d+)\.(\\*|\\d+)\.(\\*|\\d+)(\/\\d{1,2})?$"}
]
}
},
Expand All @@ -32,7 +32,7 @@ defmodule Annon.Plugins.IPRestriction.SettingsValidator do
"items" => %{
"type" => "string",
"oneOf" => [
%{"pattern" => "^(\\*|\\d+)\.(\\*|\\d+)\.(\\*|\\d+)\.(\\*|\\d+)$"}
%{"pattern" => "^(\\*|\\d+)\.(\\*|\\d+)\.(\\*|\\d+)\.(\\*|\\d+)(\/\\d{1,2})?$"}
]
}
}
Expand Down
7 changes: 7 additions & 0 deletions test/unit/plugins/ip_restriction_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ defmodule Annon.Plugins.IPRestrictionTest do
}}}

assert %Ecto.Changeset{valid?: false} = IPRestriction.validate_settings(changeset)

changeset = %Ecto.Changeset{valid?: true, changes: %{settings: %{
"blacklist" => ["127.0.0.0/100"],
"whitelist" => ["128.30.50.245/ab"]
}}}

assert %Ecto.Changeset{valid?: false} = IPRestriction.validate_settings(changeset)
end
end

Expand Down

0 comments on commit 6ce6128

Please sign in to comment.