Skip to content

Commit

Permalink
1111 xml body (#1639)
Browse files Browse the repository at this point in the history
* enable XML body in HTTP post

* version bump

* mix format

* reaper test fixes

* reaper test fixes

* test fixes

* bump smart_city_test and upgrade everywhere

* remove IO.inspect

* set initial body to empty string

* fix empty map body issue

* add empty list handling to body

---------

Co-authored-by: Ian Abbott <ij.abbott2306@gmail.com>
  • Loading branch information
ian-j-abbott-accenture and ijabbott authored Mar 30, 2023
1 parent 797e5fc commit 8d7e0fc
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
2 changes: 1 addition & 1 deletion apps/reaper/lib/reaper/data_extract/extract_step.ex
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ defmodule Reaper.DataExtract.ExtractStep do
{body, headers}
end

defp process_body(body, _assigns) when body in ["", nil, %{}], do: ""
defp process_body(body, _assigns) when body in ["", nil, %{}, []], do: ""

defp process_body(body, assigns) do
body |> UrlBuilder.safe_evaluate_body(assigns)
Expand Down
2 changes: 1 addition & 1 deletion apps/reaper/mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule Reaper.MixProject do
def project do
[
app: :reaper,
version: "2.0.26",
version: "2.0.27",
elixir: "~> 1.10",
build_path: "../../_build",
config_path: "../../config/config.exs",
Expand Down
33 changes: 33 additions & 0 deletions apps/reaper/test/unit/reaper/data_extract/extract_step_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,39 @@ defmodule Reaper.DataExtract.ExtractStepTest do
assert assigns == %{key: "super secret two", token: "auth_token2"}
end

test "Can use empty list for body", %{bypass: bypass, ingestion: ingestion} do
Bypass.stub(bypass, "POST", "/", fn conn ->
{:ok, body, conn} = Plug.Conn.read_body(conn)

case body do
"" -> Plug.Conn.resp(conn, 200, %{sub: %{path: "auth_token2"}} |> Jason.encode!())
_ -> Plug.Conn.resp(conn, 403, "No dice")
end
end)

steps = [
%{
type: "auth",
context: %{
path: ["sub", "path"],
destination: "token",
url: "http://localhost:#{bypass.port}",
encodeMethod: "json",
body: [],
headers: %{},
cacheTtl: nil
},
assigns: %{
key: "super secret two"
}
}
]

assigns = ExtractStep.execute_extract_steps(ingestion, steps)

assert assigns == %{key: "super secret two", token: "auth_token2"}
end

test "Can use assigns block for headers", %{bypass: bypass, ingestion: ingestion} do
Bypass.stub(bypass, "POST", "/headers", fn conn ->
if Enum.any?(conn.req_headers, fn header -> header == {"header", "super secret"} end) do
Expand Down

0 comments on commit 8d7e0fc

Please sign in to comment.