• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

supabase / supavisor / e5e7ebfe80dbec4965226225050d4ef5c8216e88-PR-605

21 Feb 2025 02:35PM UTC coverage: 45.973% (-0.03%) from 46.003%
e5e7ebfe80dbec4965226225050d4ef5c8216e88-PR-605

Pull #605

github

hauleth
fix: remaining SSL connections that need to set `verify_none` option
Pull Request #605: fix: remaining SSL connections that need to set `verify_none` option

2 of 9 new or added lines in 3 files covered. (22.22%)

267 existing lines in 26 files now uncovered.

959 of 2086 relevant lines covered (45.97%)

635.02 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

13.33
/lib/supavisor_web/ws_proxy.ex
1
defmodule SupavisorWeb.WsProxy do
2
  @moduledoc """
3
  The `Supavisor.WsProxy` module implements a WebSocket proxy for managing
4
  TCP connections between clients and a Postgres database.
5
  """
6

7
  require Logger
8
  alias Supavisor.Protocol.Server
9
  @behaviour Plug
10

11
  def call(conn, state) do
12
    Logger.debug("WsProxy is: #{inspect(self())}")
×
13
    Plug.Conn.upgrade_adapter(conn, :websocket, {__MODULE__, state, %{compress: false}})
×
14
  end
15

16
  def init(_) do
17
    %{socket: nil, acc: nil, status: :startup}
×
18
  end
19

20
  def websocket_handle(
21
        {:binary, <<len::32, startup_pkt::binary-size(len - 4), rest::binary>>},
22
        %{status: :startup} = state
23
      ) do
24
    {:ok, socket} = connect_local()
×
25
    :ok = :gen_tcp.send(socket, [<<len::32>>, startup_pkt])
×
26

27
    {:ok, %{state | acc: rest, socket: socket}}
28
  end
29

30
  def websocket_handle({:binary, bin}, %{socket: socket} = state) do
31
    :ok = :gen_tcp.send(socket, bin)
×
32
    {:ok, state}
33
  end
34

35
  def websocket_info({:tcp, _, bin}, %{status: :startup} = state) do
36
    if String.ends_with?(bin, Server.ready_for_query()) do
×
37
      acc = filter_pass_pkt(state.acc)
×
38
      :ok = :gen_tcp.send(state.socket, acc)
×
39
      {[{:binary, bin}], %{state | acc: nil, status: :idle}}
40
    else
41
      {[{:binary, bin}], state}
42
    end
43
  end
44

45
  def websocket_info({:tcp, _, bin}, %{status: :idle} = state) do
×
46
    {[{:binary, bin}], state}
47
  end
48

49
  def websocket_info(msg, state) do
50
    Logger.error("Undefined websocket_info msg: #{inspect(msg, pretty: true)}")
×
51
    {:ok, state}
52
  end
53

54
  @spec filter_pass_pkt(binary()) :: binary()
55
  def filter_pass_pkt(<<?p, len::32, _::binary-size(len - 4), rest::binary>>) do
UNCOV
56
    rest
1✔
57
  end
58

UNCOV
59
  def filter_pass_pkt(bin), do: bin
1✔
60

61
  @spec connect_local() :: {:ok, port()} | {:error, term()}
62
  defp connect_local do
63
    proxy_port = Application.fetch_env!(:supavisor, :proxy_port_transaction)
×
64
    :gen_tcp.connect(~c"localhost", proxy_port, [:binary, packet: :raw, active: true])
×
65
  end
66
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc