1 /*
2 * very basic unit test for curlsftpsink
3 */
4
5 #include <gst/check/gstcheck.h>
6 #include <glib/gstdio.h>
7 #include <curl/curl.h>
8
9 static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
10 GST_PAD_SRC,
11 GST_PAD_ALWAYS,
12 GST_STATIC_CAPS_ANY);
13
14 static GstPad *srcpad;
15
16 static GstElement *sink;
17
18 static GstElement *
setup_curlsftpsink(void)19 setup_curlsftpsink (void)
20 {
21 GST_DEBUG ("setup_curlsftpsink");
22 sink = gst_check_setup_element ("curlsftpsink");
23 srcpad = gst_check_setup_src_pad (sink, &srctemplate);
24 fail_unless (gst_pad_set_active (srcpad, TRUE));
25
26 return sink;
27 }
28
29 static void
cleanup_curlsftpsink(GstElement * sink)30 cleanup_curlsftpsink (GstElement * sink)
31 {
32 GST_DEBUG ("cleanup_curlsftpsink");
33
34 gst_check_teardown_src_pad (sink);
35 gst_check_teardown_element (sink);
36 }
37
GST_START_TEST(test_properties)38 GST_START_TEST (test_properties)
39 {
40
41 GstElement *sink;
42
43 gchar *res_location = NULL;
44 gchar *res_user = NULL;
45 gchar *res_passwd = NULL;
46 gchar *res_file_name = NULL;
47 gint res_timeout = 0;
48 gint res_qos_dscp = 0;
49
50 gchar *res_pubkey_file = NULL;
51 gchar *res_privkey_file = NULL;
52 gchar *res_passphrase = NULL;
53 gchar *res_kh_file = NULL;
54 gchar *res_host_pubkey_md5 = NULL;
55 gchar *res_host_pubkey_sha256 = NULL;
56 guint res_auth_type = 0;
57 gboolean res_accept_unkh = FALSE;
58
59 gboolean res_create_dirs = FALSE;
60
61 sink = setup_curlsftpsink ();
62
63 /* props from GstCurlBaseSink */
64 g_object_set (G_OBJECT (sink), "location", "test_location", NULL);
65 g_object_set (G_OBJECT (sink), "user", "test_user", NULL);
66 g_object_set (G_OBJECT (sink), "passwd", "test_passwd", NULL);
67 g_object_set (G_OBJECT (sink), "file-name", "test_filename", NULL);
68 g_object_set (G_OBJECT (sink), "timeout", 123, NULL);
69 g_object_set (G_OBJECT (sink), "qos-dscp", 11, NULL); /* DSCP_MIN = 0,
70 DSCP_MAX = 63
71 gstcurlbasesink.c */
72
73 /* props from GstCurlSshSink */
74 g_object_set (G_OBJECT (sink), "ssh-auth-type", CURLSSH_AUTH_PUBLICKEY, NULL);
75 g_object_set (G_OBJECT (sink), "ssh-pub-keyfile", "public_key_file", NULL);
76 g_object_set (G_OBJECT (sink), "ssh-priv-keyfile", "private_key_file", NULL);
77 g_object_set (G_OBJECT (sink), "ssh-knownhosts", "known_hosts", NULL);
78 g_object_set (G_OBJECT (sink), "ssh-host-pubkey-md5",
79 "00112233445566778899aabbccddeeff", NULL);
80 #if CURL_AT_LEAST_VERSION(7, 80, 0)
81 g_object_set (G_OBJECT (sink), "ssh-host-pubkey-sha256",
82 "TQtiu1/zwGEEKG4z/PDfPE/ak47AF9nbWHykx4CWcu9", NULL);
83 #endif
84 g_object_set (G_OBJECT (sink), "ssh-accept-unknownhost", TRUE, NULL);
85 g_object_set (G_OBJECT (sink), "ssh-key-passphrase", "SoMePaSsPhRaSe", NULL);
86
87 /* props from GstCurlSftpSink */
88 g_object_set (G_OBJECT (sink), "create-dirs", TRUE, NULL);
89
90
91 /* run a 'get' on all the above props */
92 g_object_get (sink, "location", &res_location,
93 "user", &res_user, "passwd", &res_passwd, "file-name", &res_file_name,
94 "timeout", &res_timeout, "qos-dscp", &res_qos_dscp,
95 "ssh-auth-type", &res_auth_type, "ssh-pub-keyfile", &res_pubkey_file,
96 "ssh-priv-keyfile", &res_privkey_file, "ssh-knownhosts", &res_kh_file,
97 "ssh-host-pubkey-md5", &res_host_pubkey_md5,
98 "ssh-accept-unknownhost", &res_accept_unkh,
99 "create-dirs", &res_create_dirs, "ssh-key-passphrase", &res_passphrase,
100 NULL);
101
102 #if CURL_AT_LEAST_VERSION(7, 80, 0)
103 g_object_get (sink, "ssh-host-pubkey-sha256", &res_host_pubkey_sha256, NULL);
104 #endif
105
106 fail_unless (strncmp (res_location, "test_location", strlen ("test_location"))
107 == 0);
108 fail_unless (strncmp (res_user, "test_user", strlen ("test_user")) == 0);
109 fail_unless (strncmp (res_passwd, "test_passwd", strlen ("test_passwd"))
110 == 0);
111 fail_unless (strncmp (res_file_name, "test_filename",
112 strlen ("test_filename")) == 0);
113 fail_unless (res_timeout == 123);
114 fail_unless (res_qos_dscp == 11);
115
116 fail_unless (res_auth_type == CURLSSH_AUTH_PUBLICKEY);
117 fail_unless (strncmp (res_pubkey_file, "public_key_file",
118 strlen ("public_key_file")) == 0);
119 fail_unless (strncmp (res_privkey_file, "private_key_file",
120 strlen ("private_key_file")) == 0);
121 fail_unless (strncmp (res_kh_file, "known_hosts", strlen ("known_hosts"))
122 == 0);
123 fail_unless (strncmp (res_host_pubkey_md5, "00112233445566778899aabbccddeeff",
124 strlen ("00112233445566778899aabbccddeeff")) == 0);
125 #if CURL_AT_LEAST_VERSION(7, 80, 0)
126 fail_unless (strncmp (res_host_pubkey_sha256,
127 "TQtiu1/zwGEEKG4z/PDfPE/ak47AF9nbWHykx4CWcu9",
128 strlen ("TQtiu1/zwGEEKG4z/PDfPE/ak47AF9nbWHykx4CWcu9")) == 0);
129 #endif
130 fail_unless (strncmp (res_passphrase, "SoMePaSsPhRaSe",
131 strlen ("SoMePaSsPhRaSe")) == 0);
132 fail_unless (res_accept_unkh == TRUE);
133 fail_unless (res_create_dirs == TRUE);
134
135 g_free (res_location);
136 g_free (res_user);
137 g_free (res_passwd);
138 g_free (res_file_name);
139 g_free (res_pubkey_file);
140 g_free (res_privkey_file);
141 g_free (res_passphrase);
142 g_free (res_kh_file);
143 g_free (res_host_pubkey_md5);
144 g_free (res_host_pubkey_sha256);
145
146 /* ------- change properties ------------- */
147
148 /* props from GstCurlBaseSink */
149 g_object_set (G_OBJECT (sink), "location", "new_location", NULL);
150 g_object_set (G_OBJECT (sink), "user", "new_user", NULL);
151 g_object_set (G_OBJECT (sink), "passwd", "new_passwd", NULL);
152 g_object_set (G_OBJECT (sink), "file-name", "new_filename", NULL);
153 g_object_set (G_OBJECT (sink), "timeout", 321, NULL);
154 g_object_set (G_OBJECT (sink), "qos-dscp", 22, NULL);
155
156 /* props from GstCurlSshSink */
157 g_object_set (G_OBJECT (sink), "ssh-auth-type", CURLSSH_AUTH_PASSWORD, NULL);
158 g_object_set (G_OBJECT (sink), "ssh-pub-keyfile", "/xxx/pub_key", NULL);
159 g_object_set (G_OBJECT (sink), "ssh-priv-keyfile", "/yyy/pvt_key", NULL);
160 g_object_set (G_OBJECT (sink), "ssh-knownhosts", "/zzz/known_hosts", NULL);
161 g_object_set (G_OBJECT (sink), "ssh-host-pubkey-md5",
162 "ffeeddccbbaa99887766554433221100", NULL);
163 #if CURL_AT_LEAST_VERSION(7, 80, 0)
164 g_object_set (G_OBJECT (sink), "ssh-host-pubkey-sha256",
165 "TUtitut/wGEEKG4z/PDfPE/ak47AF7nbWHykAxCWcu5", NULL);
166 #endif
167 g_object_set (G_OBJECT (sink), "ssh-accept-unknownhost", FALSE, NULL);
168 g_object_set (G_OBJECT (sink), "ssh-key-passphrase", "OtherPASSphrase", NULL);
169
170 /* props from GstCurlSftpSink */
171 g_object_set (G_OBJECT (sink), "create-dirs", FALSE, NULL);
172
173
174 /* run a 'get' on all the above props */
175 g_object_get (sink, "location", &res_location, "user", &res_user,
176 "passwd", &res_passwd, "file-name", &res_file_name,
177 "timeout", &res_timeout, "qos-dscp", &res_qos_dscp,
178 "ssh-auth-type", &res_auth_type, "ssh-pub-keyfile", &res_pubkey_file,
179 "ssh-priv-keyfile", &res_privkey_file, "ssh-knownhosts", &res_kh_file,
180 "ssh-accept-unknownhost", &res_accept_unkh,
181 "ssh-host-pubkey-md5", &res_host_pubkey_md5,
182 "ssh-key-passphrase", &res_passphrase, "create-dirs", &res_create_dirs,
183 NULL);
184
185 #if CURL_AT_LEAST_VERSION(7, 80, 0)
186 g_object_get (sink, "ssh-host-pubkey-sha256", &res_host_pubkey_sha256, NULL);
187 #endif
188
189 fail_unless (strncmp (res_location, "new_location", strlen ("new_location"))
190 == 0);
191 fail_unless (strncmp (res_user, "new_user", strlen ("new_user")) == 0);
192 fail_unless (strncmp (res_passwd, "new_passwd", strlen ("new_passwd"))
193 == 0);
194 fail_unless (strncmp (res_file_name, "new_filename",
195 strlen ("new_filename")) == 0);
196 fail_unless (res_timeout == 321);
197 fail_unless (res_qos_dscp == 22);
198
199 fail_unless (res_auth_type == CURLSSH_AUTH_PASSWORD);
200 fail_unless (strncmp (res_pubkey_file, "/xxx/pub_key",
201 strlen ("/xxx/pub_key")) == 0);
202 fail_unless (strncmp (res_privkey_file, "/yyy/pvt_key",
203 strlen ("/yyy/pvt_key")) == 0);
204 fail_unless (strncmp (res_kh_file, "/zzz/known_hosts",
205 strlen ("/zzz/known_host")) == 0);
206 fail_unless (strncmp (res_host_pubkey_md5, "ffeeddccbbaa99887766554433221100",
207 strlen ("ffeeddccbbaa99887766554433221100")) == 0);
208 #if CURL_AT_LEAST_VERSION(7, 80, 0)
209 fail_unless (strncmp (res_host_pubkey_sha256,
210 "TUtitut/wGEEKG4z/PDfPE/ak47AF7nbWHykAxCWcu5",
211 strlen ("TUtitut/wGEEKG4z/PDfPE/ak47AF7nbWHykAxCWcu5")) == 0);
212 #endif
213 fail_unless (strncmp (res_passphrase, "OtherPASSphrase",
214 strlen ("OtherPASSphrase")) == 0);
215 fail_unless (res_accept_unkh == FALSE);
216 fail_unless (res_create_dirs == FALSE);
217
218 g_free (res_location);
219 g_free (res_user);
220 g_free (res_passwd);
221 g_free (res_file_name);
222 g_free (res_pubkey_file);
223 g_free (res_privkey_file);
224 g_free (res_passphrase);
225 g_free (res_kh_file);
226 g_free (res_host_pubkey_md5);
227 g_free (res_host_pubkey_256);
228
229 cleanup_curlsftpsink (sink);
230 }
231
232 GST_END_TEST;
233
234 static Suite *
curlsink_suite(void)235 curlsink_suite (void)
236 {
237 Suite *s = suite_create ("curlsftpsink");
238 TCase *tc_chain = tcase_create ("sftpsink props");
239
240 suite_add_tcase (s, tc_chain);
241 tcase_set_timeout (tc_chain, 20);
242 tcase_add_test (tc_chain, test_properties);
243
244 return s;
245 }
246
247 GST_CHECK_MAIN (curlsink);
248