Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to Elixir 1.18 #161

Merged
merged 2 commits into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ jobs:
- uses: actions/checkout@v3
- uses: erlef/setup-beam@v1
with:
otp-version: 26.0
elixir-version: 1.16
otp-version: 27.0
elixir-version: 1.18
- run: mix deps.get
- run: mix compile --warnings-as-errors
- run: mix credo --strict --ignore design.tagtodo
Expand All @@ -27,15 +27,11 @@ jobs:
strategy:
matrix:
version:
- otp: 26.0
elixir: 1.16
os: ubuntu-latest
- otp: 22.0
- otp: 27.0
elixir: 1.18
- otp: 24.0
elixir: 1.13
# It's necessary to run on ubuntu 20.04 for OTP 20 - 23
# See https://github.com/erlef/setup-beam
os: ubuntu-20.04
runs-on: ${{ matrix.version.os }}
runs-on: ubuntu-latest
name: OTP ${{matrix.version.otp}} / Elixir ${{matrix.version.elixir}}
env:
MIX_ENV: test
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- uses: actions/checkout@v3
- uses: erlef/setup-beam@v1
with:
otp-version: 26.0
elixir-version: 1.16
otp-version: 27.0
elixir-version: 1.18
- run: mix deps.get
- run: mix hex.publish --yes
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## v0.2.11 (TBA)

* Default to using `JSON` instead of `Jason` for JSON parsing on Elixir 1.18

## v0.2.10 (2024-04-11)

Requires Elixir 1.13+
Expand Down
7 changes: 5 additions & 2 deletions lib/assent/config.ex
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,20 @@ defmodule Assent.Config do

defdelegate merge(config_a, config_b), to: Keyword

@default_json_library (Code.ensure_loaded?(JSON) && JSON) || Jason

@doc """
Fetches the JSON library in config.

If not found in provided config, this will attempt to load the JSON library
from global application environment for `:assent`. Defaults to `Jason`.
from global application environment for `:assent`. Defaults to
`#{@default_json_library}`.
"""
@spec json_library(t()) :: module()
def json_library(config) do
case get(config, :json_library, nil) do
nil ->
Application.get_env(:assent, :json_library, Jason)
Application.get_env(:assent, :json_library, @default_json_library)

json_library ->
json_library
Expand Down
8 changes: 7 additions & 1 deletion lib/assent/jwt_adapter/assent_jwt.ex
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,17 @@ defmodule Assent.JWTAdapter.AssentJWT do

defp encode_json_base64(map, opts) do
with {:ok, json_library} <- Config.fetch(opts, :json_library),
{:ok, json} <- json_library.encode(map) do
{:ok, json} <- json_encode(json_library, map) do
{:ok, Base.url_encode64(json, padding: false)}
end
end

defp json_encode(json_library, map) do
{:ok, json_library.encode!(map)}
rescue
error -> {:error, error}
end

defp encode_claims(claims, opts) do
case encode_json_base64(claims, opts) do
{:ok, encoded_claims} ->
Expand Down
3 changes: 1 addition & 2 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,12 @@ defmodule Assent.MixProject do
[
# JWT libraries
{:jose, "~> 1.8", optional: true},
# HTTP clients (Jason is required for Req)
# HTTP clients
{:certifi, ">= 0.0.0", optional: true},
{:ssl_verify_fun, ">= 0.0.0", optional: true},
{:finch, "~> 0.15", optional: true},
{:mint, "~> 1.0", optional: true},
{:req, "~> 0.4", optional: true},
{:jason, "~> 1.0", optional: true},
# Docs and tests
{:ex_doc, ">= 0.0.0", only: :dev, runtime: false},
{:credo, "~> 1.1", only: [:dev, :test]},
Expand Down
48 changes: 23 additions & 25 deletions mix.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/assent/config_test.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule Assent.ConfigTest do
use ExUnit.Case
use Assent.TestCase
doctest Assent.Config
end
4 changes: 2 additions & 2 deletions test/assent/http_adapter/finch_test.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Assent.HTTPAdapter.FinchTest do
use ExUnit.Case
use Assent.TestCase
doctest Assent.HTTPAdapter.Finch

alias Assent.HTTPAdapter.Finch, as: FinchAdapter
Expand Down Expand Up @@ -54,7 +54,7 @@ defmodule Assent.HTTPAdapter.FinchTest do
assert capture_log(fn ->
assert {:error, %Error{reason: :disconnected}} =
FinchAdapter.request(:get, bad_host_url, nil, [], supervisor: supervisor)
end) =~ "{bad_cert,hostname_check_failed}"
end) =~ "hostname_check_failed"
end

test "handles SSL with bad certificate and no verification" do
Expand Down
2 changes: 1 addition & 1 deletion test/assent/http_adapter/httpc_test.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Assent.HTTPAdapter.HttpcTest do
use ExUnit.Case
use Assent.TestCase
doctest Assent.HTTPAdapter.Httpc

alias Assent.HTTPAdapter.{Httpc, HTTPResponse}
Expand Down
2 changes: 1 addition & 1 deletion test/assent/http_adapter/mint_test.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Assent.HTTPAdapter.MintTest do
use ExUnit.Case
use Assent.TestCase
doctest Assent.HTTPAdapter.Mint

alias ExUnit.CaptureIO
Expand Down
46 changes: 34 additions & 12 deletions test/assent/http_adapter/req_test.exs
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
defmodule Assent.HTTPAdapter.ReqTest do
use ExUnit.Case
use Assent.TestCase
doctest Assent.HTTPAdapter.Req

alias Mint.TransportError
alias Req.TransportError
alias Assent.HTTPAdapter.{HTTPResponse, Req}

# Test retries quickly
@req_opts [retry_delay: 0]

describe "request/4" do
test "handles SSL" do
TestServer.start(scheme: :https)
TestServer.add("/", via: :get)

req_opts = [connect_options: [transport_opts: [cacerts: TestServer.x509_suite().cacerts]]]
req_opts =
Keyword.put(
@req_opts,
:connect_options,
transport_opts: [cacerts: TestServer.x509_suite().cacerts],
protocols: [:http2]
)

assert {:ok, %HTTPResponse{status: 200, body: "HTTP/2"}} =
Req.request(:get, TestServer.url(), nil, [], req_opts)
Expand All @@ -20,7 +29,13 @@ defmodule Assent.HTTPAdapter.ReqTest do
TestServer.start(scheme: :https)

bad_host_url = TestServer.url(host: "bad-host.localhost")
req_opts = [connect_options: [transport_opts: [cacerts: TestServer.x509_suite().cacerts]]]

req_opts =
Keyword.put(
@req_opts,
:connect_options,
transport_opts: [cacerts: TestServer.x509_suite().cacerts]
)

assert {:error, %TransportError{reason: {:tls_alert, {:handshake_failure, _error}}}} =
Req.request(:get, bad_host_url, nil, [], req_opts)
Expand All @@ -32,11 +47,12 @@ defmodule Assent.HTTPAdapter.ReqTest do

bad_host_url = TestServer.url(host: "bad-host.localhost")

req_opts = [
connect_options: [
req_opts =
Keyword.put(
@req_opts,
:connect_options,
transport_opts: [cacerts: TestServer.x509_suite().cacerts, verify: :verify_none]
]
]
)

assert {:ok, %HTTPResponse{status: 200}} =
Req.request(:get, bad_host_url, nil, [], req_opts)
Expand All @@ -62,7 +78,7 @@ defmodule Assent.HTTPAdapter.ReqTest do
)

assert {:ok, %HTTPResponse{status: 200}} =
Req.request(:get, TestServer.url("/get?a=1"), nil, [])
Req.request(:get, TestServer.url("/get?a=1"), nil, [], @req_opts)
end

test "handles POST" do
Expand All @@ -84,9 +100,15 @@ defmodule Assent.HTTPAdapter.ReqTest do
)

assert {:ok, %HTTPResponse{status: 200}} =
Req.request(:post, TestServer.url("/post"), "a=1&b=2", [
{"content-type", "application/x-www-form-urlencoded"}
])
Req.request(
:post,
TestServer.url("/post"),
"a=1&b=2",
[
{"content-type", "application/x-www-form-urlencoded"}
],
@req_opts
)
end
end
end
Loading
Loading