Bring test programs up to date - all now pass
authorJennifer Richards <jennifer@painless-security.com>
Mon, 11 Sep 2017 21:51:04 +0000 (17:51 -0400)
committerJennifer Richards <jennifer@painless-security.com>
Mon, 11 Sep 2017 21:51:04 +0000 (17:51 -0400)
  * Use new config loader
  * Fix various test config files so pass validation
  * Use tr_name_internal.h instead of tr_name.h

common/tests/cfg_test.c
common/tests/commtest.c
common/tests/filt_test.c
common/tests/idp.cfg
common/tests/name_test.c
common/tests/test-filters/filt-inforec-1.json
common/tests/test-filters/filt-tidreq-1.json
common/tests/test-filters/valid-filt.json
trp/test/ptbl_test.c
trp/test/rtbl_test.c

index f487c53..97cd03c 100644 (file)
@@ -36,7 +36,7 @@
 #include <talloc.h>
 #include <assert.h>
 
-#include <trust_router/tr_name.h>
+#include <tr_name_internal.h>
 #include <tr_comm.h>
 #include <tr_idp.h>
 #include <tr_config.h>
@@ -118,16 +118,18 @@ static int verify_rp_cfg(TR_CFG *cfg)
 int main(void)
 {
   TALLOC_CTX *mem_ctx=talloc_new(NULL);
-  TR_CFG *cfg=NULL;
+  TR_CFG_MGR *cfg_mgr=NULL;
   TR_CFG_RC rc=TR_CFG_ERROR;
+  char *fname=NULL;
 
   tr_log_open();
 
   talloc_set_log_fn(tr_talloc_log);
-  cfg=tr_cfg_new(mem_ctx);
+  cfg_mgr=tr_cfg_mgr_new(mem_ctx);
 
   printf("Parsing idp.cfg.\n");
-  rc=tr_cfg_parse_one_config_file(cfg, "idp.cfg");
+  fname="idp.cfg";
+  rc=tr_parse_config(cfg_mgr, 1, &fname);
   switch(rc) {
   case TR_CFG_SUCCESS:
     tr_debug("main: TR_CFG_SUCCESS");
@@ -147,55 +149,21 @@ int main(void)
   }
 
   printf("Verifying IDP parse results... ");
-  if (verify_idp_cfg(cfg)!=0) {
+  if (verify_idp_cfg(cfg_mgr->new)!=0) {
     printf("Error!\n");
     exit(-1);
   }
   printf("success!\n");
 
   printf("Verifying RP parse results... ");
-  if (verify_rp_cfg(cfg)!=0) {
+  if (verify_rp_cfg(cfg_mgr->new)!=0) {
     printf("Error!\n");
     exit(-1);
   }
   printf("success!\n");
 
   talloc_report_full(mem_ctx, stderr);
-  tr_cfg_free(cfg);
-
-  printf("Cleared configuration for next test.\n\n");
-
-  cfg=tr_cfg_new(mem_ctx);
-  
-  printf("Parsing rp.cfg.\n");
-  rc=tr_cfg_parse_one_config_file(cfg, "rp.cfg");
-  switch(rc) {
-  case TR_CFG_SUCCESS:
-    tr_debug("main: TR_CFG_SUCCESS");
-    break;
-  case TR_CFG_ERROR:
-    tr_debug("main: TR_CFG_ERROR");
-    break;
-  case TR_CFG_BAD_PARAMS:
-    tr_debug("main: TR_CFG_BAD_PARAMS");
-    break;
-  case TR_CFG_NOPARSE:
-    tr_debug("main: TR_CFG_NOPARSE");
-    break;
-  case TR_CFG_NOMEM:
-    tr_debug("main: TR_CFG_NOMEM");
-    break;
-  }
-
-#if 0
-  printf("Verifying RP parse results... ");
-  if (verify_rp_cfg(cfg)!=0) {
-    printf("Error!\n");
-    exit(-1);
-  }
-  printf("success!\n");
-#endif
-
+  tr_cfg_mgr_free(cfg_mgr);
   talloc_free(mem_ctx);
   return 0;
 }
index 34153cb..72a2844 100644 (file)
@@ -5,7 +5,7 @@
 #include <tr_apc.h>
 #include <tr_comm.h>
 #include <tr_rp.h>
-#include <trust_router/tr_name.h>
+#include <tr_name_internal.h>
 
 /**********************************************************************/
 /* APC test stuff */
index e86f1bb..d7dfe06 100644 (file)
  * @param filt_out Will point to the loaded filter on success
  * @return Return value from tr_cfg_parse_one_config_file()
  */
-int load_filter(const char *fname, TR_FILTER_SET **filts_out)
+int load_filter(char *fname, TR_FILTER_SET **filts_out)
 {
-  TR_CFG *cfg=tr_cfg_new(NULL);
+  TR_CFG_MGR *cfg_mgr=tr_cfg_mgr_new(NULL);
   TR_CFG_RC rc=TR_CFG_ERROR;
 
+  assert(cfg_mgr);
   assert(fname);
   assert(filts_out);
 
-  rc=tr_cfg_parse_one_config_file(cfg, fname);
+  rc=tr_parse_config(cfg_mgr, 1, &fname);
   if (rc!=TR_CFG_SUCCESS)
     goto cleanup;
 
   /* Steal the filter from the first rp_client */
-  assert(cfg);
-  assert(cfg->rp_clients);
-  assert(cfg->rp_clients->filters);
-  *filts_out=cfg->rp_clients->filters;
-  cfg->rp_clients->filters=NULL; /* can't use the _set_filter() because that will free the filter */
+  assert(cfg_mgr->new);
+  assert(cfg_mgr->new->rp_clients);
+  assert(cfg_mgr->new->rp_clients->filters);
+  *filts_out=cfg_mgr->new->rp_clients->filters;
+  cfg_mgr->new->rp_clients->filters=NULL; /* can't use the _set_filter() because that will free the filter */
   talloc_steal(NULL, *filts_out);
 
 cleanup:
-  tr_cfg_free(cfg);
+  tr_cfg_mgr_free(cfg_mgr);
   return rc;
 }
 
@@ -94,7 +95,7 @@ int test_load_filter(void)
   assert(TR_CFG_NOPARSE==load_filter(FILTER_PATH "invalid-filt-repeated-key.json", &filts));
   if (filts) tr_filter_set_free(filts);
   filts=NULL;
-  assert(TR_CFG_ERROR==load_filter(FILTER_PATH "invalid-filt-unknown-field.json", &filts));
+  assert(TR_CFG_NOPARSE==load_filter(FILTER_PATH "invalid-filt-unknown-field.json", &filts));
   if (filts) tr_filter_set_free(filts);
   filts=NULL;
   return 1;
@@ -174,7 +175,7 @@ TID_REQ *load_tid_req(const char *fname)
  * @param expected_action Expected action if the filter matches
  * @return 1 if expected result is obtained, 0 or does not return otherwise
  */
-int test_one_filter(const char *filt_fname,
+int test_one_filter(char *filt_fname,
                     TR_FILTER_TYPE ftype,
                     const char *target_fname,
                     int expected_match,
@@ -233,7 +234,7 @@ int test_filter(void)
   json_t *test_list=json_load_file(FILTER_PATH "filter-tests.json", JSON_DISABLE_EOF_CHECK, NULL);
   json_t *this;
   size_t ii;
-  const char *filt_file, *target_file;
+  char *filt_file, *target_file;
   TR_FILTER_TYPE ftype;
   int expect_match;
   TR_FILTER_ACTION action;
@@ -242,9 +243,9 @@ int test_filter(void)
     printf("Running filter test case: %s\n", json_string_value(json_object_get(this, "test label")));
     fflush(stdout);
 
-    filt_file=json_string_value(json_object_get(this, "filter file"));
+    filt_file=talloc_strdup(NULL, json_string_value(json_object_get(this, "filter file")));
     ftype=tr_filter_type_from_string(json_string_value(json_object_get(this, "filter type")));
-    target_file=json_string_value(json_object_get(this, "target file"));
+    target_file=talloc_strdup(NULL, json_string_value(json_object_get(this, "target file")));
     if (0==strcmp("yes", json_string_value(json_object_get(this, "expect match"))))
       expect_match=TR_FILTER_MATCH;
     else
@@ -256,6 +257,9 @@ int test_filter(void)
       action=TR_FILTER_ACTION_REJECT;
 
     assert(test_one_filter(filt_file, ftype, target_file, expect_match, action));
+
+    talloc_free(filt_file);
+    talloc_free(target_file);
   }
 
   return 1;
index cfb1729..2fa58b1 100644 (file)
@@ -1,4 +1,7 @@
 {
+    "tr_internal": {
+        "hostname": "server.example.com"
+    },
     "communities": [
       {
         "apcs": [],
index ae47ebb..187bd78 100644 (file)
@@ -36,7 +36,7 @@
 #include <stdlib.h>
 #include <assert.h>
 
-#include <trust_router/tr_name.h>
+#include <tr_name_internal.h>
 
 /* returns 1 on success */
 int test_wildcard_prefix_match(const char *s, const char *wcs, int expect);
index df5d1a1..f49318a 100644 (file)
@@ -1,8 +1,25 @@
 {
+  "tr_internal": {
+    "hostname": "server.example.com"
+  },
+  "communities": [
+    {
+      "apcs": [],
+      "community_id": "apc.example.com",
+      "idp_realms": ["realm"],
+      "rp_realms": ["realm"],
+      "type": "apc"
+    }
+  ],
   "local_organizations": [
     { "organization_name": "inforec filter test 1",
       "realms": [
         { "realm": "realm",
+          "identity_provider": {
+            "aaa_servers": ["rad"],
+            "apcs": ["apc.example.com"],
+            "shared_config": "no"
+          },
           "gss_names": ["gss"],
           "filters": {
             "tid_inbound": [
index 7325252..ab5cbcb 100644 (file)
@@ -1,8 +1,25 @@
 {
+  "tr_internal": {
+    "hostname": "server.example.com"
+  },
+  "communities": [
+    {
+      "apcs": [],
+      "community_id": "apc.example.com",
+      "idp_realms": ["realm"],
+      "rp_realms": ["realm"],
+      "type": "apc"
+    }
+  ],
   "local_organizations": [
     { "organization_name": "tidreq filter test 1",
       "realms": [
         { "realm": "realm",
+          "identity_provider": {
+            "aaa_servers": ["rad"],
+            "apcs": ["apc.example.com"],
+            "shared_config": "no"
+          },
           "gss_names": ["gss"],
           "filters": {
             "tid_inbound": [
index b4fdfb3..a26b117 100644 (file)
@@ -1,8 +1,25 @@
 {
+  "tr_internal": {
+    "hostname": "server.example.com"
+  },
+  "communities": [
+    {
+      "apcs": [],
+      "community_id": "apc.example.com",
+      "idp_realms": ["realm"],
+      "rp_realms": ["realm"],
+      "type": "apc"
+    }
+  ],
   "local_organizations": [
     { "organization_name": "valid filter test",
       "realms": [
         { "realm": "realm",
+            "identity_provider": {
+              "aaa_servers": ["rad"],
+              "apcs": ["apc.example.com"],
+              "shared_config": "no"
+            },
           "gss_names": ["gss"],
           "filters": {
             "tid_inbound": [
index 8311e7f..e4824ea 100644 (file)
 
 struct peer_entry {
   char *server;
+  char *gss_name;
   unsigned int port;
   unsigned int linkcost;
 };
 
 static struct peer_entry peer_data[]={
-  {"peer0", 10000, 0x0001},
-  {"peer1", 15000, 0x0002},
-  {"peer2", 20000, 0x0004},
-  {"peer3", 25000, 0x0008},
-  {"peer4", 30000, 0x0010}
+  {"peer0", "trustrouter@peer0", 10000, 0x0001},
+  {"peer1", "trustrouter@peer1", 15000, 0x0002},
+  {"peer2", "trustrouter@peer2", 20000, 0x0004},
+  {"peer3", "trustrouter@peer3", 25000, 0x0008},
+  {"peer4", "trustrouter@peer4", 30000, 0x0010}
 };
 static size_t n_peers=sizeof(peer_data)/sizeof(peer_data[0]);
 
@@ -69,6 +70,8 @@ static void populate_ptable(TRPS_INSTANCE *trps)
     assert(new_peer!=NULL);
     trp_peer_set_server(new_peer, peer_data[i].server);
     assert(trp_peer_get_server(new_peer)!=NULL);
+    trp_peer_add_gss_name(new_peer, tr_new_name(peer_data[i].gss_name));
+    assert(trp_peer_get_gss_names(new_peer)!=NULL);
     trp_peer_set_port(new_peer, peer_data[i].port);
     trp_peer_set_linkcost(new_peer, peer_data[i].linkcost);
     assert(trps_add_peer(trps, new_peer)==TRP_SUCCESS);
index e305c83..0ec1ec0 100644 (file)
@@ -37,7 +37,7 @@
 #include <string.h>
 #include <assert.h>
 
-#include <trust_router/tr_name.h>
+#include <tr_name_internal.h>
 #include <trp_internal.h>
 #include <trp_rtable.h>