1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
|
#include "hybbx/instance.h"
#include "hybbx/networks.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static int failures;
static void expect_int(const char *label, int got, int want)
{
if (got != want) {
fprintf(stderr, "FAIL %s: got %d want %d\n", label, got, want);
failures++;
}
}
static void test_enforce_hub(void)
{
hybbx_networks_config_t net;
hybbx_networks_config_defaults(&net);
net.telnet = 1;
net.ax25 = 1;
net.baycom = 1;
net.ardop = 1;
net.crdop = 1;
net.websocket = 0;
net.mains_proxy = 0;
if (hybbx_networks_enforce_instance(&net) != HYBBX_OK) {
fprintf(stderr, "FAIL enforce returned error\n");
failures++;
return;
}
switch (hybbx_instance_role()) {
case HYBBX_INSTANCE_MAIN:
expect_int("main ax25 off", net.ax25, 0);
expect_int("main baycom off", net.baycom, 0);
expect_int("main ardop off", net.ardop, 0);
expect_int("main crdop off", net.crdop, 0);
expect_int("main telnet off", net.telnet, 0);
expect_int("main websocket on", net.websocket, 1);
expect_int("main circuit on", net.circuit, 1);
break;
case HYBBX_INSTANCE_SECONDARY:
expect_int("secondary ax25 kept", net.ax25, 1);
expect_int("secondary baycom kept", net.baycom, 1);
expect_int("secondary telnet off", net.telnet, 0);
expect_int("secondary websocket off", net.websocket, 0);
expect_int("secondary mains_proxy on", net.mains_proxy, 1);
break;
case HYBBX_INSTANCE_PROXY:
expect_int("proxy ax25 kept", net.ax25, 1);
expect_int("proxy baycom kept", net.baycom, 1);
expect_int("proxy ardop kept", net.ardop, 1);
expect_int("proxy crdop kept", net.crdop, 1);
expect_int("proxy websocket off", net.websocket, 0);
expect_int("proxy circuit on", net.circuit, 1);
break;
default:
fprintf(stderr, "FAIL unknown role\n");
failures++;
break;
}
}
static void test_plugin_allow_hub(void)
{
switch (hybbx_instance_role()) {
case HYBBX_INSTANCE_MAIN:
expect_int("main packet_radio denied",
hybbx_instance_plugin_allowed("packet_radio"), 0);
expect_int("main baycom denied",
hybbx_instance_plugin_allowed("baycom"), 0);
expect_int("main ardop denied",
hybbx_instance_plugin_allowed("ardop"), 0);
expect_int("main crdop denied",
hybbx_instance_plugin_allowed("crdop"), 0);
expect_int("main websocket", hybbx_instance_plugin_allowed("websocket"), 1);
expect_int("main telnet", hybbx_instance_plugin_allowed("telnet"), 0);
expect_int("main user_bbx", hybbx_instance_offers_user_bbx(), 1);
break;
case HYBBX_INSTANCE_SECONDARY:
expect_int("secondary packet_radio",
hybbx_instance_plugin_allowed("packet_radio"), 1);
expect_int("secondary baycom",
hybbx_instance_plugin_allowed("baycom"), 1);
expect_int("secondary mains_proxy",
hybbx_instance_plugin_allowed("mains_proxy"), 1);
expect_int("secondary telnet",
hybbx_instance_plugin_allowed("telnet"), 0);
expect_int("secondary websocket",
hybbx_instance_plugin_allowed("websocket"), 0);
expect_int("secondary user_bbx", hybbx_instance_offers_user_bbx(), 0);
break;
case HYBBX_INSTANCE_PROXY:
expect_int("proxy packet_radio",
hybbx_instance_plugin_allowed("packet_radio"), 1);
expect_int("proxy baycom",
hybbx_instance_plugin_allowed("baycom"), 1);
expect_int("proxy telnet", hybbx_instance_plugin_allowed("telnet"), 1);
expect_int("proxy ssh", hybbx_instance_plugin_allowed("ssh"), 1);
expect_int("proxy websocket",
hybbx_instance_plugin_allowed("websocket"), 0);
expect_int("proxy mains_proxy",
hybbx_instance_plugin_allowed("mains_proxy"), 1);
expect_int("proxy user_bbx", hybbx_instance_offers_user_bbx(), 0);
break;
default:
break;
}
}
static void test_standalone_main(void)
{
hybbx_networks_config_t net;
if (hybbx_instance_role() != HYBBX_INSTANCE_MAIN) {
return;
}
hybbx_instance_set_standalone(1);
expect_int("standalone baycom allowed",
hybbx_instance_plugin_allowed("baycom"), 1);
expect_int("standalone packet_radio allowed",
hybbx_instance_plugin_allowed("packet_radio"), 1);
expect_int("standalone ardop allowed",
hybbx_instance_plugin_allowed("ardop"), 1);
hybbx_networks_config_defaults(&net);
net.telnet = 1;
net.ax25 = 1;
net.baycom = 1;
net.ardop = 1;
net.crdop = 1;
if (hybbx_networks_enforce_instance(&net) != HYBBX_OK) {
fprintf(stderr, "FAIL standalone enforce returned error\n");
failures++;
hybbx_instance_set_standalone(0);
return;
}
expect_int("standalone ax25 kept", net.ax25, 1);
expect_int("standalone baycom kept", net.baycom, 1);
expect_int("standalone ardop kept", net.ardop, 1);
expect_int("standalone crdop kept", net.crdop, 1);
hybbx_instance_set_standalone(0);
}
int main(void)
{
printf("instance tests role=%s binary=%s\n",
hybbx_instance_role_name(),
hybbx_instance_binary_name());
test_plugin_allow_hub();
test_enforce_hub();
test_standalone_main();
return failures == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
}
|