diff options
| author | Benjamin Dauvergne <bdauvergne@entrouvert.com> | 2011-12-16 12:18:52 +0100 |
|---|---|---|
| committer | Benjamin Dauvergne <bdauvergne@entrouvert.com> | 2011-12-16 12:18:52 +0100 |
| commit | ff3ae1ea77096ac48a42ad34850e5ad34f93f591 (patch) | |
| tree | 1ec105007798838f3275b6c693e551ff86e52805 /tests | |
| parent | 5e5c38b451cfbefe67e836fb82a1719ce00894f3 (diff) | |
| parent | e2c6b92f3f7dec057700f07836c54f180bf1bada (diff) | |
Merge branch 'rewrite-node-impl'
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/basic_tests.c | 83 | ||||
| -rw-r--r-- | tests/login_tests.c | 5 | ||||
| -rw-r--r-- | tests/login_tests_saml2.c | 12 | ||||
| -rw-r--r-- | tests/non_regression_tests.c | 9 | ||||
| -rw-r--r-- | tests/tests.c | 10 | ||||
| -rw-r--r-- | tests/tests.h | 70 |
6 files changed, 163 insertions, 26 deletions
diff --git a/tests/basic_tests.c b/tests/basic_tests.c index f2d3e51c..a73cc882 100644 --- a/tests/basic_tests.c +++ b/tests/basic_tests.c @@ -51,7 +51,9 @@ END_TEST START_TEST(test02_server_load_dump_random_string) { LassoServer *serverContext; + begin_check_do_log(G_LOG_LEVEL_CRITICAL, "libxml2: Start tag expected, '<' not found\\n", FALSE); serverContext = lasso_server_new_from_dump("foo"); + end_check_do_log(); fail_unless(serverContext == NULL, "serverContext was created from a fake dump"); } @@ -60,7 +62,9 @@ END_TEST START_TEST(test03_server_load_dump_random_xml) { LassoServer *serverContext; + begin_check_do_log(G_LOG_LEVEL_CRITICAL, " Unable to build a LassoNode from a xmlNode", TRUE); serverContext = lasso_server_new_from_dump("<?xml version=\"1.0\"?><foo/>"); + end_check_do_log(); fail_unless(serverContext == NULL, "serverContext was created from fake (but valid XML) dump"); } @@ -156,7 +160,9 @@ START_TEST(test08_test_new_from_xmlNode) "LassoTest", &this_info, 0); r = lasso_registry_default_add_direct_mapping("http://example.com", "Test1", LASSO_LASSO_HREF, "LassoTest"); fail_unless(r == 0, "no mapping for http://example.com:Test1 should exist"); + begin_check_do_log(G_LOG_LEVEL_WARNING, " Class LassoTest has no node_data so no initialization is possible", TRUE); node = lasso_node_new_from_dump("<Test1 xmlns=\"http://example.com\"></Test1>"); + end_check_do_log(); fail_unless(node != NULL, "parsing <Test1/> should return an object"); fail_unless(strcmp(G_OBJECT_TYPE_NAME(node), "LassoTest") == 0, "node classname should be LassoTest"); g_object_unref(node); @@ -1850,21 +1856,21 @@ START_TEST(test10_test_alldumps) #endif /* test deserialization of saml2:EncryptedAssertion" */ const char *encrypted_element_xml[] = { - "<EncryptedAssertion xmlns=\"urn:oasis:names:tc:SAML:2.0:assertion\">\n\ - <EncryptedData/>\ - <EncryptedKey/>\ + "<EncryptedAssertion xmlns=\"urn:oasis:names:tc:SAML:2.0:assertion\" xmlns:xmlenc=\"http://www.w3.org/2001/04/xmlenc#\">\n\ + <xmlenc:EncryptedData/>\ + <xmlenc:EncryptedKey/>\ </EncryptedAssertion>", - "<EncryptedID xmlns=\"urn:oasis:names:tc:SAML:2.0:assertion\">\n\ - <EncryptedData/>\ - <EncryptedKey/>\ + "<EncryptedID xmlns=\"urn:oasis:names:tc:SAML:2.0:assertion\" xmlns:xmlenc=\"http://www.w3.org/2001/04/xmlenc#\">\n\ + <xmlenc:EncryptedData/>\ + <xmlenc:EncryptedKey/>\ </EncryptedID>", - "<EncryptedAttribute xmlns=\"urn:oasis:names:tc:SAML:2.0:assertion\">\n\ - <EncryptedData/>\ - <EncryptedKey/>\ + "<EncryptedAttribute xmlns=\"urn:oasis:names:tc:SAML:2.0:assertion\" xmlns:xmlenc=\"http://www.w3.org/2001/04/xmlenc#\">\n\ + <xmlenc:EncryptedData/>\ + <xmlenc:EncryptedKey/>\ </EncryptedAttribute>", - "<NewEncryptedID xmlns=\"urn:oasis:names:tc:SAML:2.0:protocol\">\n\ - <EncryptedData/>\ - <EncryptedKey/>\ + "<NewEncryptedID xmlns=\"urn:oasis:names:tc:SAML:2.0:protocol\" xmlns:xmlenc=\"http://www.w3.org/2001/04/xmlenc#\">\n\ + <xmlenc:EncryptedData/>\ + <xmlenc:EncryptedKey/>\ </NewEncryptedID>", NULL }; const char **iter = encrypted_element_xml; while (*iter) { @@ -1960,11 +1966,13 @@ START_TEST(test13_test_lasso_server_load_metadata) TESTSDATADIR "/idp5-saml2/private-key.pem", NULL, /* Secret key to unlock private key */ NULL)); + block_lasso_logs; check_good_rc(lasso_server_load_metadata(server, LASSO_PROVIDER_ROLE_IDP, TESTSDATADIR "/metadata/renater-metadata.xml", TESTSDATADIR "/metadata/metadata-federation-renater.crt", &blacklisted_1, &loaded_entity_ids, LASSO_SERVER_LOAD_METADATA_FLAG_DEFAULT)); + unblock_lasso_logs; check_equals(g_hash_table_size(server->providers), 110); check_equals(g_list_length(loaded_entity_ids), 110); @@ -2012,6 +2020,54 @@ START_TEST(test14_lasso_key) } END_TEST +/* test load federation */ +START_TEST(test15_ds_key_info) +{ + LassoDsKeyInfo *ds_key_info = lasso_ds_key_info_new(); + LassoDsKeyValue *ds_key_value = lasso_ds_key_value_new(); + LassoDsX509Data *x509_data = lasso_ds_x509_data_new(); + char *dump; + GList list; + LassoNode *node; + + lasso_ds_x509_data_set_certificate(x509_data, "coucou"); + lasso_ds_key_value_set_x509_data(ds_key_value, x509_data); + ds_key_info->KeyValue = g_object_ref(ds_key_value); + dump = lasso_node_debug((LassoNode*)ds_key_info, 10); + lasso_release_gobject(ds_key_info); + lasso_release_gobject(ds_key_value); + lasso_release_gobject(x509_data); + ds_key_info = (LassoDsKeyInfo*)lasso_node_new_from_dump(dump); + lasso_release_string(dump); + check_not_null(ds_key_info); + check_true(LASSO_IS_DS_KEY_INFO(ds_key_info)); + check_not_null(ds_key_info->KeyValue); + check_true(LASSO_IS_DS_KEY_VALUE(ds_key_info->KeyValue)); + x509_data = lasso_ds_key_value_get_x509_data(ds_key_info->KeyValue); + check_not_null(x509_data); + check_true(LASSO_IS_DS_X509_DATA(x509_data)); + check_str_equals(lasso_ds_x509_data_get_certificate(x509_data), "coucou"); + /* LassoSaml2SubjectConfirmation */ + LassoSaml2SubjectConfirmation *sc = (LassoSaml2SubjectConfirmation*) \ + lasso_saml2_subject_confirmation_new(); + LassoSaml2KeyInfoConfirmationDataType *kicdt = (LassoSaml2KeyInfoConfirmationDataType*) \ + lasso_saml2_key_info_confirmation_data_type_new(); + lasso_assign_string(sc->Method, LASSO_SAML2_CONFIRMATION_METHOD_HOLDER_OF_KEY); + lasso_assign_new_gobject(sc->SubjectConfirmationData, &kicdt->parent); + list = (GList){ .data = ds_key_info, .next = NULL, .prev = NULL }; + lasso_saml2_key_info_confirmation_data_type_set_key_info(kicdt, &list); + dump = lasso_node_debug((LassoNode*)sc, 10); + printf("1 %s\n", dump); + lasso_release_gobject(sc); + lasso_release_gobject(ds_key_info); + node = lasso_node_new_from_dump(dump); + lasso_release_string(dump); + dump = lasso_node_debug(node, 10); + printf("2 %s\n", dump); + lasso_release_string(dump); +} +END_TEST + Suite* basic_suite() { @@ -2028,6 +2084,7 @@ basic_suite() TCase *tc_custom_namespace = tcase_create("Test custom namespace handling"); TCase *tc_load_metadata = tcase_create("Test loading a federation metadata file"); TCase *tc_key = tcase_create("Test loading and manipulating LassoKey objects"); + TCase *tc_key_info = tcase_create("Test creating and dumping ds:KeyInfo nodes"); suite_add_tcase(s, tc_server_load_dump_empty_string); suite_add_tcase(s, tc_server_load_dump_random_string); @@ -2041,6 +2098,7 @@ basic_suite() suite_add_tcase(s, tc_custom_namespace); suite_add_tcase(s, tc_load_metadata); suite_add_tcase(s, tc_key); + suite_add_tcase(s, tc_key_info); tcase_add_test(tc_server_load_dump_empty_string, test01_server_load_dump_empty_string); tcase_add_test(tc_server_load_dump_random_string, test02_server_load_dump_random_string); @@ -2056,6 +2114,7 @@ basic_suite() tcase_add_test(tc_custom_namespace, test12_custom_namespace); tcase_add_test(tc_load_metadata, test13_test_lasso_server_load_metadata); tcase_add_test(tc_key, test14_lasso_key); + tcase_add_test(tc_key_info, test15_ds_key_info); tcase_set_timeout(tc_load_metadata, 10); return s; } diff --git a/tests/login_tests.c b/tests/login_tests.c index 850aa4a4..90573afc 100644 --- a/tests/login_tests.c +++ b/tests/login_tests.c @@ -285,7 +285,10 @@ START_TEST(test02_serviceProviderLogin) fail_unless(found != NULL, "We must find an InResponseTo attribute"); found[sizeof("InResponseTo=\"")] = '?'; lasso_set_flag("no-verify-signature"); + begin_check_do_log(G_LOG_LEVEL_DEBUG, " If inResponseTo attribute is present, a matching " + "request must be present too in the LassoLogin object", TRUE); check_not_equals(lasso_login_process_response_msg(spLoginContext, soapResponseMsg), 0); + end_check_do_log(); lasso_set_flag("verify-signature"); check_good_rc(lasso_login_accept_sso(spLoginContext)); fail_unless(rc == 0, "lasso_login_accept_sso must fail"); @@ -517,7 +520,7 @@ END_TEST Suite* login_suite() { - Suite *s = suite_create("Login"); + Suite *s = suite_create("Login using ID-FF 1.2"); TCase *tc_generate = tcase_create("Generate Server Contexts"); TCase *tc_spLogin = tcase_create("Login initiated by service provider"); TCase *tc_spLoginMemory = tcase_create("Login initiated by service provider without key loading"); diff --git a/tests/login_tests_saml2.c b/tests/login_tests_saml2.c index 5576ee1c..1052c61a 100644 --- a/tests/login_tests_saml2.c +++ b/tests/login_tests_saml2.c @@ -785,8 +785,10 @@ START_TEST(test05_sso_idp_with_key_rollover) check_good_rc(lasso_login_accept_sso(spLoginContext)); /* Process response 2 */ + block_lasso_logs; check_good_rc(lasso_login_process_authn_response_msg(spLoginContext, idpLoginContext2->parent.msg_body)); + unblock_lasso_logs; check_good_rc(lasso_login_accept_sso(spLoginContext)); /* Cleanup */ @@ -838,7 +840,9 @@ sso_sp_with_key_rollover(LassoServer *idp_context, LassoServer *sp_context) LASSO_SAML2_NAME_IDENTIFIER_FORMAT_PERSISTENT); LASSO_SAMLP2_AUTHN_REQUEST(idp_login_context->parent.request)->NameIDPolicy->AllowCreate = 1; + block_lasso_logs; check_good_rc(lasso_login_process_authn_request_msg(idp_login_context, NULL)); + unblock_lasso_logs; check_good_rc(lasso_login_validate_request_msg(idp_login_context, 1, /* authentication_result */ 0 /* is_consent_obtained */ @@ -855,8 +859,10 @@ sso_sp_with_key_rollover(LassoServer *idp_context, LassoServer *sp_context) check_not_null(idp_login_context->parent.msg_url); /* Process response */ + block_lasso_logs; check_good_rc(lasso_login_process_authn_response_msg(sp_login_context, idp_login_context->parent.msg_body)); + unblock_lasso_logs; check_good_rc(lasso_login_accept_sso(sp_login_context)); /* Cleanup */ @@ -940,7 +946,6 @@ sso_initiated_by_sp(LassoServer *idp_context, LassoServer *sp_context) LASSO_SAMLP2_AUTHN_REQUEST(sp_login_context->parent.request)->NameIDPolicy->AllowCreate = 1; check_good_rc(lasso_login_build_authn_request_msg(sp_login_context)); check_not_null(sp_login_context->parent.msg_url); - printf("authn_request: %s", sp_login_context->parent.msg_url); authn_request_query = strchr(sp_login_context->parent.msg_url, '?'); check_not_null(authn_request_query); authn_request_query += 1; @@ -960,7 +965,6 @@ sso_initiated_by_sp(LassoServer *idp_context, LassoServer *sp_context) check_good_rc(lasso_login_build_authn_response_msg(idp_login_context)); check_not_null(idp_login_context->parent.msg_body); check_not_null(idp_login_context->parent.msg_url); - printf("Xml Response: %s\n", lasso_node_export_to_xml(idp_login_context->parent.response)); /* Process response */ check_good_rc(lasso_login_process_authn_response_msg(sp_login_context, @@ -988,7 +992,9 @@ START_TEST(test07_sso_sp_with_hmac_sha1_signatures) test07_make_context(idp_context, "idp6-saml2", LASSO_PROVIDER_ROLE_SP, "sp6-saml2", key) test07_make_context(sp_context, "sp6-saml2", LASSO_PROVIDER_ROLE_IDP, "idp6-saml2", key) + block_lasso_logs; sso_initiated_by_sp(idp_context, sp_context); + unblock_lasso_logs; /* Cleanup */ lasso_release_gobject(idp_context); @@ -1000,7 +1006,7 @@ END_TEST Suite* login_saml2_suite() { - Suite *s = suite_create("Login"); + Suite *s = suite_create("Login using SAML 2.0"); TCase *tc_generate = tcase_create("Generate Server Contexts"); TCase *tc_spLogin = tcase_create("Login initiated by service provider"); TCase *tc_spLoginMemory = tcase_create("Login initiated by service provider without key loading"); diff --git a/tests/non_regression_tests.c b/tests/non_regression_tests.c index 03c11a35..64886e94 100644 --- a/tests/non_regression_tests.c +++ b/tests/non_regression_tests.c @@ -165,26 +165,17 @@ START_TEST(indexed_endpoints_20101008) } END_TEST -void error_log_func(G_GNUC_UNUSED const gchar *log_domain, G_GNUC_UNUSED GLogLevelFlags log_level, - const gchar *message, G_GNUC_UNUSED gpointer user_data) -{ - fail_unless(FALSE, "error_func called... %s", message); -} - START_TEST(remove_warning_when_parssing_unknown_SNIPPET_LIST_NODES_20111007) { LassoNode *node; xmlDoc *xmldoc; const char content[] = "<saml:Attribute Name=\"urn:oid:1.3.6.1.4.1.5923.1.1.1.10\" NameFormat=\"urn:oasis:names:tc:SAML:2.0:attrname-format:uri\" FriendlyName=\"eduPersonTargetedID\" xmlns:saml=\"urn:oasis:names:tc:SAML:2.0:assertion\"><saml:AttributeValue><NameID Format=\"urn:oasis:names:tc:SAML:2.0:nameid-format:persistent\" NameQualifier=\"https://services-federation.renater.fr/test/idp\" SPNameQualifier=\"https://univnautes.entrouvert.lan/authsaml2/metadata\">C8NQsm1Y3Gas9m0AMDhxU7UxCSI=</NameID></saml:AttributeValue></saml:Attribute>"; - guint log_handler; xmldoc = xmlReadMemory(content, sizeof(content)-1, NULL, NULL, 0); check_not_null(xmldoc); - log_handler = g_log_set_handler("Lasso", G_LOG_LEVEL_MASK, error_log_func, NULL); node = lasso_node_new_from_xmlNode(xmlDocGetRootElement(xmldoc)); check_not_null(node); check_true(LASSO_IS_SAML2_ATTRIBUTE(node)); - g_log_remove_handler("Lasso", log_handler); check_true(LASSO_IS_NODE(node)); xmlFreeDoc(xmldoc); lasso_release_gobject(node); diff --git a/tests/tests.c b/tests/tests.c index a32d32e9..8ec4a40f 100644 --- a/tests/tests.c +++ b/tests/tests.c @@ -26,8 +26,9 @@ #include <config.h> #include <check.h> +#include <glib.h> #include "../lasso/lasso.h" -#include "lasso_config.h" +#include "../lasso/lasso_config.h" extern Suite* basic_suite(); extern Suite* login_suite(); @@ -55,6 +56,12 @@ SuiteFunction suites[] = { #endif NULL }; +void error_logger(const gchar *log_domain, GLogLevelFlags log_level, + const gchar *message, G_GNUC_UNUSED gpointer user_data) +{ + fail("No logging output expected: message «%s» was emitted for domain «%s» at the level" + " «%d»", message, log_domain, log_level); +} int main(int argc, char *argv[]) @@ -71,6 +78,7 @@ main(int argc, char *argv[]) } lasso_init(); + g_log_set_default_handler(error_logger, NULL); sr = srunner_create(suites[0]()); diff --git a/tests/tests.h b/tests/tests.h index ce89ac98..62f01719 100644 --- a/tests/tests.h +++ b/tests/tests.h @@ -23,6 +23,8 @@ #ifndef __TESTS_H__ #define __TESTS_H__ +#include "../lasso/lasso_config.h" + #define check_not_null(what) \ fail_unless((what) != NULL, "%s:%i: " #what " returned NULL", __func__, __LINE__); @@ -72,4 +74,72 @@ fail_unless(g_strcmp0(__tmp, to) != 0, "%s:%i: " #what " is equal to %s", __func__, __LINE__, to); \ } +static inline void mute_logger(G_GNUC_UNUSED const gchar *domain, + G_GNUC_UNUSED GLogLevelFlags log_level, G_GNUC_UNUSED const gchar *message, + G_GNUC_UNUSED gpointer user_data) { +} +G_GNUC_UNUSED static guint mute_log_handler = 0; + +#define block_lasso_logs mute_log_handler = g_log_set_handler(LASSO_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, \ + mute_logger, NULL) + +#define unblock_lasso_logs g_log_remove_handler(LASSO_LOG_DOMAIN, mute_log_handler) + +struct CheckingLogHandlerUserData { + GLogLevelFlags log_level; + const char *message; + gboolean endswith; + GLogLevelFlags log_level_found; + const char *message_found; +}; +G_GNUC_UNUSED static guint checking_log_handler = 0; +G_GNUC_UNUSED static guint checking_log_handler_flag = 0; +G_GNUC_UNUSED static struct CheckingLogHandlerUserData checking_logger_user_data; + +static inline gboolean check_message(const char *a, const char *b, gboolean endswith) { + if (endswith) { + return strlen(a) >= strlen(b) && + strcmp(a+(strlen(a)-strlen(b)), b) == 0; + } else { + return strcmp(a, b) == 0; + } +} + +static inline void checking_logger(G_GNUC_UNUSED const gchar *domain, + G_GNUC_UNUSED GLogLevelFlags log_level, G_GNUC_UNUSED const gchar *message, + G_GNUC_UNUSED gpointer user_data) { + struct CheckingLogHandlerUserData *ck_user_data = user_data; + if (log_level == ck_user_data->log_level && check_message(message, ck_user_data->message, + ck_user_data->endswith)) { + } else { + g_log_default_handler(domain, log_level, message, user_data); + checking_log_handler_flag = 0; + } + ck_user_data->log_level_found = log_level; + ck_user_data->message_found = g_strdup(message); +} +/* begin_check_do_log(level, message, endswith)/end_check_do_log() with check that the only + * message emitted between the two macros is one equals to message at the level level, + * or ending with message if endswith is True. + */ +static inline void begin_check_do_log(GLogLevelFlags level, const char *message, gboolean endswith) { + memset(&checking_logger_user_data, 0, sizeof(struct CheckingLogHandlerUserData)); + checking_logger_user_data.log_level = level; + checking_logger_user_data.message = message; + checking_logger_user_data.endswith = endswith; + checking_log_handler = g_log_set_handler(LASSO_LOG_DOMAIN, level, checking_logger, &checking_logger_user_data); + checking_log_handler_flag = 1; +} + +static inline void end_check_do_log() { + g_log_remove_handler(LASSO_LOG_DOMAIN, checking_log_handler); + checking_log_handler = 0; + fail_unless(checking_log_handler_flag, "Logging failure: expected log level %d and message «%s», got %d and «%s»", + checking_logger_user_data.log_level, + checking_logger_user_data.message, + checking_logger_user_data.log_level_found, + checking_logger_user_data.message_found); + checking_log_handler_flag = 0; +} + #endif /*__TESTS_H__ */ |
