From 9ce4b8536012e87bb95c0d3a2dfb9fc38533bd7e Mon Sep 17 00:00:00 2001 From: Bruno Silva Date: Thu, 1 Oct 2020 11:13:46 -0300 Subject: [PATCH 1/5] (feat) Add sobelow into CI for static analysis --- .circleci/config.yml | 12 ++++++++++++ mix.exs | 3 ++- mix.lock | 1 + 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 0c50643..0c252d2 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -40,6 +40,14 @@ jobs: - run: mix deps.get - run: mix hex.publish --yes + sec_code_analysis: + docker: + - image: circleci/elixir:1.7.3 + + steps: + - checkout + - run: mix sobelow + workflows: version: 2.1 build_and_test: @@ -54,6 +62,9 @@ workflows: - hexpm/elixir:1.9.4-erlang-20.3.8.26-alpine-3.12.0 - hexpm/elixir:1.10.4-erlang-21.3.8.17-alpine-3.12.0 - hexpm/elixir:1.10.4-erlang-23.0.3-alpine-3.12.0 + - sec_code_analysis: + requires: + - build_and_test - publish_production_approval: type: approval filters: @@ -70,3 +81,4 @@ workflows: - master requires: - publish_production_approval + - sec_code_analysis \ No newline at end of file diff --git a/mix.exs b/mix.exs index ef73020..a51eff1 100644 --- a/mix.exs +++ b/mix.exs @@ -52,7 +52,8 @@ defmodule BRAN.MixProject do {:credo, "~> 1.4", only: [:dev, :test], runtime: false}, {:junit_formatter, "~> 3.1", only: :test, runtime: false}, {:excoveralls, "~> 0.10", only: :test}, - {:ex_parameterized, "~> 1.3", only: [:test]} + {:ex_parameterized, "~> 1.3", only: [:test]}, + {:sobelow, "~> 0.10.4", only: :dev} ] end end diff --git a/mix.lock b/mix.lock index 4d4a0b5..bb89c05 100644 --- a/mix.lock +++ b/mix.lock @@ -17,6 +17,7 @@ "mimerl": {:hex, :mimerl, "1.2.0", "67e2d3f571088d5cfd3e550c383094b47159f3eee8ffa08e64106cdf5e981be3", [:rebar3], [], "hexpm", "f278585650aa581986264638ebf698f8bb19df297f66ad91b18910dfc6e19323"}, "nimble_parsec": {:hex, :nimble_parsec, "0.6.0", "32111b3bf39137144abd7ba1cce0914533b2d16ef35e8abc5ec8be6122944263", [:mix], [], "hexpm", "27eac315a94909d4dc68bc07a4a83e06c8379237c5ea528a9acff4ca1c873c52"}, "parse_trans": {:hex, :parse_trans, "3.3.0", "09765507a3c7590a784615cfd421d101aec25098d50b89d7aa1d66646bc571c1", [:rebar3], [], "hexpm", "17ef63abde837ad30680ea7f857dd9e7ced9476cdd7b0394432af4bfc241b960"}, + "sobelow": {:hex, :sobelow, "0.10.4", "44ba642da120d84fedb9e85473375084034330c8f15a992351dd164a82963103", [:mix], [], "hexpm", "fea62a94a4112de45ee9c9d076fd636fbbc10b7c7c2ea99a928e7c289b8498d1"}, "ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.6", "cf344f5692c82d2cd7554f5ec8fd961548d4fd09e7d22f5b62482e5aeaebd4b0", [:make, :mix, :rebar3], [], "hexpm", "bdb0d2471f453c88ff3908e7686f86f9be327d065cc1ec16fa4540197ea04680"}, "unicode_util_compat": {:hex, :unicode_util_compat, "0.5.0", "8516502659002cec19e244ebd90d312183064be95025a319a6c7e89f4bccd65b", [:rebar3], [], "hexpm", "d48d002e15f5cc105a696cf2f1bbb3fc72b4b770a184d8420c8db20da2674b38"}, } From f6bec03bb1b90e54067bf3268c4bc7dd93806698 Mon Sep 17 00:00:00 2001 From: Bruno Silva Date: Thu, 1 Oct 2020 11:19:48 -0300 Subject: [PATCH 2/5] (fix) Attach workspace/update mix for running sobelow --- .circleci/config.yml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 0c252d2..c1a6490 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -43,9 +43,17 @@ jobs: sec_code_analysis: docker: - image: circleci/elixir:1.7.3 + environment: + MIX_ENV: dev steps: - - checkout + - attach_workspace: + at: ~/ + - run: + name: Fetch dependencies + command: | + mix local.hex --force + mix local.rebar --force - run: mix sobelow workflows: From 2ace88612788f90fa3239d0d22c7d8df1afc123b Mon Sep 17 00:00:00 2001 From: Bruno Silva Date: Fri, 2 Oct 2020 16:28:24 -0300 Subject: [PATCH 3/5] fix - Use correct environment --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index c1a6490..d0ca6d4 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -44,7 +44,7 @@ jobs: docker: - image: circleci/elixir:1.7.3 environment: - MIX_ENV: dev + MIX_ENV: test steps: - attach_workspace: From 06046c706fa2a4b34fefaa0bcf4dd47230e62281 Mon Sep 17 00:00:00 2001 From: Bruno Silva Date: Fri, 2 Oct 2020 16:34:04 -0300 Subject: [PATCH 4/5] feat - Add sobelow on build pipeline --- .circleci/config.yml | 27 ++++++--------------------- mix.exs | 2 +- 2 files changed, 7 insertions(+), 22 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index d0ca6d4..ae7c27f 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -28,6 +28,11 @@ jobs: - store_test_results: # upload junit test results for display in Test Summary path: _build/test/lib - run: mix credo + - run: + name: Install and run sast + command: | + mix archive.install hex sobelow --force + mix sobelow publish: parallelism: 1 docker: @@ -40,22 +45,6 @@ jobs: - run: mix deps.get - run: mix hex.publish --yes - sec_code_analysis: - docker: - - image: circleci/elixir:1.7.3 - environment: - MIX_ENV: test - - steps: - - attach_workspace: - at: ~/ - - run: - name: Fetch dependencies - command: | - mix local.hex --force - mix local.rebar --force - - run: mix sobelow - workflows: version: 2.1 build_and_test: @@ -70,9 +59,6 @@ workflows: - hexpm/elixir:1.9.4-erlang-20.3.8.26-alpine-3.12.0 - hexpm/elixir:1.10.4-erlang-21.3.8.17-alpine-3.12.0 - hexpm/elixir:1.10.4-erlang-23.0.3-alpine-3.12.0 - - sec_code_analysis: - requires: - - build_and_test - publish_production_approval: type: approval filters: @@ -88,5 +74,4 @@ workflows: only: - master requires: - - publish_production_approval - - sec_code_analysis \ No newline at end of file + - publish_production_approval \ No newline at end of file diff --git a/mix.exs b/mix.exs index a51eff1..13a31c6 100644 --- a/mix.exs +++ b/mix.exs @@ -52,7 +52,7 @@ defmodule BRAN.MixProject do {:credo, "~> 1.4", only: [:dev, :test], runtime: false}, {:junit_formatter, "~> 3.1", only: :test, runtime: false}, {:excoveralls, "~> 0.10", only: :test}, - {:ex_parameterized, "~> 1.3", only: [:test]}, + {:ex_parameterized, "~> 1.3", only: [:dev, :test]}, {:sobelow, "~> 0.10.4", only: :dev} ] end From 5cb62e406731c31d10360f2e5443ea5223d32ccb Mon Sep 17 00:00:00 2001 From: Bruno Roberto Cardoso Silva Date: Mon, 1 Mar 2021 15:54:10 -0300 Subject: [PATCH 5/5] (feat) Add UT for digit_calculator mod function --- test/digit_calculator_test.exs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 test/digit_calculator_test.exs diff --git a/test/digit_calculator_test.exs b/test/digit_calculator_test.exs new file mode 100644 index 0000000..d767636 --- /dev/null +++ b/test/digit_calculator_test.exs @@ -0,0 +1,32 @@ +defmodule BRAN.DigitCalculatorTest do + use ExUnit.Case + use ExUnit.Parameterized + + alias BRAN.DigitCalculator + + @itau_weight [2, 1, 2, 1, 2, 1, 2, 1, 2] + @itau_mod_factor 10 + + test_with_params "returns mod to consider on Itau validation", + fn account_number, mod_factor, weights, sum_result, expected -> + assert DigitCalculator.mod( + account_number, + mod_factor, + weights, + sum_result + ) == expected + end do + [ + # Valid Accounts + {[4, 3, 1, 3, 4, 3, 1, 2, 9, 0], @itau_mod_factor, @itau_weight, true, 10}, + { + [7, 0, 6, 8, 6, 0, 5, 2, 8, 8], + @itau_mod_factor, + @itau_weight, + true, + 1 + }, + {[4, 3, 1, 3, 4, 3, 1, 2, 9, 0], @itau_mod_factor, @itau_weight, false, 1} + ] + end +end