danielberkompas / ex_twilio

Twilio API client for Elixir
MIT License
336 stars 147 forks source link

Missing instruction for running test locally #157

Open kianmeng opened 3 years ago

kianmeng commented 3 years ago

I've checked the documentation but couldn't find instruction for setting the required environment variables for running the test locally. Did I miss out or overlook something?

Elixir / Erlang OTP environment:

$ asdf current
elixir        1.12.1          /home/foobar/.tool-versions
erlang        24.0.2          /home/foobar/.tool-versions

Result of the test:

$ ./bin/test

Compiling 74 files (.ex)
Generated ex_twilio app
Finding applications for analysis
Finding suitable PLTs
Looking up modules in dialyze_erlang-24.0.2_elixir-1.12.1_deps-test.plt
Finding applications for dialyze_erlang-24.0.2_elixir-1.12.1_deps-test.plt
Finding modules for dialyze_erlang-24.0.2_elixir-1.12.1_deps-test.plt
Checking 563 modules in dialyze_erlang-24.0.2_elixir-1.12.1_deps-test.plt
Finding modules for analysis
Analysing 78 modules with dialyze_erlang-24.0.2_elixir-1.12.1_deps-test.plt
Generating docs...
View "html" docs at "doc/index.html"
.........

  1) doctest ExTwilio.UrlGenerator.build_url/3 (1) (ExTwilio.UrlGeneratorTest)
     test/ex_twilio/url_generator_test.exs:61
     Doctest failed
     doctest:
       iex> build_url(Resource)
       "https://api.twilio.com/2010-04-01/Accounts//Resources.json"
     code:  build_url(Resource) === "https://api.twilio.com/2010-04-01/Accounts//Resources.json"
     left:  "https://api.twilio.com/2010-04-01/Resources.json"
     right: "https://api.twilio.com/2010-04-01/Accounts//Resources.json"
     stacktrace:
       lib/ex_twilio/url_generator.ex:19: ExTwilio.UrlGenerator (module)

....

  2) doctest ExTwilio.UrlGenerator.build_url/3 (6) (ExTwilio.UrlGeneratorTest)
     test/ex_twilio/url_generator_test.exs:61
     Doctest failed
     doctest:
       iex> build_url(Resource, nil, iso_country_code: "US", type: "Mobile", page: 20)
       "https://api.twilio.com/2010-04-01/Accounts//Resources/US/Mobile.json?Page=20"
     code:  build_url(Resource, nil, iso_country_code: "US", type: "Mobile", page: 20) === "https://api.twilio.com/2010-04-01/Accounts//Resources/US/Mobile.json?Page=20"
     left:  "https://api.twilio.com/2010-04-01/Resources/US/Mobile.json?Page=20"
     right: "https://api.twilio.com/2010-04-01/Accounts//Resources/US/Mobile.json?Page=20"
     stacktrace:
       lib/ex_twilio/url_generator.ex:34: ExTwilio.UrlGenerator (module)

..

  3) doctest ExTwilio.UrlGenerator.build_url/3 (4) (ExTwilio.UrlGeneratorTest)
     test/ex_twilio/url_generator_test.exs:61
     Doctest failed
     doctest:
       iex> build_url(Resource, 1)
       "https://api.twilio.com/2010-04-01/Accounts//Resources/1.json"
     code:  build_url(Resource, 1) === "https://api.twilio.com/2010-04-01/Accounts//Resources/1.json"
     left:  "https://api.twilio.com/2010-04-01/Resources/1.json"
     right: "https://api.twilio.com/2010-04-01/Accounts//Resources/1.json"
     stacktrace:
       lib/ex_twilio/url_generator.ex:28: ExTwilio.UrlGenerator (module)

..

  4) doctest ExTwilio.UrlGenerator.build_url/3 (5) (ExTwilio.UrlGeneratorTest)
     test/ex_twilio/url_generator_test.exs:61
     Doctest failed
     doctest:
       iex> build_url(Resource, nil, page: 20)
       "https://api.twilio.com/2010-04-01/Accounts//Resources.json?Page=20"
     code:  build_url(Resource, nil, page: 20) === "https://api.twilio.com/2010-04-01/Accounts//Resources.json?Page=20"
     left:  "https://api.twilio.com/2010-04-01/Resources.json?Page=20"
     right: "https://api.twilio.com/2010-04-01/Accounts//Resources.json?Page=20"
     stacktrace:
       lib/ex_twilio/url_generator.ex:31: ExTwilio.UrlGenerator (module)

........................

  5) test .process_request_headers adds the correct headers (ExTwilio.ApiTest)
     test/ex_twilio/api_test.exs:94
     Assertion with == failed
     code:  assert Keyword.keys(headers) == [:Authorization, :"Content-Type"]
     left:  [:"Content-Type"]
     right: [:Authorization, :"Content-Type"]
     stacktrace:
       test/ex_twilio/api_test.exs:98: (test)

...........

  6) test .token sets the issuer to the account sid (ExTwilio.WorkerCapabilityTest)
     test/ex_twilio/worker_capability_test.exs:35
     ** (Joken.Error) Couldn't recognize the signer algorithm.

     Possible values are:

     ["HS256", "HS384", "HS512", "RS256", "RS384", "RS512", "ES256", "ES384", "ES512", "PS256", "PS384", "PS512", "Ed25519", "Ed25519ph", "Ed448", "Ed448ph"]

     code: assert decoded_token(ExTwilio.WorkerCapability.new("worker_sid", "workspace_sid")).claims[
     stacktrace:
       (joken 2.3.0) lib/joken/signer.ex:102: Joken.Signer.create/3
       test/ex_twilio/worker_capability_test.exs:51: ExTwilio.WorkerCapabilityTest.decoded_token/1
       test/ex_twilio/worker_capability_test.exs:36: (test)

.....

  7) test .token sets 9 policies (ExTwilio.WorkerCapabilityTest)
     test/ex_twilio/worker_capability_test.exs:41
     ** (Joken.Error) Couldn't recognize the signer algorithm.

     Possible values are:

     ["HS256", "HS384", "HS512", "RS256", "RS384", "RS512", "ES256", "ES384", "ES512", "PS256", "PS384", "PS512", "Ed25519", "Ed25519ph", "Ed448", "Ed448ph"]

     code: assert length(decoded_token(jwt).claims["policies"]) == 9
     stacktrace:
       (joken 2.3.0) lib/joken/signer.ex:102: Joken.Signer.create/3
       test/ex_twilio/worker_capability_test.exs:51: ExTwilio.WorkerCapabilityTest.decoded_token/1
       test/ex_twilio/worker_capability_test.exs:47: (test)

......

  8) test .token sets the outgoing scope when parameters specified (ExTwilio.CapabilityTest)
     test/ex_twilio/capability_test.exs:100
     ** (Joken.Error) Couldn't recognize the signer algorithm.

     Possible values are:

     ["HS256", "HS384", "HS512", "RS256", "RS384", "RS512", "ES256", "ES384", "ES512", "PS256", "PS384", "PS512", "Ed25519", "Ed25519ph", "Ed448", "Ed448ph"]

     code: assert decoded_token(capability).claims["scope"] ==
     stacktrace:
       (joken 2.3.0) lib/joken/signer.ex:102: Joken.Signer.create/3
       test/ex_twilio/capability_test.exs:120: ExTwilio.CapabilityTest.decoded_token/1
       test/ex_twilio/capability_test.exs:105: (test)

  9) test .token sets the outgoing scope when no parameters specified (ExTwilio.CapabilityTest)
     test/ex_twilio/capability_test.exs:92
     ** (Joken.Error) Couldn't recognize the signer algorithm.

     Possible values are:

     ["HS256", "HS384", "HS512", "RS256", "RS384", "RS512", "ES256", "ES384", "ES512", "PS256", "PS384", "PS512", "Ed25519", "Ed25519ph", "Ed448", "Ed448ph"]

     code: assert decoded_token(capability).claims["scope"] == "scope:client:outgoing?appSid=app%20sid"
     stacktrace:
       (joken 2.3.0) lib/joken/signer.ex:102: Joken.Signer.create/3
       test/ex_twilio/capability_test.exs:120: ExTwilio.CapabilityTest.decoded_token/1
       test/ex_twilio/capability_test.exs:97: (test)

...

 10) test .token sets an expiration time of one hour from now (ExTwilio.CapabilityTest)
     test/ex_twilio/capability_test.exs:82
     ** (Joken.Error) Couldn't recognize the signer algorithm.

     Possible values are:

     ["HS256", "HS384", "HS512", "RS256", "RS384", "RS512", "ES256", "ES384", "ES512", "PS256", "PS384", "PS512", "Ed25519", "Ed25519ph", "Ed448", "Ed448ph"]

     code: assert_in_delta decoded_token(ExTwilio.Capability.new()).claims["exp"],
     stacktrace:
       (joken 2.3.0) lib/joken/signer.ex:102: Joken.Signer.create/3
       test/ex_twilio/capability_test.exs:120: ExTwilio.CapabilityTest.decoded_token/1
       test/ex_twilio/capability_test.exs:83: (test)

......

 11) test .token sets the incoming scope (ExTwilio.CapabilityTest)
     test/ex_twilio/capability_test.exs:109
     ** (Joken.Error) Couldn't recognize the signer algorithm.

     Possible values are:

     ["HS256", "HS384", "HS512", "RS256", "RS384", "RS512", "ES256", "ES384", "ES512", "PS256", "PS384", "PS512", "Ed25519", "Ed25519ph", "Ed448", "Ed448ph"]

     code: assert decoded_token(capability).claims["scope"] ==
     stacktrace:
       (joken 2.3.0) lib/joken/signer.ex:102: Joken.Signer.create/3
       test/ex_twilio/capability_test.exs:120: ExTwilio.CapabilityTest.decoded_token/1
       test/ex_twilio/capability_test.exs:115: (test)

 12) test .token sets the issuer to the account sid (ExTwilio.CapabilityTest)
     test/ex_twilio/capability_test.exs:88
     ** (Joken.Error) Couldn't recognize the signer algorithm.

     Possible values are:

     ["HS256", "HS384", "HS512", "RS256", "RS384", "RS512", "ES256", "ES384", "ES512", "PS256", "PS384", "PS512", "Ed25519", "Ed25519ph", "Ed448", "Ed448ph"]

     code: assert decoded_token(ExTwilio.Capability.new()).claims["iss"] == Config.account_sid()
     stacktrace:
       (joken 2.3.0) lib/joken/signer.ex:102: Joken.Signer.create/3
       test/ex_twilio/capability_test.exs:120: ExTwilio.CapabilityTest.decoded_token/1
       test/ex_twilio/capability_test.exs:89: (test)

.........

Finished in 2.7 seconds (0.5s async, 2.1s sync)
17 doctests, 76 tests, 12 failures

Randomized with seed 974738
Elixir tests failed!
dminer-papa commented 2 years ago

This happened to me initially as well. I was missing the environment values in my test environment that the test configuration file is looking for. This error message is unfortunate for the situation!

Besides setting those env vars (make sure you're setting them in your MIX_ENV=test environment), you can verify this is the cause by testing with this config/test.exs:

use Mix.Config

config :ex_twilio,
  account_sid: "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
  auth_token: "xxxxxxxxxxxx",
  workspace_sid: {:system, "TWILIO_TEST_WORKSPACE_SID"}

config :logger, level: :info

Setting the account_sid and auth_token to the values above allowed the tests to pass locally for me after encountering the error OP mentioned.