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   guint res_auth_type = 0;
56   gboolean res_accept_unkh = FALSE;
57 
58   gboolean res_create_dirs = FALSE;
59 
60   sink = setup_curlsftpsink ();
61 
62   /* props from GstCurlBaseSink */
63   g_object_set (G_OBJECT (sink), "location", "test_location", NULL);
64   g_object_set (G_OBJECT (sink), "user", "test_user", NULL);
65   g_object_set (G_OBJECT (sink), "passwd", "test_passwd", NULL);
66   g_object_set (G_OBJECT (sink), "file-name", "test_filename", NULL);
67   g_object_set (G_OBJECT (sink), "timeout", 123, NULL);
68   g_object_set (G_OBJECT (sink), "qos-dscp", 11, NULL); /* DSCP_MIN = 0,
69                                                            DSCP_MAX = 63
70                                                            gstcurlbasesink.c */
71 
72   /* props from GstCurlSshSink */
73   g_object_set (G_OBJECT (sink), "ssh-auth-type", CURLSSH_AUTH_PUBLICKEY, NULL);
74   g_object_set (G_OBJECT (sink), "ssh-pub-keyfile", "public_key_file", NULL);
75   g_object_set (G_OBJECT (sink), "ssh-priv-keyfile", "private_key_file", NULL);
76   g_object_set (G_OBJECT (sink), "ssh-knownhosts", "known_hosts", NULL);
77   g_object_set (G_OBJECT (sink), "ssh-host-pubkey-md5",
78       "00112233445566778899aabbccddeeff", NULL);
79   g_object_set (G_OBJECT (sink), "ssh-accept-unknownhost", TRUE, NULL);
80   g_object_set (G_OBJECT (sink), "ssh-key-passphrase", "SoMePaSsPhRaSe", NULL);
81 
82   /* props from GstCurlSftpSink */
83   g_object_set (G_OBJECT (sink), "create-dirs", TRUE, NULL);
84 
85 
86   /* run a 'get' on all the above props */
87   g_object_get (sink, "location", &res_location,
88       "user", &res_user, "passwd", &res_passwd, "file-name", &res_file_name,
89       "timeout", &res_timeout, "qos-dscp", &res_qos_dscp,
90       "ssh-auth-type", &res_auth_type, "ssh-pub-keyfile", &res_pubkey_file,
91       "ssh-priv-keyfile", &res_privkey_file, "ssh-knownhosts", &res_kh_file,
92       "ssh-host-pubkey-md5", &res_host_pubkey_md5,
93       "ssh-accept-unknownhost", &res_accept_unkh,
94       "create-dirs", &res_create_dirs, "ssh-key-passphrase", &res_passphrase,
95       NULL);
96 
97   fail_unless (strncmp (res_location, "test_location", strlen ("test_location"))
98       == 0);
99   fail_unless (strncmp (res_user, "test_user", strlen ("test_user")) == 0);
100   fail_unless (strncmp (res_passwd, "test_passwd", strlen ("test_passwd"))
101       == 0);
102   fail_unless (strncmp (res_file_name, "test_filename",
103           strlen ("test_filename")) == 0);
104   fail_unless (res_timeout == 123);
105   fail_unless (res_qos_dscp == 11);
106 
107   fail_unless (res_auth_type == CURLSSH_AUTH_PUBLICKEY);
108   fail_unless (strncmp (res_pubkey_file, "public_key_file",
109           strlen ("public_key_file")) == 0);
110   fail_unless (strncmp (res_privkey_file, "private_key_file",
111           strlen ("private_key_file")) == 0);
112   fail_unless (strncmp (res_kh_file, "known_hosts", strlen ("known_hosts"))
113       == 0);
114   fail_unless (strncmp (res_host_pubkey_md5, "00112233445566778899aabbccddeeff",
115           strlen ("00112233445566778899aabbccddeeff")) == 0);
116   fail_unless (strncmp (res_passphrase, "SoMePaSsPhRaSe",
117           strlen ("SoMePaSsPhRaSe")) == 0);
118   fail_unless (res_accept_unkh == TRUE);
119   fail_unless (res_create_dirs == TRUE);
120 
121   g_free (res_location);
122   g_free (res_user);
123   g_free (res_passwd);
124   g_free (res_file_name);
125   g_free (res_pubkey_file);
126   g_free (res_privkey_file);
127   g_free (res_passphrase);
128   g_free (res_kh_file);
129   g_free (res_host_pubkey_md5);
130 
131   /* ------- change properties ------------- */
132 
133   /* props from GstCurlBaseSink */
134   g_object_set (G_OBJECT (sink), "location", "new_location", NULL);
135   g_object_set (G_OBJECT (sink), "user", "new_user", NULL);
136   g_object_set (G_OBJECT (sink), "passwd", "new_passwd", NULL);
137   g_object_set (G_OBJECT (sink), "file-name", "new_filename", NULL);
138   g_object_set (G_OBJECT (sink), "timeout", 321, NULL);
139   g_object_set (G_OBJECT (sink), "qos-dscp", 22, NULL);
140 
141   /* props from GstCurlSshSink */
142   g_object_set (G_OBJECT (sink), "ssh-auth-type", CURLSSH_AUTH_PASSWORD, NULL);
143   g_object_set (G_OBJECT (sink), "ssh-pub-keyfile", "/xxx/pub_key", NULL);
144   g_object_set (G_OBJECT (sink), "ssh-priv-keyfile", "/yyy/pvt_key", NULL);
145   g_object_set (G_OBJECT (sink), "ssh-knownhosts", "/zzz/known_hosts", NULL);
146   g_object_set (G_OBJECT (sink), "ssh-host-pubkey-md5",
147       "ffeeddccbbaa99887766554433221100", NULL);
148   g_object_set (G_OBJECT (sink), "ssh-accept-unknownhost", FALSE, NULL);
149   g_object_set (G_OBJECT (sink), "ssh-key-passphrase", "OtherPASSphrase", NULL);
150 
151   /* props from GstCurlSftpSink */
152   g_object_set (G_OBJECT (sink), "create-dirs", FALSE, NULL);
153 
154 
155   /* run a 'get' on all the above props */
156   g_object_get (sink, "location", &res_location, "user", &res_user,
157       "passwd", &res_passwd, "file-name", &res_file_name,
158       "timeout", &res_timeout, "qos-dscp", &res_qos_dscp,
159       "ssh-auth-type", &res_auth_type, "ssh-pub-keyfile", &res_pubkey_file,
160       "ssh-priv-keyfile", &res_privkey_file, "ssh-knownhosts", &res_kh_file,
161       "ssh-accept-unknownhost", &res_accept_unkh,
162       "ssh-host-pubkey-md5", &res_host_pubkey_md5,
163       "ssh-key-passphrase", &res_passphrase, "create-dirs", &res_create_dirs,
164       NULL);
165 
166   fail_unless (strncmp (res_location, "new_location", strlen ("new_location"))
167       == 0);
168   fail_unless (strncmp (res_user, "new_user", strlen ("new_user")) == 0);
169   fail_unless (strncmp (res_passwd, "new_passwd", strlen ("new_passwd"))
170       == 0);
171   fail_unless (strncmp (res_file_name, "new_filename",
172           strlen ("new_filename")) == 0);
173   fail_unless (res_timeout == 321);
174   fail_unless (res_qos_dscp == 22);
175 
176   fail_unless (res_auth_type == CURLSSH_AUTH_PASSWORD);
177   fail_unless (strncmp (res_pubkey_file, "/xxx/pub_key",
178           strlen ("/xxx/pub_key")) == 0);
179   fail_unless (strncmp (res_privkey_file, "/yyy/pvt_key",
180           strlen ("/yyy/pvt_key")) == 0);
181   fail_unless (strncmp (res_kh_file, "/zzz/known_hosts",
182           strlen ("/zzz/known_host")) == 0);
183   fail_unless (strncmp (res_host_pubkey_md5, "ffeeddccbbaa99887766554433221100",
184           strlen ("ffeeddccbbaa99887766554433221100")) == 0);
185   fail_unless (strncmp (res_passphrase, "OtherPASSphrase",
186           strlen ("OtherPASSphrase")) == 0);
187   fail_unless (res_accept_unkh == FALSE);
188   fail_unless (res_create_dirs == FALSE);
189 
190   g_free (res_location);
191   g_free (res_user);
192   g_free (res_passwd);
193   g_free (res_file_name);
194   g_free (res_pubkey_file);
195   g_free (res_privkey_file);
196   g_free (res_passphrase);
197   g_free (res_kh_file);
198   g_free (res_host_pubkey_md5);
199 
200   cleanup_curlsftpsink (sink);
201 }
202 
203 GST_END_TEST;
204 
205 static Suite *
curlsink_suite(void)206 curlsink_suite (void)
207 {
208   Suite *s = suite_create ("curlsftpsink");
209   TCase *tc_chain = tcase_create ("sftpsink props");
210 
211   suite_add_tcase (s, tc_chain);
212   tcase_set_timeout (tc_chain, 20);
213   tcase_add_test (tc_chain, test_properties);
214 
215   return s;
216 }
217 
218 GST_CHECK_MAIN (curlsink);
219