INN commit: branches/2.6/tests/nnrpd (auth-ext-t.c)

INN Commit rra at isc.org
Thu Dec 24 22:32:35 UTC 2020


    Date: Thursday, December 24, 2020 @ 14:32:34
  Author: eagle
Revision: 10466

Switch nnrpd/auth-ext to the new test API

Use the new test API so that failures will be reported with
more detail in the hope that this will help track down the
intermittant failure.

Modified:
  branches/2.6/tests/nnrpd/auth-ext-t.c

--------------+
 auth-ext-t.c |   81 ++++++++++++++++++++++++++++-----------------------------
 1 file changed, 41 insertions(+), 40 deletions(-)

Modified: auth-ext-t.c
===================================================================
--- auth-ext-t.c	2020-12-24 22:26:47 UTC (rev 10465)
+++ auth-ext-t.c	2020-12-24 22:32:34 UTC (rev 10466)
@@ -1,6 +1,8 @@
 /* $Id$ */
 /* Test suite for auth_external. */
 
+#define LIBTEST_NEW_FORMAT 1
+
 #include "config.h"
 #include "clibrary.h"
 
@@ -41,10 +43,10 @@
     return client;
 }
 
-/* Validate the input file against the expected data.  Takes the current test
-   number and a flag indicating whether we ran an authenticator. */
+/* Validate the input file against the expected data.  Takes a flag indicating
+   whether we ran an authenticator. */
 static void
-validate_input(int n, bool auth)
+validate_input(bool auth)
 {
     char *wanted, *seen;
 
@@ -55,9 +57,9 @@
     seen = ReadInFile("input", NULL);
     if (seen == NULL) {
         syswarn("unable to read input");
-        ok(n, false);
+        ok(false, "no input");
     } else {
-        ok_string(n, wanted, seen);
+        is_string(wanted, seen, "input is as expected");
         free(seen);
     }
     unlink("input");
@@ -64,25 +66,27 @@
     free(wanted);
 }
 
-/* Run the test authenticator, checking its input and output.  Takes the test
-   number, the fake client struct, the argument to pass to the authenticator,
-   the expected username, and the expected error output.  Tries it both as a
-   resolver and an authenticator to be sure there are no surprises.  Returns
-   the next test number. */
-static int
-ok_external(int n, struct client *client, const char *arg, const char *user,
-            const char *error)
+/* Run the test authenticator, checking its input and output.  Takes the fake
+   client struct, the argument to pass to the authenticator, the expected
+   username, and the expected error output.  Tries it both as a resolver and
+   an authenticator to be sure there are no surprises.  Returns the next test
+   number. */
+static void
+test_external(struct client *client, const char *arg, const char *user,
+              const char *error)
 {
     char *result;
     char *command;
 
+    diag("mode %s", arg);
+
     command = concat("auth-test ", arg, (char *) 0);
     errors_capture();
     result = auth_external(client, command, ".", NULL, NULL);
     errors_uncapture();
-    validate_input(n++, false);
-    ok_string(n++, user, result);
-    ok_string(n++, error, errors);
+    validate_input(false);
+    is_string(user, result, "user");
+    is_string(error, errors, "errors");
     if (errors && (error == NULL || strcmp(error, errors) != 0))
         warn("%s", errors);
     free(errors);
@@ -91,15 +95,13 @@
     errors_capture();
     result = auth_external(client, command, ".", "tester", "s0pers3cret");
     errors_uncapture();
-    validate_input(n++, true);
-    ok_string(n++, user, result);
-    ok_string(n++, error, errors);
+    validate_input(true);
+    is_string(user, result, "user with username and password");
+    is_string(error, errors, "errors with username and password");
     if (errors && (error == NULL || strcmp(error, errors) != 0))
         warn("%s", errors);
     free(errors);
     errors = NULL;
-
-    return n;
 }
 
 int
@@ -106,7 +108,6 @@
 main(void)
 {
     struct client *client;
-    int n = 1;
 
     if (access("auth-test", F_OK) < 0) {
         if (access("nnrpd/auth-test", F_OK) == 0) {
@@ -117,25 +118,25 @@
     }
     client = client_new();
 
-    test_init(11 * 6);
+    plan(11 * 6);
 
-    n = ok_external(n, client, "okay", "tester", NULL);
-    n = ok_external(n, client, "garbage", "tester", NULL);
-    n = ok_external(n, client, "error", NULL,
-                    "example.com auth: program error: This is an error\n");
-    n = ok_external(n, client, "interspersed", "tester",
-                    "example.com auth: program error: This is an error\n");
-    n = ok_external(n, client, "empty", NULL, NULL);
-    n = ok_external(n, client, "empty-error", NULL,
-                    "example.com auth: program exited with status 1\n");
-    n = ok_external(n, client, "okay-error", NULL,
-                    "example.com auth: program exited with status 1\n");
-    n = ok_external(n, client, "signal", NULL,
-                    "example.com auth: program caught signal 1\n");
-    n = ok_external(n, client, "newline", "tester", NULL);
-    n = ok_external(n, client, "partial", "tester", NULL);
-    ok_external(n, client, "partial-error", NULL,
-                    "example.com auth: program error: This is an error\n");
+    test_external(client, "okay", "tester", NULL);
+    test_external(client, "garbage", "tester", NULL);
+    test_external(client, "error", NULL,
+                  "example.com auth: program error: This is an error\n");
+    test_external(client, "interspersed", "tester",
+                  "example.com auth: program error: This is an error\n");
+    test_external(client, "empty", NULL, NULL);
+    test_external(client, "empty-error", NULL,
+                  "example.com auth: program exited with status 1\n");
+    test_external(client, "okay-error", NULL,
+                  "example.com auth: program exited with status 1\n");
+    test_external(client, "signal", NULL,
+                  "example.com auth: program caught signal 1\n");
+    test_external(client, "newline", "tester", NULL);
+    test_external(client, "partial", "tester", NULL);
+    test_external(client, "partial-error", NULL,
+                  "example.com auth: program error: This is an error\n");
 
     return 0;
 }



More information about the inn-committers mailing list