summaryrefslogtreecommitdiff
path: root/lib/ssl/test
diff options
context:
space:
mode:
authorIngela Anderton Andin <ingela@erlang.org>2021-02-15 16:30:33 +0100
committerIngela Anderton Andin <ingela@erlang.org>2021-03-12 15:55:11 +0100
commit1955e07ba61cc1acbe7933b631a85775dd8d5bae (patch)
tree10eb15c0ec4453eb3073c7c80c6ae2310a780d79 /lib/ssl/test
parent8179adacea61b4c5468c5aa72e8f877ac3e7ce3b (diff)
downloaderlang-1955e07ba61cc1acbe7933b631a85775dd8d5bae.tar.gz
ssl: Add white box tests for pre TLS-1.3 session cache
Diffstat (limited to 'lib/ssl/test')
-rw-r--r--lib/ssl/test/Makefile1
-rw-r--r--lib/ssl/test/ssl_session_cache_api_SUITE.erl105
2 files changed, 106 insertions, 0 deletions
diff --git a/lib/ssl/test/Makefile b/lib/ssl/test/Makefile
index ea59bc9ffb..4e81a761f6 100644
--- a/lib/ssl/test/Makefile
+++ b/lib/ssl/test/Makefile
@@ -76,6 +76,7 @@ MODULES = \
ssl_pem_cache_SUITE \
ssl_session_SUITE \
ssl_session_cache_SUITE \
+ ssl_session_cache_api_SUITE\ \
ssl_session_ticket_SUITE \
openssl_session_ticket_SUITE \
openssl_session_SUITE \
diff --git a/lib/ssl/test/ssl_session_cache_api_SUITE.erl b/lib/ssl/test/ssl_session_cache_api_SUITE.erl
new file mode 100644
index 0000000000..28ae9bd897
--- /dev/null
+++ b/lib/ssl/test/ssl_session_cache_api_SUITE.erl
@@ -0,0 +1,105 @@
+%%
+%% %CopyrightBegin%
+%%
+%% Copyright Ericsson AB 2010-2020. All Rights Reserved.
+%%
+%% Licensed under the Apache License, Version 2.0 (the "License");
+%% you may not use this file except in compliance with the License.
+%% You may obtain a copy of the License at
+%%
+%% http://www.apache.org/licenses/LICENSE-2.0
+%%
+%% Unless required by applicable law or agreed to in writing, software
+%% distributed under the License is distributed on an "AS IS" BASIS,
+%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+%% See the License for the specific language governing permissions and
+%% limitations under the License.
+%%
+%% %CopyrightEnd%
+%%
+
+%%
+
+-module(ssl_session_cache_api_SUITE).
+
+-behaviour(ct_suite).
+
+-include_lib("common_test/include/ct.hrl").
+-include("tls_handshake.hrl").
+
+%% Callback functions
+-export([all/0]).
+
+%% Testcases
+-export([server_cb/0,
+ server_cb/1,
+ client_cb/0,
+ client_cb/1
+ ]).
+
+%%--------------------------------------------------------------------
+%% Common Test interface functions -----------------------------------
+%%--------------------------------------------------------------------
+all() ->
+ [server_cb,
+ client_cb].
+%%--------------------------------------------------------------------
+%% Test Cases --------------------------------------------------------
+%%--------------------------------------------------------------------
+server_cb() ->
+ [{doc, "Test ssl_session_cache_api server callback implementation"
+ "Note that default implementation is treated special to avoid"
+ "an extra process to handle the functional db structure used"
+ "The callback is provided for the main purpose of having a"
+ "session table that may survive node restart an assumes
+ a db reference that is not updated"
+ }].
+
+server_cb(Config) when is_list(Config) ->
+ Cb = ssl_server_session_cache_db,
+ Db0 = Cb:init([]),
+ Id0 = crypto:strong_rand_bytes(32),
+ DummySession0 = #session{session_id = Id0},
+ 0 = Cb:size(Db0),
+
+ Db1 = Cb:update(Db0, Id0, DummySession0),
+ 1 = Cb:size(Db1),
+
+ Id1 = crypto:strong_rand_bytes(32),
+ DummySession1 = #session{session_id = Id1},
+ Db2 = Cb:update(Db1, Id1, DummySession1),
+ 2 = Cb:size(Db2),
+
+ DummySession0 = Cb:lookup(Db2, Id0),
+ DummySession1 = Cb:lookup(Db2, Id1),
+
+ Db3 = Cb:delete(Db2, Id1),
+ 1 = Cb:size(Db3),
+ undefined = Cb:lookup(Db3, crypto:strong_rand_bytes(32)),
+ Cb:terminate(Db3).
+
+client_cb() ->
+ [{doc, "Test ssl_session_cache_api client callback implementation"}].
+
+client_cb(Config) when is_list(Config) ->
+ Cb = ssl_session_cache,
+ Db = Cb:init([]),
+ Id0 = crypto:strong_rand_bytes(32),
+ DummySession0 = #session{session_id = Id0},
+ 0 = Cb:size(Db),
+
+ Cb:update(Db, Id0, DummySession0),
+ 1 = Cb:size(Db),
+
+ Id1 = crypto:strong_rand_bytes(32),
+ DummySession1 = #session{session_id = Id1},
+ Cb:update(Db, Id1, DummySession1),
+ 2 = Cb:size(Db),
+
+ DummySession0 = Cb:lookup(Db, Id0),
+ DummySession1 = Cb:lookup(Db, Id1),
+ undefined = Cb:lookup(Db, crypto:strong_rand_bytes(32)),
+
+ Cb:delete(Db, Id1),
+ 1 = Cb:size(Db),
+ Cb:terminate(Db).