<commit_before>%%%-------------------------------------------------------------------
%%% @author <NAME>
%%% @copyright (C) 2018 ACK CYFRONET AGH
%%% This software is released under the MIT license
%%% cited in 'LICENSE.txt'.
%%% @end
%%%-------------------------------------------------------------------
%%% @doc
%%% Provider to Zone connection tests
%%% @end
%%%-------------------------------------------------------------------
-module(zone_connection_test_SUITE).
-author("<NAME>").

-include("http/gui_paths.hrl").
-include("global_definitions.hrl").
-include("modules/fslogic/fslogic_common.hrl").
-include_lib("ctool/include/logging.hrl").
-include_lib("ctool/include/onedata.hrl").
-include_lib("ctool/include/test/test_utils.hrl").
-include_lib("ctool/include/test/assertions.hrl").
-include_lib("ctool/include/test/performance.hrl").
-include_lib("ctool/include/posix/file_attr.hrl").
-include_lib("ctool/include/posix/errors.hrl").

%% API
-export([
    all/0,
    init_per_suite/1, end_per_suite/1,
    init_per_testcase/2, end_per_testcase/2
]).

-export([
    oneprovider_should_not_connect_to_incompatible_onezone/1
]).

all() ->
    ?ALL([
        oneprovider_should_not_connect_to_incompatible_onezone
    ]).


%%%===================================================================
%%% Test functions
%%%===================================================================

oneprovider_should_not_connect_to_incompatible_onezone(Config) ->
    [P1Worker, P2Worker] = ?config(op_worker_nodes, Config),
    timer:sleep(15),
    % One of providers should not connect because of mocked compatibility
    % check function in init_per_testcase.
    ?assertMatch(false, is_connected_to_oz(P1Worker), 30),
    ?assertMatch(true, is_connected_to_oz(P2Worker), 30).


is_connected_to_oz(Worker) ->
    Domain = ?GET_DOMAIN(Worker),
    Url = str_utils:format_bin("https://~s~s", [Domain, ?NAGIOS_OZ_CONNECTIVITY_PATH]),
    CaCerts = rpc:call(Worker, https_listener, get_cert_chain_pems, []),
    {ok, Domain} = test_utils:get_env(Worker, ?APP_NAME, test_web_cert_domain),
    Opts = [{ssl_options, [{cacerts, CaCerts}, {hostname, str_utils:to_binary(Domain)}]}],
    case http_client:get(Url, #{}, <<>>, Opts) of
        {ok, 200, _, Body} ->
            case json_utils:decode(Body) of
                #{<<"status">> := <<"ok">>} -> true;
                #{<<"status">> := <<"error">>} -> false
            end;<commit_msg>VFS-6044 Fix a badmatch in zone_connection_test_SUITE<commit_after>%%%-------------------------------------------------------------------
%%% @author <NAME>
%%% @copyright (C) 2018 ACK CYFRONET AGH
%%% This software is released under the MIT license
%%% cited in 'LICENSE.txt'.
%%% @end
%%%-------------------------------------------------------------------
%%% @doc
%%% Provider to Zone connection tests
%%% @end
%%%-------------------------------------------------------------------
-module(zone_connection_test_SUITE).
-author("<NAME>").

-include("http/gui_paths.hrl").
-include("global_definitions.hrl").
-include("modules/fslogic/fslogic_common.hrl").
-include_lib("ctool/include/logging.hrl").
-include_lib("ctool/include/onedata.hrl").
-include_lib("ctool/include/test/test_utils.hrl").
-include_lib("ctool/include/test/assertions.hrl").
-include_lib("ctool/include/test/performance.hrl").
-include_lib("ctool/include/posix/file_attr.hrl").
-include_lib("ctool/include/posix/errors.hrl").

%% API
-export([
    all/0,
    init_per_suite/1, end_per_suite/1,
    init_per_testcase/2, end_per_testcase/2
]).

-export([
    oneprovider_should_not_connect_to_incompatible_onezone/1
]).

all() ->
    ?ALL([
        oneprovider_should_not_connect_to_incompatible_onezone
    ]).


%%%===================================================================
%%% Test functions
%%%===================================================================

oneprovider_should_not_connect_to_incompatible_onezone(Config) ->
    [P1Worker, P2Worker] = ?config(op_worker_nodes, Config),
    timer:sleep(15),
    % One of providers should not connect because of mocked compatibility
    % check function in init_per_testcase.
    ?assertMatch(false, is_connected_to_oz(P1Worker), 30),
    ?assertMatch(true, is_connected_to_oz(P2Worker), 30).


is_connected_to_oz(Worker) ->
    {ok, Domain} = test_utils:get_env(Worker, ?APP_NAME, test_web_cert_domain),
    Url = str_utils:format_bin("https://~s~s", [Domain, ?NAGIOS_OZ_CONNECTIVITY_PATH]),
    CaCerts = rpc:call(Worker, https_listener, get_cert_chain_pems, []),
    Opts = [{ssl_options, [{cacerts, CaCerts}, {hostname, str_utils:to_binary(Domain)}]}],
    case http_client:get(Url, #{}, <<>>, Opts) of
        {ok, 200, _, Body} ->
            case json_utils:decode(Body) of
                #{<<"status">> := <<"ok">>} -> true;
                #{<<"status">> := <<"error">>} -> false
            end;
{'fraction_non_alphanumeric': 0.2847763643824374, 'fraction_numerical': 0.010258514567090685, 'mean_word_length': 3.145408163265306, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 39, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6808225', 'n_tokens_mistral': 1615, 'n_tokens_neox': 1544, 'n_words': 240}