1 | /* |
---|
2 | * Test suite for streaming data from the server. |
---|
3 | * |
---|
4 | * Written by Russ Allbery <rra@stanford.edu> |
---|
5 | * Copyright 2006, 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 | |
---|
13 | #include <signal.h> |
---|
14 | #include <sys/wait.h> |
---|
15 | |
---|
16 | #include <client/internal.h> |
---|
17 | #include <client/remctl.h> |
---|
18 | #include <tests/tap/basic.h> |
---|
19 | #include <tests/tap/kerberos.h> |
---|
20 | #include <tests/tap/remctl.h> |
---|
21 | #include <util/util.h> |
---|
22 | |
---|
23 | |
---|
24 | int |
---|
25 | main(void) |
---|
26 | { |
---|
27 | char *principal, *config, *path; |
---|
28 | struct remctl *r; |
---|
29 | struct remctl_output *output; |
---|
30 | pid_t remctld; |
---|
31 | const char *command[] = { "test", "streaming", NULL }; |
---|
32 | |
---|
33 | /* Unless we have Kerberos available, we can't really do anything. */ |
---|
34 | if (chdir(getenv("BUILD")) < 0) |
---|
35 | bail("can't chdir to BUILD"); |
---|
36 | principal = kerberos_setup(); |
---|
37 | if (principal == NULL) |
---|
38 | skip_all("Kerberos tests not configured"); |
---|
39 | plan(32); |
---|
40 | config = concatpath(getenv("SOURCE"), "data/conf-simple"); |
---|
41 | path = concatpath(getenv("BUILD"), "../server/remctld"); |
---|
42 | remctld = remctld_start(path, principal, config); |
---|
43 | |
---|
44 | /* First, version 2. */ |
---|
45 | r = remctl_new(); |
---|
46 | ok(r != NULL, "remctl_new"); |
---|
47 | ok(remctl_open(r, "localhost", 14373, principal), "remctl_open"); |
---|
48 | ok(remctl_command(r, command), "remctl_command"); |
---|
49 | output = remctl_output(r); |
---|
50 | ok(output != NULL, "output is not null"); |
---|
51 | is_int(REMCTL_OUT_OUTPUT, output->type, "...and is correct type"); |
---|
52 | is_int(23, output->length, "right length for first line"); |
---|
53 | if (output->data == NULL) |
---|
54 | ok(0, "...right data for first line"); |
---|
55 | else |
---|
56 | ok(memcmp("This is the first line\n", output->data, 23) == 0, |
---|
57 | "...right data for first line"); |
---|
58 | is_int(1, output->stream, "...right stream"); |
---|
59 | output = remctl_output(r); |
---|
60 | ok(output != NULL, "second output is not null"); |
---|
61 | is_int(REMCTL_OUT_OUTPUT, output->type, "...and is correct type"); |
---|
62 | is_int(24, output->length, "right length for second line"); |
---|
63 | if (output->data == NULL) |
---|
64 | ok(0, "...right data for second line"); |
---|
65 | else |
---|
66 | ok(memcmp("This is the second line\n", output->data, 24) == 0, |
---|
67 | "...right data for second line"); |
---|
68 | is_int(2, output->stream, "...right stream"); |
---|
69 | output = remctl_output(r); |
---|
70 | ok(output != NULL, "third output is not null"); |
---|
71 | is_int(REMCTL_OUT_OUTPUT, output->type, "...and is correct type"); |
---|
72 | is_int(23, output->length, "right length for third line"); |
---|
73 | if (output->data == NULL) |
---|
74 | ok(0, "...right data for third line"); |
---|
75 | else |
---|
76 | ok(memcmp("This is the third line\n", output->data, 23) == 0, |
---|
77 | "...right data for third line"); |
---|
78 | is_int(1, output->stream, "...right stream"); |
---|
79 | output = remctl_output(r); |
---|
80 | ok(output != NULL, "status is not null"); |
---|
81 | is_int(REMCTL_OUT_STATUS, output->type, "...and is right type"); |
---|
82 | is_int(0, output->status, "...and is right status"); |
---|
83 | remctl_close(r); |
---|
84 | |
---|
85 | /* Now, version 1. */ |
---|
86 | r = remctl_new(); |
---|
87 | r->protocol = 1; |
---|
88 | ok(r != NULL, "remctl_new protocol version 1"); |
---|
89 | ok(remctl_open(r, "localhost", 14373, principal), "remctl_open"); |
---|
90 | ok(remctl_command(r, command), "remctl_command"); |
---|
91 | output = remctl_output(r); |
---|
92 | ok(output != NULL, "output is not null"); |
---|
93 | is_int(REMCTL_OUT_OUTPUT, output->type, "...and is right type"); |
---|
94 | is_int(70, output->length, "...and right length"); |
---|
95 | if (output->data == NULL) |
---|
96 | ok(0, "...and right data"); |
---|
97 | else |
---|
98 | ok(memcmp("This is the first line\nThis is the second line\n" |
---|
99 | "This is the third line\n", output->data, 70) == 0, |
---|
100 | "...and right data"); |
---|
101 | is_int(1, output->stream, "...and right stream"); |
---|
102 | output = remctl_output(r); |
---|
103 | ok(output != NULL, "status token is not null"); |
---|
104 | is_int(REMCTL_OUT_STATUS, output->type, "...and is right type"); |
---|
105 | is_int(0, output->status, "...and is right status"); |
---|
106 | remctl_close(r); |
---|
107 | |
---|
108 | remctld_stop(remctld); |
---|
109 | kerberos_cleanup(); |
---|
110 | return 0; |
---|
111 | } |
---|