1 | /* |
---|
2 | * Test suite for the server passing data to programs on standard input. |
---|
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 <client/remctl.h> |
---|
15 | #include <tests/tap/basic.h> |
---|
16 | #include <tests/tap/kerberos.h> |
---|
17 | #include <tests/tap/remctl.h> |
---|
18 | #include <util/util.h> |
---|
19 | |
---|
20 | |
---|
21 | /* |
---|
22 | * Run a stdin test case. Takes the principal to use for the connection, the |
---|
23 | * first argument to the stdin program, and the data to send and ensures that |
---|
24 | * the client returns "Okay". |
---|
25 | */ |
---|
26 | static void |
---|
27 | test_stdin(const char *principal, const char *test, const void *data, |
---|
28 | size_t length) |
---|
29 | { |
---|
30 | struct remctl *r; |
---|
31 | struct iovec *command; |
---|
32 | struct remctl_output *output; |
---|
33 | |
---|
34 | command = xcalloc(4, sizeof(struct iovec)); |
---|
35 | command[0].iov_base = (char *) "test"; |
---|
36 | command[0].iov_len = strlen("test"); |
---|
37 | command[1].iov_base = (char *) "stdin"; |
---|
38 | command[1].iov_len = strlen("stdin"); |
---|
39 | command[2].iov_base = (char *) test; |
---|
40 | command[2].iov_len = strlen(test); |
---|
41 | command[3].iov_base = (void *) data; |
---|
42 | command[3].iov_len = length; |
---|
43 | r = remctl_new(); |
---|
44 | if (r == NULL) |
---|
45 | bail("cannot create remctl client"); |
---|
46 | if (!remctl_open(r, "localhost", 14373, principal)) |
---|
47 | bail("can't connect: %s", remctl_error(r)); |
---|
48 | ok(remctl_commandv(r, command, 4), "sent command for %s", test); |
---|
49 | output = remctl_output(r); |
---|
50 | ok(output != NULL, "first output token is not null"); |
---|
51 | is_int(REMCTL_OUT_OUTPUT, output->type, "...and is right type"); |
---|
52 | is_int(strlen("Okay"), output->length, "...and is right length"); |
---|
53 | if (output->data == NULL) |
---|
54 | ok(0, "...and is right data"); |
---|
55 | else { |
---|
56 | notice("# data: %.*s", output->length, output->data); |
---|
57 | ok(memcmp("Okay", output->data, 4) == 0, "...and is right data"); |
---|
58 | } |
---|
59 | is_int(1, output->stream, "...and is right stream"); |
---|
60 | output = remctl_output(r); |
---|
61 | ok(output != NULL, "second output token is not null"); |
---|
62 | is_int(REMCTL_OUT_STATUS, output->type, "...and is right type"); |
---|
63 | is_int(0, output->status, "...and is right status"); |
---|
64 | remctl_close(r); |
---|
65 | } |
---|
66 | |
---|
67 | |
---|
68 | int |
---|
69 | main(void) |
---|
70 | { |
---|
71 | char *principal, *config, *path, *buffer; |
---|
72 | pid_t remctld; |
---|
73 | |
---|
74 | /* Unless we have Kerberos available, we can't really do anything. */ |
---|
75 | if (chdir(getenv("BUILD")) < 0) |
---|
76 | bail("can't chdir to BUILD"); |
---|
77 | principal = kerberos_setup(); |
---|
78 | if (principal == NULL) |
---|
79 | skip_all("Kerberos tests not configured"); |
---|
80 | plan(9 * 9); |
---|
81 | config = concatpath(getenv("SOURCE"), "data/conf-simple"); |
---|
82 | path = concatpath(getenv("BUILD"), "../server/remctld"); |
---|
83 | remctld = remctld_start(path, principal, config); |
---|
84 | |
---|
85 | /* Run the tests. */ |
---|
86 | test_stdin(principal, "read", "Okay", 4); |
---|
87 | test_stdin(principal, "write", "Okay", 4); |
---|
88 | test_stdin(principal, "exit", "Okay", 4); |
---|
89 | buffer = xmalloc(1024 * 1024); |
---|
90 | memset(buffer, 'A', 1024 * 1024); |
---|
91 | test_stdin(principal, "exit", buffer, 1024 * 1024); |
---|
92 | test_stdin(principal, "close", "Okay", 4); |
---|
93 | test_stdin(principal, "close", buffer, 1024 * 1024); |
---|
94 | test_stdin(principal, "nuls", "T\0e\0s\0t\0", 8); |
---|
95 | test_stdin(principal, "large", buffer, 1024 * 1024); |
---|
96 | test_stdin(principal, "delay", buffer, 1024 * 1024); |
---|
97 | |
---|
98 | remctld_stop(remctld); |
---|
99 | kerberos_cleanup(); |
---|
100 | return 0; |
---|
101 | } |
---|