コード例 #1
0
ファイル: test_cstat.c プロジェクト: rubenk/burp
static void test_cstat_remove_teardown(struct conf ***globalcs,
	struct cstat **clist)
{
	confs_free(globalcs);
	cstat_list_free_sdirs(*clist);
	cstat_list_free(clist);
	clean();
	alloc_check();
}
コード例 #2
0
ファイル: test_cstat.c プロジェクト: rubenk/burp
END_TEST

START_TEST(test_cstat_get_client_names)
{
	struct cstat *clist=NULL;
	const char *cnames[] =
		{"cli1", "cli2", "cli3", NULL};
	const char *cnames_add[] =
		{"cli0", "cli1", "cli2", "cli2a", "cli3", "cli4", NULL};
	const char *cnames_rm[] =
		{"cli2", NULL};
	const char *tmp_files[] =
		{".abc", "xyz~", NULL };

	clean();
	build_clientconfdir_files(cnames);
	fail_unless(!cstat_get_client_names(&clist, CLIENTCONFDIR));
	assert_cstat_list(clist, cnames);

	// Call again with the same clientconfdir files.
	clean();
	build_clientconfdir_files(cnames);
	fail_unless(!cstat_get_client_names(&clist, CLIENTCONFDIR));
	assert_cstat_list(clist, cnames);

	// Call again with extra clientconfdir files.
	clean();
	build_clientconfdir_files(cnames_add);
	fail_unless(!cstat_get_client_names(&clist, CLIENTCONFDIR));
	assert_cstat_list(clist, cnames_add);

	// Call again with fewer clientconfdir files.
	// The list will not be shorter.
	clean();
	build_clientconfdir_files(cnames_rm);
	fail_unless(!cstat_get_client_names(&clist, CLIENTCONFDIR));
	assert_cstat_list(clist, cnames_add);

	// Temporary files should be missed.
	clean();
	build_clientconfdir_files(tmp_files);
	fail_unless(!cstat_get_client_names(&clist, CLIENTCONFDIR));
	assert_cstat_list(clist, cnames_add);

	// Cause an error.
	clean();
	fail_unless(cstat_get_client_names(&clist, CLIENTCONFDIR)==-1);

	cstat_list_free(&clist);
	clean();
	alloc_check();
}
コード例 #3
0
ファイル: test_cstat.c プロジェクト: rubenk/burp
END_TEST

static void do_test_cstat_reload_from_client_confs(enum protocol protocol)
{
	struct cstat *c1;
	struct cstat *c2;
	struct cstat *clist=NULL;
	c1=setup_cstat("cli1", protocol);
	c2=setup_cstat("cli2", protocol);
	cstat_add_to_list(&clist, c1);
	cstat_add_to_list(&clist, c2);
	c1->permitted=1;

	// First time, nothing is reloaded.
	fail_unless(reload_from_clientdir(&clist)==0);
	fail_unless(c1->run_status==RUN_STATUS_IDLE);
	fail_unless(c2->run_status==RUN_STATUS_UNSET);
	fail_unless(c1->bu==NULL);
	fail_unless(c2->bu==NULL);

	// Add some storage dirs, and c1 is loaded.
	build_storage_dirs((struct sdirs *)c1->sdirs,
		sd123, ARR_LEN(sd123));
	fail_unless(reload_from_clientdir(&clist)==1);
	fail_unless(c1->run_status==RUN_STATUS_IDLE);
	fail_unless(c2->run_status==RUN_STATUS_UNSET);
	fail_unless(c1->bu!=NULL);
	fail_unless(c2->bu==NULL);

	// Go again, nothing should be reloaded.
	fail_unless(reload_from_clientdir(&clist)==0);

	// Get a lock.
	lock_get_quick(((struct sdirs *)c1->sdirs)->lock);
	fail_unless(reload_from_clientdir(&clist)==1);

	sdirs_free((struct sdirs **)&c1->sdirs);
	sdirs_free((struct sdirs **)&c2->sdirs);
	cstat_list_free(&clist);
	clean();
	alloc_check();
}
コード例 #4
0
ファイル: test_json_output.c プロジェクト: ZungBang/burp
static void do_test_json_send_clients_with_backup(const char *path,
        struct sd *sd, int s, const char *specific_client)
{
    struct asfd *asfd;
    struct cstat *c=NULL;
    struct cstat *clist=NULL;
    const char *cnames[] = {"cli1", "cli2", "cli3", NULL};
    fail_unless(recursive_delete(CLIENTCONFDIR)==0);
    build_clientconfdir_files(cnames, NULL);
    fail_unless(!cstat_get_client_names(&clist, CLIENTCONFDIR));
    assert_cstat_list(clist, cnames);
    for(c=clist; c; c=c->next)
    {
        c->permitted=1;
        c->protocol=PROTO_1;
        fail_unless((c->sdirs=setup_sdirs(c->protocol, c->name))!=NULL);
        build_storage_dirs((struct sdirs *)c->sdirs, sd, s);
        fail_unless(!cstat_set_backup_list(c));
        fail_unless(c->bu!=NULL);
        // Hack the cntr timestamps so that they are always the same.
        c->cntr->ent[(uint8_t)CMD_TIMESTAMP]->count=200;
        c->cntr->ent[(uint8_t)CMD_TIMESTAMP_END]->count=400;

    }
    asfd=asfd_setup(path);

    c=NULL;
    if(specific_client)
        fail_unless((c=cstat_get_by_name(clist, specific_client))!=NULL);

    fail_unless(!json_send(asfd, clist, c, NULL, NULL, NULL, 0/*cache*/));
    cstat_list_free_sdirs(clist);
    cstat_list_free(&clist);
    fail_unless(!recursive_delete(SDIRS));
    tear_down(&asfd);
}