From 1bf55afb87bda7c945904759758980afa05017c6 Mon Sep 17 00:00:00 2001 From: Guilherme Sehn Date: Tue, 12 Sep 2023 14:42:17 -0300 Subject: [PATCH 1/7] raise when sweet_xml is missing --- lib/ex_aws/sts/parsers.ex | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/ex_aws/sts/parsers.ex b/lib/ex_aws/sts/parsers.ex index b892d14..a2679b8 100644 --- a/lib/ex_aws/sts/parsers.ex +++ b/lib/ex_aws/sts/parsers.ex @@ -136,7 +136,25 @@ if Code.ensure_loaded?(SweetXml) do end else defmodule ExAws.STS.Parsers do + def parse({:ok, %{body: _xml} = _resp}, :assume_role), do: missing_sweetxml() + + def parse({:ok, %{body: _xml} = _resp}, :assume_role_with_web_identity), + do: missing_sweetxml() + + def parse({:ok, %{body: _xml} = _resp}, :get_access_key_info), do: missing_sweetxml() + def parse({:ok, %{body: _xml} = _resp}, :assume_role_with_s_a_m_l), do: missing_sweetxml() + def parse({:ok, %{body: _xml} = _resp}, :get_caller_identity), do: missing_sweetxml() + def parse({:ok, %{body: _xml} = _resp}, :get_federation_token), do: missing_sweetxml() + def parse({:ok, %{body: _xml} = _resp}, :get_session_token), do: missing_sweetxml() + def parse({:error, {_type, _http_status_code, %{body: _xml}}}, _), do: missing_sweetxml() def parse(val, _), do: val + + def parse({:ok, %{body: _xml} = _resp}, :decode_authorization_message, _config), + do: missing_sweetxml() + def parse(val, _, _), do: val + + defp missing_sweetxml, + do: raise("Dependency sweet_xml is required for role based authentication") end end From 6c2297b8e2652890874266ac2ff2801dcb4039aa Mon Sep 17 00:00:00 2001 From: Guilherme Sehn Date: Tue, 12 Sep 2023 14:42:27 -0300 Subject: [PATCH 2/7] add a way to test missing sweet_xml --- mix.exs | 12 ++++++++++-- test/lib/parsers_test.exs | 26 ++++++++++++++++++-------- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/mix.exs b/mix.exs index b76149c..a62f4d9 100644 --- a/mix.exs +++ b/mix.exs @@ -50,10 +50,11 @@ defmodule ExAws.STS.Mixfile do {:briefly, ">= 0.0.3", only: :test}, {:ex_doc, ">= 0.0.0", only: :dev, runtime: false}, {:hackney, ">= 0.0.0", only: [:dev, :test]}, - {:sweet_xml, ">= 0.0.0", only: [:dev, :test]}, {:jason, ">= 0.0.0", only: [:dev, :test]}, - ex_aws() + ex_aws(), + sweet_xml() ] + |> Enum.reject(&is_nil/1) end defp docs do @@ -72,4 +73,11 @@ defmodule ExAws.STS.Mixfile do _ -> {:ex_aws, "~> 2.2"} end end + + defp sweet_xml do + case System.get_env("SWEET_XML") do + "DISABLED" -> nil + _ -> {:sweet_xml, ">= 0.0.0", only: [:dev, :test]} + end + end end diff --git a/test/lib/parsers_test.exs b/test/lib/parsers_test.exs index 7151918..248da6b 100644 --- a/test/lib/parsers_test.exs +++ b/test/lib/parsers_test.exs @@ -29,14 +29,24 @@ defmodule ExAws.STS.ParsersTest do get_federation_token: 2 ] - # Build tests for all actions and verifies that mock responses were parsed - for {action, arity} <- @actions do - @tag action: action - test "parses `:#{action}` using mock response" do - assert {:ok, %{body: body}} = parse_mock_response(unquote(action), unquote(arity)) - - for {_, value} <- body do - assert value && value != "", "did not parse value for response" + if System.get_env("SWEET_XML") == "DISABLED" do + for {action, arity} <- @actions do + test "raises missing sweet xml error for `:#{action}`" do + assert_raise RuntimeError, + "Dependency sweet_xml is required for role based authentication", + fn -> parse_mock_response(unquote(action), unquote(arity)) end + end + end + else + # Build tests for all actions and verifies that mock responses were parsed + for {action, arity} <- @actions do + @tag action: action + test "parses `:#{action}` using mock response" do + assert {:ok, %{body: body}} = parse_mock_response(unquote(action), unquote(arity)) + + for {_, value} <- body do + assert value && value != "", "did not parse value for response" + end end end end From 8af7654ac1d44631cbdaf69ed4335460a80c1142 Mon Sep 17 00:00:00 2001 From: Guilherme Sehn Date: Tue, 12 Sep 2023 14:43:30 -0300 Subject: [PATCH 3/7] typo --- test/lib/parsers_test.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/lib/parsers_test.exs b/test/lib/parsers_test.exs index 248da6b..51e6573 100644 --- a/test/lib/parsers_test.exs +++ b/test/lib/parsers_test.exs @@ -31,7 +31,7 @@ defmodule ExAws.STS.ParsersTest do if System.get_env("SWEET_XML") == "DISABLED" do for {action, arity} <- @actions do - test "raises missing sweet xml error for `:#{action}`" do + test "raises missing sweet_xml error for `:#{action}`" do assert_raise RuntimeError, "Dependency sweet_xml is required for role based authentication", fn -> parse_mock_response(unquote(action), unquote(arity)) end From 25f19de9f7ae5eb1729b5a9c80d9659de99389c7 Mon Sep 17 00:00:00 2001 From: Guilherme Sehn Date: Tue, 12 Sep 2023 20:21:31 -0300 Subject: [PATCH 4/7] refactor --- lib/ex_aws/sts/parsers.ex | 281 ++++++++++++++++------------------ lib/ex_aws/sts/parsers/xml.ex | 14 ++ test/lib/parsers_test.exs | 4 +- 3 files changed, 145 insertions(+), 154 deletions(-) create mode 100644 lib/ex_aws/sts/parsers/xml.ex diff --git a/lib/ex_aws/sts/parsers.ex b/lib/ex_aws/sts/parsers.ex index a2679b8..19102d3 100644 --- a/lib/ex_aws/sts/parsers.ex +++ b/lib/ex_aws/sts/parsers.ex @@ -1,160 +1,137 @@ -if Code.ensure_loaded?(SweetXml) do - defmodule ExAws.STS.Parsers do - import SweetXml, only: [sigil_x: 2] - - def parse({:ok, %{body: xml} = resp}, :assume_role) do - parsed_body = - xml - |> SweetXml.xpath(~x"//AssumeRoleResponse", - access_key_id: ~x"./AssumeRoleResult/Credentials/AccessKeyId/text()"s, - secret_access_key: ~x"./AssumeRoleResult/Credentials/SecretAccessKey/text()"s, - session_token: ~x"./AssumeRoleResult/Credentials/SessionToken/text()"s, - expiration: ~x"./AssumeRoleResult/Credentials/Expiration/text()"s, - assumed_role_id: ~x"./AssumeRoleResult/AssumedRoleUser/AssumedRoleId/text()"s, - assumed_role_arn: ~x"./AssumeRoleResult/AssumedRoleUser/Arn/text()"s, - request_id: request_id_xpath() - ) - - {:ok, Map.put(resp, :body, parsed_body)} - end - - def parse({:ok, %{body: xml} = resp}, :assume_role_with_web_identity) do - parsed_body = - xml - |> SweetXml.xpath(~x"//AssumeRoleWithWebIdentityResponse", - access_key_id: ~x"./AssumeRoleWithWebIdentityResult/Credentials/AccessKeyId/text()"s, - secret_access_key: - ~x"./AssumeRoleWithWebIdentityResult/Credentials/SecretAccessKey/text()"s, - session_token: ~x"./AssumeRoleWithWebIdentityResult/Credentials/SessionToken/text()"s, - expiration: ~x"./AssumeRoleWithWebIdentityResult/Credentials/Expiration/text()"s, - assumed_role_id: - ~x"./AssumeRoleWithWebIdentityResult/AssumedRoleUser/AssumedRoleId/text()"s, - assumed_role_arn: ~x"./AssumeRoleWithWebIdentityResult/AssumedRoleUser/Arn/text()"s, - request_id: request_id_xpath() - ) - - {:ok, Map.put(resp, :body, parsed_body)} - end - - def parse({:ok, %{body: xml} = resp}, :get_access_key_info) do - parsed_body = - SweetXml.xpath(xml, ~x"//GetAccessKeyInfoResponse", - account: ~x"./GetAccessKeyInfoResult/Account/text()"s, - request_id: request_id_xpath() - ) - - {:ok, Map.put(resp, :body, parsed_body)} - end - - def parse({:ok, %{body: xml} = resp}, :assume_role_with_s_a_m_l) do - parsed_body = - xml - |> SweetXml.xpath(~x"//AssumeRoleWithSAMLResponse", - access_key_id: ~x"./AssumeRoleResult/Credentials/AccessKeyId/text()"s, - secret_access_key: ~x"./AssumeRoleResult/Credentials/SecretAccessKey/text()"s, - session_token: ~x"./AssumeRoleResult/Credentials/SessionToken/text()"s, - expiration: ~x"./AssumeRoleResult/Credentials/Expiration/text()"s, - assumed_role_id: ~x"./AssumeRoleResult/AssumedRoleUser/AssumedRoleId/text()"s, - assumed_role_arn: ~x"./AssumeRoleResult/AssumedRoleUser/Arn/text()"s, - request_id: request_id_xpath() - ) - - {:ok, Map.put(resp, :body, parsed_body)} - end - - def parse({:ok, %{body: xml} = resp}, :get_caller_identity) do - parsed_body = - SweetXml.xpath(xml, ~x"//GetCallerIdentityResponse", - arn: ~x"./GetCallerIdentityResult/Arn/text()"s, - user_id: ~x"./GetCallerIdentityResult/UserId/text()"s, - account: ~x"./GetCallerIdentityResult/Account/text()"s, - request_id: request_id_xpath() - ) - - {:ok, Map.put(resp, :body, parsed_body)} - end - - def parse({:ok, %{body: xml} = resp}, :get_federation_token) do - parsed_body = - xml - |> SweetXml.xpath(~x"//GetFederationTokenResponse", - access_key_id: ~x"./GetFederationTokenResult/Credentials/AccessKeyId/text()"s, - secret_access_key: ~x"./GetFederationTokenResult/Credentials/SecretAccessKey/text()"s, - session_token: ~x"./GetFederationTokenResult/Credentials/SessionToken/text()"s, - expiration: ~x"./GetFederationTokenResult/Credentials/Expiration/text()"s, - request_id: request_id_xpath() - ) - - {:ok, Map.put(resp, :body, parsed_body)} - end - - def parse({:ok, %{body: xml} = resp}, :get_session_token) do - parsed_body = - xml - |> SweetXml.xpath(~x"//GetSessionTokenResponse", - access_key_id: ~x"./GetSessionTokenResult/Credentials/AccessKeyId/text()"s, - secret_access_key: ~x"./GetSessionTokenResult/Credentials/SecretAccessKey/text()"s, - session_token: ~x"./GetSessionTokenResult/Credentials/SessionToken/text()"s, - expiration: ~x"./GetSessionTokenResult/Credentials/Expiration/text()"s, - request_id: request_id_xpath() - ) - - {:ok, Map.put(resp, :body, parsed_body)} - end - - def parse({:error, {type, http_status_code, %{body: xml}}}, _) do - parsed_body = - xml - |> SweetXml.xpath(~x"//ErrorResponse", - request_id: ~x"./RequestId/text()"s, - type: ~x"./Error/Type/text()"s, - code: ~x"./Error/Code/text()"s, - message: ~x"./Error/Message/text()"s, - detail: ~x"./Error/Detail/text()"s - ) - - {:error, {type, http_status_code, parsed_body}} - end - - def parse(val, _), do: val - - def parse({:ok, %{body: xml} = resp}, :decode_authorization_message, config) do - parsed_body = - xml - |> SweetXml.xpath(~x"//DecodeAuthorizationMessageResponse", - decoded_message: ~x"./DecodedMessage/text()"s, - request_id: ~x"./RequestId/text()"s - ) - |> Map.update!(:decoded_message, fn msg -> config[:json_codec].decode!(msg) end) - - {:ok, Map.put(resp, :body, parsed_body)} - end - - defp request_id_xpath do - ~x"./ResponseMetadata/RequestId/text()"s - end +defmodule ExAws.STS.Parsers do + alias ExAws.STS.Parsers.XML + + import XML, only: [sigil_x: 2] + + def parse({:ok, %{body: xml} = resp}, :assume_role) do + parsed_body = + xml + |> XML.xpath(~x"//AssumeRoleResponse", + access_key_id: ~x"./AssumeRoleResult/Credentials/AccessKeyId/text()"s, + secret_access_key: ~x"./AssumeRoleResult/Credentials/SecretAccessKey/text()"s, + session_token: ~x"./AssumeRoleResult/Credentials/SessionToken/text()"s, + expiration: ~x"./AssumeRoleResult/Credentials/Expiration/text()"s, + assumed_role_id: ~x"./AssumeRoleResult/AssumedRoleUser/AssumedRoleId/text()"s, + assumed_role_arn: ~x"./AssumeRoleResult/AssumedRoleUser/Arn/text()"s, + request_id: request_id_xpath() + ) + + {:ok, Map.put(resp, :body, parsed_body)} end -else - defmodule ExAws.STS.Parsers do - def parse({:ok, %{body: _xml} = _resp}, :assume_role), do: missing_sweetxml() - def parse({:ok, %{body: _xml} = _resp}, :assume_role_with_web_identity), - do: missing_sweetxml() + def parse({:ok, %{body: xml} = resp}, :assume_role_with_web_identity) do + parsed_body = + xml + |> XML.xpath(~x"//AssumeRoleWithWebIdentityResponse", + access_key_id: ~x"./AssumeRoleWithWebIdentityResult/Credentials/AccessKeyId/text()"s, + secret_access_key: + ~x"./AssumeRoleWithWebIdentityResult/Credentials/SecretAccessKey/text()"s, + session_token: ~x"./AssumeRoleWithWebIdentityResult/Credentials/SessionToken/text()"s, + expiration: ~x"./AssumeRoleWithWebIdentityResult/Credentials/Expiration/text()"s, + assumed_role_id: + ~x"./AssumeRoleWithWebIdentityResult/AssumedRoleUser/AssumedRoleId/text()"s, + assumed_role_arn: ~x"./AssumeRoleWithWebIdentityResult/AssumedRoleUser/Arn/text()"s, + request_id: request_id_xpath() + ) + + {:ok, Map.put(resp, :body, parsed_body)} + end + + def parse({:ok, %{body: xml} = resp}, :get_access_key_info) do + parsed_body = + XML.xpath(xml, ~x"//GetAccessKeyInfoResponse", + account: ~x"./GetAccessKeyInfoResult/Account/text()"s, + request_id: request_id_xpath() + ) + + {:ok, Map.put(resp, :body, parsed_body)} + end + + def parse({:ok, %{body: xml} = resp}, :assume_role_with_s_a_m_l) do + parsed_body = + xml + |> XML.xpath(~x"//AssumeRoleWithSAMLResponse", + access_key_id: ~x"./AssumeRoleResult/Credentials/AccessKeyId/text()"s, + secret_access_key: ~x"./AssumeRoleResult/Credentials/SecretAccessKey/text()"s, + session_token: ~x"./AssumeRoleResult/Credentials/SessionToken/text()"s, + expiration: ~x"./AssumeRoleResult/Credentials/Expiration/text()"s, + assumed_role_id: ~x"./AssumeRoleResult/AssumedRoleUser/AssumedRoleId/text()"s, + assumed_role_arn: ~x"./AssumeRoleResult/AssumedRoleUser/Arn/text()"s, + request_id: request_id_xpath() + ) + + {:ok, Map.put(resp, :body, parsed_body)} + end + + def parse({:ok, %{body: xml} = resp}, :get_caller_identity) do + parsed_body = + XML.xpath(xml, ~x"//GetCallerIdentityResponse", + arn: ~x"./GetCallerIdentityResult/Arn/text()"s, + user_id: ~x"./GetCallerIdentityResult/UserId/text()"s, + account: ~x"./GetCallerIdentityResult/Account/text()"s, + request_id: request_id_xpath() + ) + + {:ok, Map.put(resp, :body, parsed_body)} + end + + def parse({:ok, %{body: xml} = resp}, :get_federation_token) do + parsed_body = + xml + |> XML.xpath(~x"//GetFederationTokenResponse", + access_key_id: ~x"./GetFederationTokenResult/Credentials/AccessKeyId/text()"s, + secret_access_key: ~x"./GetFederationTokenResult/Credentials/SecretAccessKey/text()"s, + session_token: ~x"./GetFederationTokenResult/Credentials/SessionToken/text()"s, + expiration: ~x"./GetFederationTokenResult/Credentials/Expiration/text()"s, + request_id: request_id_xpath() + ) + + {:ok, Map.put(resp, :body, parsed_body)} + end + + def parse({:ok, %{body: xml} = resp}, :get_session_token) do + parsed_body = + xml + |> XML.xpath(~x"//GetSessionTokenResponse", + access_key_id: ~x"./GetSessionTokenResult/Credentials/AccessKeyId/text()"s, + secret_access_key: ~x"./GetSessionTokenResult/Credentials/SecretAccessKey/text()"s, + session_token: ~x"./GetSessionTokenResult/Credentials/SessionToken/text()"s, + expiration: ~x"./GetSessionTokenResult/Credentials/Expiration/text()"s, + request_id: request_id_xpath() + ) + + {:ok, Map.put(resp, :body, parsed_body)} + end + + def parse({:error, {type, http_status_code, %{body: xml}}}, _) do + parsed_body = + xml + |> XML.xpath(~x"//ErrorResponse", + request_id: ~x"./RequestId/text()"s, + type: ~x"./Error/Type/text()"s, + code: ~x"./Error/Code/text()"s, + message: ~x"./Error/Message/text()"s, + detail: ~x"./Error/Detail/text()"s + ) + + {:error, {type, http_status_code, parsed_body}} + end - def parse({:ok, %{body: _xml} = _resp}, :get_access_key_info), do: missing_sweetxml() - def parse({:ok, %{body: _xml} = _resp}, :assume_role_with_s_a_m_l), do: missing_sweetxml() - def parse({:ok, %{body: _xml} = _resp}, :get_caller_identity), do: missing_sweetxml() - def parse({:ok, %{body: _xml} = _resp}, :get_federation_token), do: missing_sweetxml() - def parse({:ok, %{body: _xml} = _resp}, :get_session_token), do: missing_sweetxml() - def parse({:error, {_type, _http_status_code, %{body: _xml}}}, _), do: missing_sweetxml() - def parse(val, _), do: val + def parse(val, _), do: val - def parse({:ok, %{body: _xml} = _resp}, :decode_authorization_message, _config), - do: missing_sweetxml() + def parse({:ok, %{body: xml} = resp}, :decode_authorization_message, config) do + parsed_body = + xml + |> XML.xpath(~x"//DecodeAuthorizationMessageResponse", + decoded_message: ~x"./DecodedMessage/text()"s, + request_id: ~x"./RequestId/text()"s + ) + |> Map.update!(:decoded_message, fn msg -> config[:json_codec].decode!(msg) end) - def parse(val, _, _), do: val + {:ok, Map.put(resp, :body, parsed_body)} + end - defp missing_sweetxml, - do: raise("Dependency sweet_xml is required for role based authentication") + defp request_id_xpath do + ~x"./ResponseMetadata/RequestId/text()"s end end diff --git a/lib/ex_aws/sts/parsers/xml.ex b/lib/ex_aws/sts/parsers/xml.ex new file mode 100644 index 0000000..2aca024 --- /dev/null +++ b/lib/ex_aws/sts/parsers/xml.ex @@ -0,0 +1,14 @@ +defmodule ExAws.STS.Parsers.XML do + @moduledoc false + + if Code.ensure_loaded?(SweetXml) do + defdelegate xpath(parent, spec, subspec), to: SweetXml + defdelegate sigil_x(path, modifiers), to: SweetXml + else + def xpath(_parent, _spec, _subspec), + do: raise("Dependency sweet_xml is required for role based authentication") + + def sigil_x(_path, _modifiers), + do: raise("Dependency sweet_xml is required for role based authentication") + end +end diff --git a/test/lib/parsers_test.exs b/test/lib/parsers_test.exs index 51e6573..a0b1b00 100644 --- a/test/lib/parsers_test.exs +++ b/test/lib/parsers_test.exs @@ -33,8 +33,8 @@ defmodule ExAws.STS.ParsersTest do for {action, arity} <- @actions do test "raises missing sweet_xml error for `:#{action}`" do assert_raise RuntimeError, - "Dependency sweet_xml is required for role based authentication", - fn -> parse_mock_response(unquote(action), unquote(arity)) end + "Dependency sweet_xml is required for role based authentication", + fn -> parse_mock_response(unquote(action), unquote(arity)) end end end else From 94614e77212cf0cc2ff10f5736a5ff52ef3a7604 Mon Sep 17 00:00:00 2001 From: Guilherme Sehn Date: Tue, 12 Sep 2023 20:52:34 -0300 Subject: [PATCH 5/7] simplify test setup --- lib/ex_aws/sts/parsers/xml.ex | 21 +++++++++++++-------- mix.exs | 11 ++--------- test/lib/parsers_test.exs | 34 +++++++++++++++++++++------------- 3 files changed, 36 insertions(+), 30 deletions(-) diff --git a/lib/ex_aws/sts/parsers/xml.ex b/lib/ex_aws/sts/parsers/xml.ex index 2aca024..c78a641 100644 --- a/lib/ex_aws/sts/parsers/xml.ex +++ b/lib/ex_aws/sts/parsers/xml.ex @@ -1,14 +1,19 @@ defmodule ExAws.STS.Parsers.XML do @moduledoc false - if Code.ensure_loaded?(SweetXml) do - defdelegate xpath(parent, spec, subspec), to: SweetXml - defdelegate sigil_x(path, modifiers), to: SweetXml - else - def xpath(_parent, _spec, _subspec), - do: raise("Dependency sweet_xml is required for role based authentication") + def xpath(parent, spec, subspec) do + xml_module().xpath(parent, spec, subspec) + rescue + _ in UndefinedFunctionError -> + raise "Dependency sweet_xml is required for role based authentication" + end - def sigil_x(_path, _modifiers), - do: raise("Dependency sweet_xml is required for role based authentication") + def sigil_x(path, modifiers) do + xml_module().sigil_x(path, modifiers) + rescue + _ in UndefinedFunctionError -> + raise "Dependency sweet_xml is required for role based authentication" end + + defp xml_module, do: Application.get_env(:ex_aws_sts, :xml_module, SweetXml) end diff --git a/mix.exs b/mix.exs index a62f4d9..a4ca887 100644 --- a/mix.exs +++ b/mix.exs @@ -50,9 +50,9 @@ defmodule ExAws.STS.Mixfile do {:briefly, ">= 0.0.3", only: :test}, {:ex_doc, ">= 0.0.0", only: :dev, runtime: false}, {:hackney, ">= 0.0.0", only: [:dev, :test]}, + {:sweet_xml, ">= 0.0.0", only: [:dev, :test]}, {:jason, ">= 0.0.0", only: [:dev, :test]}, - ex_aws(), - sweet_xml() + ex_aws() ] |> Enum.reject(&is_nil/1) end @@ -73,11 +73,4 @@ defmodule ExAws.STS.Mixfile do _ -> {:ex_aws, "~> 2.2"} end end - - defp sweet_xml do - case System.get_env("SWEET_XML") do - "DISABLED" -> nil - _ -> {:sweet_xml, ">= 0.0.0", only: [:dev, :test]} - end - end end diff --git a/test/lib/parsers_test.exs b/test/lib/parsers_test.exs index a0b1b00..df65907 100644 --- a/test/lib/parsers_test.exs +++ b/test/lib/parsers_test.exs @@ -29,7 +29,27 @@ defmodule ExAws.STS.ParsersTest do get_federation_token: 2 ] - if System.get_env("SWEET_XML") == "DISABLED" do + # Build tests for all actions and verifies that mock responses were parsed + for {action, arity} <- @actions do + @tag action: action + test "parses `:#{action}` using mock response" do + assert {:ok, %{body: body}} = parse_mock_response(unquote(action), unquote(arity)) + + for {_, value} <- body do + assert value && value != "", "did not parse value for response" + end + end + end + + describe "when sweet_xml is not installed" do + setup do + Application.put_env(:ex_aws_sts, :xml_module, MissingSweetXml) + + on_exit(fn -> + Application.delete_env(:ex_aws_sts, :xml_module) + end) + end + for {action, arity} <- @actions do test "raises missing sweet_xml error for `:#{action}`" do assert_raise RuntimeError, @@ -37,17 +57,5 @@ defmodule ExAws.STS.ParsersTest do fn -> parse_mock_response(unquote(action), unquote(arity)) end end end - else - # Build tests for all actions and verifies that mock responses were parsed - for {action, arity} <- @actions do - @tag action: action - test "parses `:#{action}` using mock response" do - assert {:ok, %{body: body}} = parse_mock_response(unquote(action), unquote(arity)) - - for {_, value} <- body do - assert value && value != "", "did not parse value for response" - end - end - end end end From 596b1f5ee80ebb828bdfb7acd622e2477e8f56fe Mon Sep 17 00:00:00 2001 From: Guilherme Sehn Date: Tue, 12 Sep 2023 20:54:48 -0300 Subject: [PATCH 6/7] remove unnecessary code --- mix.exs | 1 - 1 file changed, 1 deletion(-) diff --git a/mix.exs b/mix.exs index a4ca887..b76149c 100644 --- a/mix.exs +++ b/mix.exs @@ -54,7 +54,6 @@ defmodule ExAws.STS.Mixfile do {:jason, ">= 0.0.0", only: [:dev, :test]}, ex_aws() ] - |> Enum.reject(&is_nil/1) end defp docs do From 3b93f2847674e454a94706523098b5ccd905b9de Mon Sep 17 00:00:00 2001 From: Guilherme Sehn Date: Mon, 18 Sep 2023 22:05:42 -0300 Subject: [PATCH 7/7] change async to false due to change in application envs in test code --- test/lib/parsers_test.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/lib/parsers_test.exs b/test/lib/parsers_test.exs index df65907..daff707 100644 --- a/test/lib/parsers_test.exs +++ b/test/lib/parsers_test.exs @@ -1,5 +1,5 @@ defmodule ExAws.STS.ParsersTest do - use ExUnit.Case, async: true + use ExUnit.Case, async: false alias ExAws.STS.Parsers