~ubuntu-branches/ubuntu/utopic/glib-networking/utopic

« back to all changes in this revision

Viewing changes to tls/tests/certificate.c

  • Committer: Package Import Robot
  • Author(s): Sjoerd Simons
  • Date: 2014-09-20 10:18:53 UTC
  • mfrom: (1.4.16) (14.1.9 sid)
  • Revision ID: package-import@ubuntu.com-20140920101853-8v2ef9heulbirrzs
Tags: 2.41.92-2
Target unstable

Show diffs side-by-side

added added

removed removed

Lines of Context:
220
220
  g_assert (issuer == NULL);
221
221
}
222
222
 
 
223
static void
 
224
test_create_list (void)
 
225
{
 
226
  GList *list;
 
227
  GError *error = NULL;
 
228
 
 
229
  list = g_tls_certificate_list_new_from_file (tls_test_file_path ("ca-roots.pem"), &error);
 
230
  g_assert_no_error (error);
 
231
  g_assert_cmpint (g_list_length (list), ==, 8);
 
232
 
 
233
  g_list_free_full (list, g_object_unref);
 
234
}
 
235
 
 
236
static void
 
237
test_create_list_bad (void)
 
238
{
 
239
  GList *list;
 
240
  GError *error = NULL;
 
241
 
 
242
  list = g_tls_certificate_list_new_from_file (tls_test_file_path ("ca-roots-bad.pem"), &error);
 
243
  g_assert_error (error, G_TLS_ERROR, G_TLS_ERROR_BAD_CERTIFICATE);
 
244
  g_assert_null (list);
 
245
}
 
246
 
223
247
/* -----------------------------------------------------------------------------
224
248
 * CERTIFICATE VERIFY
225
249
 */
283
307
test_verify_certificate_good (TestVerify      *test,
284
308
                              gconstpointer    data)
285
309
{
 
310
  GSocketConnectable *identity;
 
311
  GSocketAddress *addr;
286
312
  GTlsCertificateFlags errors;
287
313
 
288
314
  errors = g_tls_certificate_verify (test->cert, test->identity, test->anchor);
290
316
 
291
317
  errors = g_tls_certificate_verify (test->cert, NULL, test->anchor);
292
318
  g_assert_cmpuint (errors, ==, 0);
 
319
 
 
320
  identity = g_network_address_new ("192.168.1.10", 80);
 
321
  errors = g_tls_certificate_verify (test->cert, identity, test->anchor);
 
322
  g_assert_cmpuint (errors, ==, 0);
 
323
  g_object_unref (identity);
 
324
 
 
325
  addr = g_inet_socket_address_new_from_string ("192.168.1.10", 80);
 
326
  errors = g_tls_certificate_verify (test->cert, G_SOCKET_CONNECTABLE (addr), test->anchor);
 
327
  g_assert_cmpuint (errors, ==, 0);
 
328
  g_object_unref (addr);
293
329
}
294
330
 
295
331
static void
298
334
{
299
335
  GSocketConnectable *identity;
300
336
  GTlsCertificateFlags errors;
 
337
  GSocketAddress *addr;
301
338
 
302
339
  identity = g_network_address_new ("other.example.com", 80);
303
 
 
304
 
  errors = g_tls_certificate_verify (test->cert, identity, test->anchor);
305
 
  g_assert_cmpuint (errors, ==, G_TLS_CERTIFICATE_BAD_IDENTITY);
306
 
 
307
 
  g_object_unref (identity);
 
340
  errors = g_tls_certificate_verify (test->cert, identity, test->anchor);
 
341
  g_assert_cmpuint (errors, ==, G_TLS_CERTIFICATE_BAD_IDENTITY);
 
342
  g_object_unref (identity);
 
343
 
 
344
  identity = g_network_address_new ("127.0.0.1", 80);
 
345
  errors = g_tls_certificate_verify (test->cert, identity, test->anchor);
 
346
  g_assert_cmpuint (errors, ==, G_TLS_CERTIFICATE_BAD_IDENTITY);
 
347
  g_object_unref (identity);
 
348
 
 
349
  addr = g_inet_socket_address_new_from_string ("127.0.0.1", 80);
 
350
  errors = g_tls_certificate_verify (test->cert, G_SOCKET_CONNECTABLE (addr), test->anchor);
 
351
  g_assert_cmpuint (errors, ==, G_TLS_CERTIFICATE_BAD_IDENTITY);
 
352
  g_object_unref (addr);
308
353
}
309
354
 
310
355
static void
449
494
              setup_certificate, test_create_with_key_der, teardown_certificate);
450
495
  g_test_add ("/tls/certificate/create-with-issuer", TestCertificate, NULL,
451
496
              setup_certificate, test_create_certificate_with_issuer, teardown_certificate);
 
497
  g_test_add_func ("/tls/certificate/create-list", test_create_list);
 
498
  g_test_add_func ("/tls/certificate/create-list-bad", test_create_list_bad);
452
499
 
453
500
  g_test_add ("/tls/certificate/verify-good", TestVerify, NULL,
454
501
              setup_verify, test_verify_certificate_good, teardown_verify);