diff --git a/apps/kolab_guam/test/kolab_guam_rules_SUITE.erl b/apps/kolab_guam/test/kolab_guam_rules_SUITE.erl index 8992e9e..35d8696 100644 --- a/apps/kolab_guam/test/kolab_guam_rules_SUITE.erl +++ b/apps/kolab_guam/test/kolab_guam_rules_SUITE.erl @@ -1,105 +1,140 @@ %% Copyright 2015 Kolab Systems AG (http://www.kolabsys.com) %% %% Aaron Seigo (Kolab Systems) %% %% This program is free software: you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published by %% the Free Software Foundation, either version 3 of the License, or %% (at your option) any later version. %% %% This program is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty of %% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the %% GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public License %% along with this program. If not, see . -module(kolab_guam_rules_SUITE). % easier than exporting by name -compile(export_all). % required for common_test to work -include("ct.hrl"). +-include("../src/rules/kolab_guam_rule_filter_groupware.hrl"). %%%%%%%%%%%%%%%%%%%%%%%%%%% %% common test callbacks %% %%%%%%%%%%%%%%%%%%%%%%%%%%% % Specify a list of all unit test functions all() -> [ kolab_guam_rule_filter_groupware_responsefiltering_test, kolab_guam_rule_filter_groupware_responsefiltering_multipacket_test ]. % required, but can just return Config. this is a suite level setup function. init_per_suite(Config) -> + application:load(kolab_guam), Config. % required, but can just return Config. this is a suite level tear down function. end_per_suite(Config) -> Config. % optional, can do function level setup for all functions, % or for individual functions by matching on TestCase. init_per_testcase(_TestCase, Config) -> Config. % optional, can do function level tear down for all functions, % or for individual functions by matching on TestCase. end_per_testcase(_TestCase, Config) -> Config. % c("apps/kolab_guam/test/kolab_guam_sup_tests.erl"). eunit:test(kolab_guam_sup_tests). kolab_guam_rule_filter_groupware_responsefiltering_test(_TestConfig) -> %% Data to be fed into the test, one tuple per iteration - %% Tuple format: { input_data, correct_output } + %% Tuple format: { [] = folder_blacklist, input_data, correct_output } Data = [ { + [ + {<<"Calendar">>, <<"Calendar/">>}, + {<<"Calendar/Personal Calendar">>, <<"Calendar/Personal Calendar/">>}, + {<<"Configuration">>, <<"Configuration/">>}, + {<<"Contacts">>, <<"Contacts/">>}, + {<<"Contacts/Personal Contacts">>, <<"Contacts/Personal Contacts/">>}, + {<<"Files">>, <<"Files/">>}, + {<<"Journal">>, <<"Journal/">>}, + {<<"Notes">>, <<"Notes/">>}, + {<<"Tasks">>, <<"Tasks/">>} + ], <<"* LIST (\\Noinferiors \\Subscribed) \"/\" INBOX\r\n* LIST (\\Subscribed) \"/\" Archive\r\n* LIST (\\Subscribed \\HasChildren) \"/\" Calendar\r\n* LIST (\\Subscribed) \"/\" \"Calendar/Personal Calendar\"\r\n* LIST (\\Subscribed) \"/\" Configuration\r\n* LIST (\\Subscribed \\HasChildren) \"/\" Contacts\r\n* LIST (\\Subscribed) \"/\" \"Contacts/Personal Contacts\"\r\n* LIST (\\Subscribed) \"/\" Drafts\r\n* LIST (\\Subscribed) \"/\" Files\r\n* LIST (\\Subscribed) \"/\" Journal\r\n* LIST (\\Subscribed) \"/\" Notes\r\n* LIST (\\Subscribed) \"/\" Sent\r\n* LIST (\\Subscribed) \"/\" Spam\r\n* LIST (\\Subscribed) \"/\" Tasks\r\n* LIST (\\Subscribed) \"/\" Trash\r\n7 OK Completed (0.000 secs 15 calls)\r\n">>, <<"* LIST (\\Noinferiors \\Subscribed) \"/\" INBOX\r\n* LIST (\\Subscribed) \"/\" Archive\r\n* LIST (\\Subscribed) \"/\" Drafts\r\n* LIST (\\Subscribed) \"/\" Sent\r\n* LIST (\\Subscribed) \"/\" Spam\r\n* LIST (\\Subscribed) \"/\" Trash\r\n7 OK Completed (0.000 secs 15 calls)\r\n">> } ], %% setup boilerplate Config = {}, %%TODO? State = kolab_guam_rule_filter_groupware:new(Config), ServerConfig = kolab_guam_sup:default_imap_server_config(), { ok, ImapSession } = eimap:start_link(ServerConfig), %% create the rule, ready for testing - { _, ReadyState } = kolab_guam_rule_filter_groupware:apply_to_client_message(ImapSession, <<"7 list (subscribed) \"\" \"*\" return (special-use)">>, State), + ClientData = <<"7 list (subscribed) \"\" \"*\" return (special-use)">>, + Split = eimap_utils:split_command_into_components(ClientData), + { _, ReadyState } = kolab_guam_rule_filter_groupware:apply_to_client_message(ImapSession, ClientData, Split, State), %% run the dataset through the rule - lists:foreach(fun({ Input, Filtered }) -> { Filtered, NewState } = kolab_guam_rule_filter_groupware:apply_to_server_message(ImapSession, Input, ReadyState) end, Data). + lists:foreach(fun({ Blacklist, Input, Filtered }) -> + BlacklistState = ReadyState#state{ blacklist = Blacklist }, + { Filtered, _NewState } = kolab_guam_rule_filter_groupware:apply_to_server_message(ImapSession, Input, BlacklistState) end, + Data). kolab_guam_rule_filter_groupware_responsefiltering_multipacket_test(_TestConfig) -> %% Data to be fed into the test, one tuple per iteration %% Tuple format: { [ input_packets ] = complete_message, correct_output } Data = [ { + [ + {<<"Calendar">>, <<"Calendar/">>}, + {<<"Calendar/Personal Calendar">>, <<"Calendar/Personal Calendar/">>}, + {<<"Configuration">>, <<"Configuration/">>}, + {<<"Contacts">>, <<"Contacts/">>}, + {<<"Contacts/Personal Contacts">>, <<"Contacts/Personal Contacts/">>}, + {<<"Files">>, <<"Files/">>}, + {<<"Journal">>, <<"Journal/">>}, + {<<"Notes">>, <<"Notes/">>}, + {<<"Tasks">>, <<"Tasks/">>} + ], [ <<"* LIST (\\Noinferiors \\Subscribed) \"/\" INBOX\r\n* LIST (\\Subscribed) \"/\" Archive\r\n* LIST (\\Subscribed \\HasChildren) \"/\" Calendar\r\n* LIST (\\Subscribed) \"/\" \"Calendar/Personal Calendar\"\r\n* LIST (\\Subscribed) \"/\" Configuration\r\n* LIST (\\Subscribed \\HasChildren) \"/\" Contacts\r\n* LIST (\\Subscribed) \"/\" \"Contacts/Personal Contacts\"\r\n* LIST (\\Subscribed) \"/\" Drafts\r\n* LIST (\\Subscribed) \"/\" Files\r\n* LIST (\\Subscribed) \"/\" Journal\r\n* LIST (\\Subscribed)">>, <<"\"/\" Notes\r\n* LIST (\\Subscribed) \"/\" Sent\r\n* LIST (\\Subscribed) \"/\" Spam\r\n* LIST (\\Subscribed) \"/\" Tasks\r\n* LIST (\\Subscribed) \"/\" Trash\r\n7 OK Completed (0.000 secs 15 calls)\r\n">> ], <<"* LIST (\\Noinferiors \\Subscribed) \"/\" INBOX\r\n* LIST (\\Subscribed) \"/\" Archive\r\n* LIST (\\Subscribed) \"/\" Drafts\r\n* LIST (\\Subscribed) \"/\" Sent\r\n* LIST (\\Subscribed) \"/\" Spam\r\n* LIST (\\Subscribed) \"/\" Trash\r\n7 OK Completed (0.000 secs 15 calls)\r\n">> } ], %% setup boilerplate Config = {}, %%TODO? - Config = {}, %%TODO? State = kolab_guam_rule_filter_groupware:new(Config), + ServerConfig = kolab_guam_sup:default_imap_server_config(), + { ok, ImapSession } = eimap:start_link(ServerConfig), %% create the rule, ready for testing - { _, ReadyState } = kolab_guam_rule_filter_groupware:apply_to_client_message(<<"7 list (subscribed) \"\" \"*\" return (special-use)">>, State), + ClientData = <<"7 list (subscribed) \"\" \"*\" return (special-use)">>, + Split = eimap_utils:split_command_into_components(ClientData), + { _, ReadyState } = kolab_guam_rule_filter_groupware:apply_to_client_message(ImapSession, ClientData, Split, State), %% run the dataset through the rule - lists:foreach(fun({ Input, Filtered }) -> Filtered = filter_groupware_packets(ReadyState, Input, <<>>) end, Data). - -filter_groupware_packets(_ReadyState, [], Buffer) -> Buffer; -filter_groupware_packets(ReadyState, [Input|More], Buffer) -> - { Processed, State } = kolab_guam_rule_filter_groupware:apply_to_server_message(Input, ReadyState), - filter_groupware_packets(State, More, <>). + lists:foreach(fun({ Blacklist, Input, Filtered }) -> + BlacklistState = ReadyState#state{ blacklist = Blacklist }, + Filtered = filter_groupware_packets(ImapSession, BlacklistState, Input, <<>>) end, + Data). + +filter_groupware_packets(_ImapSession, _ReadyState, [], Buffer) -> Buffer; +filter_groupware_packets(ImapSession, ReadyState, [Input|More], Buffer) -> + { Processed, State } = kolab_guam_rule_filter_groupware:apply_to_server_message(ImapSession, Input, ReadyState), + filter_groupware_packets(ImapSession, State, More, <>). diff --git a/apps/kolab_guam/test/kolab_guam_sup_SUITE.erl b/apps/kolab_guam/test/kolab_guam_sup_SUITE.erl index c7d6bbc..f4ed533 100644 --- a/apps/kolab_guam/test/kolab_guam_sup_SUITE.erl +++ b/apps/kolab_guam/test/kolab_guam_sup_SUITE.erl @@ -1,65 +1,66 @@ %% Copyright 2015 Kolab Systems AG (http://www.kolabsys.com) %% %% Aaron Seigo (Kolab Systems) %% %% This program is free software: you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published by %% the Free Software Foundation, either version 3 of the License, or %% (at your option) any later version. %% %% This program is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty of %% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the %% GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public License %% along with this program. If not, see . -module(kolab_guam_sup_SUITE). % easier than exporting by name -compile(export_all). % required for common_test to work -include("ct.hrl"). %%%%%%%%%%%%%%%%%%%%%%%%%%% %% common test callbacks %% %%%%%%%%%%%%%%%%%%%%%%%%%%% % Specify a list of all unit test functions -all() -> [imap_server_config_test, imap_server_settings_to_config_test]. +all() -> [default_imap_server_config_test, imap_server_config_test]. % required, but can just return Config. this is a suite level setup function. init_per_suite(Config) -> + application:load(kolab_guam), Config. % required, but can just return Config. this is a suite level tear down function. end_per_suite(Config) -> Config. % optional, can do function level setup for all functions, % or for individual functions by matching on TestCase. init_per_testcase(_TestCase, Config) -> Config. % optional, can do function level tear down for all functions, % or for individual functions by matching on TestCase. end_per_testcase(_TestCase, Config) -> Config. % c("apps/kolab_guam/test/kolab_guam_sup_tests.erl"). eunit:test(kolab_guam_sup_tests). default_imap_server_config_test(_TestConfig) -> Expected = [ { host, "192.168.56.102" }, { port, 994 }, { tls, true } ], Expected = kolab_guam_sup:default_imap_server_config(). imap_server_config_test(_TestConfig) -> Configs = [ { test_default, [ { host, "192.168.56.101" }, { port, 993 }, { tls, false } ] } ], lists:foreach(fun({ Config, Record }) -> Record = kolab_guam_sup:imap_server_config(Config) end, Configs).