diff --git a/.github/workflows/elixir.yml b/.github/workflows/elixir.yml new file mode 100644 index 0000000..475e3ff --- /dev/null +++ b/.github/workflows/elixir.yml @@ -0,0 +1,73 @@ +name: Elixir CI + +on: push + +env: + MIX_ENV: test + +jobs: + build: + runs-on: ubuntu-latest + + strategy: + matrix: + elixir: ["1.13", "1.14", "1.15"] + otp: ["25", "26"] + exclude: + - elixir: 1.13 + otp: 26 + - elixir: 1.14 + otp: 26 + + steps: + - uses: actions/checkout@v3 + + - name: Setup elixir + uses: erlef/setup-beam@v1 + with: + elixir-version: ${{ matrix.elixir }} + otp-version: ${{ matrix.otp }} + + - name: Restore dependencies cache + uses: actions/cache@v3 + id: mix-cache + with: + path: deps + key: ${{ runner.os }}-mix-${{ hashFiles('**/mix.lock') }} + restore-keys: ${{ runner.os }}-mix-${{ hashFiles('**/mix.lock') }} + + - name: Install dependencies + if: steps.mix-cache.outputs.cache-hit != 'true' + run: | + mix local.rebar --force + mix local.hex --force + mix deps.get + + - name: Compile & error on warning + run: mix compile --warnings-as-errors + + - name: Check formatting + run: mix format --check-formatted + + - name: Run credo + run: mix credo --strict + + - name: Retrieve PLT cache + uses: actions/cache@v3 + id: plt-cache + with: + path: priv/plts + key: ${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-plts-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }} + restore-keys: ${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-plts-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }} + + - name: Create PLTs + if: steps.plt-cache.outputs.cache-hit != 'true' + run: | + mkdir -p priv/plts + mix dialyzer --plt + + - name: Run dialyzer + run: mix dialyzer --no-check --halt-exit-status + + - name: Run tests + run: mix coveralls.github diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 1061b2c..0000000 --- a/.travis.yml +++ /dev/null @@ -1,11 +0,0 @@ -language: elixir -elixir: - - 1.7.4 - - 1.8.2 - - 1.9.4 -env: - - MIX_ENV=test -script: - - mix coveralls.travis - - mix credo --strict - - mix format --check-formatted diff --git a/lib/soap/request/params.ex b/lib/soap/request/params.ex index 7f10aa8..c4a97d3 100644 --- a/lib/soap/request/params.ex +++ b/lib/soap/request/params.ex @@ -21,7 +21,8 @@ defmodule Soap.Request.Params do Returns XML-like string. """ - @spec build_body(wsdl :: map(), operation :: String.t() | atom(), params :: map() | tuple(), headers :: map()) :: String.t() + @spec build_body(wsdl :: map(), operation :: String.t() | atom(), params :: map() | tuple(), headers :: map()) :: + String.t() def build_body(wsdl, operation, params, headers) do with {:ok, body} <- build_soap_body(wsdl, operation, params), {:ok, header} <- build_soap_header(wsdl, operation, headers) do @@ -75,9 +76,7 @@ defmodule Soap.Request.Params do if Map.has_key?(val_map, k) do validate_param_attributes(val_map, k, v) else - "Invalid SOAP message:Invalid content was found starting with element '#{k}'. One of {#{ - Enum.join(Map.keys(val_map), ", ") - }} is expected." + "Invalid SOAP message:Invalid content was found starting with element '#{k}'. One of {#{Enum.join(Map.keys(val_map), ", ")}} is expected." end end end diff --git a/lib/soap/wsdl.ex b/lib/soap/wsdl.ex index 439ab17..80bc851 100644 --- a/lib/soap/wsdl.ex +++ b/lib/soap/wsdl.ex @@ -76,9 +76,7 @@ defmodule Soap.Wsdl do xpath( wsdl, - ~x"//#{ns("types", protocol_ns)}/#{ns("schema", schema_namespace)}/#{ns("import", schema_namespace)}[@namespace='#{ - value - }']" + ~x"//#{ns("types", protocol_ns)}/#{ns("schema", schema_namespace)}/#{ns("import", schema_namespace)}[@namespace='#{value}']" ) -> {string_key, %{value: value, type: :xsd}} @@ -91,9 +89,7 @@ defmodule Soap.Wsdl do def get_endpoint(wsdl, protocol_ns, soap_ns) do wsdl |> xpath( - ~x"//#{ns("definitions", protocol_ns)}/#{ns("service", protocol_ns)}/#{ns("port", protocol_ns)}/#{ - ns("address", soap_ns) - }/@location"s + ~x"//#{ns("definitions", protocol_ns)}/#{ns("service", protocol_ns)}/#{ns("port", protocol_ns)}/#{ns("address", soap_ns)}/@location"s ) end diff --git a/lib/soap/xsd.ex b/lib/soap/xsd.ex index a056f77..8f31cbb 100644 --- a/lib/soap/xsd.ex +++ b/lib/soap/xsd.ex @@ -27,6 +27,7 @@ defmodule Soap.Xsd do @spec parse_from_url(String.t(), keyword()) :: {:ok, map()} | {:error, atom()} def parse_from_url(path, opts \\ []) do request_opts = Keyword.merge([follow_redirect: true, max_redirect: 5], opts) + case Request.get_http_client().get(path, [], request_opts) do {:ok, %HTTPoison.Response{status_code: 404}} -> {:error, :not_found} {:ok, %HTTPoison.Response{body: body}} -> parse_xsd(body) diff --git a/mix.lock b/mix.lock index 71b3b0a..14c3a39 100644 --- a/mix.lock +++ b/mix.lock @@ -21,7 +21,7 @@ "mock": {:hex, :mock, "0.3.7", "75b3bbf1466d7e486ea2052a73c6e062c6256fb429d6797999ab02fa32f29e03", [:mix], [{:meck, "~> 0.9.2", [hex: :meck, repo: "hexpm", optional: false]}], "hexpm", "4da49a4609e41fd99b7836945c26f373623ea968cfb6282742bcb94440cf7e5c"}, "nimble_parsec": {:hex, :nimble_parsec, "1.2.0", "b44d75e2a6542dcb6acf5d71c32c74ca88960421b6874777f79153bbbbd7dccc", [:mix], [], "hexpm", "52b2871a7515a5ac49b00f214e4165a40724cf99798d8e4a65e4fd64ebd002c1"}, "parse_trans": {:hex, :parse_trans, "3.3.1", "16328ab840cc09919bd10dab29e431da3af9e9e7e7e6f0089dd5a2d2820011d8", [:rebar3], [], "hexpm", "07cd9577885f56362d414e8c4c4e6bdf10d43a8767abb92d24cbe8b24c54888b"}, - "ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.6", "cf344f5692c82d2cd7554f5ec8fd961548d4fd09e7d22f5b62482e5aeaebd4b0", [:make, :mix, :rebar3], [], "hexpm", "bdb0d2471f453c88ff3908e7686f86f9be327d065cc1ec16fa4540197ea04680"}, + "ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.7", "354c321cf377240c7b8716899e182ce4890c5938111a1296add3ec74cf1715df", [:make, :mix, :rebar3], [], "hexpm", "fe4c190e8f37401d30167c8c405eda19469f34577987c76dde613e838bbc67f8"}, "sweet_xml": {:hex, :sweet_xml, "0.7.2", "4729f997286811fabdd8288f8474e0840a76573051062f066c4b597e76f14f9f", [:mix], [], "hexpm", "6894e68a120f454534d99045ea3325f7740ea71260bc315f82e29731d570a6e8"}, "unicode_util_compat": {:hex, :unicode_util_compat, "0.7.0", "bc84380c9ab48177092f43ac89e4dfa2c6d62b40b8bd132b1059ecc7232f9a78", [:rebar3], [], "hexpm", "25eee6d67df61960cf6a794239566599b09e17e668d3700247bc498638152521"}, "xml_builder": {:hex, :xml_builder, "2.2.0", "cc5f1eeefcfcde6e90a9b77fb6c490a20bc1b856a7010ce6396f6da9719cbbab", [:mix], [], "hexpm", "9d66d52fb917565d358166a4314078d39ef04d552904de96f8e73f68f64a62c9"}, diff --git a/test/soap/request/params_test.exs b/test/soap/request/params_test.exs index 636330c..939afe3 100644 --- a/test/soap/request/params_test.exs +++ b/test/soap/request/params_test.exs @@ -90,10 +90,20 @@ defmodule Soap.Request.ParamsTest do xml_body = "runTransaction-template.xml" |> Fixtures.load_xml() - |> String.replace("{{BODY}}", ~s{JoeDirt}) + |> String.replace( + "{{BODY}}", + ~s{JoeDirt} + ) {_, wsdl} = Wsdl.parse_from_file(Fixtures.get_file_path("wsdl/CyberSourceTransaction.wsdl")) - function_result = Params.build_body(wsdl, "runTransaction", %{test: {:Person, %{id: "something"}, %{firstName: "Joe", lastName: "Dirt"}}}, nil) + + function_result = + Params.build_body( + wsdl, + "runTransaction", + %{test: {:Person, %{id: "something"}, %{firstName: "Joe", lastName: "Dirt"}}}, + nil + ) assert function_result == xml_body end diff --git a/test/soap/request_test.exs b/test/soap/request_test.exs index c607755..140c64c 100644 --- a/test/soap/request_test.exs +++ b/test/soap/request_test.exs @@ -69,7 +69,8 @@ defmodule Soap.RequestTest do params = {%{token: "barbaz"}, {:body, %{foo: "bar"}, "Hello John"}} with_mock HTTPoison, post: fn _, body, _, _ -> body end do - assert Request.call(wsdl, operation, params) == String.replace(@request_with_header, "", ~s{}) + assert Request.call(wsdl, operation, params) == + String.replace(@request_with_header, "", ~s{}) end end end