1 /*
2 	liblinphone_tester - liblinphone test suite
3 	Copyright (C) 2013  Belledonne Communications SARL
4 
5 	This program is free software: you can redistribute it and/or modify
6 	it under the terms of the GNU General Public License as published by
7 	the Free Software Foundation, either version 2 of the License, or
8 	(at your option) any later version.
9 
10 	This program is distributed in the hope that it will be useful,
11 	but WITHOUT ANY WARRANTY; without even the implied warranty of
12 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 	GNU General Public License for more details.
14 
15 	You should have received a copy of the GNU General Public License
16 	along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 
20 #include "linphone/core.h"
21 #include "private.h"
22 #include "liblinphone_tester.h"
23 
linphone_configuration_status(LinphoneCore * lc,LinphoneConfiguringState status,const char * message)24 void linphone_configuration_status(LinphoneCore *lc, LinphoneConfiguringState status, const char *message) {
25 	stats* counters;
26 	ms_message("Configuring state = %i with message %s", status, message?message:"");
27 
28 	counters = get_stats(lc);
29 	if (status == LinphoneConfiguringSkipped) {
30 		counters->number_of_LinphoneConfiguringSkipped++;
31 	} else if (status == LinphoneConfiguringFailed) {
32 		counters->number_of_LinphoneConfiguringFailed++;
33 	} else if (status == LinphoneConfiguringSuccessful) {
34 		counters->number_of_LinphoneConfiguringSuccessful++;
35 	}
36 }
37 
remote_provisioning_skipped(void)38 static void remote_provisioning_skipped(void) {
39 	LinphoneCoreManager* marie = linphone_core_manager_new2("marie_rc", FALSE);
40 	BC_ASSERT_TRUE(wait_for(marie->lc,NULL,&marie->stat.number_of_LinphoneConfiguringSkipped,1));
41 	linphone_core_manager_destroy(marie);
42 }
43 
remote_provisioning_http(void)44 static void remote_provisioning_http(void) {
45 	LinphoneCoreManager* marie = linphone_core_manager_new2("marie_remote_rc", FALSE);
46 	BC_ASSERT_TRUE(wait_for(marie->lc,NULL,&marie->stat.number_of_LinphoneConfiguringSuccessful,1));
47 	BC_ASSERT_TRUE(wait_for(marie->lc,NULL,&marie->stat.number_of_LinphoneRegistrationOk,1));
48 	linphone_core_manager_destroy(marie);
49 }
50 
remote_provisioning_transient(void)51 static void remote_provisioning_transient(void) {
52 	LinphoneCoreManager* marie = linphone_core_manager_new2("marie_transient_remote_rc", FALSE);
53 	BC_ASSERT_TRUE(wait_for(marie->lc,NULL,&marie->stat.number_of_LinphoneConfiguringSuccessful,1));
54 	BC_ASSERT_TRUE(wait_for(marie->lc,NULL,&marie->stat.number_of_LinphoneRegistrationOk,1));
55 	BC_ASSERT_TRUE(linphone_core_is_provisioning_transient(marie->lc));
56 	BC_ASSERT_PTR_NULL(linphone_core_get_provisioning_uri(marie->lc));
57 	linphone_core_manager_destroy(marie);
58 }
59 
remote_provisioning_https(void)60 static void remote_provisioning_https(void) {
61 	if (transport_supported(LinphoneTransportTls)) {
62 		LinphoneCoreManager* marie = linphone_core_manager_new2("marie_remote_https_rc", FALSE);
63 		BC_ASSERT_TRUE(wait_for(marie->lc,NULL,&marie->stat.number_of_LinphoneConfiguringSuccessful,1));
64 		BC_ASSERT_TRUE(wait_for(marie->lc,NULL,&marie->stat.number_of_LinphoneRegistrationOk,1));
65 		linphone_core_manager_destroy(marie);
66 	}
67 }
68 
remote_provisioning_not_found(void)69 static void remote_provisioning_not_found(void) {
70 	LinphoneCoreManager* marie = linphone_core_manager_new2("marie_remote_404_rc", FALSE);
71 	BC_ASSERT_TRUE(wait_for(marie->lc,NULL,&marie->stat.number_of_LinphoneConfiguringFailed,1));
72 	linphone_core_manager_destroy(marie);
73 }
74 
remote_provisioning_invalid(void)75 static void remote_provisioning_invalid(void) {
76 	LinphoneCoreManager* marie = linphone_core_manager_new2("marie_remote_invalid_rc", FALSE);
77 	BC_ASSERT_TRUE(wait_for(marie->lc,NULL,&marie->stat.number_of_LinphoneConfiguringFailed,1));
78 	linphone_core_manager_destroy(marie);
79 }
80 
remote_provisioning_invalid_uri(void)81 static void remote_provisioning_invalid_uri(void) {
82 	LinphoneCoreManager* marie = linphone_core_manager_new2("marie_remote_invalid_uri_rc", FALSE);
83 	BC_ASSERT_TRUE(wait_for(marie->lc,NULL,&marie->stat.number_of_LinphoneConfiguringFailed,1));
84 	linphone_core_manager_destroy(marie);
85 }
86 
remote_provisioning_default_values(void)87 static void remote_provisioning_default_values(void) {
88 	LinphoneProxyConfig *lpc;
89 	LinphoneCoreManager* marie = linphone_core_manager_new2("marie_remote_default_values_rc", FALSE);
90 	BC_ASSERT_TRUE(wait_for(marie->lc,NULL,&marie->stat.number_of_LinphoneConfiguringSuccessful,1));
91 	lpc = linphone_core_create_proxy_config(marie->lc);
92 	BC_ASSERT_TRUE(lpc->reg_sendregister);
93 	BC_ASSERT_EQUAL(lpc->expires, 604800, int, "%d");
94 	BC_ASSERT_STRING_EQUAL(lpc->reg_proxy, "<sip:sip.linphone.org:5223;transport=tls>");
95 	BC_ASSERT_STRING_EQUAL(lpc->reg_route, "<sip:sip.linphone.org:5223;transport=tls>");
96 	BC_ASSERT_STRING_EQUAL(lpc->reg_identity, "sip:?@sip.linphone.org");
97 	{
98 		LpConfig* lp = linphone_core_get_config(marie->lc);
99 		BC_ASSERT_STRING_EQUAL(lp_config_get_string(lp,"app","toto","empty"),"titi");
100 	}
101 	linphone_proxy_config_destroy(lpc);
102 	linphone_core_manager_destroy(marie);
103 }
104 
remote_provisioning_file(void)105 static void remote_provisioning_file(void) {
106 	LinphoneCoreManager* marie;
107 	const LpConfig* conf;
108 #if TARGET_OS_IPHONE
109 	ms_message("Skipping remote provisioning from file on iOS");
110 	return;
111 #elif defined(__ANDROID__)
112 	marie = linphone_core_manager_new2("marie_remote_localfile_android_rc", FALSE);
113 #elif defined(LINPHONE_WINDOWS_UNIVERSAL)
114 	marie = linphone_core_manager_new2("marie_remote_localfile_win10_rc", FALSE);
115 #else
116 	marie = ms_new0(LinphoneCoreManager, 1);
117 	linphone_core_manager_init(marie, "marie_remote_localfile_rc",NULL);
118 	// fix relative path to absolute path
119 	{
120 		char* path = bc_tester_res("rcfiles/marie_remote_localfile2_rc");
121 		char* abspath = ms_strdup_printf("file://%s", path);
122 		lp_config_set_string(marie->lc->config, "misc", "config-uri", abspath);
123 		linphone_core_manager_start(marie, 1);
124 		ms_free(path);
125 		ms_free(abspath);
126 	}
127 #endif
128 	BC_ASSERT_TRUE(wait_for(marie->lc,NULL,&marie->stat.number_of_LinphoneConfiguringSuccessful,1));
129 
130 	conf = linphone_core_get_config( marie->lc );
131 	BC_ASSERT_EQUAL( lp_config_get_int(conf,"misc","tester_file_ok", 0), 1 , int, "%d");
132 
133 	linphone_core_manager_destroy(marie);
134 }
135 
136 
137 test_t remote_provisioning_tests[] = {
138 	TEST_NO_TAG("Remote provisioning skipped", remote_provisioning_skipped),
139 	TEST_NO_TAG("Remote provisioning successful behind http", remote_provisioning_http),
140 	TEST_NO_TAG("Remote provisioning successful behind https", remote_provisioning_https),
141 	TEST_NO_TAG("Remote provisioning 404 not found", remote_provisioning_not_found),
142 	TEST_NO_TAG("Remote provisioning invalid", remote_provisioning_invalid),
143 	TEST_NO_TAG("Remote provisioning transient successful", remote_provisioning_transient),
144 	TEST_NO_TAG("Remote provisioning default values", remote_provisioning_default_values),
145 	TEST_NO_TAG("Remote provisioning from file", remote_provisioning_file),
146 	TEST_NO_TAG("Remote provisioning invalid URI", remote_provisioning_invalid_uri)
147 };
148 
149 test_suite_t remote_provisioning_test_suite = {"RemoteProvisioning", NULL, NULL, liblinphone_tester_before_each, liblinphone_tester_after_each,
150 											   sizeof(remote_provisioning_tests) / sizeof(remote_provisioning_tests[0]),
151 											   remote_provisioning_tests};
152