diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6a850244..e2b22d5b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,39 +16,52 @@ jobs: env: MIX_ENV: test steps: - - uses: actions/checkout@v1 - - uses: actions/setup-elixir@v1.2.0 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + - uses: erlef/setup-beam@54075bcc5e249e4758d363f27d099f55d843f124 # v1.24.1 with: - otp-version: 22.2 - elixir-version: '1.10' + otp-version: '25.3.2' + version-type: strict + elixir-version: '1.15.7' - name: Install dependencies run: mix deps.get - name: Check format run: mix format --check-formatted test: - name: OTP ${{ matrix.otp }} / Elixir ${{ matrix.elixir }} + name: Elixir ${{ matrix.elixir }} / OTP ${{ matrix.otp }} runs-on: ubuntu-latest + container: + image: hexpm/elixir:${{ matrix.elixir }}-erlang-${{ matrix.otp }}-debian-bullseye-20210902-slim strategy: fail-fast: false matrix: - otp: [22.2] - elixir: [1.6, 1.7, 1.8, 1.9, '1.10'] + include: + - elixir: '1.6.6' + otp: '21.3.8.24' + - elixir: '1.7.4' + otp: '22.3.4.26' + - elixir: '1.8.2' + otp: '22.3.4.26' + - elixir: '1.9.4' + otp: '22.3.4.26' + coverage: true + - elixir: '1.10.4' + otp: '22.3.4.26' env: MIX_ENV: test steps: - - uses: actions/checkout@v1.0.0 - - uses: actions/setup-elixir@v1.2.0 - with: - otp-version: ${{ matrix.otp }} - elixir-version: ${{ matrix.elixir }} + - name: Install git + run: | + sed -i '/security.debian.org/d' /etc/apt/sources.list + apt-get update -y && apt-get install -y git + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - name: Set up dependency cache - uses: actions/cache@v1 + uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 with: path: deps/ key: ${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-deps-${{ hashFiles('**/mix.lock') }} restore-keys: ${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-deps- - name: Set up build cache - uses: actions/cache@v1 + uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 with: path: _build/test/ key: ${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-build-${{ hashFiles('**/mix.lock') }} @@ -63,10 +76,10 @@ jobs: mix deps.compile mix compile --force --warnings-as-errors - name: Run tests - if: matrix.elixir != '1.9' + if: '!matrix.coverage' run: mix test - name: Run tests (with coverage) - if: matrix.elixir == '1.9' + if: matrix.coverage env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: mix coveralls.github diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..e1463b6b --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,25 @@ +name: Release +on: + release: + types: [created] +jobs: + publish: + name: Hex Publish + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + - uses: erlef/setup-beam@5304e04ea2b355f03681464e683d92e3b2f18451 # v1.18.2 + with: + otp-version: '25.3.2' + version-type: strict + elixir-version: '1.14.4' + - name: Build + run: | + mix local.rebar --force + mix local.hex --force + mix deps.get + - name: Publish + env: + HEX_API_KEY: ${{ secrets.HEX_API_KEY }} + run: | + mix hex.publish --yes diff --git a/lib/thrift/binary/framed/client.ex b/lib/thrift/binary/framed/client.ex index 18be648b..6a9d87d1 100644 --- a/lib/thrift/binary/framed/client.ex +++ b/lib/thrift/binary/framed/client.ex @@ -333,9 +333,7 @@ defmodule Thrift.Binary.Framed.Client do TApplicationException.exception( type: :bad_sequence_id, message: - "Invalid sequence id. The client sent #{seq_id}, but the server replied with #{ - mismatched_seq_id - }" + "Invalid sequence id. The client sent #{seq_id}, but the server replied with #{mismatched_seq_id}" ) {:error, {:exception, exception}} diff --git a/lib/thrift/binary/framed/protocol_handler.ex b/lib/thrift/binary/framed/protocol_handler.ex index db721ce2..f9b4955a 100644 --- a/lib/thrift/binary/framed/protocol_handler.ex +++ b/lib/thrift/binary/framed/protocol_handler.ex @@ -70,9 +70,7 @@ defmodule Thrift.Binary.Framed.ProtocolHandler do {:error, reason} -> # :ssl.format_error handles posix errors as well as ssl errors Logger.info(fn -> - "#{inspect(handler_module)} (#{inspect(self())}) connection error: #{ - :ssl.format_error(reason) - } (#{inspect(reason)})" + "#{inspect(handler_module)} (#{inspect(self())}) connection error: #{:ssl.format_error(reason)} (#{inspect(reason)})" end) :ok = transport.close(socket) @@ -97,9 +95,7 @@ defmodule Thrift.Binary.Framed.ProtocolHandler do {:error, reason} -> Logger.info(fn -> - "#{inspect(handler_module)} (#{inspect(self())}) handshake error: #{ - :ssl.format_error(reason) - } (#{inspect(reason)})" + "#{inspect(handler_module)} (#{inspect(self())}) handshake error: #{:ssl.format_error(reason)} (#{inspect(reason)})" end) end end @@ -156,9 +152,7 @@ defmodule Thrift.Binary.Framed.ProtocolHandler do {:error, reason} -> # :ssl.format_error handles posix error as well as ssl Logger.info(fn -> - "#{inspect(handler_module)} (#{inspect(self())}) connection error: #{ - :ssl.format_error(reason) - } (#{inspect(reason)})" + "#{inspect(handler_module)} (#{inspect(self())}) connection error: #{:ssl.format_error(reason)} (#{inspect(reason)})" end) :ok = transport.close(socket) diff --git a/lib/thrift/transport/ssl.ex b/lib/thrift/transport/ssl.ex index 3cede535..f810d4fc 100644 --- a/lib/thrift/transport/ssl.ex +++ b/lib/thrift/transport/ssl.ex @@ -18,7 +18,7 @@ defmodule Thrift.Transport.SSL do credentials or to change the configuration during run time. """ - @type configure :: {module, function, list} | (() -> {:ok, [option]} | {:error, Exception.t()}) + @type configure :: {module, function, list} | (-> {:ok, [option]} | {:error, Exception.t()}) @type option :: :ssl.ssl_option() | {:enabled, boolean} | {:optional, boolean} | {:configure, configure} diff --git a/test/support/certs/cert.pem b/test/support/certs/cert.pem new file mode 100644 index 00000000..ce7cfd93 --- /dev/null +++ b/test/support/certs/cert.pem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vbuEEDoS3lqGTzU +-----END CERTIFICATE----- diff --git a/test/support/certs/key.pem b/test/support/certs/key.pem new file mode 100644 index 00000000..0c696463 --- /dev/null +++ b/test/support/certs/key.pem @@ -0,0 +1,28 @@ +-----BEGIN PRIVATE KEY----- +MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCbxpk/kBrAeLnh +56rbaER/6Tw+6u8So9XGRD1h3oAz8IHMSXLxsG0hKW1EaGGF9WuMmI07R+m9UOKG ++S27heUAcP+RRnb7oa2mao1SuA+8EU5kkNhD665lFavA5XiNnaVL2ypADiRraHgR +27mm8Rg3PgEIfdoAbpfN/67U4vSFcLr0Dxfm/5vSQhVUWnVPiB0M5EM6nX/pXhat +9rDo38PRgzNR5lktN0XZUzLcp4zbJJ4OPvMDgd+ol274fHzfTb4OiPQmwFhnBWKw +9j5NHmwEvmOKmyLG6IFqmg2yqAU3DJYVObP1kUjbXGABrkdGN5ZQhFWfUxwbdCbp +UbdGwSZnAgMBAAECggEAJdXw9v1bYhBwpawNVclXifHujiGl+9MLY2LDvfe7D+KE +xEe6wXVmrD1RquHnfhAEFVwgQZvP7AmvW7U+JGP7IUZQ7Mo+sBOvB9KtjL/kInvZ +nJeJz8V40FiZJPsXct4tfeU3t+M3eVcggsXpq+C3TwOiYJugzaYO/RvzLQYK+jXr +9THwn7ZT4wlIgQ7fPsDpjdqmfM6TF+PglFLVMhlE7toRjU7DzGSsDRaNet7U1FGq +PQTSJJqhVABTVnGl+EqFPTkePepjeFBDruOJPu4aYYtreHgEC8aKmOH8WiDAwu6i +R3arrVd5AP4B48VaPy6XXANSgAlra4YDBjIU/9WKMQKBgQDZlpyy/yFZp1envn/J +o5MSluBybzHcTmqWSE2gGmEPRalcs5+Q86Xa0QrrKvoWCQaxJv57cHRjUm1yGVJX +c/Bj69m1LCgScdbDVUyJq3wFA7Gw+1sWtsVkc/vpgpjfKFYUsIWTzDIAxSHnHPVi +B3tAJlhHv2qBk9ItN3NPcEkiGwKBgQC3RoPUlnGUdJ5l1AG2vhA/U+J8wbCJrEW9 +UGit6rprNWAvNdUHifC/X1fGPWWMYodzBQ01tcc9H1xWHecC8I0oF1MaMqXjjd93 +ATpZRpYP6Eku6SCEbV+kMZEHyMrQ9FC3ZYZN9tKegZxNsxqk6CJrSY3Tux0CR0eu +Ciz3EbUxpQKBgC6zRrqcS5okconMNz0d4IkS3OVyvC7enb3XkuGUB9TxTKJa4xqH +UMegKknDFZ35HfiTt/bicfiHTno4uRWQCr5HdpiN+6PJzyBphF3f8mRZIKAtsqUz +YTZoNl8t6oWq8J7MLD9GikzkApzJ+Fir5mYkVLpBeSiKg4e06QjZvriVAoGAKMDw +XZxag0VvV3tOKkGXQU245j73r5V0KIWx0UKJ038Z9UWGKlf9BcEAtp8+bnoWXng4 +GMJkHG5VzPx3OwsciFavbvrmMnSAxWirfeCZS84+P8UtKuVbSBqRgmae2toI/M8B +j2KcMQznIcv618KarLq9Y+COscwB32x51TLF1NUCgYAQ/r3DXGe+WXQSCehjl5cz +wn+WF2CJtFFYX6OpIlZq77Idh9k2zMos7IlX1GhkxaLhvuHn96CZZ644BD1/e4LR +BmK9mHQG45lVVXBr7RGOuE+sGWbD+pQeePdKg7xptX9GzKLhv/T1lnDd7Bub3RDt +O63335zNxLX/Xzwt2Z/6dg== +-----END PRIVATE KEY----- diff --git a/test/thrift/binary/framed/server_test.exs b/test/thrift/binary/framed/server_test.exs index 43b73e5c..9848b5cf 100644 --- a/test/thrift/binary/framed/server_test.exs +++ b/test/thrift/binary/framed/server_test.exs @@ -148,7 +148,7 @@ defmodule Servers.Binary.Framed.IntegrationTest do end thrift_test "it can handle bogus data", ctx do - {:ok, socket} = :gen_tcp.connect('localhost', ctx.port, [:binary, packet: 4, active: false]) + {:ok, socket} = :gen_tcp.connect(~c"localhost", ctx.port, [:binary, packet: 4, active: false]) :ok = :gen_tcp.send(socket, <<1, 2, 3, 4, 5>>) assert {:error, :closed} == :gen_tcp.recv(socket, 0) diff --git a/test/thrift/binary/framed/ssl_test.exs b/test/thrift/binary/framed/ssl_test.exs index 84a8a619..26af7781 100644 --- a/test/thrift/binary/framed/ssl_test.exs +++ b/test/thrift/binary/framed/ssl_test.exs @@ -106,12 +106,11 @@ defmodule Servers.Binary.Framed.SSLTest do ## Helpers defp get_certs() do - certs_path = Application.app_dir(:ssl, "examples/certs/etc/server") - cacerts = Path.join(certs_path, "cacerts.pem") + certs_path = Path.join([__DIR__, "..", "..", "..", "support", "certs"]) |> Path.expand() cert = Path.join(certs_path, "cert.pem") key = Path.join(certs_path, "key.pem") - {:ok, [cacertfile: cacerts, certfile: cert, keyfile: key]} + {:ok, [certfile: cert, keyfile: key]} end def test_configure() do diff --git a/test/thrift/parser/lexer_test.exs b/test/thrift/parser/lexer_test.exs index 205d2a50..901e3cf6 100644 --- a/test/thrift/parser/lexer_test.exs +++ b/test/thrift/parser/lexer_test.exs @@ -147,19 +147,19 @@ defmodule Thrift.Parser.LexerTest do assert tokenize("{'hello':'world'}") == [ {:"{", 1}, - {:string, 1, 'hello'}, + {:string, 1, ~c"hello"}, {:":", 1}, - {:string, 1, 'world'}, + {:string, 1, ~c"world"}, {:"}", 1} ] assert tokenize("{'a':1,'b':2}") == [ {:"{", 1}, - {:string, 1, 'a'}, + {:string, 1, ~c"a"}, {:":", 1}, {:int, 1, 1}, {:",", 1}, - {:string, 1, 'b'}, + {:string, 1, ~c"b"}, {:":", 1}, {:int, 1, 2}, {:"}", 1} @@ -173,11 +173,11 @@ defmodule Thrift.Parser.LexerTest do end test "identifiers" do - assert tokenize("abc_123.xzy") == [{:ident, 1, 'abc_123.xzy'}] + assert tokenize("abc_123.xzy") == [{:ident, 1, ~c"abc_123.xzy"}] end test "typedef" do - assert tokenize("typedef i32 Integer") == [{:typedef, 1}, {:i32, 1}, {:ident, 1, 'Integer'}] + assert tokenize("typedef i32 Integer") == [{:typedef, 1}, {:i32, 1}, {:ident, 1, ~c"Integer"}] end test "enum definition" do @@ -190,21 +190,21 @@ defmodule Thrift.Parser.LexerTest do } """) == [ {:enum, 1}, - {:ident, 1, 'Operation'}, + {:ident, 1, ~c"Operation"}, {:"{", 1}, - {:ident, 2, 'ADD'}, + {:ident, 2, ~c"ADD"}, {:=, 2}, {:int, 2, 1}, {:",", 2}, - {:ident, 3, 'SUBTRACT'}, + {:ident, 3, ~c"SUBTRACT"}, {:=, 3}, {:int, 3, 2}, {:",", 3}, - {:ident, 4, 'MULTIPLY'}, + {:ident, 4, ~c"MULTIPLY"}, {:=, 4}, {:int, 4, 3}, {:",", 4}, - {:ident, 5, 'DIVIDE'}, + {:ident, 5, ~c"DIVIDE"}, {:=, 5}, {:int, 5, 4}, {:"}", 6} @@ -221,30 +221,30 @@ defmodule Thrift.Parser.LexerTest do } """) == [ {:struct, 1}, - {:ident, 1, 'Work'}, + {:ident, 1, ~c"Work"}, {:"{", 1}, {:int, 2, 1}, {:":", 2}, {:i32, 2}, - {:ident, 2, 'num1'}, + {:ident, 2, ~c"num1"}, {:=, 2}, {:int, 2, 0}, {:",", 2}, {:int, 3, 2}, {:":", 3}, {:i32, 3}, - {:ident, 3, 'num2'}, + {:ident, 3, ~c"num2"}, {:",", 3}, {:int, 4, 3}, {:":", 4}, - {:ident, 4, 'Operation'}, - {:ident, 4, 'op'}, + {:ident, 4, ~c"Operation"}, + {:ident, 4, ~c"op"}, {:",", 4}, {:int, 5, 4}, {:":", 5}, {:optional, 5}, {:string, 5}, - {:ident, 5, 'comment'}, + {:ident, 5, ~c"comment"}, {:",", 5}, {:"}", 6} ] @@ -258,17 +258,17 @@ defmodule Thrift.Parser.LexerTest do } """) == [ {:exception, 1}, - {:ident, 1, 'InvalidOperation'}, + {:ident, 1, ~c"InvalidOperation"}, {:"{", 1}, {:int, 2, 1}, {:":", 2}, {:i32, 2}, - {:ident, 2, 'whatOp'}, + {:ident, 2, ~c"whatOp"}, {:",", 2}, {:int, 3, 2}, {:":", 3}, {:string, 3}, - {:ident, 3, 'why'}, + {:ident, 3, ~c"why"}, {:"}", 4} ] end @@ -282,32 +282,32 @@ defmodule Thrift.Parser.LexerTest do } """) == [ {:service, 1}, - {:ident, 1, 'Calculator'}, + {:ident, 1, ~c"Calculator"}, {:extends, 1}, - {:ident, 1, 'shared.SharedService'}, + {:ident, 1, ~c"shared.SharedService"}, {:"{", 1}, {:void, 2}, - {:ident, 2, 'ping'}, + {:ident, 2, ~c"ping"}, {:"(", 2}, {:")", 2}, {:",", 2}, {:i32, 3}, - {:ident, 3, 'add'}, + {:ident, 3, ~c"add"}, {:"(", 3}, {:int, 3, 1}, {:":", 3}, {:i32, 3}, - {:ident, 3, 'num1'}, + {:ident, 3, ~c"num1"}, {:",", 3}, {:int, 3, 2}, {:":", 3}, {:i32, 3}, - {:ident, 3, 'num2'}, + {:ident, 3, ~c"num2"}, {:")", 3}, {:",", 3}, {:oneway, 4}, {:void, 4}, - {:ident, 4, 'zip'}, + {:ident, 4, ~c"zip"}, {:"(", 4}, {:")", 4}, {:"}", 5} @@ -323,20 +323,20 @@ defmodule Thrift.Parser.LexerTest do #@namespace elixir Bar """) == [ {:namespace, 1}, - {:ident, 1, 'elixir'}, - {:ident, 1, 'Foo'}, + {:ident, 1, ~c"elixir"}, + {:ident, 1, ~c"Foo"}, {:namespace, 2}, - {:ident, 2, 'py'}, - {:ident, 2, 'foo.bar.baz'}, + {:ident, 2, ~c"py"}, + {:ident, 2, ~c"foo.bar.baz"}, {:namespace, 3}, - {:ident, 3, 'java'}, - {:ident, 3, 'com.pinterest.foo.bar.baz'}, + {:ident, 3, ~c"java"}, + {:ident, 3, ~c"com.pinterest.foo.bar.baz"}, {:namespace, 4}, {:*, 4}, - {:ident, 4, 'foo.bar'}, + {:ident, 4, ~c"foo.bar"}, {:namespace, 5}, - {:ident, 5, 'elixir'}, - {:ident, 5, 'Bar'} + {:ident, 5, ~c"elixir"}, + {:ident, 5, ~c"Bar"} ] end @@ -344,7 +344,7 @@ defmodule Thrift.Parser.LexerTest do assert tokenize("const my_const = 32") == [ {:const, 1}, - {:ident, 1, 'my_const'}, + {:ident, 1, ~c"my_const"}, {:=, 1}, {:int, 1, 32} ] @@ -355,9 +355,9 @@ defmodule Thrift.Parser.LexerTest do [ {:const, 1}, {:string, 1}, - {:ident, 1, 'my_const'}, + {:ident, 1, ~c"my_const"}, {:=, 1}, - {:ident, 1, 'MyEnum.VALUE'} + {:ident, 1, ~c"MyEnum.VALUE"} ] end end