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_new(tmp_ctx, tr_new_name(ae->hostname));
244 if ((aaa==NULL) || (aaa->hostname==NULL))
247 talloc_steal(mem_ctx, aaa);
249 talloc_free(tmp_ctx);
254 /**********************************************************************/
255 /* TR_IDP_REALM test stuff */
257 struct idp_realm_entry {
259 struct aaa_entry *aaa_servers;
260 struct apc_entry *apcs;
263 static TR_IDP_REALM *idp_realm_entry_to_idp_realm(TALLOC_CTX *mem_ctx, struct idp_realm_entry *re)
265 TALLOC_CTX *tmp_ctx=talloc_new(NULL);
266 TR_IDP_REALM *realm=NULL;
268 realm=tr_idp_realm_new(tmp_ctx);
270 tr_idp_realm_set_id(realm, tr_new_name(re->id));
271 realm->aaa_servers=aaa_entry_to_aaa_server(realm, re->aaa_servers);
272 if (realm->aaa_servers==NULL)
273 realm=NULL; /* still in tmp_ctx so will be freed */
275 tr_idp_realm_set_apcs(realm, apc_entry_to_apc(tmp_ctx, re->apcs));
276 if (tr_idp_realm_get_apcs(realm)==NULL)
282 talloc_steal(mem_ctx, realm);
284 talloc_free(tmp_ctx);
288 static int add_idp_realm_set(TR_COMM_TABLE *ctab, struct idp_realm_entry *entries)
290 TALLOC_CTX *tmp_ctx=talloc_new(NULL);
291 struct idp_realm_entry *this=NULL;
292 TR_IDP_REALM *realm=NULL;
295 for (this=entries; this->id!=NULL; this++) {
296 realm=idp_realm_entry_to_idp_realm(tmp_ctx, this);
298 printf("Error creating IDP realm %s.\n", this->id);
302 tr_comm_table_add_idp_realm(ctab, realm);
307 talloc_free(tmp_ctx);
311 static int verify_idp_realm_set(TR_COMM_TABLE *ctab, struct idp_realm_entry *entries)
313 struct idp_realm_entry *this=NULL;
314 TR_IDP_REALM *idp_realm=NULL;
315 TR_NAME *this_id=NULL;
317 for (this=entries; this->id!=NULL; this++) {
318 this_id=tr_new_name(this->id);
319 idp_realm=tr_comm_table_find_idp_realm(ctab, this_id);
320 tr_free_name(this_id); this_id=NULL;
322 if (idp_realm==NULL) {
323 printf("Error, IDP realm %s missing from community table.\n", this->id);
330 /* removes entry n from ctab */
331 static int remove_idp_realm_set_member(TR_COMM_TABLE *ctab, struct idp_realm_entry *entries, size_t n)
333 TR_NAME *idp_realm_name=tr_new_name(entries[n].id);
334 TR_IDP_REALM *idp_realm=tr_comm_table_find_idp_realm(ctab, idp_realm_name);
335 TR_IDP_REALM *idp_realm2=NULL;
337 if (idp_realm==NULL) {
338 printf("Can't remove IDP realm %s, not in table.\n", entries[n].id);
339 tr_free_name(idp_realm_name);
343 tr_comm_table_remove_idp_realm(ctab, idp_realm);
344 idp_realm2=tr_comm_table_find_idp_realm(ctab, idp_realm_name);
345 if (idp_realm2!=NULL) {
346 printf("IDP realm %s still in table after removal.\n", entries[n].id);
347 tr_idp_realm_free(idp_realm);
348 tr_free_name(idp_realm_name);
352 tr_idp_realm_free(idp_realm);
353 tr_free_name(idp_realm_name);
357 /**********************************************************************/
358 /* Community Membership test stuff */
360 struct comm_memb_entry {
362 const char *realm_name;
363 const char *comm_name;
365 /* TODO: test provenance */
368 /* add an existing realm to an existing community (these must
369 * exist in the community table lists) */
370 static int add_comm_membership(TR_COMM_TABLE *ctab, struct comm_memb_entry *entry)
372 TR_NAME *comm_name=tr_new_name(entry->comm_name);
373 TR_NAME *realm_name=tr_new_name(entry->realm_name);
374 TR_COMM *comm=tr_comm_table_find_comm(ctab, comm_name);
375 TR_RP_REALM *rp_realm=(entry->role==TR_ROLE_RP)?(tr_comm_table_find_rp_realm(ctab, realm_name)):(NULL);
376 TR_IDP_REALM *idp_realm=(entry->role==TR_ROLE_IDP)?(tr_comm_table_find_idp_realm(ctab, realm_name)):(NULL);
379 if ((comm==NULL) || ((rp_realm==NULL)&&(idp_realm==NULL)))
383 if (entry->origin!=NULL)
384 json_array_append(prov, json_string(entry->origin));
386 switch (entry->role) {
388 tr_comm_add_idp_realm(ctab, comm, idp_realm, 0, prov, NULL); /* Expiry!? */
391 tr_comm_add_rp_realm(ctab, comm, rp_realm, 0, prov, NULL); /* Expiry!? */
400 static int add_member_set(TR_COMM_TABLE *ctab, struct comm_memb_entry *entries)
402 struct comm_memb_entry *this=NULL;
404 for (this=entries; this->role!=TR_ROLE_UNKNOWN; this++) {
405 if (0!=add_comm_membership(ctab, this)) {
406 printf("Error adding %s realm %s to community %s (origin %s).\n",
407 (this->role==TR_ROLE_RP)?"RP":"IDP",
410 (this->origin!=NULL)?(this->origin):"null");
417 static int remove_membership(TR_COMM_TABLE *ctab, struct comm_memb_entry *entries, size_t n)
419 TR_NAME *realm_name=tr_new_name(entries[n].realm_name);
420 TR_NAME *comm_name=tr_new_name(entries[n].comm_name);
421 TR_NAME *origin=(entries[n].origin!=NULL)?(tr_new_name(entries[n].origin)):NULL;
422 TR_COMM_MEMB *memb=NULL;
425 switch (entries[n].role) {
427 memb=tr_comm_table_find_idp_memb_origin(ctab, realm_name, comm_name, origin);
430 memb=tr_comm_table_find_rp_memb_origin(ctab, realm_name, comm_name, origin);
438 printf("%s realm %s not in comm %s from origin %s, can't remove membership.\n",
439 (entries[n].role==TR_ROLE_RP)?"RP":"IDP",
440 entries[n].realm_name,
441 entries[n].comm_name,
442 (entries[n].origin!=NULL)?(entries[n].origin):"null");
446 tr_comm_table_remove_memb(ctab, memb);
447 tr_comm_memb_free(memb);
451 tr_free_name(realm_name);
452 tr_free_name(comm_name);
454 tr_free_name(origin);
458 /**********************************************************************/
461 struct apc_entry apc_1={ "apc" };
463 struct comm_entry comm_set_1[]={
464 { "apc", TR_COMM_APC, NULL },
465 { "comm 1", TR_COMM_COI, &apc_1 },
466 { "comm 2", TR_COMM_COI, &apc_1 },
470 struct rp_realm_entry rp_realm_set_1[]={
477 struct aaa_entry aaa_1= { "aaa 1" };
478 struct aaa_entry aaa_2= { "aaa 2" };
479 struct aaa_entry aaa_3= { "aaa 3" };
481 struct idp_realm_entry idp_realm_set_1[]={
482 { "idp 1", &aaa_1, &apc_1 },
483 { "idp 2", &aaa_2, &apc_1 },
484 { "idp 3", &aaa_3, &apc_1 },
488 struct comm_memb_entry member_set_1[]={
489 { TR_ROLE_RP, "rp 1", "apc", NULL },
490 { TR_ROLE_RP, "rp 2", "apc", NULL },
491 { TR_ROLE_RP, "rp 3", "apc", NULL },
492 { TR_ROLE_IDP, "idp 1", "apc", NULL },
493 { TR_ROLE_IDP, "idp 2", "apc", NULL },
494 { TR_ROLE_IDP, "idp 3", "apc", NULL },
495 { TR_ROLE_RP, "rp 1", "comm 1", NULL },
496 { TR_ROLE_RP, "rp 2", "comm 1", NULL },
497 { TR_ROLE_RP, "rp 2", "comm 1", "peer 1" },
498 { TR_ROLE_RP, "rp 2", "comm 1", "peer 2" },
499 { TR_ROLE_IDP, "idp 1", "comm 1", NULL },
500 { TR_ROLE_IDP, "idp 1", "comm 1", "peer 1" },
501 { TR_ROLE_IDP, "idp 1", "comm 1", "peer 2" },
502 { TR_ROLE_IDP, "idp 2", "comm 1", NULL },
503 { TR_ROLE_RP, "rp 1", "comm 2", NULL },
504 { TR_ROLE_RP, "rp 2", "comm 2", NULL },
505 { TR_ROLE_RP, "rp 2", "comm 2", "peer 1" },
506 { TR_ROLE_RP, "rp 2", "comm 2", "peer 2" },
507 { TR_ROLE_IDP, "idp 1", "comm 2", NULL },
508 { TR_ROLE_IDP, "idp 1", "comm 2", "peer 1" },
509 { TR_ROLE_IDP, "idp 1", "comm 2", "peer 2" },
510 { TR_ROLE_IDP, "idp 2", "comm 2", NULL },
515 /**********************************************************************/
518 /* the first few tests here insert a few things into the community table (comms,
519 * rp_realms, or idp_realms), then verify that they're all there. They
520 * then remove them in various orders, put them back, try removing
521 * things that are not present, etc. */
523 static int community_test(void)
525 TALLOC_CTX *mem_ctx=talloc_new(NULL);
526 TR_COMM_TABLE *ctab=tr_comm_table_new(mem_ctx);
528 assert(0==tr_comm_table_size(ctab));
530 /* add communities */
532 assert(0==add_comm_set(ctab, comm_set_1));
533 assert(3==tr_comm_table_size(ctab));
534 assert(0==verify_comm_set(ctab, comm_set_1));
537 assert(0==remove_comm_set_member(ctab, comm_set_1, 0));
538 assert(2==tr_comm_table_size(ctab));
539 assert(0==remove_comm_set_member(ctab, comm_set_1, 1));
540 assert(1==tr_comm_table_size(ctab));
541 assert(0==remove_comm_set_member(ctab, comm_set_1, 2));
542 assert(0==tr_comm_table_size(ctab));
544 /* add communities */
546 assert(0==add_comm_set(ctab, comm_set_1));
547 assert(3==tr_comm_table_size(ctab));
548 assert(0==verify_comm_set(ctab, comm_set_1));
551 assert(0==remove_comm_set_member(ctab, comm_set_1, 0));
552 assert(2==tr_comm_table_size(ctab));
553 assert(0==remove_comm_set_member(ctab, comm_set_1, 2));
554 assert(1==tr_comm_table_size(ctab));
555 assert(0==remove_comm_set_member(ctab, comm_set_1, 1));
556 assert(0==tr_comm_table_size(ctab));
558 /* add communities */
560 assert(0==add_comm_set(ctab, comm_set_1));
561 assert(3==tr_comm_table_size(ctab));
562 assert(0==verify_comm_set(ctab, comm_set_1));
565 assert(0==remove_comm_set_member(ctab, comm_set_1, 1));
566 assert(2==tr_comm_table_size(ctab));
567 assert(0==remove_comm_set_member(ctab, comm_set_1, 0));
568 assert(1==tr_comm_table_size(ctab));
569 assert(0==remove_comm_set_member(ctab, comm_set_1, 2));
570 assert(0==tr_comm_table_size(ctab));
572 assert(1==remove_comm_set_member(ctab, comm_set_1, 1)); /* should not be in the table */
573 assert(0==tr_comm_table_size(ctab));
575 /* add communities */
577 assert(0==add_comm_set(ctab, comm_set_1));
578 assert(3==tr_comm_table_size(ctab));
579 assert(0==verify_comm_set(ctab, comm_set_1));
582 assert(0==remove_comm_set_member(ctab, comm_set_1, 1));
583 assert(2==tr_comm_table_size(ctab));
584 assert(1==remove_comm_set_member(ctab, comm_set_1, 1)); /* should not be in the table */
585 assert(2==tr_comm_table_size(ctab));
586 assert(0==remove_comm_set_member(ctab, comm_set_1, 2));
587 assert(1==tr_comm_table_size(ctab));
588 assert(0==remove_comm_set_member(ctab, comm_set_1, 0));
589 assert(0==tr_comm_table_size(ctab));
591 /* add communities */
593 assert(0==add_comm_set(ctab, comm_set_1));
594 assert(3==tr_comm_table_size(ctab));
595 assert(0==verify_comm_set(ctab, comm_set_1));
598 assert(0==remove_comm_set_member(ctab, comm_set_1, 2));
599 assert(2==tr_comm_table_size(ctab));
600 assert(0==remove_comm_set_member(ctab, comm_set_1, 0));
601 assert(1==tr_comm_table_size(ctab));
602 assert(0==remove_comm_set_member(ctab, comm_set_1, 1));
603 assert(0==tr_comm_table_size(ctab));
604 assert(1==remove_comm_set_member(ctab, comm_set_1, 1)); /* should not be in the table */
605 assert(0==tr_comm_table_size(ctab));
607 /* add communities */
609 assert(0==add_comm_set(ctab, comm_set_1));
610 assert(3==tr_comm_table_size(ctab));
611 assert(0==verify_comm_set(ctab, comm_set_1));
614 assert(0==remove_comm_set_member(ctab, comm_set_1, 2));
615 assert(2==tr_comm_table_size(ctab));
616 assert(0==remove_comm_set_member(ctab, comm_set_1, 1));
617 assert(1==tr_comm_table_size(ctab));
618 assert(1==remove_comm_set_member(ctab, comm_set_1, 1)); /* should not be in the table */
619 assert(1==tr_comm_table_size(ctab));
620 assert(0==remove_comm_set_member(ctab, comm_set_1, 0));
621 assert(0==tr_comm_table_size(ctab));
623 talloc_free(mem_ctx);
627 static int rp_realm_test(void)
629 TALLOC_CTX *mem_ctx=talloc_new(NULL);
630 TR_COMM_TABLE *ctab=tr_comm_table_new(mem_ctx);
634 assert(0==add_rp_realm_set(ctab, rp_realm_set_1));
635 assert(0==verify_rp_realm_set(ctab, rp_realm_set_1));
638 assert(0==remove_rp_realm_set_member(ctab, rp_realm_set_1, 0));
639 assert(0==remove_rp_realm_set_member(ctab, rp_realm_set_1, 1));
640 assert(0==remove_rp_realm_set_member(ctab, rp_realm_set_1, 2));
644 assert(0==add_rp_realm_set(ctab, rp_realm_set_1));
645 assert(0==verify_rp_realm_set(ctab, rp_realm_set_1));
648 assert(0==remove_rp_realm_set_member(ctab, rp_realm_set_1, 0));
649 assert(0==remove_rp_realm_set_member(ctab, rp_realm_set_1, 2));
650 assert(0==remove_rp_realm_set_member(ctab, rp_realm_set_1, 1));
654 assert(0==add_rp_realm_set(ctab, rp_realm_set_1));
655 assert(0==verify_rp_realm_set(ctab, rp_realm_set_1));
658 assert(0==remove_rp_realm_set_member(ctab, rp_realm_set_1, 1));
659 assert(0==remove_rp_realm_set_member(ctab, rp_realm_set_1, 0));
660 assert(0==remove_rp_realm_set_member(ctab, rp_realm_set_1, 2));
662 assert(1==remove_rp_realm_set_member(ctab, rp_realm_set_1, 1)); /* should not be in the table */
666 assert(0==add_rp_realm_set(ctab, rp_realm_set_1));
667 assert(0==verify_rp_realm_set(ctab, rp_realm_set_1));
670 assert(0==remove_rp_realm_set_member(ctab, rp_realm_set_1, 1));
671 assert(1==remove_rp_realm_set_member(ctab, rp_realm_set_1, 1)); /* should not be in the table */
672 assert(0==remove_rp_realm_set_member(ctab, rp_realm_set_1, 2));
673 assert(0==remove_rp_realm_set_member(ctab, rp_realm_set_1, 0));
677 assert(0==add_rp_realm_set(ctab, rp_realm_set_1));
678 assert(0==verify_rp_realm_set(ctab, rp_realm_set_1));
681 assert(0==remove_rp_realm_set_member(ctab, rp_realm_set_1, 2));
682 assert(0==remove_rp_realm_set_member(ctab, rp_realm_set_1, 0));
683 assert(0==remove_rp_realm_set_member(ctab, rp_realm_set_1, 1));
684 assert(1==remove_rp_realm_set_member(ctab, rp_realm_set_1, 1)); /* should not be in the table */
688 assert(0==add_rp_realm_set(ctab, rp_realm_set_1));
689 assert(0==verify_rp_realm_set(ctab, rp_realm_set_1));
692 assert(0==remove_rp_realm_set_member(ctab, rp_realm_set_1, 2));
693 assert(0==remove_rp_realm_set_member(ctab, rp_realm_set_1, 1));
694 assert(1==remove_rp_realm_set_member(ctab, rp_realm_set_1, 1)); /* should not be in the table */
695 assert(0==remove_rp_realm_set_member(ctab, rp_realm_set_1, 0));
697 talloc_free(mem_ctx);
701 static int idp_realm_test(void)
703 TALLOC_CTX *mem_ctx=talloc_new(NULL);
704 TR_COMM_TABLE *ctab=tr_comm_table_new(mem_ctx);
708 assert(0==add_idp_realm_set(ctab, idp_realm_set_1));
709 assert(0==verify_idp_realm_set(ctab, idp_realm_set_1));
712 assert(0==remove_idp_realm_set_member(ctab, idp_realm_set_1, 0));
713 assert(0==remove_idp_realm_set_member(ctab, idp_realm_set_1, 1));
714 assert(0==remove_idp_realm_set_member(ctab, idp_realm_set_1, 2));
718 assert(0==add_idp_realm_set(ctab, idp_realm_set_1));
719 assert(0==verify_idp_realm_set(ctab, idp_realm_set_1));
722 assert(0==remove_idp_realm_set_member(ctab, idp_realm_set_1, 0));
723 assert(0==remove_idp_realm_set_member(ctab, idp_realm_set_1, 2));
724 assert(0==remove_idp_realm_set_member(ctab, idp_realm_set_1, 1));
728 assert(0==add_idp_realm_set(ctab, idp_realm_set_1));
729 assert(0==verify_idp_realm_set(ctab, idp_realm_set_1));
732 assert(0==remove_idp_realm_set_member(ctab, idp_realm_set_1, 1));
733 assert(0==remove_idp_realm_set_member(ctab, idp_realm_set_1, 0));
734 assert(0==remove_idp_realm_set_member(ctab, idp_realm_set_1, 2));
736 assert(1==remove_idp_realm_set_member(ctab, idp_realm_set_1, 1)); /* should not be in the table */
740 assert(0==add_idp_realm_set(ctab, idp_realm_set_1));
741 assert(0==verify_idp_realm_set(ctab, idp_realm_set_1));
744 assert(0==remove_idp_realm_set_member(ctab, idp_realm_set_1, 1));
745 assert(1==remove_idp_realm_set_member(ctab, idp_realm_set_1, 1)); /* should not be in the table */
746 assert(0==remove_idp_realm_set_member(ctab, idp_realm_set_1, 2));
747 assert(0==remove_idp_realm_set_member(ctab, idp_realm_set_1, 0));
751 assert(0==add_idp_realm_set(ctab, idp_realm_set_1));
752 assert(0==verify_idp_realm_set(ctab, idp_realm_set_1));
755 assert(0==remove_idp_realm_set_member(ctab, idp_realm_set_1, 2));
756 assert(0==remove_idp_realm_set_member(ctab, idp_realm_set_1, 0));
757 assert(0==remove_idp_realm_set_member(ctab, idp_realm_set_1, 1));
758 assert(1==remove_idp_realm_set_member(ctab, idp_realm_set_1, 1)); /* should not be in the table */
762 assert(0==add_idp_realm_set(ctab, idp_realm_set_1));
763 assert(0==verify_idp_realm_set(ctab, idp_realm_set_1));
766 assert(0==remove_idp_realm_set_member(ctab, idp_realm_set_1, 2));
767 assert(0==remove_idp_realm_set_member(ctab, idp_realm_set_1, 1));
768 assert(1==remove_idp_realm_set_member(ctab, idp_realm_set_1, 1)); /* should not be in the table */
769 assert(0==remove_idp_realm_set_member(ctab, idp_realm_set_1, 0));
771 talloc_free(mem_ctx);
775 static int membership_test(void)
777 TALLOC_CTX *mem_ctx=talloc_new(NULL);
778 TR_COMM_TABLE *ctab=tr_comm_table_new(mem_ctx);
783 assert(0==add_comm_set(ctab, comm_set_1));
784 assert(0==add_rp_realm_set(ctab, rp_realm_set_1));
785 assert(0==add_idp_realm_set(ctab, idp_realm_set_1));
786 assert(0==add_member_set(ctab, member_set_1));
788 size=tr_comm_table_size(ctab);
789 tr_comm_table_sweep(ctab);
790 assert(size==tr_comm_table_size(ctab));
792 /* now remove memberships */
793 for (ii=0; member_set_1[ii].role!=TR_ROLE_UNKNOWN; ii++) {
794 assert(0==remove_membership(ctab, member_set_1, ii));
795 assert(2==remove_membership(ctab, member_set_1, ii)); /* should not be in the table */
798 assert(NULL==ctab->memberships);
801 assert(0==add_member_set(ctab, member_set_1));
802 /* tr_comm_table_print(stdout, ctab); */
804 tr_comm_table_sweep(ctab);
805 assert(size==tr_comm_table_size(ctab));
807 /* remove in the reverse order */
809 assert(0==remove_membership(ctab, member_set_1, ii-1));
810 assert(2==remove_membership(ctab, member_set_1, ii-1)); /* should not be in the table */
811 /* tr_comm_table_print(stdout, ctab); */
814 assert(NULL==ctab->memberships);
816 assert(size==tr_comm_table_size(ctab));
817 tr_comm_table_sweep(ctab);
818 assert(0==tr_comm_table_size(ctab));
820 talloc_free(mem_ctx);
825 /**********************************************************************/
829 assert(0==community_test());
830 printf("Community tests passed.\n");
831 assert(0==rp_realm_test());
832 printf("RP realm tests passed.\n");
833 assert(0==idp_realm_test());
834 printf("IDP realm tests passed.\n");
835 assert(0==membership_test());
836 printf("Membership tests passed.\n");