Browse Source

Make it compatible with OTP-26

* Don't call `prim_inet` port directly
* Add `verify=verify_none` option in SSL tests
Sergey Prokhorov 2 years ago
parent
commit
71a6b90439
3 changed files with 21 additions and 7 deletions
  1. 12 3
      src/epgsql_sock.erl
  2. 6 3
      test/epgsql_SUITE.erl
  3. 3 1
      test/epgsql_replication_SUITE.erl

+ 12 - 3
src/epgsql_sock.erl

@@ -488,6 +488,15 @@ send_multi(#state{mod = Mod, sock = Sock}, List) ->
                                  end, List)).
 
 do_send(gen_tcp, Sock, Bin) ->
+    gen_tcp_send(Sock, Bin);
+do_send(ssl, Sock, Bin) ->
+    ssl:send(Sock, Bin).
+
+-if(?OTP_RELEASE >= 26).
+gen_tcp_send(Sock, Bin) ->
+    gen_tcp:send(Sock, Bin).
+-else.
+gen_tcp_send(Sock, Bin) ->
     %% Why not gen_tcp:send/2?
     %% See https://github.com/rabbitmq/rabbitmq-common/blob/v3.7.4/src/rabbit_writer.erl#L367-L384
     %% Since `epgsql' uses `{active, true}' socket option by-default, it may potentially quickly
@@ -496,15 +505,15 @@ do_send(gen_tcp, Sock, Bin) ->
     %% `{active, true}' is still the default.
     %%
     %% Because we use `inet' driver directly, we also have `handle_info({inet_reply, ...`
+    %% This `gen_tcp:send/2' problem have been solved in OTP-26, so this hack is no longer needed.
     try erlang:port_command(Sock, Bin) of
         true ->
             ok
     catch
         error:_Error ->
             {error, einval}
-    end;
-do_send(ssl, Sock, Bin) ->
-    ssl:send(Sock, Bin).
+    end.
+-endif.
 
 loop(#state{data = Data, handler = Handler, subproto_state = Repl} = State) ->
     case epgsql_wire:decode_message(Data) of

+ 6 - 3
test/epgsql_SUITE.erl

@@ -306,7 +306,7 @@ connect_with_ssl(Config) ->
              {ok, _Cols, [{true}]} = Module:equery(C, "select ssl_is_used()")
         end,
         "epgsql_test",
-        [{ssl, true}]).
+        [{ssl, true}, {ssl_opts, [{verify, verify_none}]}]).
 
 cancel_query_for_connection_with_ssl(Config) ->
     Module = ?config(module, Config),
@@ -314,6 +314,7 @@ cancel_query_for_connection_with_ssl(Config) ->
     Module = ?config(module, Config),
     Args2 = [ {port, Port}, {database, "epgsql_test_db1"}
             | [ {ssl, true}
+              , {ssl_opts, [{verify, verify_none}]}
               , {timeout, 1000} ]
             ],
     {ok, C} = Module:connect(Host, "epgsql_test", Args2),
@@ -377,7 +378,8 @@ connect_with_client_cert(Config) ->
          end,
          "epgsql_test_cert",
         [{ssl, true}, {ssl_opts, [{keyfile, File("client.key")},
-                                  {certfile, File("client.crt")}]}]).
+                                  {certfile, File("client.crt")},
+                                  {verify, verify_none}]}]).
 
 connect_with_invalid_client_cert(Config) ->
     {Host, Port} = epgsql_ct:connection_data(Config),
@@ -407,6 +409,7 @@ connect_with_invalid_client_cert(Config) ->
            ssl_opts =>
                [{keyfile, File("bad-client.key")},
                 {certfile, File("bad-client.crt")},
+                {verify, verify_none},
                 %% TLS-1.3 seems to connect fine, but then sends alert asynchronously
                 {versions, ['tlsv1.2']}
                ]}
@@ -1649,7 +1652,7 @@ incremental_sock_active_n_ssl(Config) ->
              ?assertEqual(10241, length(Rows))
          end,
          "epgsql_test",
-         [{ssl, true}, {socket_active, 2}]).
+         [{ssl, true}, {ssl_opts, [{verify, verify_none}]}, {socket_active, 2}]).
 -else.
 %% {active, N} for SSL is only supported on OTP-21+
 incremental_sock_active_n_ssl(_Config) ->

+ 3 - 1
test/epgsql_replication_SUITE.erl

@@ -72,7 +72,9 @@ replication_sync_active_n_socket(Config) ->
 
 -ifdef(OTP_RELEASE).
 replication_async_active_n_ssl(Config) ->
-  replication_test_run(Config, self(), [{socket_active, 1}, {ssl, require}]).
+  replication_test_run(Config, self(), [{socket_active, 1},
+                                        {ssl, require},
+                                        {ssl_opts, [{verify, verify_none}]}]).
 -else.
 %% {active, N} for SSL is only supported on OTP-21+
 replication_async_active_n_ssl(Config) ->