diff --git a/.formatter.exs b/.formatter.exs index 6f1014c..d2cda26 100644 --- a/.formatter.exs +++ b/.formatter.exs @@ -1,5 +1,4 @@ # Used by "mix format" [ - inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"], - force_do_end_blocks: true + inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"] ] diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..477e836 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,42 @@ +version: 2 +updates: + - package-ecosystem: npm + directory: /ts + schedule: + interval: monthly + + groups: + ts-dev: + patterns: + - concurrently + - '@tsconfig/*' + - '@types/*' + - '@typescript-eslint/*' + - eslint + - 'eslint-plugin-*' + - prettier + - 'ts-*' + - tsup + - typedoc + - typescript + - vitest + + - package-ecosystem: mix + directory: /elixir + schedule: + interval: monthly + + - package-ecosystem: bundler + directory: /ruby + schedule: + interval: monthly + + - package-ecosystem: github-actions + directory: / + schedule: + interval: monthly + + groups: + actions: + patterns: + - '*' diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml deleted file mode 100644 index 03cec2b..0000000 --- a/.github/workflows/build.yml +++ /dev/null @@ -1,84 +0,0 @@ -name: build - -on: - workflow_dispatch: - push: - branches: - - main - pull_request: - branches: - - main - -jobs: - ci: - strategy: - fail-fast: false - matrix: - include: - - elixir: '1.8' - otp: '20' - - elixir: '1.9' - otp: '20' - - elixir: '1.10' - otp: '21' - - elixir: '1.11' - otp: '21' - - elixir: '1.11' - otp: '23' - - elixir: '1.12' - otp: '24' - - name: Elixir ${{ matrix.elixir }} (OTP ${{ matrix.otp }}) - - runs-on: ubuntu-latest - - steps: - - name: Checkout repository - uses: actions/checkout@v2 - - - id: install - name: Install Elixir - uses: erlef/setup-elixir@v1 - with: - otp-version: ${{ matrix.otp }} - elixir-version: ${{ matrix.elixir }} - - - name: Restore cached build - uses: actions/cache@v2 - with: - key: builds@elixir-${{ steps.install.outputs.elixir-version }}-otp-${{ steps.install.outputs.otp-version }}-mix-${{ hashFiles('mix.lock') }} - path: | - deps - _build - - - name: Install dependencies - run: mix do deps.get, deps.compile - - - name: Check formatting - run: mix format --check-formatted - - - name: Compile - run: mix compile --warnings-as-errors - - - name: Run unit tests - run: mix test - - - name: Restore cached integrations - uses: actions/cache@v2 - with: - key: integrations@elixir-${{ steps.install.outputs.elixir-version }}-otp-${{ steps.install.outputs.otp-version }}-mix-${{ hashFiles('integration/tests/*/mix.lock') }} - path: | - integration/tests/*/deps - integration/tests/*/_build - - - name: Restore cached PLTs - uses: actions/cache@v2 - with: - key: plts@elixir-${{ steps.install.outputs.elixir-version }}-otp-${{ steps.install.outputs.otp-version }}-mix-${{ hashFiles('mix.lock') }} - path: | - priv/plts - restore-keys: | - plts@elixir-${{ steps.install.outputs.elixir-version }}-otp-${{ steps.install.outputs.otp-version }}-mix- - - - name: Run dialyzer - run: mix dialyzer diff --git a/.github/workflows/dco-check.yml b/.github/workflows/dco-check.yml new file mode 100644 index 0000000..2d662b2 --- /dev/null +++ b/.github/workflows/dco-check.yml @@ -0,0 +1,10 @@ +name: Check DCO + +on: + pull_request: + +jobs: + check-dco: + runs-on: ubuntu-latest + steps: + - uses: KineticCafe/actions-dco@v1.1 diff --git a/.github/workflows/dependabot-automerge.yml b/.github/workflows/dependabot-automerge.yml new file mode 100644 index 0000000..9345e3c --- /dev/null +++ b/.github/workflows/dependabot-automerge.yml @@ -0,0 +1,17 @@ +name: Dependabot auto-merge + +on: + pull_request: + +permissions: + contents: write + pull-requests: write + +jobs: + dependabot-automerge: + runs-on: ubuntu-latest + + steps: + - uses: KineticCafe/actions/dependabot-automerge@v1.0 + with: + update-type: minor diff --git a/.github/workflows/elixir.yml b/.github/workflows/elixir.yml new file mode 100644 index 0000000..75cb06f --- /dev/null +++ b/.github/workflows/elixir.yml @@ -0,0 +1,100 @@ +name: Elixir CI + +on: + pull_request: + push: + branches: + - main + merge_group: + types: + - checks_requested + workflow_dispatch: + +jobs: + elixir-ci: + name: Elixir ${{ matrix.elixir }} (OTP ${{ matrix.otp }}) + + env: + LANG: en_US.UTF-8 + LC_CTYPE: en_US.UTF-8 + + strategy: + fail-fast: true + matrix: + include: + - elixir: '1.8' + otp: '20' + os: ubuntu-20.04 + - elixir: '1.9' + otp: '20' + os: ubuntu-20.04 + - elixir: '1.10' + otp: '21' + os: ubuntu-20.04 + - elixir: '1.11' + otp: '21' + os: ubuntu-20.04 + - elixir: '1.11' + otp: '23' + os: ubuntu-20.04 + - elixir: '1.12' + otp: '24' + os: ubuntu-22.04 + - elixir: '1.13' + otp: '24' + os: ubuntu-22.04 + - elixir: '1.14' + otp: '25' + os: ubuntu-22.04 + - elixir: '1.15' + otp: '26' + os: ubuntu-22.04 + check_formatted: true + warnings_as_errors: true + dialyzer: true + credo: true + + runs-on: ${{ matrix.os }} + + steps: + - uses: actions/checkout@v3 + - uses: erlef/setup-elixir@v1 + id: install + with: + otp-version: ${{ matrix.otp }} + elixir-version: ${{ matrix.elixir }} + + - uses: actions/cache@v3 + with: + key: builds@elixir-${{ steps.install.outputs.elixir-version }}-otp-${{ steps.install.outputs.otp-version }}-mix-${{ hashFiles('mix.lock') }} + path: | + deps + _build + + - run: mix 'do' deps.get, deps.compile + + - run: mix format --check-formatted + if: matrix.check_formatted + + - run: mix compile --warnings-as-errors + if: matrix.warnings_as_errors + + - run: mix compile + if: ${{ !matrix.warnings_as_errors }} + + - run: mix test + + - run: mix credo --strict + if: matrix.credo + + - uses: actions/cache@v3 + if: matrix.dialyzer + with: + key: plts@elixir-${{ steps.install.outputs.elixir-version }}-otp-${{ steps.install.outputs.otp-version }}-mix-${{ hashFiles('mix.lock') }} + path: | + priv/plts + restore-keys: | + plts@elixir-${{ steps.install.outputs.elixir-version }}-otp-${{ steps.install.outputs.otp-version }}-mix- + + - run: mix dialyzer + if: matrix.dialyzer diff --git a/Changelog.md b/Changelog.md index 29faab2..6a15114 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,5 +1,21 @@ # Changelog +## 1.0.1 + +- Extended GitHub Actions testing range, 1.8 to 1.15. + + NOTE: credo, dialyxir, and ex_doc are only configured for 1.15 or later. + +- Added DCO checking (we will require sign-offs moving forward). + +- Added Dependabot configuration and automerge. + +- Updated dependencies to the latest versions and verified dialyzer + cleanliness. + +- Undid the formatting when I enabled `force_do_end_blocks: true` in + `.formatter.exs`. + ## 1.0.0 - Initial release, extracted from one of our projects originally based on diff --git a/Contributing.md b/Contributing.md index 24a5f8f..1825d74 100644 --- a/Contributing.md +++ b/Contributing.md @@ -1,6 +1,6 @@ # Contributing -We value any contribution to IPAccessControl you can provide: a bug +We value any contribution to IpAccessControl you can provide: a bug report, a feature request, or code contributions. Here are our guidelines for contributions: @@ -29,6 +29,24 @@ Here's the most direct way to get your work merged into the project: - Create a pull request against KineticCafe/ip_access_controland describe your change does and the why you think it should be merged. +## Developer Certificate of Origin + +All contributors **must** certify they are able and willing to provide their +contributions under the terms of this project's licenses with the certification +of the [Developer Certificate of Origin (Version 1.1)][dco]. + +Such certification is provided by ensuring that the following line must be +included as the last line of a commit message for every commit contributed: + + Signed-off-by: FirstName LastName + +The `Signed-off-by` line can be automatically added by git with the `-s` or +`--signoff` option on `git commit`: + +```sh +git commit --signoff +``` + ## Contributors - Austin Ziegler created `ip_access_control`, based in part on @@ -37,3 +55,4 @@ Here's the most direct way to get your work merged into the project: [quality commit messages]: http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html [credo]: https://github.com/rrrene/credo [`plug_ip_whitelist`]: https://github.com/ForwardFinancing/plug_ip_whitelist +[dco]: https://developercertificate.org diff --git a/Licence.md b/Licence.md index 95d6139..c37c150 100644 --- a/Licence.md +++ b/Licence.md @@ -2,7 +2,7 @@ This software is available under an MIT-style licence. -- Copyright 2019-2020 Kinetic Commerce and contributors. +- Copyright 2019-2023 Kinetic Commerce and contributors. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index a4f8229..9402042 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ dependency and configure that as well. ```elixir def deps do [ - {:ip_access_control, "~> 1.0.0"}, + {:ip_access_control, "~> 1.0.1"}, {:remote_ip, "~> 1.0"} # Required if behind a proxy ] end diff --git a/lib/ip_access_control.ex b/lib/ip_access_control.ex index ac4dcaf..13e66e8 100644 --- a/lib/ip_access_control.ex +++ b/lib/ip_access_control.ex @@ -120,9 +120,7 @@ defmodule IpAccessControl do @doc "Initialize the plug with options." @spec init(IpAccessControl.Options.input_config()) :: IpAccessControl.Options.config() - def init(options) do - IpAccessControl.Options.pack(options) - end + def init(options), do: IpAccessControl.Options.pack(options) @spec call(Conn.t(), IpAccessControl.Options.config()) :: Conn.t() def call(conn, options) do @@ -138,9 +136,9 @@ defmodule IpAccessControl do end @spec ip_access_on_blocked(Conn.t(), IpAccessControl.Options.config()) :: Conn.t() - def ip_access_on_blocked(conn, options) do - Conn.send_resp(conn, options[:response_code_on_blocked], options[:response_body_on_blocked]) - end + def ip_access_on_blocked(conn, options), + do: + Conn.send_resp(conn, options[:response_code_on_blocked], options[:response_body_on_blocked]) @doc """ Returns `true` if the remote IP is in the given allow list. The remote IP @@ -157,32 +155,18 @@ defmodule IpAccessControl do """ @spec allowed?( Conn.t() | binary() | :inet.ip_address() | nil | BitwiseIp.t(), - [binary(), ...] | (() -> [binary(), ...]) | ip_block_list() | nil + [binary(), ...] | (-> [binary(), ...]) | ip_block_list() | nil ) :: boolean - def allowed?(_, []) do - false - end - - def allowed?(_, nil) do - false - end - - def allowed?(nil, _) do - false - end + def allowed?(_, []), do: false + def allowed?(_, nil), do: false + def allowed?(nil, _), do: false + def allowed?("", _), do: false - def allowed?("", _) do - false - end - - def allowed?(remote_ip, allow_fn) when is_function(allow_fn, 0) do - allowed?(remote_ip, allow_fn.()) - end + def allowed?(remote_ip, allow_fn) when is_function(allow_fn, 0), + do: allowed?(remote_ip, allow_fn.()) - def allowed?(%Conn{remote_ip: remote_ip}, allow_list) do - allowed?(remote_ip, allow_list) - end + def allowed?(%Conn{remote_ip: remote_ip}, allow_list), do: allowed?(remote_ip, allow_list) def allowed?(remote_ip, allow_list) when is_binary(remote_ip) do case BitwiseIp.parse(remote_ip) do @@ -191,17 +175,13 @@ defmodule IpAccessControl do end end - def allowed?(remote_ip, allow_list) when is_tuple(remote_ip) do - allowed?(BitwiseIp.encode(remote_ip), allow_list) - end + def allowed?(remote_ip, allow_list) when is_tuple(remote_ip), + do: allowed?(BitwiseIp.encode(remote_ip), allow_list) - def allowed?(%BitwiseIp{} = remote_ip, allow_list) do - BitwiseIp.Blocks.member?(parse_allow_list(allow_list), remote_ip) - end + def allowed?(%BitwiseIp{} = remote_ip, allow_list), + do: BitwiseIp.Blocks.member?(parse_allow_list(allow_list), remote_ip) - def allowed?(_, _) do - false - end + def allowed?(_, _), do: false @doc false def parse_allow_list(list) do diff --git a/lib/ip_access_control/options.ex b/lib/ip_access_control/options.ex index 11df687..cb3fb4d 100644 --- a/lib/ip_access_control/options.ex +++ b/lib/ip_access_control/options.ex @@ -7,14 +7,14 @@ defmodule IpAccessControl.Options do @type input_config :: [ module: module, - allow: (() -> [binary(), ...]) | [binary(), ...], + allow: (-> [binary(), ...]) | [binary(), ...], on_blocked: (Plug.Conn.t(), Plug.opts() -> Plug.Conn.t()) | module, response_code_on_blocked: integer(), response_body_on_blocked: String.t() ] @type config :: %{ - allow: (() -> [binary(), ...]) | [binary(), ...], + allow: (-> [binary(), ...]) | [binary(), ...], on_blocked: (Plug.Conn.t(), Plug.opts() -> Plug.Conn.t()), response_code_on_blocked: integer(), response_body_on_blocked: String.t() @@ -28,17 +28,11 @@ defmodule IpAccessControl.Options do def default(option) - def default(:on_blocked) do - @on_blocked - end + def default(:on_blocked), do: @on_blocked - def default(:response_code_on_blocked) do - @response_code_on_blocked - end + def default(:response_code_on_blocked), do: @response_code_on_blocked - def default(:response_body_on_blocked) do - @response_body_on_blocked - end + def default(:response_body_on_blocked), do: @response_body_on_blocked @doc """ Pre-processes keyword options. Where possible, function resolution will be @@ -119,9 +113,7 @@ defmodule IpAccessControl.Options do end end - defp unpack(options, option) do - Map.fetch!(options, option) - end + defp unpack(options, option), do: Map.fetch!(options, option) defp evaluate(:allow, allow_list) do allow_list @@ -129,7 +121,5 @@ defmodule IpAccessControl.Options do |> BitwiseIp.Blocks.optimize() end - defp evaluate(_option, value) do - value - end + defp evaluate(_option, value), do: value end diff --git a/mix.exs b/mix.exs index 1516224..1525413 100644 --- a/mix.exs +++ b/mix.exs @@ -3,8 +3,8 @@ defmodule IpAccessControlPlug.MixProject do use Mix.Project - @project_url "https://github.com/KineticCafe/ip_access_control_plug" - @version "1.0.0" + @project_url "https://github.com/KineticCafe/ip_access_control" + @version "1.0.1" def project do [ @@ -22,7 +22,7 @@ defmodule IpAccessControlPlug.MixProject do dialyzer: [ plt_file: {:no_warn, "priv/plts/dialyzer.plt"} ], - deps: deps(), + deps: deps() ++ dev_deps(), docs: docs() ] end @@ -51,7 +51,7 @@ defmodule IpAccessControlPlug.MixProject do [ source_ref: "v#{@version}", canonical: "http://hexdocs.pm/ip_access_control", - main: "IPAccessControl", + main: "IpAccessControl", source_url: @project_url, extras: ["README.md", "Changelog.md", "Contributing.md", "Licence.md"] ] @@ -60,10 +60,19 @@ defmodule IpAccessControlPlug.MixProject do defp deps do [ {:plug, "~> 1.0"}, - {:bitwise_ip, "~> 1.0"}, - {:credo, "~> 1.0", only: [:dev], runtime: false}, - {:dialyxir, "~> 1.1", only: [:dev], runtime: false}, - {:ex_doc, "~> 0.19", only: :dev, runtime: false} + {:bitwise_ip, "~> 1.0"} ] end + + if Version.compare(System.version(), "1.15.0") == :lt do + defp dev_deps, do: [] + else + defp dev_deps do + [ + {:credo, "~> 1.0", only: [:dev], runtime: false}, + {:dialyxir, "~> 1.4", only: [:dev], runtime: false}, + {:ex_doc, "~> 0.30", only: [:dev], runtime: false} + ] + end + end end diff --git a/mix.lock b/mix.lock index 9d6a5e1..c6c7be9 100644 --- a/mix.lock +++ b/mix.lock @@ -1,21 +1,19 @@ %{ "bitwise_ip": {:hex, :bitwise_ip, "1.0.0", "0193c618d078ae606cf13194ae40cb9709b7de3e5e07a3e58c1acd7423db1351", [:mix], [], "hexpm", "87436527b22c3b579919031b732bd647c0ae4356bdd50f49258baafd2095d18d"}, - "bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [:mix], [], "hexpm", "7af5c7e09fe1d40f76c8e4f9dd2be7cebd83909f31fee7cd0e9eadc567da8353"}, - "combine": {:hex, :combine, "0.10.0", "eff8224eeb56498a2af13011d142c5e7997a80c8f5b97c499f84c841032e429f", [:mix], [], "hexpm", "1b1dbc1790073076580d0d1d64e42eae2366583e7aecd455d1215b0d16f2451b"}, - "credo": {:hex, :credo, "1.5.4", "9914180105b438e378e94a844ec3a5088ae5875626fc945b7c1462b41afc3198", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2.8", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "cf51af45eadc0a3f39ba13b56fdac415c91b34f7b7533a13dc13550277141bc4"}, - "dialyxir": {:hex, :dialyxir, "1.1.0", "c5aab0d6e71e5522e77beff7ba9e08f8e02bad90dfbeffae60eaf0cb47e29488", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "07ea8e49c45f15264ebe6d5b93799d4dd56a44036cf42d0ad9c960bc266c0b9a"}, - "earmark_parser": {:hex, :earmark_parser, "1.4.12", "b245e875ec0a311a342320da0551da407d9d2b65d98f7a9597ae078615af3449", [:mix], [], "hexpm", "711e2cc4d64abb7d566d43f54b78f7dc129308a63bc103fbd88550d2174b3160"}, + "bunt": {:hex, :bunt, "0.2.1", "e2d4792f7bc0ced7583ab54922808919518d0e57ee162901a16a1b6664ef3b14", [:mix], [], "hexpm", "a330bfb4245239787b15005e66ae6845c9cd524a288f0d141c148b02603777a5"}, + "credo": {:hex, :credo, "1.7.1", "6e26bbcc9e22eefbff7e43188e69924e78818e2fe6282487d0703652bc20fd62", [:mix], [{:bunt, "~> 0.2.1", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2.8", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "e9871c6095a4c0381c89b6aa98bc6260a8ba6addccf7f6a53da8849c748a58a2"}, + "dialyxir": {:hex, :dialyxir, "1.4.2", "764a6e8e7a354f0ba95d58418178d486065ead1f69ad89782817c296d0d746a5", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "516603d8067b2fd585319e4b13d3674ad4f314a5902ba8130cd97dc902ce6bbd"}, + "earmark_parser": {:hex, :earmark_parser, "1.4.37", "2ad73550e27c8946648b06905a57e4d454e4d7229c2dafa72a0348c99d8be5f7", [:mix], [], "hexpm", "6b19783f2802f039806f375610faa22da130b8edc21209d0bff47918bb48360e"}, "erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"}, - "ex_doc": {:hex, :ex_doc, "0.23.0", "a069bc9b0bf8efe323ecde8c0d62afc13d308b1fa3d228b65bca5cf8703a529d", [:mix], [{:earmark_parser, "~> 1.4.0", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm", "f5e2c4702468b2fd11b10d39416ddadd2fcdd173ba2a0285ebd92c39827a5a16"}, + "ex_doc": {:hex, :ex_doc, "0.30.9", "d691453495c47434c0f2052b08dd91cc32bc4e1a218f86884563448ee2502dd2", [:mix], [{:earmark_parser, "~> 1.4.31", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "d7aaaf21e95dc5cddabf89063327e96867d00013963eadf2c6ad135506a8bc10"}, "file_system": {:hex, :file_system, "0.2.10", "fb082005a9cd1711c05b5248710f8826b02d7d1784e7c3451f9c1231d4fc162d", [:mix], [], "hexpm", "41195edbfb562a593726eda3b3e8b103a309b733ad25f3d642ba49696bf715dc"}, - "inet_cidr": {:hex, :inet_cidr, "1.0.4", "a05744ab7c221ca8e395c926c3919a821eb512e8f36547c062f62c4ca0cf3d6e", [:mix], [], "hexpm", "64a2d30189704ae41ca7dbdd587f5291db5d1dda1414e0774c29ffc81088c1bc"}, - "jason": {:hex, :jason, "1.2.2", "ba43e3f2709fd1aa1dce90aaabfd039d000469c05c56f0b8e31978e03fa39052", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "18a228f5f0058ee183f29f9eae0805c6e59d61c3b006760668d8d18ff0d12179"}, - "makeup": {:hex, :makeup, "1.0.5", "d5a830bc42c9800ce07dd97fa94669dfb93d3bf5fcf6ea7a0c67b2e0e4a7f26c", [:mix], [{:nimble_parsec, "~> 0.5 or ~> 1.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "cfa158c02d3f5c0c665d0af11512fed3fba0144cf1aadee0f2ce17747fba2ca9"}, - "makeup_elixir": {:hex, :makeup_elixir, "0.15.0", "98312c9f0d3730fde4049985a1105da5155bfe5c11e47bdc7406d88e01e4219b", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.1", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "75ffa34ab1056b7e24844c90bfc62aaf6f3a37a15faa76b07bc5eba27e4a8b4a"}, - "mime": {:hex, :mime, "1.5.0", "203ef35ef3389aae6d361918bf3f952fa17a09e8e43b5aa592b93eba05d0fb8d", [:mix], [], "hexpm", "55a94c0f552249fc1a3dd9cd2d3ab9de9d3c89b559c2bd01121f824834f24746"}, - "nimble_parsec": {:hex, :nimble_parsec, "1.1.0", "3a6fca1550363552e54c216debb6a9e95bd8d32348938e13de5eda962c0d7f89", [:mix], [], "hexpm", "08eb32d66b706e913ff748f11694b17981c0b04a33ef470e33e11b3d3ac8f54b"}, - "plug": {:hex, :plug, "1.11.0", "f17217525597628298998bc3baed9f8ea1fa3f1160aa9871aee6df47a6e4d38e", [:mix], [{:mime, "~> 1.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "2d9c633f0499f9dc5c2fd069161af4e2e7756890b81adcbb2ceaa074e8308876"}, - "plug_crypto": {:hex, :plug_crypto, "1.2.0", "1cb20793aa63a6c619dd18bb33d7a3aa94818e5fd39ad357051a67f26dfa2df6", [:mix], [], "hexpm", "a48b538ae8bf381ffac344520755f3007cc10bd8e90b240af98ea29b69683fc2"}, - "remote_ip": {:hex, :remote_ip, "1.0.0", "3d7fb45204a5704443f480cee9515e464997f52c35e0a60b6ece1f81484067ae", [:mix], [{:combine, "~> 0.10", [hex: :combine, repo: "hexpm", optional: false]}, {:plug, "~> 1.10", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "9e9fcad4e50c43b5234bb6a9629ed6ab223f3ed07147bd35470e4ee5c8caf907"}, - "telemetry": {:hex, :telemetry, "0.4.2", "2808c992455e08d6177322f14d3bdb6b625fbcfd233a73505870d8738a2f4599", [:rebar3], [], "hexpm", "2d1419bd9dda6a206d7b5852179511722e2b18812310d304620c7bd92a13fcef"}, + "jason": {:hex, :jason, "1.4.1", "af1504e35f629ddcdd6addb3513c3853991f694921b1b9368b0bd32beb9f1b63", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "fbb01ecdfd565b56261302f7e1fcc27c4fb8f32d56eab74db621fc154604a7a1"}, + "makeup": {:hex, :makeup, "1.1.0", "6b67c8bc2882a6b6a445859952a602afc1a41c2e08379ca057c0f525366fc3ca", [:mix], [{:nimble_parsec, "~> 1.2.2 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "0a45ed501f4a8897f580eabf99a2e5234ea3e75a4373c8a52824f6e873be57a6"}, + "makeup_elixir": {:hex, :makeup_elixir, "0.16.1", "cc9e3ca312f1cfeccc572b37a09980287e243648108384b97ff2b76e505c3555", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "e127a341ad1b209bd80f7bd1620a15693a9908ed780c3b763bccf7d200c767c6"}, + "makeup_erlang": {:hex, :makeup_erlang, "0.1.2", "ad87296a092a46e03b7e9b0be7631ddcf64c790fa68a9ef5323b6cbb36affc72", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "f3f5a1ca93ce6e092d92b6d9c049bcda58a3b617a8d888f8e7231c85630e8108"}, + "mime": {:hex, :mime, "2.0.5", "dc34c8efd439abe6ae0343edbb8556f4d63f178594894720607772a041b04b02", [:mix], [], "hexpm", "da0d64a365c45bc9935cc5c8a7fc5e49a0e0f9932a761c55d6c52b142780a05c"}, + "nimble_parsec": {:hex, :nimble_parsec, "1.3.1", "2c54013ecf170e249e9291ed0a62e5832f70a476c61da16f6aac6dca0189f2af", [:mix], [], "hexpm", "2682e3c0b2eb58d90c6375fc0cc30bc7be06f365bf72608804fb9cffa5e1b167"}, + "plug": {:hex, :plug, "1.15.1", "b7efd81c1a1286f13efb3f769de343236bd8b7d23b4a9f40d3002fc39ad8f74c", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2 or ~> 2.0", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.3 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "459497bd94d041d98d948054ec6c0b76feacd28eec38b219ca04c0de13c79d30"}, + "plug_crypto": {:hex, :plug_crypto, "2.0.0", "77515cc10af06645abbfb5e6ad7a3e9714f805ae118fa1a70205f80d2d70fe73", [:mix], [], "hexpm", "53695bae57cc4e54566d993eb01074e4d894b65a3766f1c43e2c61a1b0f45ea9"}, + "telemetry": {:hex, :telemetry, "1.2.1", "68fdfe8d8f05a8428483a97d7aab2f268aaff24b49e0f599faa091f1d4e7f61c", [:rebar3], [], "hexpm", "dad9ce9d8effc621708f99eac538ef1cbe05d6a874dd741de2e689c47feafed5"}, } diff --git a/test/ip_access_control/options_test.exs b/test/ip_access_control/options_test.exs index b4f705e..5aac95f 100644 --- a/test/ip_access_control/options_test.exs +++ b/test/ip_access_control/options_test.exs @@ -15,34 +15,23 @@ defmodule IpAccessControl.OptionsTest do defmodule Complete do @moduledoc false - def ip_access_allow_list do - ["1.2.3.4", "1:2:3::4"] - end - - def ip_access_on_blocked(conn, _options) do - Plug.Conn.send_resp(conn, 321, "Contact!") - end + def ip_access_allow_list, do: ["1.2.3.4", "1:2:3::4"] + def ip_access_on_blocked(conn, _options), do: Plug.Conn.send_resp(conn, 321, "Contact!") end defmodule AllowOnly do @moduledoc false - def ip_access_allow_list do - ["1:2:3::4", "1.2.3.4"] - end + def ip_access_allow_list, do: ["1:2:3::4", "1.2.3.4"] end defmodule OnBlockedOnly do - def ip_access_on_blocked(conn, _options) do - Plug.Conn.send_resp(conn, 500, "Server Error") - end + def ip_access_on_blocked(conn, _options), do: Plug.Conn.send_resp(conn, 500, "Server Error") end describe "pack/1" do test "Fails if :allow is missing" do - assert_raise KeyError, fn -> - Options.pack([]) - end + assert_raise KeyError, fn -> Options.pack([]) end end test "skips unknown options" do @@ -248,7 +237,5 @@ defmodule IpAccessControl.OptionsTest do end end - def test_allow_list do - ["1.2.3.4"] - end + def test_allow_list, do: ["1.2.3.4"] end diff --git a/test/ip_access_control_test.exs b/test/ip_access_control_test.exs index d75ea56..c6b6093 100644 --- a/test/ip_access_control_test.exs +++ b/test/ip_access_control_test.exs @@ -8,9 +8,7 @@ defmodule IpAccessControlTest do %{allow: "10.0.0.0/24", good: ["10.0.0.0", "10.0.0.127", "10.0.0.255"], bad: ["10.0.1.0"]} ] - def call(conn, opts \\ []) do - IpAccessControl.call(conn, IpAccessControl.init(opts)) - end + def call(conn, opts \\ []), do: IpAccessControl.call(conn, IpAccessControl.init(opts)) describe "call/2" do for %{allow: allow, good: good, bad: bad} <- @data do