source: web/old/remctl-2.14/tests/server/logging-t.c @ f6f3e91

web
Last change on this file since f6f3e91 was f6f3e91, checked in by Jessica B. Hamrick <jhamrick@…>, 15 years ago

Preserve directory hierarchy (not sure what happened to it)

  • Property mode set to 100644
File size: 3.6 KB
Line 
1/*
2 * Test suite for server command logging.
3 *
4 * Written by Russ Allbery <rra@stanford.edu>
5 * Copyright 2009 Board of Trustees, Leland Stanford Jr. University
6 *
7 * See LICENSE for licensing terms.
8 */
9
10#include <config.h>
11#include <portable/system.h>
12#include <portable/uio.h>
13
14#include <server/internal.h>
15#include <tests/tap/basic.h>
16#include <tests/tap/messages.h>
17#include <util/util.h>
18
19
20int
21main(void)
22{
23    struct confline confline = {
24        NULL, 0, NULL, NULL, NULL, NULL, NULL, 0, NULL
25    };
26    struct iovec **command;
27    int i;
28
29    plan(8);
30
31    /* Command without subcommand. */
32    command = xcalloc(5, sizeof(struct iovec *));
33    command[0] = xmalloc(sizeof(struct iovec));
34    command[0]->iov_base = xstrdup("foo");
35    command[0]->iov_len = strlen("foo");
36    command[1] = NULL;
37    errors_capture();
38    server_log_command(command, &confline, "test@EXAMPLE.ORG");
39    is_string("COMMAND from test@EXAMPLE.ORG: foo\n", errors,
40              "command without subcommand logging");
41
42    /* Filtering of non-printable characters. */
43    command[1] = xmalloc(sizeof(struct iovec));
44    command[1]->iov_base = xstrdup("f\1o\33o\37o\177");
45    command[1]->iov_len = strlen("f\1o\33o\37o\177");
46    command[2] = NULL;
47    errors_capture();
48    server_log_command(command, &confline, "test");
49    is_string("COMMAND from test: foo f.o.o.o.\n", errors,
50              "logging of unprintable characters");
51
52    /* Simple command. */
53    for (i = 2; i < 5; i++)
54        command[i] = xmalloc(sizeof(struct iovec));
55    free(command[1]->iov_base);
56    command[1]->iov_base = xstrdup("bar");
57    command[1]->iov_len = strlen("bar");
58    command[2]->iov_base = xstrdup("arg1");
59    command[2]->iov_len = strlen("arg1");
60    command[3]->iov_base = xstrdup("arg2");
61    command[3]->iov_len = strlen("arg2");
62    command[4] = NULL;
63    errors_capture();
64    server_log_command(command, &confline, "test@EXAMPLE.ORG");
65    is_string("COMMAND from test@EXAMPLE.ORG: foo bar arg1 arg2\n", errors,
66              "simple command logging");
67
68    /* Command with stdin numeric argument. */
69    confline.stdin_arg = 2;
70    errors_capture();
71    server_log_command(command, &confline, "test");
72    is_string("COMMAND from test: foo bar **DATA** arg2\n", errors,
73              "stdin argument");
74
75    /* Command with stdin set to "last". */
76    confline.stdin_arg = -1;
77    errors_capture();
78    server_log_command(command, &confline, "test");
79    is_string("COMMAND from test: foo bar arg1 **DATA**\n", errors,
80              "stdin last argument");
81
82    /* Logmask of a single argument. */
83    confline.stdin_arg = 0;
84    confline.logmask = xmalloc(2 * sizeof(unsigned int));
85    confline.logmask[0] = 2;
86    confline.logmask[1] = 0;
87    errors_capture();
88    server_log_command(command, &confline, "test");
89    is_string("COMMAND from test: foo bar **MASKED** arg2\n", errors,
90              "one masked parameter");
91
92    /* Logmask that doesn't apply to this command. */
93    confline.logmask[0] = 4;
94    errors_capture();
95    server_log_command(command, &confline, "test@EXAMPLE.ORG");
96    is_string("COMMAND from test@EXAMPLE.ORG: foo bar arg1 arg2\n", errors,
97              "mask that doesn't apply");
98
99    /* Logmask of the subcommand and multiple masks. */
100    free(confline.logmask);
101    confline.logmask = xmalloc(4 * sizeof(unsigned int));
102    confline.logmask[0] = 4;
103    confline.logmask[1] = 1;
104    confline.logmask[2] = 3;
105    confline.logmask[3] = 0;
106    errors_capture();
107    server_log_command(command, &confline, "test");
108    is_string("COMMAND from test: foo **MASKED** arg1 **MASKED**\n", errors,
109              "two masked parameters");
110
111    return 0;
112}
Note: See TracBrowser for help on using the repository browser.