From 4d8eeae324faefbe2bfb6608912d5a620fc18780 Mon Sep 17 00:00:00 2001 From: Mike Cifelli Date: Sun, 17 Mar 2024 10:21:30 -0400 Subject: [PATCH] Add unit tests --- .formatter.exs | 3 +- config/config.exs | 3 +- config/prod.exs | 3 +- lib/chronoscope/nts/key_establishment.ex | 28 +++++----- .../components/core_components.ex | 22 ++------ .../components/layouts/app.html.heex | 5 +- .../controllers/page_html/home.html.heex | 55 ++++-------------- mix.exs | 8 +-- .../nts/key_establishment_test.exs | 56 +++++++++++++++++++ 9 files changed, 92 insertions(+), 91 deletions(-) create mode 100644 test/chronoscope/nts/key_establishment_test.exs diff --git a/.formatter.exs b/.formatter.exs index e945e12..b030704 100644 --- a/.formatter.exs +++ b/.formatter.exs @@ -1,5 +1,6 @@ [ import_deps: [:phoenix], plugins: [Phoenix.LiveView.HTMLFormatter], - inputs: ["*.{heex,ex,exs}", "{config,lib,test}/**/*.{heex,ex,exs}"] + inputs: ["*.{heex,ex,exs}", "{config,lib,test}/**/*.{heex,ex,exs}"], + line_length: 120 ] diff --git a/config/config.exs b/config/config.exs index 2d473b1..f4905e5 100644 --- a/config/config.exs +++ b/config/config.exs @@ -34,8 +34,7 @@ config :chronoscope, Chronoscope.Mailer, adapter: Swoosh.Adapters.Local config :esbuild, version: "0.17.11", chronoscope: [ - args: - ~w(js/app.js --bundle --target=es2017 --outdir=../priv/static/assets --external:/fonts/* --external:/images/*), + args: ~w(js/app.js --bundle --target=es2017 --outdir=../priv/static/assets --external:/fonts/* --external:/images/*), cd: Path.expand("../assets", __DIR__), env: %{"NODE_PATH" => Path.expand("../deps", __DIR__)} ] diff --git a/config/prod.exs b/config/prod.exs index dfa10e7..fec8974 100644 --- a/config/prod.exs +++ b/config/prod.exs @@ -5,8 +5,7 @@ import Config # manifest is generated by the `mix assets.deploy` task, # which you should run after static files are built and # before starting your production server. -config :chronoscope, ChronoscopeWeb.Endpoint, - cache_static_manifest: "priv/static/cache_manifest.json" +config :chronoscope, ChronoscopeWeb.Endpoint, cache_static_manifest: "priv/static/cache_manifest.json" # Configures Swoosh API Client config :swoosh, api_client: Swoosh.ApiClient.Finch, finch_name: Chronoscope.Finch diff --git a/lib/chronoscope/nts/key_establishment.ex b/lib/chronoscope/nts/key_establishment.ex index 3c405ac..9d55c86 100644 --- a/lib/chronoscope/nts/key_establishment.ex +++ b/lib/chronoscope/nts/key_establishment.ex @@ -118,6 +118,20 @@ defmodule Chronoscope.NTS.KeyEstablishment do do_parse_response(remaining, acc) end + defp parse_next_protocol_list(next_protocols) do + do_parse_next_protocol_list(next_protocols, []) + end + + defp do_parse_next_protocol_list([], acc) do + acc + end + + defp do_parse_next_protocol_list([high, low | rest], acc) do + @next_protocols + |> Map.get(combine_octets(high, low), "UNASSIGNED") + |> then(&do_parse_next_protocol_list(rest, [&1 | acc])) + end + defp parse_aead_algorithm_list(aead_algorithms) do do_parse_aead_algorithm_list(aead_algorithms, []) end @@ -132,20 +146,6 @@ defmodule Chronoscope.NTS.KeyEstablishment do |> then(&do_parse_aead_algorithm_list(rest, [&1 | acc])) end - defp parse_next_protocol_list(next_protocols) do - do_parse_next_protocol_list(next_protocols, []) - end - - defp do_parse_next_protocol_list([], acc) do - acc - end - - defp do_parse_next_protocol_list([high, low | rest], acc) do - @next_protocols - |> Map.get(combine_octets(high, low), "UNASSIGNED") - |> then(&do_parse_aead_algorithm_list(rest, [&1 | acc])) - end - defp combine_octets(high, low) do high <<< 8 ||| low end diff --git a/lib/chronoscope_web/components/core_components.ex b/lib/chronoscope_web/components/core_components.ex index faf9130..5b05439 100644 --- a/lib/chronoscope_web/components/core_components.ex +++ b/lib/chronoscope_web/components/core_components.ex @@ -277,8 +277,7 @@ defmodule ChronoscopeWeb.CoreComponents do values: ~w(checkbox color date datetime-local email file hidden month number password range radio search select tel text textarea time url week) - attr :field, Phoenix.HTML.FormField, - doc: "a form field struct retrieved from the form, for example: @form[:email]" + attr :field, Phoenix.HTML.FormField, doc: "a form field struct retrieved from the form, for example: @form[:email]" attr :errors, :list, default: [] attr :checked, :boolean, doc: "the checked flag for checkbox inputs" @@ -286,8 +285,7 @@ defmodule ChronoscopeWeb.CoreComponents do attr :options, :list, doc: "the options to pass to Phoenix.HTML.Form.options_for_select/2" attr :multiple, :boolean, default: false, doc: "the multiple flag for select inputs" - attr :rest, :global, - include: ~w(accept autocomplete capture cols disabled form list max maxlength min minlength + attr :rest, :global, include: ~w(accept autocomplete capture cols disabled form list max maxlength min minlength multiple pattern placeholder readonly required rows size step) slot :inner_block @@ -505,10 +503,7 @@ defmodule ChronoscopeWeb.CoreComponents do
- + <%= render_slot(action, @row_item.(row)) %>
@@ -560,10 +555,7 @@ defmodule ChronoscopeWeb.CoreComponents do def back(assigns) do ~H"""
- <.link - navigate={@navigate} - class="text-sm font-semibold leading-6 text-zinc-900 hover:text-zinc-700" - > + <.link navigate={@navigate} class="text-sm font-semibold leading-6 text-zinc-900 hover:text-zinc-700"> <.icon name="hero-arrow-left-solid" class="h-3 w-3" /> <%= render_slot(@inner_block) %> @@ -604,8 +596,7 @@ defmodule ChronoscopeWeb.CoreComponents do JS.show(js, to: selector, transition: - {"transition-all transform ease-out duration-300", - "opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95", + {"transition-all transform ease-out duration-300", "opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95", "opacity-100 translate-y-0 sm:scale-100"} ) end @@ -615,8 +606,7 @@ defmodule ChronoscopeWeb.CoreComponents do to: selector, time: 200, transition: - {"transition-all transform ease-in duration-200", - "opacity-100 translate-y-0 sm:scale-100", + {"transition-all transform ease-in duration-200", "opacity-100 translate-y-0 sm:scale-100", "opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"} ) end diff --git a/lib/chronoscope_web/components/layouts/app.html.heex b/lib/chronoscope_web/components/layouts/app.html.heex index e23bfc8..0997ae9 100644 --- a/lib/chronoscope_web/components/layouts/app.html.heex +++ b/lib/chronoscope_web/components/layouts/app.html.heex @@ -15,10 +15,7 @@ GitHub - + Get Started
diff --git a/lib/chronoscope_web/controllers/page_html/home.html.heex b/lib/chronoscope_web/controllers/page_html/home.html.heex index dc1820b..60b5231 100644 --- a/lib/chronoscope_web/controllers/page_html/home.html.heex +++ b/lib/chronoscope_web/controllers/page_html/home.html.heex @@ -1,12 +1,6 @@ <.flash_group flash={@flash} />