END_TEST START_TEST (check_credential_address_s) { stringer_t *cred; char *errmsg = NULL; log_unit("%-64.64s", "OBJECTS / USERS / CERDENTIALS / ADDRESS / SINGLE THREADED:"); if (!errmsg && (!(cred = credential_address(CONSTANT("*****@*****.**"))) || st_cmp_ci_eq(cred, CONSTANT("*****@*****.**")))) { errmsg = "Address boiler failed [1]."; //printf("r1 = %lx\n", (unsigned long) cred); if (cred) printf("xxx: [%.*s] [%u]\n", (int)st_length_get(cred), st_char_get(cred), (int)st_length_get(cred)); } st_cleanup(cred); cred = NULL; if (!errmsg && (!(cred = credential_address(CONSTANT(" TEST @ DOMAIN.COM "))) || st_cmp_ci_eq(cred, CONSTANT("*****@*****.**")))) { errmsg = "Address boiler failed [2]."; //printf("r2 = %lx\n", (unsigned long) cred); if (cred) printf("xxx: [%.*s] [%u]\n", (int)st_length_get(cred), st_char_get(cred), (int)st_length_get(cred)); } st_cleanup(cred); cred = NULL; if (!errmsg && (!(cred = credential_address(CONSTANT("*****@*****.**"))) || st_cmp_ci_eq(cred, CONSTANT("*****@*****.**")))) { errmsg = "Address boiler failed [5]."; } st_cleanup(cred); cred = NULL; if (!errmsg && (!(cred = credential_address(CONSTANT("*****@*****.**"))) || st_cmp_ci_eq(cred, CONSTANT("*****@*****.**")))) { errmsg = "Address boiler failed [2]."; //printf("rx2 = %lx\n", (unsigned long) cred); if (cred) printf("xxx: [%.*s] [%u]\n", (int)st_length_get(cred), st_char_get(cred), (int)st_length_get(cred)); } st_cleanup(cred); cred = NULL; if (!errmsg && (!(cred = credential_address(CONSTANT(" TEST @ DOMAIN.COM "))) || st_cmp_ci_eq(cred, CONSTANT("*****@*****.**")))) { errmsg = "Address boiler failed [5]."; } st_cleanup(cred); cred = NULL; if (!errmsg && (!(cred = credential_address(CONSTANT("*****@*****.**"))) || st_cmp_ci_eq(cred, CONSTANT("*****@*****.**")))) { errmsg = "Address boiler failed [11]."; } st_cleanup(cred); cred = NULL; log_unit("%10.10s\n", (!status() ? "SKIPPED" : !errmsg ? "PASSED" : "FAILED")); fail_unless(!errmsg, errmsg); } END_TEST
/** * @brief Check to see if the specified command line option specified an optional parameter, and adjust the index accordingly. * @note This function will automatically generate an error through display_usage() if the parameters are incorrect. * @param xargv a pointer to the main function's argv array. * @param iptr a pointer to the xargv option index to be checked and updated. * @param xargc the number of items in the xargv array. * @return a pointer to the value of the current index's optional parameter if specified, or NULL if one wasn't. */ chr_t * check_next_opt(char *xargv[], int *iptr, int xargc) { chr_t *result; // If this is an optional parameter then there still must be a config file specified after it. if (*iptr == (xargc-1)) { check_display_usage(xargv[0]); } // If the next argument begins with '-' then our option has a null parameter. else if (!mm_cmp_cs_eq(xargv[*iptr+1], "-", 1)) { (*iptr)++; return NULL; } // If the following parameter is the last one, it must be the config file and this is a null option. if (*iptr+1 == (xargc-1)) { (*iptr)++; return NULL; } (*iptr) += 2; if (!(result = ns_dupe(xargv[*iptr-1]))) { log_unit("Memory allocation encountered while preparing checks. Exiting.\n"); } return result; }
END_TEST START_TEST (check_warehouse_domains_s) { char *errmsg = NULL; bool_t outcome = true; log_unit("%-64.64s", "OBJECTS / WAREHOUSE / DOMAINS / SINGLE THREADED:"); if (status() && (domain_wildcard(CONSTANT("lavabit.com")) != 0 || domain_dkim(CONSTANT("lavabit.com")) != 1 || domain_spf(CONSTANT("lavabit.com")) != 1 || domain_wildcard(CONSTANT("mailshack.com")) != 0 || domain_dkim(CONSTANT("mailshack.com")) != 1 || domain_spf(CONSTANT("mailshack.com")) != 1 || domain_wildcard(CONSTANT("nerdshack.com")) != 0 || domain_dkim(CONSTANT("nerdshack.com")) != 1 || domain_spf(CONSTANT("nerdshack.com")) != 1 || domain_wildcard(CONSTANT("squeak-seo.com")) != 1 || domain_dkim(CONSTANT("squeak-seo.com")) != 0 || domain_spf(CONSTANT("squeak-seo.com")) != 1 || domain_wildcard(CONSTANT("texasteenage.org")) != 1 || domain_dkim(CONSTANT("texasteenage.org")) != 0 || domain_spf(CONSTANT("texasteenage.org")) != 0 || domain_wildcard(CONSTANT("ronweb.net")) != 1 || domain_dkim(CONSTANT("ronweb.net")) != 1 || domain_spf(CONSTANT("ronweb.net")) != 1 || domain_wildcard(CONSTANT("slashdot.org")) != -1 || domain_dkim(CONSTANT("slashdot.org")) != -1 || domain_spf(CONSTANT("slashdot.org")) != -1 || domain_wildcard(NULLER("lavabit.com")) != 0 || domain_dkim(NULLER("lavabit.com")) != 1 || domain_spf(NULLER("lavabit.com")) != 1 || domain_wildcard(NULLER("mailshack.com")) != 0 || domain_dkim(NULLER("mailshack.com")) != 1 || domain_spf(NULLER("mailshack.com")) != 1 || domain_wildcard(NULLER("nerdshack.com")) != 0 || domain_dkim(NULLER("nerdshack.com")) != 1 || domain_spf(NULLER("nerdshack.com")) != 1 || domain_wildcard(NULLER("squeak-seo.com")) != 1 || domain_dkim(NULLER("squeak-seo.com")) != 0 || domain_spf(NULLER("squeak-seo.com")) != 1 || domain_wildcard(NULLER("texasteenage.org")) != 1 || domain_dkim(NULLER("texasteenage.org")) != 0 || domain_spf(NULLER("texasteenage.org")) != 0 || domain_wildcard(NULLER("ronweb.net")) != 1 || domain_dkim(NULLER("ronweb.net")) != 1 || domain_spf(NULLER("ronweb.net")) != 1 || domain_wildcard(NULLER("slashdot.org")) != -1 || domain_dkim(NULLER("slashdot.org")) != -1 || domain_spf(NULLER("slashdot.org")) != -1 || domain_wildcard(PLACER("lavabit.com", 11)) != 0 || domain_dkim(PLACER("lavabit.com", 11)) != 1 || domain_spf(PLACER("lavabit.com", 11)) != 1 || domain_wildcard(PLACER("mailshack.com", 13)) != 0 || domain_dkim(PLACER("mailshack.com", 13)) != 1 || domain_spf(PLACER("mailshack.com", 13)) != 1 || domain_wildcard(PLACER("nerdshack.com", 13)) != 0 || domain_dkim(PLACER("nerdshack.com", 13)) != 1 || domain_spf(PLACER("nerdshack.com", 13)) != 1 || domain_wildcard(PLACER("squeak-seo.com", 14)) != 1 || domain_dkim(PLACER("squeak-seo.com", 14)) != 0 || domain_spf(PLACER("squeak-seo.com", 14)) != 1 || domain_wildcard(PLACER("texasteenage.org", 16)) != 1 || domain_dkim(PLACER("texasteenage.org", 16)) != 0 || domain_spf(PLACER("texasteenage.org", 16)) != 0 || domain_wildcard(PLACER("ronweb.net", 10)) != 1 || domain_dkim(PLACER("ronweb.net", 10)) != 1 || domain_spf(PLACER("ronweb.net", 10)) != 1 || domain_wildcard(PLACER("slashdot.org", 12)) != -1 || domain_dkim(PLACER("slashdot.org", 12)) != -1 || domain_spf(PLACER("slashdot.org", 12)) != -1)) { errmsg = "Domain checks failed."; outcome = false; } outcome = errmsg ? false : true; log_unit("%10.10s\n", (outcome ? "PASSED" : status() ? "FAILED" : "SKIPPED")); fail_unless(outcome, errmsg); }
} END_TEST START_TEST (check_credential_auth_creation_s) { credential_t *cred; char *errmsg = NULL; log_unit("%-64.64s", "OBJECTS / USERS / CREDENTIALS / AUTH CREATION / SINGLE THREADED:"); if (!(cred = credential_alloc_auth(CONSTANT("ladar"), CONSTANT("test")))) { errmsg = "Credential creation failed."; } else if (st_cmp_cs_eq(cred->auth.password, CONSTANT("46c3c0f5c777aacbdb0c25b14d6889b98efa62fa0ae551ec067d7aa126392805e3e3a2ce07d36" \ "df7e715e24f35c88105fff5a9eebff0532f990644cf07a4751f"))) { errmsg = "The credential password hash doesn't match the expected value."; } if (cred) { credential_free(cred); cred = NULL; } if (!errmsg && !(cred = credential_alloc_auth(CONSTANT("*****@*****.**"), CONSTANT("test")))) { errmsg = "Credential creation failed."; } else if (!errmsg && st_cmp_cs_eq(cred->auth.password, CONSTANT("46c3c0f5c777aacbdb0c25b14d6889b98efa62fa0ae551ec067d7aa126392805e3e3a2ce07d36" \ "df7e715e24f35c88105fff5a9eebff0532f990644cf07a4751f"))) { errmsg = "The credential password hash doesn't match the expected value."; } if (cred) { credential_free(cred); } log_unit("%10.10s\n", (!status() ? "SKIPPED" : !errmsg ? "PASSED" : "FAILED")); fail_unless(!errmsg, errmsg); } END_TEST
void check_rand_mthread_wrap(void) { stringer_t *result = NULL; if (!thread_start()) { log_unit("Unable to setup the thread context."); pthread_exit(st_dupe(NULLER("Thread startup error."))); return; } result = check_rand_sthread(); thread_stop(); pthread_exit(result); return; }
int main(int argc, char *argv[]) { SRunner *sr; int_t failed = 0; time_t prog_start, test_start, test_end; if (process_kill(PLACER("magmad", 18), SIGTERM, 10) < 0) { log_unit("Another instance of the Magma Daemon is already running and refuses to die."); exit(EXIT_FAILURE); } // Setup prog_start = time(NULL); // Updates the location of the config file if it was specified on the command line. check_args_parse(argc, argv); if (do_virus_check && !virus_check_data_path) { virus_check_data_path = ns_dupe(VIRUS_CHECK_DATA_PATH); } if (do_tank_check && !tank_check_data_path) { tank_check_data_path = ns_dupe(TANK_CHECK_DATA_PATH); } if (do_dspam_check && !dspam_check_data_path) { dspam_check_data_path = ns_dupe(DSPAM_CHECK_DATA_PATH); } /*if (do_virus_check) printf("doing virus check: [%s]\n", !virus_check_data_path ? "NONE" : virus_check_data_path); else printf ("skipping virus check\n"); if (do_tank_check) printf("doing tank check: [%s]\n", !tank_check_data_path ? "NONE" : tank_check_data_path); else printf ("skipping tank check\n"); if (do_dspam_check) printf("doing dspam check: [%s]\n", !dspam_check_data_path ? "NONE" : dspam_check_data_path); else printf ("skipping dspam check\n"); printf("config file: [%s]\n", magma.config.file); exit(EXIT_SUCCESS);*/ if (!process_start()) { log_unit("Initialization error. Exiting.\n"); status_set(-1); process_stop(); exit(EXIT_FAILURE); } // Only during development... cache_flush(); // Unit Test Config sr = srunner_create(suite_check_magma()); // Add the suites. srunner_add_suite(sr, suite_check_core()); srunner_add_suite(sr, suite_check_provide()); srunner_add_suite(sr, suite_check_network()); srunner_add_suite(sr, suite_check_objects()); srunner_add_suite(sr, suite_check_users()); // If were being run under Valgrind, we need to disable forking and increase the default timeout. // Under Valgrind, forked checks appear to improperly timeout. if (RUNNING_ON_VALGRIND == 0 && (failed = running_on_debugger()) == 0) { log_unit("Not being traced or profiled...\n"); srunner_set_fork_status (sr, CK_FORK); case_timeout = RUN_TEST_CASE_TIMEOUT; } else { // Trace detection attempted was thwarted. if (failed == -1) log_unit("Trace detection was thwarted.\n"); else log_unit("Tracing or debugging is active...\n"); srunner_set_fork_status (sr, CK_NOFORK); case_timeout = PROFILE_TEST_CASE_TIMEOUT; } // Execute log_unit("--------------------------------------------------------------------------\n"); test_start = time(NULL); srunner_run_all(sr, CK_SILENT); test_end = time(NULL); // Output timing. log_unit("--------------------------------------------------------------------------\n"); log_unit("%-63.63s %9lus\n", "TEST DURATION:", test_end - test_start); log_unit("%-63.63s %9lus\n", "TOTAL DURATION:", test_end - prog_start); // Summary log_unit("--------------------------------------------------------------------------\n"); failed = srunner_ntests_failed(sr); srunner_print(sr, CK_NORMAL); // The Check Output Ending log_unit("--------------------------------------------------------------------------\n"); // Cleanup and free the resources allocated by the check code. status_set(-1); srunner_free(sr); ns_cleanup(virus_check_data_path); ns_cleanup(tank_check_data_path); ns_cleanup(dspam_check_data_path); // Cleanup and free the resources allocated by the magma code. process_stop(); system_init_umask(); exit((failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE); }
} END_TEST START_TEST (check_credential_mail_creation_s) { credential_t *cred; char *errmsg = NULL; log_unit("%-64.64s", "OBJECTS / USERS / CREDENTIALS / MAIL CREATION / SINGLE THREADED:"); if ((cred = credential_alloc_mail(CONSTANT("ladar")))) { errmsg = "Credential creation should have failed but didn't."; } if (cred) { credential_free(cred); cred = NULL; } if ((cred = credential_alloc_mail(CONSTANT("ladar@")))) { errmsg = "Credential creation should have failed but didn't."; } if (cred) { credential_free(cred); cred = NULL; } if ((cred = credential_alloc_mail(CONSTANT("@lavabit.com")))) { errmsg = "Credential creation should have failed but didn't."; } if (cred) { credential_free(cred); cred = NULL; } if (!errmsg && !(cred = credential_alloc_mail(CONSTANT("*****@*****.**")))) { errmsg = "Credential creation failed."; } else if (!errmsg && (st_cmp_cs_eq(cred->mail.address, CONSTANT("*****@*****.**")) || st_cmp_cs_eq(cred->mail.domain, CONSTANT("lavabit.com")))) { errmsg = "The credential password hash doesn't match the expected value."; } if (cred) { credential_free(cred); } if (!errmsg && !(cred = credential_alloc_mail(CONSTANT("*****@*****.**")))) { errmsg = "Credential creation failed."; } else if (!errmsg && (st_cmp_cs_eq(cred->mail.address, CONSTANT("*****@*****.**")) || st_cmp_cs_eq(cred->mail.domain, CONSTANT("lavabit.com")))) { errmsg = "The credential password hash doesn't match the expected value."; } if (cred) { credential_free(cred); } if (!errmsg && !(cred = credential_alloc_mail(CONSTANT("*****@*****.**")))) { errmsg = "Credential creation failed."; } else if (!errmsg && (st_cmp_cs_eq(cred->mail.address, CONSTANT("*****@*****.**")) || st_cmp_cs_eq(cred->mail.domain, CONSTANT("nerdshack.com")))) { errmsg = "The credential password hash doesn't match the expected value."; } if (cred) { credential_free(cred); } if (!errmsg && !(cred = credential_alloc_mail(CONSTANT("*****@*****.**")))) { errmsg = "Credential creation failed."; } else if (!errmsg && (st_cmp_cs_eq(cred->mail.address, CONSTANT("*****@*****.**")) || st_cmp_cs_eq(cred->mail.domain, CONSTANT("nerdshack.com")))) { errmsg = "The credential password hash doesn't match the expected value."; } if (cred) { credential_free(cred); } if (!errmsg && !(cred = credential_alloc_mail(CONSTANT("*****@*****.**")))) { errmsg = "Credential creation failed."; } else if (!errmsg && (st_cmp_cs_eq(cred->mail.address, CONSTANT("*****@*****.**")) || st_cmp_cs_eq(cred->mail.domain, CONSTANT("mailshack.com")))) { errmsg = "The credential password hash doesn't match the expected value."; } if (cred) { credential_free(cred); } if (!errmsg && !(cred = credential_alloc_mail(CONSTANT("*****@*****.**")))) { errmsg = "Credential creation failed."; } else if (!errmsg && (st_cmp_cs_eq(cred->mail.address, CONSTANT("*****@*****.**")) || st_cmp_cs_eq(cred->mail.domain, CONSTANT("mailshack.com")))) { errmsg = "The credential password hash doesn't match the expected value."; } if (cred) { credential_free(cred); } if (!errmsg && !(cred = credential_alloc_mail(CONSTANT("*****@*****.**")))) { errmsg = "Credential creation failed."; } else if (!errmsg && (st_cmp_cs_eq(cred->mail.address, CONSTANT("*****@*****.**")) || st_cmp_cs_eq(cred->mail.domain, CONSTANT("domain.com")))) { errmsg = "The credential password hash doesn't match the expected value."; } if (cred) { credential_free(cred); } if (!errmsg && !(cred = credential_alloc_mail(CONSTANT("*****@*****.**")))) { errmsg = "Credential creation failed."; } else if (!errmsg && (st_cmp_cs_eq(cred->mail.address, CONSTANT("*****@*****.**")) || st_cmp_cs_eq(cred->mail.domain, CONSTANT("domain.com")))) { errmsg = "The credential password hash doesn't match the expected value."; } if (cred) { credential_free(cred); } log_unit("%10.10s\n", (!status() ? "SKIPPED" : !errmsg ? "PASSED" : "FAILED")); fail_unless(!errmsg, errmsg); } END_TEST
} END_TEST START_TEST (check_credential_username_s) { stringer_t *cred; char *errmsg = NULL; log_unit("%-64.64s", "OBJECTS / USERS / CREDENTIALS / USERNAME / SINGLE THREADED:"); if (!(cred = credential_username(CONSTANT("TEST"))) || st_cmp_ci_eq(cred, CONSTANT("test"))) { errmsg = "Username boiler failed [1]."; //printf("rx1 = %lx\n", (unsigned long) cred); if (cred) printf("xxx: [%.*s] [%u]\n", (int)st_length_get(cred), st_char_get(cred), (int)st_length_get(cred)); } st_cleanup(cred); cred = NULL; if (!errmsg && (!(cred = credential_username(CONSTANT("*****@*****.**"))) || st_cmp_ci_eq(cred, CONSTANT("test_case")))) { errmsg = "Username boiler failed [3]."; } st_cleanup(cred); cred = NULL; if (!errmsg && (!(cred = credential_username(CONSTANT("*****@*****.**"))) || !st_cmp_ci_eq(cred, CONSTANT("test")) || st_cmp_ci_eq(cred, CONSTANT("*****@*****.**")))) { errmsg = "Username boiler failed [4]."; } st_cleanup(cred); cred = NULL; if (!errmsg && (!(cred = credential_username(CONSTANT("*****@*****.**"))) || !st_cmp_ci_eq(cred, CONSTANT("test_case")) || st_cmp_ci_eq(cred, CONSTANT("*****@*****.**")))) { errmsg = "Username boiler failed [6]."; } st_cleanup(cred); cred = NULL; if (!errmsg && (!(cred = credential_username(CONSTANT("*****@*****.**"))) || !st_cmp_ci_eq(cred, CONSTANT("test")) || st_cmp_ci_eq(cred, CONSTANT("*****@*****.**")))) { errmsg = "Username boiler failed [3]."; //printf("rx2 = %lx\n", (unsigned long) cred); if (cred) printf("xxx: [%.*s] [%u]\n", (int)st_length_get(cred), st_char_get(cred), (int)st_length_get(cred)); } st_cleanup(cred); cred = NULL; if (!errmsg && (!(cred = credential_username(CONSTANT(" TEST "))) || st_cmp_ci_eq(cred, CONSTANT("test")))) { errmsg = "Username boiler failed [4]."; } st_cleanup(cred); cred = NULL; if (!errmsg && (!(cred = credential_username(CONSTANT(" TEST @ DOMAIN.COM "))) || !st_cmp_ci_eq(cred, CONSTANT("test")) || st_cmp_ci_eq(cred, CONSTANT("*****@*****.**")))) { errmsg = "Username boiler failed [6]."; } st_cleanup(cred); cred = NULL; if (!errmsg && (!(cred = credential_username(CONSTANT("TEST.CASE"))) || st_cmp_ci_eq(cred, CONSTANT("test_case")))) { errmsg = "Username boiler failed [7]."; } st_cleanup(cred); cred = NULL; if (!errmsg && (!(cred = credential_username(CONSTANT("*****@*****.**"))) || st_cmp_ci_eq(cred, CONSTANT("test_case")) || !st_cmp_ci_eq(cred, CONSTANT("*****@*****.**")))) { errmsg = "Username boiler failed [8]."; } st_cleanup(cred); cred = NULL; if (!errmsg && (!(cred = credential_username(CONSTANT("test+tag"))) || st_cmp_ci_eq(cred, CONSTANT("test")))) { errmsg = "Username boiler failed [9]."; } st_cleanup(cred); cred = NULL; if (!errmsg && (!(cred = credential_username(CONSTANT("*****@*****.**"))) || !st_cmp_ci_eq(cred, CONSTANT("test")) || st_cmp_ci_eq(cred, CONSTANT("*****@*****.**")))) { errmsg = "Username boiler failed [10]."; } st_cleanup(cred); cred = NULL; log_unit("%10.10s\n", (!status() ? "SKIPPED" : !errmsg ? "PASSED" : "FAILED")); fail_unless(!errmsg, errmsg); } END_TEST