8 #include <tr_name_internal.h>
10 /**********************************************************************/
13 const char *id; /* only allows a single entry for now */
16 static TR_APC *apc_entry_to_apc(TALLOC_CTX *mem_ctx, struct apc_entry *ae)
18 TALLOC_CTX *tmp_ctx=talloc_new(NULL);
21 apcs=tr_apc_new(tmp_ctx);
23 tr_apc_set_id(apcs, tr_new_name(ae->id));
24 talloc_steal(mem_ctx, apcs);
31 /**********************************************************************/
32 /* TR_COMM test stuff */
37 struct apc_entry *apcs;
40 static TR_COMM *comm_entry_to_comm(TALLOC_CTX *mem_ctx, struct comm_entry *ce)
42 TALLOC_CTX *tmp_ctx=talloc_new(NULL);
43 TR_COMM *comm=tr_comm_new(tmp_ctx);
46 tr_comm_set_id(comm, tr_new_name(ce->id));
47 tr_comm_set_type(comm, ce->type);
49 tr_comm_set_apcs(comm, apc_entry_to_apc(tmp_ctx, ce->apcs));
51 if ((tr_comm_get_id(comm)==NULL) ||
52 ((ce->apcs!=NULL)&&(tr_comm_get_apcs(comm)==NULL)))
53 comm=NULL; /* it's in tmp_ctx, so will be freed */
55 talloc_steal(mem_ctx, comm);
62 static int add_comm_set(TR_COMM_TABLE *ctab, struct comm_entry *entries)
64 TALLOC_CTX *tmp_ctx=talloc_new(NULL);
65 struct comm_entry *this=NULL;
70 for (this=entries,ii=0; this->id!=NULL; this++, ii++) {
71 new=comm_entry_to_comm(tmp_ctx, this);
73 printf("Error creating community %u.\n", (unsigned int)ii+1);
77 tr_comm_table_add_comm(ctab, new);
87 static int verify_comm_set(TR_COMM_TABLE *ctab, struct comm_entry *entries)
89 struct comm_entry *this=NULL;
91 TR_NAME *this_id=NULL;
93 for (this=entries; this->id!=NULL; this++) {
94 this_id=tr_new_name(this->id);
95 comm=tr_comm_table_find_comm(ctab, this_id);
96 tr_free_name(this_id); this_id=NULL;
99 printf("Error, community %s missing from community table.\n", this->id);
102 if (tr_comm_get_type(comm)!=this->type) {
103 printf("Error, community %s has wrong type (was %s, expected %s).\n",
105 tr_comm_type_to_str(tr_comm_get_type(comm)),
106 tr_comm_type_to_str(this->type));
109 /* TODO: verify apcs */
114 /* removes entry n from ctab */
115 static int remove_comm_set_member(TR_COMM_TABLE *ctab, struct comm_entry *entries, size_t n)
117 TR_NAME *comm_name=tr_new_name(entries[n].id);
118 TR_COMM *comm=tr_comm_table_find_comm(ctab, comm_name);
122 printf("Can't remove community %s, not in table.\n", entries[n].id);
123 tr_free_name(comm_name);
127 tr_comm_table_remove_comm(ctab, comm);
128 comm2=tr_comm_table_find_comm(ctab, comm_name);
130 printf("Community %s still in table after removal.\n", entries[n].id);
132 tr_free_name(comm_name);
137 tr_free_name(comm_name);
141 /**********************************************************************/
142 /* TR_RP_REALM test stuff */
144 struct rp_realm_entry {
148 static TR_RP_REALM *rp_realm_entry_to_rp_realm(TALLOC_CTX *mem_ctx, struct rp_realm_entry *re)
150 TALLOC_CTX *tmp_ctx=talloc_new(NULL);
151 TR_RP_REALM *realm=NULL;
153 realm=tr_rp_realm_new(tmp_ctx);
155 tr_rp_realm_set_id(realm, tr_new_name(re->id));
156 talloc_steal(mem_ctx, realm);
159 talloc_free(tmp_ctx);
163 static int add_rp_realm_set(TR_COMM_TABLE *ctab, struct rp_realm_entry *entries)
165 TALLOC_CTX *tmp_ctx=talloc_new(NULL);
166 struct rp_realm_entry *this=NULL;
167 TR_RP_REALM *realm=NULL;
170 for (this=entries; this->id!=NULL; this++) {
171 realm=rp_realm_entry_to_rp_realm(tmp_ctx, this);
173 printf("Error creating RP realm %s.\n", this->id);
177 tr_comm_table_add_rp_realm(ctab, realm);
182 talloc_free(tmp_ctx);
186 static int verify_rp_realm_set(TR_COMM_TABLE *ctab, struct rp_realm_entry *entries)
188 struct rp_realm_entry *this=NULL;
189 TR_RP_REALM *rp_realm=NULL;
190 TR_NAME *this_id=NULL;
192 for (this=entries; this->id!=NULL; this++) {
193 this_id=tr_new_name(this->id);
194 rp_realm=tr_comm_table_find_rp_realm(ctab, this_id);
195 tr_free_name(this_id); this_id=NULL;
197 if (rp_realm==NULL) {
198 printf("Error, RP realm %s missing from community table.\n", this->id);
205 /* removes entry n from ctab */
206 static int remove_rp_realm_set_member(TR_COMM_TABLE *ctab, struct rp_realm_entry *entries, size_t n)
208 TR_NAME *rp_realm_name=tr_new_name(entries[n].id);
209 TR_RP_REALM *rp_realm=tr_comm_table_find_rp_realm(ctab, rp_realm_name);
210 TR_RP_REALM *rp_realm2=NULL;
212 if (rp_realm==NULL) {
213 printf("Can't remove RP realm %s, not in table.\n", entries[n].id);
214 tr_free_name(rp_realm_name);
218 tr_comm_table_remove_rp_realm(ctab, rp_realm);
219 rp_realm2=tr_comm_table_find_rp_realm(ctab, rp_realm_name);
220 if (rp_realm2!=NULL) {
221 printf("RP realm %s still in table after removal.\n", entries[n].id);
222 tr_rp_realm_free(rp_realm);
223 tr_free_name(rp_realm_name);
227 tr_rp_realm_free(rp_realm);
228 tr_free_name(rp_realm_name);
232 /**********************************************************************/
233 /* TR_AAA_SERVER test stuff */
236 const char *hostname; /* only supports one for testing right now */
239 static TR_AAA_SERVER *aaa_entry_to_aaa_server(TALLOC_CTX *mem_ctx, struct aaa_entry *ae)
241 TALLOC_CTX *tmp_ctx=talloc_new(NULL);
242 TR_AAA_SERVER *aaa=tr_aaa_server_from_string(tmp_ctx, ae->hostname);
245 talloc_steal(mem_ctx, aaa);
247 talloc_free(tmp_ctx);
252 /**********************************************************************/
253 /* TR_IDP_REALM test stuff */
255 struct idp_realm_entry {
257 struct aaa_entry *aaa_servers;
258 struct apc_entry *apcs;
261 static TR_IDP_REALM *idp_realm_entry_to_idp_realm(TALLOC_CTX *mem_ctx, struct idp_realm_entry *re)
263 TALLOC_CTX *tmp_ctx=talloc_new(NULL);
264 TR_IDP_REALM *realm=NULL;
266 realm=tr_idp_realm_new(tmp_ctx);
268 tr_idp_realm_set_id(realm, tr_new_name(re->id));
269 realm->aaa_servers=aaa_entry_to_aaa_server(realm, re->aaa_servers);
270 if (realm->aaa_servers==NULL)
271 realm=NULL; /* still in tmp_ctx so will be freed */
273 tr_idp_realm_set_apcs(realm, apc_entry_to_apc(tmp_ctx, re->apcs));
274 if (tr_idp_realm_get_apcs(realm)==NULL)
280 talloc_steal(mem_ctx, realm);
282 talloc_free(tmp_ctx);
286 static int add_idp_realm_set(TR_COMM_TABLE *ctab, struct idp_realm_entry *entries)
288 TALLOC_CTX *tmp_ctx=talloc_new(NULL);
289 struct idp_realm_entry *this=NULL;
290 TR_IDP_REALM *realm=NULL;
293 for (this=entries; this->id!=NULL; this++) {
294 realm=idp_realm_entry_to_idp_realm(tmp_ctx, this);
296 printf("Error creating IDP realm %s.\n", this->id);
300 tr_comm_table_add_idp_realm(ctab, realm);
305 talloc_free(tmp_ctx);
309 static int verify_idp_realm_set(TR_COMM_TABLE *ctab, struct idp_realm_entry *entries)
311 struct idp_realm_entry *this=NULL;
312 TR_IDP_REALM *idp_realm=NULL;
313 TR_NAME *this_id=NULL;
315 for (this=entries; this->id!=NULL; this++) {
316 this_id=tr_new_name(this->id);
317 idp_realm=tr_comm_table_find_idp_realm(ctab, this_id);
318 tr_free_name(this_id); this_id=NULL;
320 if (idp_realm==NULL) {
321 printf("Error, IDP realm %s missing from community table.\n", this->id);
328 /* removes entry n from ctab */
329 static int remove_idp_realm_set_member(TR_COMM_TABLE *ctab, struct idp_realm_entry *entries, size_t n)
331 TR_NAME *idp_realm_name=tr_new_name(entries[n].id);
332 TR_IDP_REALM *idp_realm=tr_comm_table_find_idp_realm(ctab, idp_realm_name);
333 TR_IDP_REALM *idp_realm2=NULL;
335 if (idp_realm==NULL) {
336 printf("Can't remove IDP realm %s, not in table.\n", entries[n].id);
337 tr_free_name(idp_realm_name);
341 tr_comm_table_remove_idp_realm(ctab, idp_realm);
342 idp_realm2=tr_comm_table_find_idp_realm(ctab, idp_realm_name);
343 if (idp_realm2!=NULL) {
344 printf("IDP realm %s still in table after removal.\n", entries[n].id);
345 tr_idp_realm_free(idp_realm);
346 tr_free_name(idp_realm_name);
350 tr_idp_realm_free(idp_realm);
351 tr_free_name(idp_realm_name);
355 /**********************************************************************/
356 /* Community Membership test stuff */
358 struct comm_memb_entry {
360 const char *realm_name;
361 const char *comm_name;
363 /* TODO: test provenance */
366 /* add an existing realm to an existing community (these must
367 * exist in the community table lists) */
368 static int add_comm_membership(TR_COMM_TABLE *ctab, struct comm_memb_entry *entry)
370 TR_NAME *comm_name=tr_new_name(entry->comm_name);
371 TR_NAME *realm_name=tr_new_name(entry->realm_name);
372 TR_COMM *comm=tr_comm_table_find_comm(ctab, comm_name);
373 TR_RP_REALM *rp_realm=(entry->role==TR_ROLE_RP)?(tr_comm_table_find_rp_realm(ctab, realm_name)):(NULL);
374 TR_IDP_REALM *idp_realm=(entry->role==TR_ROLE_IDP)?(tr_comm_table_find_idp_realm(ctab, realm_name)):(NULL);
377 if ((comm==NULL) || ((rp_realm==NULL)&&(idp_realm==NULL)))
381 if (entry->origin!=NULL)
382 json_array_append(prov, json_string(entry->origin));
384 switch (entry->role) {
386 tr_comm_add_idp_realm(ctab, comm, idp_realm, 0, prov, NULL); /* Expiry!? */
389 tr_comm_add_rp_realm(ctab, comm, rp_realm, 0, prov, NULL); /* Expiry!? */
398 static int add_member_set(TR_COMM_TABLE *ctab, struct comm_memb_entry *entries)
400 struct comm_memb_entry *this=NULL;
402 for (this=entries; this->role!=TR_ROLE_UNKNOWN; this++) {
403 if (0!=add_comm_membership(ctab, this)) {
404 printf("Error adding %s realm %s to community %s (origin %s).\n",
405 (this->role==TR_ROLE_RP)?"RP":"IDP",
408 (this->origin!=NULL)?(this->origin):"null");
415 static int remove_membership(TR_COMM_TABLE *ctab, struct comm_memb_entry *entries, size_t n)
417 TR_NAME *realm_name=tr_new_name(entries[n].realm_name);
418 TR_NAME *comm_name=tr_new_name(entries[n].comm_name);
419 TR_NAME *origin=(entries[n].origin!=NULL)?(tr_new_name(entries[n].origin)):NULL;
420 TR_COMM_MEMB *memb=NULL;
423 switch (entries[n].role) {
425 memb=tr_comm_table_find_idp_memb_origin(ctab, realm_name, comm_name, origin);
428 memb=tr_comm_table_find_rp_memb_origin(ctab, realm_name, comm_name, origin);
436 printf("%s realm %s not in comm %s from origin %s, can't remove membership.\n",
437 (entries[n].role==TR_ROLE_RP)?"RP":"IDP",
438 entries[n].realm_name,
439 entries[n].comm_name,
440 (entries[n].origin!=NULL)?(entries[n].origin):"null");
444 tr_comm_table_remove_memb(ctab, memb);
445 tr_comm_memb_free(memb);
449 tr_free_name(realm_name);
450 tr_free_name(comm_name);
452 tr_free_name(origin);
456 /**********************************************************************/
459 struct apc_entry apc_1={ "apc" };
461 struct comm_entry comm_set_1[]={
462 { "apc", TR_COMM_APC, NULL },
463 { "comm 1", TR_COMM_COI, &apc_1 },
464 { "comm 2", TR_COMM_COI, &apc_1 },
468 struct rp_realm_entry rp_realm_set_1[]={
475 struct aaa_entry aaa_1= { "aaa 1" };
476 struct aaa_entry aaa_2= { "aaa 2" };
477 struct aaa_entry aaa_3= { "aaa 3" };
479 struct idp_realm_entry idp_realm_set_1[]={
480 { "idp 1", &aaa_1, &apc_1 },
481 { "idp 2", &aaa_2, &apc_1 },
482 { "idp 3", &aaa_3, &apc_1 },
486 struct comm_memb_entry member_set_1[]={
487 { TR_ROLE_RP, "rp 1", "apc", NULL },
488 { TR_ROLE_RP, "rp 2", "apc", NULL },
489 { TR_ROLE_RP, "rp 3", "apc", NULL },
490 { TR_ROLE_IDP, "idp 1", "apc", NULL },
491 { TR_ROLE_IDP, "idp 2", "apc", NULL },
492 { TR_ROLE_IDP, "idp 3", "apc", NULL },
493 { TR_ROLE_RP, "rp 1", "comm 1", NULL },
494 { TR_ROLE_RP, "rp 2", "comm 1", NULL },
495 { TR_ROLE_RP, "rp 2", "comm 1", "peer 1" },
496 { TR_ROLE_RP, "rp 2", "comm 1", "peer 2" },
497 { TR_ROLE_IDP, "idp 1", "comm 1", NULL },
498 { TR_ROLE_IDP, "idp 1", "comm 1", "peer 1" },
499 { TR_ROLE_IDP, "idp 1", "comm 1", "peer 2" },
500 { TR_ROLE_IDP, "idp 2", "comm 1", NULL },
501 { TR_ROLE_RP, "rp 1", "comm 2", NULL },
502 { TR_ROLE_RP, "rp 2", "comm 2", NULL },
503 { TR_ROLE_RP, "rp 2", "comm 2", "peer 1" },
504 { TR_ROLE_RP, "rp 2", "comm 2", "peer 2" },
505 { TR_ROLE_IDP, "idp 1", "comm 2", NULL },
506 { TR_ROLE_IDP, "idp 1", "comm 2", "peer 1" },
507 { TR_ROLE_IDP, "idp 1", "comm 2", "peer 2" },
508 { TR_ROLE_IDP, "idp 2", "comm 2", NULL },
513 /**********************************************************************/
516 /* the first few tests here insert a few things into the community table (comms,
517 * rp_realms, or idp_realms), then verify that they're all there. They
518 * then remove them in various orders, put them back, try removing
519 * things that are not present, etc. */
521 static int community_test(void)
523 TALLOC_CTX *mem_ctx=talloc_new(NULL);
524 TR_COMM_TABLE *ctab=tr_comm_table_new(mem_ctx);
526 assert(0==tr_comm_table_size(ctab));
528 /* add communities */
530 assert(0==add_comm_set(ctab, comm_set_1));
531 assert(3==tr_comm_table_size(ctab));
532 assert(0==verify_comm_set(ctab, comm_set_1));
535 assert(0==remove_comm_set_member(ctab, comm_set_1, 0));
536 assert(2==tr_comm_table_size(ctab));
537 assert(0==remove_comm_set_member(ctab, comm_set_1, 1));
538 assert(1==tr_comm_table_size(ctab));
539 assert(0==remove_comm_set_member(ctab, comm_set_1, 2));
540 assert(0==tr_comm_table_size(ctab));
542 /* add communities */
544 assert(0==add_comm_set(ctab, comm_set_1));
545 assert(3==tr_comm_table_size(ctab));
546 assert(0==verify_comm_set(ctab, comm_set_1));
549 assert(0==remove_comm_set_member(ctab, comm_set_1, 0));
550 assert(2==tr_comm_table_size(ctab));
551 assert(0==remove_comm_set_member(ctab, comm_set_1, 2));
552 assert(1==tr_comm_table_size(ctab));
553 assert(0==remove_comm_set_member(ctab, comm_set_1, 1));
554 assert(0==tr_comm_table_size(ctab));
556 /* add communities */
558 assert(0==add_comm_set(ctab, comm_set_1));
559 assert(3==tr_comm_table_size(ctab));
560 assert(0==verify_comm_set(ctab, comm_set_1));
563 assert(0==remove_comm_set_member(ctab, comm_set_1, 1));
564 assert(2==tr_comm_table_size(ctab));
565 assert(0==remove_comm_set_member(ctab, comm_set_1, 0));
566 assert(1==tr_comm_table_size(ctab));
567 assert(0==remove_comm_set_member(ctab, comm_set_1, 2));
568 assert(0==tr_comm_table_size(ctab));
570 assert(1==remove_comm_set_member(ctab, comm_set_1, 1)); /* should not be in the table */
571 assert(0==tr_comm_table_size(ctab));
573 /* add communities */
575 assert(0==add_comm_set(ctab, comm_set_1));
576 assert(3==tr_comm_table_size(ctab));
577 assert(0==verify_comm_set(ctab, comm_set_1));
580 assert(0==remove_comm_set_member(ctab, comm_set_1, 1));
581 assert(2==tr_comm_table_size(ctab));
582 assert(1==remove_comm_set_member(ctab, comm_set_1, 1)); /* should not be in the table */
583 assert(2==tr_comm_table_size(ctab));
584 assert(0==remove_comm_set_member(ctab, comm_set_1, 2));
585 assert(1==tr_comm_table_size(ctab));
586 assert(0==remove_comm_set_member(ctab, comm_set_1, 0));
587 assert(0==tr_comm_table_size(ctab));
589 /* add communities */
591 assert(0==add_comm_set(ctab, comm_set_1));
592 assert(3==tr_comm_table_size(ctab));
593 assert(0==verify_comm_set(ctab, comm_set_1));
596 assert(0==remove_comm_set_member(ctab, comm_set_1, 2));
597 assert(2==tr_comm_table_size(ctab));
598 assert(0==remove_comm_set_member(ctab, comm_set_1, 0));
599 assert(1==tr_comm_table_size(ctab));
600 assert(0==remove_comm_set_member(ctab, comm_set_1, 1));
601 assert(0==tr_comm_table_size(ctab));
602 assert(1==remove_comm_set_member(ctab, comm_set_1, 1)); /* should not be in the table */
603 assert(0==tr_comm_table_size(ctab));
605 /* add communities */
607 assert(0==add_comm_set(ctab, comm_set_1));
608 assert(3==tr_comm_table_size(ctab));
609 assert(0==verify_comm_set(ctab, comm_set_1));
612 assert(0==remove_comm_set_member(ctab, comm_set_1, 2));
613 assert(2==tr_comm_table_size(ctab));
614 assert(0==remove_comm_set_member(ctab, comm_set_1, 1));
615 assert(1==tr_comm_table_size(ctab));
616 assert(1==remove_comm_set_member(ctab, comm_set_1, 1)); /* should not be in the table */
617 assert(1==tr_comm_table_size(ctab));
618 assert(0==remove_comm_set_member(ctab, comm_set_1, 0));
619 assert(0==tr_comm_table_size(ctab));
621 talloc_free(mem_ctx);
625 static int rp_realm_test(void)
627 TALLOC_CTX *mem_ctx=talloc_new(NULL);
628 TR_COMM_TABLE *ctab=tr_comm_table_new(mem_ctx);
632 assert(0==add_rp_realm_set(ctab, rp_realm_set_1));
633 assert(0==verify_rp_realm_set(ctab, rp_realm_set_1));
636 assert(0==remove_rp_realm_set_member(ctab, rp_realm_set_1, 0));
637 assert(0==remove_rp_realm_set_member(ctab, rp_realm_set_1, 1));
638 assert(0==remove_rp_realm_set_member(ctab, rp_realm_set_1, 2));
642 assert(0==add_rp_realm_set(ctab, rp_realm_set_1));
643 assert(0==verify_rp_realm_set(ctab, rp_realm_set_1));
646 assert(0==remove_rp_realm_set_member(ctab, rp_realm_set_1, 0));
647 assert(0==remove_rp_realm_set_member(ctab, rp_realm_set_1, 2));
648 assert(0==remove_rp_realm_set_member(ctab, rp_realm_set_1, 1));
652 assert(0==add_rp_realm_set(ctab, rp_realm_set_1));
653 assert(0==verify_rp_realm_set(ctab, rp_realm_set_1));
656 assert(0==remove_rp_realm_set_member(ctab, rp_realm_set_1, 1));
657 assert(0==remove_rp_realm_set_member(ctab, rp_realm_set_1, 0));
658 assert(0==remove_rp_realm_set_member(ctab, rp_realm_set_1, 2));
660 assert(1==remove_rp_realm_set_member(ctab, rp_realm_set_1, 1)); /* should not be in the table */
664 assert(0==add_rp_realm_set(ctab, rp_realm_set_1));
665 assert(0==verify_rp_realm_set(ctab, rp_realm_set_1));
668 assert(0==remove_rp_realm_set_member(ctab, rp_realm_set_1, 1));
669 assert(1==remove_rp_realm_set_member(ctab, rp_realm_set_1, 1)); /* should not be in the table */
670 assert(0==remove_rp_realm_set_member(ctab, rp_realm_set_1, 2));
671 assert(0==remove_rp_realm_set_member(ctab, rp_realm_set_1, 0));
675 assert(0==add_rp_realm_set(ctab, rp_realm_set_1));
676 assert(0==verify_rp_realm_set(ctab, rp_realm_set_1));
679 assert(0==remove_rp_realm_set_member(ctab, rp_realm_set_1, 2));
680 assert(0==remove_rp_realm_set_member(ctab, rp_realm_set_1, 0));
681 assert(0==remove_rp_realm_set_member(ctab, rp_realm_set_1, 1));
682 assert(1==remove_rp_realm_set_member(ctab, rp_realm_set_1, 1)); /* should not be in the table */
686 assert(0==add_rp_realm_set(ctab, rp_realm_set_1));
687 assert(0==verify_rp_realm_set(ctab, rp_realm_set_1));
690 assert(0==remove_rp_realm_set_member(ctab, rp_realm_set_1, 2));
691 assert(0==remove_rp_realm_set_member(ctab, rp_realm_set_1, 1));
692 assert(1==remove_rp_realm_set_member(ctab, rp_realm_set_1, 1)); /* should not be in the table */
693 assert(0==remove_rp_realm_set_member(ctab, rp_realm_set_1, 0));
695 talloc_free(mem_ctx);
699 static int idp_realm_test(void)
701 TALLOC_CTX *mem_ctx=talloc_new(NULL);
702 TR_COMM_TABLE *ctab=tr_comm_table_new(mem_ctx);
706 assert(0==add_idp_realm_set(ctab, idp_realm_set_1));
707 assert(0==verify_idp_realm_set(ctab, idp_realm_set_1));
710 assert(0==remove_idp_realm_set_member(ctab, idp_realm_set_1, 0));
711 assert(0==remove_idp_realm_set_member(ctab, idp_realm_set_1, 1));
712 assert(0==remove_idp_realm_set_member(ctab, idp_realm_set_1, 2));
716 assert(0==add_idp_realm_set(ctab, idp_realm_set_1));
717 assert(0==verify_idp_realm_set(ctab, idp_realm_set_1));
720 assert(0==remove_idp_realm_set_member(ctab, idp_realm_set_1, 0));
721 assert(0==remove_idp_realm_set_member(ctab, idp_realm_set_1, 2));
722 assert(0==remove_idp_realm_set_member(ctab, idp_realm_set_1, 1));
726 assert(0==add_idp_realm_set(ctab, idp_realm_set_1));
727 assert(0==verify_idp_realm_set(ctab, idp_realm_set_1));
730 assert(0==remove_idp_realm_set_member(ctab, idp_realm_set_1, 1));
731 assert(0==remove_idp_realm_set_member(ctab, idp_realm_set_1, 0));
732 assert(0==remove_idp_realm_set_member(ctab, idp_realm_set_1, 2));
734 assert(1==remove_idp_realm_set_member(ctab, idp_realm_set_1, 1)); /* should not be in the table */
738 assert(0==add_idp_realm_set(ctab, idp_realm_set_1));
739 assert(0==verify_idp_realm_set(ctab, idp_realm_set_1));
742 assert(0==remove_idp_realm_set_member(ctab, idp_realm_set_1, 1));
743 assert(1==remove_idp_realm_set_member(ctab, idp_realm_set_1, 1)); /* should not be in the table */
744 assert(0==remove_idp_realm_set_member(ctab, idp_realm_set_1, 2));
745 assert(0==remove_idp_realm_set_member(ctab, idp_realm_set_1, 0));
749 assert(0==add_idp_realm_set(ctab, idp_realm_set_1));
750 assert(0==verify_idp_realm_set(ctab, idp_realm_set_1));
753 assert(0==remove_idp_realm_set_member(ctab, idp_realm_set_1, 2));
754 assert(0==remove_idp_realm_set_member(ctab, idp_realm_set_1, 0));
755 assert(0==remove_idp_realm_set_member(ctab, idp_realm_set_1, 1));
756 assert(1==remove_idp_realm_set_member(ctab, idp_realm_set_1, 1)); /* should not be in the table */
760 assert(0==add_idp_realm_set(ctab, idp_realm_set_1));
761 assert(0==verify_idp_realm_set(ctab, idp_realm_set_1));
764 assert(0==remove_idp_realm_set_member(ctab, idp_realm_set_1, 2));
765 assert(0==remove_idp_realm_set_member(ctab, idp_realm_set_1, 1));
766 assert(1==remove_idp_realm_set_member(ctab, idp_realm_set_1, 1)); /* should not be in the table */
767 assert(0==remove_idp_realm_set_member(ctab, idp_realm_set_1, 0));
769 talloc_free(mem_ctx);
773 static int membership_test(void)
775 TALLOC_CTX *mem_ctx=talloc_new(NULL);
776 TR_COMM_TABLE *ctab=tr_comm_table_new(mem_ctx);
781 assert(0==add_comm_set(ctab, comm_set_1));
782 assert(0==add_rp_realm_set(ctab, rp_realm_set_1));
783 assert(0==add_idp_realm_set(ctab, idp_realm_set_1));
784 assert(0==add_member_set(ctab, member_set_1));
786 size=tr_comm_table_size(ctab);
787 tr_comm_table_sweep(ctab);
788 assert(size==tr_comm_table_size(ctab));
790 /* now remove memberships */
791 for (ii=0; member_set_1[ii].role!=TR_ROLE_UNKNOWN; ii++) {
792 assert(0==remove_membership(ctab, member_set_1, ii));
793 assert(2==remove_membership(ctab, member_set_1, ii)); /* should not be in the table */
796 assert(NULL==ctab->memberships);
799 assert(0==add_member_set(ctab, member_set_1));
800 /* tr_comm_table_print(stdout, ctab); */
802 tr_comm_table_sweep(ctab);
803 assert(size==tr_comm_table_size(ctab));
805 /* remove in the reverse order */
807 assert(0==remove_membership(ctab, member_set_1, ii-1));
808 assert(2==remove_membership(ctab, member_set_1, ii-1)); /* should not be in the table */
809 /* tr_comm_table_print(stdout, ctab); */
812 assert(NULL==ctab->memberships);
814 assert(size==tr_comm_table_size(ctab));
815 tr_comm_table_sweep(ctab);
816 assert(0==tr_comm_table_size(ctab));
818 talloc_free(mem_ctx);
823 /**********************************************************************/
827 assert(0==community_test());
828 printf("Community tests passed.\n");
829 assert(0==rp_realm_test());
830 printf("RP realm tests passed.\n");
831 assert(0==idp_realm_test());
832 printf("IDP realm tests passed.\n");
833 assert(0==membership_test());
834 printf("Membership tests passed.\n");