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

INN Commit rra at isc.org
Sun Nov 15 21:11:34 UTC 2020


    Date: Sunday, November 15, 2020 @ 13:11:33
  Author: eagle
Revision: 10403

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:
  trunk/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-11-13 22:20:07 UTC (rev 10402)
+++ auth-ext-t.c	2020-11-15 21:11:33 UTC (rev 10403)
@@ -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