• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

proftpd / proftpd / 30135626854

25 Jul 2026 12:15AM UTC coverage: 93.034% (+0.6%) from 92.428%
30135626854

push

github

51363 of 55209 relevant lines covered (93.03%)

219.82 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

99.94
/tests/api/jot.c
1
/*
2
 * ProFTPD - FTP server testsuite
3
 * Copyright (c) 2020-2026 The ProFTPD Project team
4
 *
5
 * This program is free software; you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License as published by
7
 * the Free Software Foundation; either version 2 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, see <https://www.gnu.org/licenses/>.
17
 *
18
 * As a special exemption, The ProFTPD Project team and other respective
19
 * copyright holders give permission to link this program with OpenSSL, and
20
 * distribute the resulting executable, without including the source code for
21
 * OpenSSL in the source distribution.
22
 */
23

24
/* Jot API tests. */
25

26
#include "tests.h"
27
#include "logfmt.h"
28
#include "json.h"
29
#include "jot.h"
30

31
extern pr_response_t *resp_list;
32

33
static pool *p = NULL;
34

35
static void set_up(void) {
36
  if (p == NULL) {
67✔
37
    p = permanent_pool = make_sub_pool(NULL);
67✔
38
  }
67✔
39

40
  if (getenv("TEST_VERBOSE") != NULL) {
41
    pr_trace_set_levels("jot", 1, 20);
67✔
42
  }
67✔
43

44
  init_fs();
45
  (void) var_init();
67✔
46
}
67✔
47

67✔
48
static void tear_down(void) {
49
  if (session.c != NULL) {
67✔
50
    pr_inet_close(p, session.c);
67✔
51
    session.c = NULL;
×
52
  }
×
53

54
  if (getenv("TEST_VERBOSE") != NULL) {
55
    pr_trace_set_levels("jot", 0, 0);
67✔
56
  }
67✔
57

58
  (void) var_free();
59

67✔
60
  if (p != NULL) {
61
    destroy_pool(p);
67✔
62
    p = permanent_pool = NULL;
67✔
63
  }
67✔
64
}
65

67✔
66
/* Tests */
67

68
static void assert_jot_class_filter(const char *class_name) {
69
  pr_jot_filters_t *filters;
14✔
70
  const char *rules;
14✔
71

14✔
72
  rules = class_name;
73

14✔
74
  mark_point();
75
  filters = pr_jot_filters_create(p, rules, PR_JOT_FILTER_TYPE_CLASSES, 0);
14✔
76
  ck_assert_msg(filters != NULL, "Failed to create filters from '%s': %s",
14✔
77
    rules, strerror(errno));
14✔
78
  (void) pr_jot_filters_destroy(filters);
79

14✔
80
  rules = pstrcat(p, "!", class_name, NULL);
81

14✔
82
  mark_point();
83
  filters = pr_jot_filters_create(p, rules, PR_JOT_FILTER_TYPE_CLASSES, 0);
14✔
84
  ck_assert_msg(filters != NULL, "Failed to create filters from '%s': %s",
14✔
85
    rules, strerror(errno));
14✔
86
  (void) pr_jot_filters_destroy(filters);
87
}
14✔
88

14✔
89
static void assert_jot_command_with_class_filter(const char *rules) {
90
  pr_jot_filters_t *filters;
10✔
91

10✔
92
  mark_point();
93
  filters = pr_jot_filters_create(p, rules,
10✔
94
    PR_JOT_FILTER_TYPE_COMMANDS_WITH_CLASSES, 0);
10✔
95
  ck_assert_msg(filters != NULL, "Failed to create filters from '%s': %s",
96
    rules, strerror(errno));
10✔
97
  (void) pr_jot_filters_destroy(filters);
98
}
10✔
99

10✔
100
START_TEST (jot_filters_create_test) {
101
  pr_jot_filters_t *filters;
1✔
102
  const char *rules;
1✔
103

1✔
104
  mark_point();
105
  filters = pr_jot_filters_create(NULL, NULL, 0, 0);
1✔
106
  ck_assert_msg(filters == NULL, "Failed to handle null pool");
1✔
107
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
108
    strerror(errno), errno);
1✔
109

110
  mark_point();
111
  filters = pr_jot_filters_create(p, NULL, 0, 0);
1✔
112
  ck_assert_msg(filters == NULL, "Failed to handle null rules");
1✔
113
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
114
    strerror(errno), errno);
1✔
115

116
  rules = "foo";
117

1✔
118
  mark_point();
119
  filters = pr_jot_filters_create(p, rules, -1, 0);
1✔
120
  ck_assert_msg(filters == NULL, "Failed to handle invalid rules type");
1✔
121
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
122
    strerror(errno), errno);
1✔
123

124
  /* Class rules */
125

126
  mark_point();
127
  filters = pr_jot_filters_create(p, rules, PR_JOT_FILTER_TYPE_CLASSES, 0);
1✔
128
  ck_assert_msg(filters == NULL, "Failed to handle invalid class name '%s'",
1✔
129
    rules);
1✔
130
  ck_assert_msg(errno == ENOENT, "Expected ENOENT (%d), got %s (%d)", ENOENT,
131
    strerror(errno), errno);
1✔
132

133
  assert_jot_class_filter("NONE");
134
  assert_jot_class_filter("ALL");
1✔
135
  assert_jot_class_filter("AUTH");
1✔
136
  assert_jot_class_filter("INFO");
1✔
137
  assert_jot_class_filter("DIRS");
1✔
138
  assert_jot_class_filter("READ");
1✔
139
  assert_jot_class_filter("WRITE");
1✔
140
  assert_jot_class_filter("SEC");
1✔
141
  assert_jot_class_filter("SECURE");
1✔
142
  assert_jot_class_filter("CONNECT");
1✔
143
  assert_jot_class_filter("EXIT");
1✔
144
  assert_jot_class_filter("DISCONNECT");
1✔
145
  assert_jot_class_filter("SSH");
1✔
146
  assert_jot_class_filter("SFTP");
1✔
147

1✔
148
  rules = "AUTH,!INFO";
149

1✔
150
  mark_point();
151
  filters = pr_jot_filters_create(p, rules, PR_JOT_FILTER_TYPE_CLASSES, 0);
1✔
152
  ck_assert_msg(filters != NULL, "Failed to create filters from '%s': %s",
1✔
153
    rules, strerror(errno));
1✔
154
  (void) pr_jot_filters_destroy(filters);
155

1✔
156
  rules = "!INFO|AUTH";
157

1✔
158
  mark_point();
159
  filters = pr_jot_filters_create(p, rules, PR_JOT_FILTER_TYPE_CLASSES, 0);
1✔
160
  ck_assert_msg(filters != NULL, "Failed to create filters from '%s': %s",
1✔
161
    rules, strerror(errno));
1✔
162
  (void) pr_jot_filters_destroy(filters);
163

1✔
164
  /* Command rules */
165

166
  rules = "FOO,BAR";
167
  mark_point();
1✔
168
  filters = pr_jot_filters_create(p, rules, PR_JOT_FILTER_TYPE_COMMANDS, 0);
1✔
169
  ck_assert_msg(filters != NULL, "Failed to create filters from '%s': %s",
1✔
170
    rules, strerror(errno));
1✔
171
  (void) pr_jot_filters_destroy(filters);
172

1✔
173
  rules = "APPE,RETR,STOR,STOU";
174
  mark_point();
1✔
175
  filters = pr_jot_filters_create(p, rules, PR_JOT_FILTER_TYPE_COMMANDS, 0);
1✔
176
  ck_assert_msg(filters != NULL, "Failed to create filters from '%s': %s",
1✔
177
    rules, strerror(errno));
1✔
178
  (void) pr_jot_filters_destroy(filters);
179

1✔
180
  /* Rules with commands and classes */
181

182
  rules = "CONNECT,RETR,STOR,DISCONNECT";
183
  assert_jot_command_with_class_filter(rules);
1✔
184

1✔
185
  rules = "RETR,STOR,AUTH";
186
  assert_jot_command_with_class_filter(rules);
1✔
187

1✔
188
  rules = "RETR,STOR,DIRS";
189
  assert_jot_command_with_class_filter(rules);
1✔
190

1✔
191
  rules = "RETR,STOR,INFO";
192
  assert_jot_command_with_class_filter(rules);
1✔
193

1✔
194
  rules = "RETR,STOR,MISC";
195
  assert_jot_command_with_class_filter(rules);
1✔
196

1✔
197
  rules = "READ,RETR,STOR";
198
  assert_jot_command_with_class_filter(rules);
1✔
199

1✔
200
  rules = "RETR,SEC,STOR";
201
  assert_jot_command_with_class_filter(rules);
1✔
202

1✔
203
  rules = "RETR,SFTP,STOR";
204
  assert_jot_command_with_class_filter(rules);
1✔
205

1✔
206
  rules = "RETR,SSH,STOR";
207
  assert_jot_command_with_class_filter(rules);
1✔
208

1✔
209
  rules = "RETR,STOR,WRITE";
210
  assert_jot_command_with_class_filter(rules);
1✔
211

1✔
212
  rules = "ALL";
213
  mark_point();
1✔
214
  filters = pr_jot_filters_create(p, rules,
1✔
215
    PR_JOT_FILTER_TYPE_COMMANDS_WITH_CLASSES, 0);
1✔
216
  ck_assert_msg(filters != NULL, "Failed to create filters from '%s': %s",
217
    rules, strerror(errno));
1✔
218
  (void) pr_jot_filters_destroy(filters);
219

1✔
220
  /* Flags */
221

222
  rules = "ALL";
223
  mark_point();
1✔
224
  filters = pr_jot_filters_create(p, rules,
1✔
225
    PR_JOT_FILTER_TYPE_COMMANDS_WITH_CLASSES, PR_JOT_FILTER_FL_ALL_INCL_ALL);
1✔
226
  ck_assert_msg(filters != NULL, "Failed to create filters from '%s': %s",
227
    rules, strerror(errno));
1✔
228
  (void) pr_jot_filters_destroy(filters);
229
}
1✔
230
END_TEST
1✔
231

232
START_TEST (jot_filters_destroy_test) {
233
  int res;
1✔
234
  pr_jot_filters_t *filters;
1✔
235

1✔
236
  mark_point();
237
  res = pr_jot_filters_destroy(NULL);
1✔
238
  ck_assert_msg(res < 0, "Failed to handle null filters");
1✔
239
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
240
    strerror(errno), errno);
1✔
241

242
  filters = pr_jot_filters_create(p, "NONE", PR_JOT_FILTER_TYPE_CLASSES, 0);
243

1✔
244
  mark_point();
245
  res = pr_jot_filters_destroy(filters);
1✔
246
  ck_assert_msg(res == 0, "Failed to destroy filters: %s", strerror(errno));
1✔
247
}
1✔
248
END_TEST
1✔
249

250
START_TEST (jot_filters_include_classes_test) {
251
  int res;
1✔
252
  pr_jot_filters_t *filters;
1✔
253

1✔
254
  mark_point();
255
  res = pr_jot_filters_include_classes(NULL, 0);
1✔
256
  ck_assert_msg(res < 0, "Failed to handle null filters");
1✔
257
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
258
    strerror(errno), errno);
1✔
259

260
  filters = pr_jot_filters_create(p, "NONE", PR_JOT_FILTER_TYPE_CLASSES, 0);
261

1✔
262
  res = pr_jot_filters_include_classes(filters, CL_ALL);
263
  ck_assert_msg(res == FALSE, "Expected FALSE, got %d", res);
1✔
264

1✔
265
  res = pr_jot_filters_include_classes(filters, CL_NONE);
266
  ck_assert_msg(res == TRUE, "Expected TRUE, got %d", res);
1✔
267

1✔
268
  res = pr_jot_filters_destroy(filters);
269
  ck_assert_msg(res == 0, "Failed to destroy filters: %s", strerror(errno));
1✔
270
}
1✔
271
END_TEST
1✔
272

273
START_TEST (jot_filters_parse_sifts_test) {
274
  int res;
275
  pr_jot_filters_t *filters;
276

277
  mark_point();
278
  res = pr_jot_filters_parse_sifts(NULL, NULL, NULL, 0);
55✔
279
  ck_assert_msg(res < 0, "Failed to handle null pool");
280
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
55✔
281
    strerror(errno), errno);
55✔
282

283
  mark_point();
284
  res = pr_jot_filters_parse_sifts(p, NULL, NULL, 0);
5✔
285
  ck_assert_msg(res < 0, "Failed to handle null filter");
286
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
5✔
287
    strerror(errno), errno);
5✔
288

289
  mark_point();
290
  filters = pr_jot_filters_create(p, "NONE", PR_JOT_FILTER_TYPE_CLASSES, 0);
45✔
291

45✔
292
  mark_point();
45✔
293
  res = pr_jot_filters_parse_sifts(p, filters, NULL, 0);
294
  ck_assert_msg(res < 0, "Failed to handle null sifts");
295
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
296
    strerror(errno), errno);
1✔
297

1✔
298
  mark_point();
1✔
299
  res = pr_jot_filters_parse_sifts(p, filters, "A,!B,!C", 0);
300
  ck_assert_msg(res == 0, "Failed to handle sifts: %s", strerror(errno));
1✔
301

1✔
302
  res = pr_jot_filters_destroy(filters);
1✔
303
  ck_assert_msg(res == 0, "Failed to destroy filters: %s", strerror(errno));
1✔
304
}
305
END_TEST
306

1✔
307
static unsigned int parse_on_meta_count = 0;
308
static unsigned int parse_on_unknown_count = 0;
1✔
309
static unsigned int parse_on_other_count = 0;
1✔
310

1✔
311
static int parse_on_meta(pool *jot_pool, pr_jot_ctx_t *jot_ctx,
1✔
312
    unsigned char logfmt_id, const char *text, size_t text_len) {
313
  parse_on_meta_count++;
314
  return 0;
1✔
315
}
1✔
316

317
static int parse_on_unknown(pool *jot_pool, pr_jot_ctx_t *jot_ctx,
1✔
318
    const char *text, size_t text_len) {
1✔
319
  parse_on_unknown_count++;
1✔
320
  return 0;
321
}
1✔
322

323
static int parse_on_other(pool *jot_pool, pr_jot_ctx_t *jot_ctx, char ch) {
324
  parse_on_other_count++;
1✔
325
  return 0;
1✔
326
}
1✔
327

1✔
328
START_TEST (jot_parse_on_meta_test) {
329
  int res;
1✔
330
  pr_jot_ctx_t *jot_ctx;
1✔
331
  pr_jot_parsed_t *jot_parsed;
1✔
332

1✔
333
  mark_point();
334
  res = pr_jot_parse_on_meta(p, NULL, 0, NULL, 0);
335
  ck_assert_msg(res < 0, "Failed to handle null jot_ctx");
1✔
336
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
337
    strerror(errno), errno);
1✔
338

1✔
339
  jot_ctx = pcalloc(p, sizeof(pr_jot_ctx_t));
1✔
340

1✔
341
  mark_point();
342
  res = pr_jot_parse_on_meta(p, jot_ctx, 0, NULL, 0);
343
  ck_assert_msg(res < 0, "Failed to handle null jot_ctx->log");
1✔
344
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
345
    strerror(errno), errno);
346

1✔
347
  jot_parsed = pcalloc(p, sizeof(pr_jot_parsed_t));
1✔
348
  jot_ctx->log = jot_parsed;
1✔
349

350
  mark_point();
1✔
351
  res = pr_jot_parse_on_meta(p, jot_ctx, 0, NULL, 0);
352
  ck_assert_msg(res == 0, "Failed to handle parse_on_meta callback: %s",
353
    strerror(errno));
1✔
354
}
1✔
355
END_TEST
1✔
356

1✔
357
START_TEST (jot_parse_on_unknown_test) {
358
  int res;
1✔
359
  pr_jot_ctx_t *jot_ctx;
1✔
360
  pr_jot_parsed_t *jot_parsed;
1✔
361

1✔
362
  mark_point();
363
  res = pr_jot_parse_on_unknown(p, NULL, NULL, 0);
364
  ck_assert_msg(res < 0, "Failed to handle null jot_ctx");
1✔
365
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
366
    strerror(errno), errno);
1✔
367

1✔
368
  jot_ctx = pcalloc(p, sizeof(pr_jot_ctx_t));
1✔
369

1✔
370
  mark_point();
371
  res = pr_jot_parse_on_unknown(p, jot_ctx, NULL, 0);
372
  ck_assert_msg(res < 0, "Failed to handle null jot_ctx->log");
1✔
373
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
374
    strerror(errno), errno);
375

1✔
376
  jot_parsed = pcalloc(p, sizeof(pr_jot_parsed_t));
1✔
377
  jot_ctx->log = jot_parsed;
1✔
378

379
  mark_point();
1✔
380
  res = pr_jot_parse_on_unknown(p, jot_ctx, NULL, 0);
381
  ck_assert_msg(res == 0, "Failed to handle parse_on_unknown callback: %s",
382
    strerror(errno));
1✔
383
}
1✔
384
END_TEST
1✔
385

1✔
386
START_TEST (jot_parse_on_other_test) {
1✔
387
  int res;
388
  pr_jot_ctx_t *jot_ctx;
1✔
389
  pr_jot_parsed_t *jot_parsed;
1✔
390

1✔
391
  mark_point();
1✔
392
  res = pr_jot_parse_on_other(p, NULL, 0);
393
  ck_assert_msg(res < 0, "Failed to handle null jot_ctx");
394
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
395
    strerror(errno), errno);
1✔
396

1✔
397
  jot_ctx = pcalloc(p, sizeof(pr_jot_ctx_t));
1✔
398

399
  mark_point();
400
  res = pr_jot_parse_on_other(p, jot_ctx, 0);
1✔
401
  ck_assert_msg(res < 0, "Failed to handle null jot_ctx->log");
402
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
403
    strerror(errno), errno);
1✔
404

1✔
405
  jot_parsed = pcalloc(p, sizeof(pr_jot_parsed_t));
1✔
406
  jot_ctx->log = jot_parsed;
407

408
  mark_point();
1✔
409
  res = pr_jot_parse_on_other(p, jot_ctx, 0);
410
  ck_assert_msg(res == 0, "Failed to handle parse_on_other callback: %s",
1✔
411
    strerror(errno));
1✔
412
}
1✔
413
END_TEST
1✔
414

415
START_TEST (jot_parse_logfmt_test) {
416
  int res;
1✔
417
  const char *text;
418
  size_t text_len;
1✔
419
  pr_jot_ctx_t *jot_ctx;
1✔
420

1✔
421
  mark_point();
1✔
422
  res = pr_jot_parse_logfmt(NULL, NULL, NULL, NULL, NULL, NULL, 0);
423
  ck_assert_msg(res < 0, "Failed to handle null pool");
1✔
424
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
425
    strerror(errno), errno);
1✔
426

427
  mark_point();
428
  res = pr_jot_parse_logfmt(p, NULL, NULL, NULL, NULL, NULL, 0);
1✔
429
  ck_assert_msg(res < 0, "Failed to handle null text");
1✔
430
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
431
    strerror(errno), errno);
1✔
432

1✔
433
  text = "Hello, World!";
434

1✔
435
  mark_point();
1✔
436
  res = pr_jot_parse_logfmt(p, text, NULL, NULL, NULL, NULL, 0);
437
  ck_assert_msg(res < 0, "Failed to handle null ctx");
1✔
438
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
439
    strerror(errno), errno);
1✔
440

441
  jot_ctx = pcalloc(p, sizeof(pr_jot_ctx_t));
442

443
  mark_point();
1✔
444
  res = pr_jot_parse_logfmt(p, text, jot_ctx, NULL, NULL, NULL, 0);
1✔
445
  ck_assert_msg(res < 0, "Failed to handle null on_meta");
1✔
446
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
447
    strerror(errno), errno);
1✔
448

1✔
449
  parse_on_meta_count = parse_on_unknown_count = parse_on_other_count = 0;
450

1✔
451
  mark_point();
1✔
452
  res = pr_jot_parse_logfmt(p, text, jot_ctx, parse_on_meta, NULL, NULL, 0);
453
  ck_assert_msg(res == 0, "Failed to parse text '%s': %s", text, strerror(errno));
1✔
454
  ck_assert_msg(parse_on_meta_count == 0,
455
    "Expected on_meta count 0, got %u", parse_on_meta_count);
1✔
456
  ck_assert_msg(parse_on_unknown_count == 0,
457
    "Expected on_unknown count 0, got %u", parse_on_unknown_count);
458
  ck_assert_msg(parse_on_other_count == 0,
1✔
459
    "Expected on_other count 0, got %u", parse_on_other_count);
1✔
460

1✔
461
  parse_on_meta_count = parse_on_unknown_count = parse_on_other_count = 0;
462
  text_len = strlen(text);
1✔
463

1✔
464
  mark_point();
465
  res = pr_jot_parse_logfmt(p, text, jot_ctx, parse_on_meta, NULL,
1✔
466
    parse_on_other, 0);
1✔
467
  ck_assert_msg(res == 0, "Failed to parse text '%s': %s", text, strerror(errno));
468
  ck_assert_msg(parse_on_meta_count == 0,
1✔
469
    "Expected on_meta count 0, got %u", parse_on_meta_count);
470
  ck_assert_msg(parse_on_unknown_count == 0,
1✔
471
    "Expected on_unknown count 0, got %u", parse_on_unknown_count);
472
  ck_assert_msg((unsigned long) parse_on_other_count == text_len,
1✔
473
    "Expected on_other count %lu, got %u", (unsigned long) text_len,
474
    parse_on_other_count);
475

1✔
476
  parse_on_meta_count = parse_on_unknown_count = parse_on_other_count = 0;
1✔
477
  text = "%A %b %{epoch} %{unknown key here}, boo!";
1✔
478
  text_len = strlen(text);
1✔
479

1✔
480
  mark_point();
1✔
481
  res = pr_jot_parse_logfmt(p, text, jot_ctx, parse_on_meta, parse_on_unknown,
1✔
482
    parse_on_other, 0);
483
  ck_assert_msg(res == 0, "Failed to parse text '%s': %s", text, strerror(errno));
484
  ck_assert_msg(parse_on_meta_count == 3,
485
    "Expected on_meta count 0, got %u", parse_on_meta_count);
486
  ck_assert_msg(parse_on_unknown_count == 1,
487
    "Expected on_unknown count 0, got %u", parse_on_unknown_count);
488
  ck_assert_msg(parse_on_other_count == 9,
489
    "Expected on_other count 9, got %u", parse_on_other_count);
490

491
  parse_on_meta_count = parse_on_unknown_count = parse_on_other_count = 0;
492
  text = "%A %b %{epoch} %{unknown key here}, %{not closed";
493
  text_len = strlen(text);
494

495
  mark_point();
496
  res = pr_jot_parse_logfmt(p, text, jot_ctx, parse_on_meta, parse_on_unknown,
497
    parse_on_other, 0);
498
  ck_assert_msg(res == 0, "Failed to parse text '%s': %s", text, strerror(errno));
499
  ck_assert_msg(parse_on_meta_count == 3,
500
    "Expected on_meta count 0, got %u", parse_on_meta_count);
501
  ck_assert_msg(parse_on_unknown_count == 1,
502
    "Expected on_unknown count 0, got %u", parse_on_unknown_count);
503
  ck_assert_msg(parse_on_other_count == 17,
504
    "Expected on_other count 17, got %u", parse_on_other_count);
505
}
506
END_TEST
507

508
START_TEST (jot_parse_logfmt_short_vars_test) {
509
  register unsigned int i;
510
  int res;
511
  unsigned int text_count = 0;
512
  pr_jot_ctx_t *jot_ctx;
513
  const char *text;
514
  const char *texts[] = {
1✔
515
    "%A",
1✔
516
    "%D",
1✔
517
    "%E",
518
    "%F",
519
    "%H",
520
    "%I",
521
    "%J",
522
    "%L",
523
    "%O",
524
    "%R",
1✔
525
    "%S",
1✔
526
    "%T",
527
    "%U",
1✔
528
    "%V",
1✔
529
    "%a",
530
    "%b",
1✔
531
    "%c",
532
    "%d",
533
    "%f",
1✔
534
    "%g",
1✔
535
    "%h",
536
    "%l",
1✔
537
    "%m",
1✔
538
    "%p",
539
    "%r",
1✔
540
    "%s",
1✔
541
    "%u",
542
    "%v",
1✔
543
    "%w",
544
    NULL
1✔
545
  };
546

547
  jot_ctx = pcalloc(p, sizeof(pr_jot_ctx_t));
1✔
548
  text = "%X";
1✔
549
  parse_on_meta_count = parse_on_unknown_count = parse_on_other_count = 0;
550

30✔
551
  /* Here we expect an other count of 2, for the '%' and the 'X'.  This is
29✔
552
   * not a recognized/supported short variable, and definitely not a long
29✔
553
   * variable, and thus the entire text is treated as "other", for each
554
   * character.
29✔
555
   */
29✔
556

557
  mark_point();
29✔
558
  res = pr_jot_parse_logfmt(p, text, jot_ctx, parse_on_meta, NULL,
559
    parse_on_other, 0);
560
  ck_assert_msg(res == 0, "Failed to parse text '%s': %s", text, strerror(errno));
561
  ck_assert_msg(parse_on_meta_count == 0, "Expected on_meta count 0, got %u",
1✔
562
    parse_on_meta_count);
563
  ck_assert_msg(parse_on_other_count == 2, "Expected on_other count 2, got %u",
1✔
564
    parse_on_other_count);
565

1✔
566
  text = "%{0}";
567
  parse_on_meta_count = parse_on_unknown_count = parse_on_other_count = 0;
1✔
568

569
  mark_point();
570
  res = pr_jot_parse_logfmt(p, text, jot_ctx, parse_on_meta, parse_on_unknown,
5✔
571
    parse_on_other, 0);
572
  ck_assert_msg(res == 0, "Failed to parse text '%s': %s", text, strerror(errno));
5✔
573
  ck_assert_msg(parse_on_meta_count == 0,
5✔
574
    "Expected on_meta count 0, got %u", parse_on_meta_count);
575
  ck_assert_msg(parse_on_unknown_count == 1,
576
    "Expected on_unknown count 1, got %u", parse_on_unknown_count);
5✔
577
  ck_assert_msg(parse_on_other_count == 0,
578
    "Expected on_other count 0, got %u", parse_on_other_count);
579

1✔
580
  parse_on_meta_count = parse_on_unknown_count = parse_on_other_count = 0;
1✔
581
  text_count = 0;
1✔
582

1✔
583
  for (i = 0; texts[i]; i++) {
1✔
584
    text = (const char *) texts[i];
1✔
585
    text_count++;
1✔
586

587
    mark_point();
588
    res = pr_jot_parse_logfmt(p, text, jot_ctx, parse_on_meta, parse_on_unknown,
589
      parse_on_other, 0);
590
    ck_assert_msg(res == 0, "Failed to parse text '%s': %s", text,
591
      strerror(errno));
592
  }
593

594
  ck_assert_msg(parse_on_meta_count == text_count,
595
    "Expected on_meta count %d, got %u", text_count, parse_on_meta_count);
596
  ck_assert_msg(parse_on_unknown_count == 0,
597
    "Expected on_unknown count 0, got %u", parse_on_unknown_count);
598
  ck_assert_msg(parse_on_other_count == 0,
599
    "Expected on_other count 0, got %u", parse_on_other_count);
600
}
601
END_TEST
602

603
static int long_on_meta(pool *jot_pool, pr_jot_ctx_t *jot_ctx,
604
    unsigned char logfmt_id, const char *text, size_t text_len) {
605
  if (strncmp(text, "FOOBAR", text_len) == 0) {
606
    parse_on_meta_count++;
607
  }
608

1✔
609
  return 0;
1✔
610
}
1✔
611

612
START_TEST (jot_parse_logfmt_long_vars_test) {
1✔
613
  register unsigned int i;
1✔
614
  int res;
615
  unsigned int text_count = 0;
1✔
616
  pr_jot_ctx_t *jot_ctx;
1✔
617
  const char *text;
618
  const char *texts[] = {
1✔
619
    "%{basename}",
620
    "%{epoch}",
621
    "%{file-modified}",
1✔
622
    "%{file-offset}",
1✔
623
    "%{file-size}",
624
    "%{gid}",
1✔
625
    "%{iso8601}",
1✔
626
    "%{microsecs}",
627
    "%{millisecs}",
1✔
628
    "%{protocol}",
1✔
629
    "%{remote-port}",
630
    "%{transfer-failure}",
1✔
631
    "%{transfer-millisecs}",
632
    "%{transfer-port}",
633
    "%{transfer-speed}",
1✔
634
    "%{transfer-status}",
1✔
635
    "%{transfer-type}",
636
    "%{uid}",
1✔
637
    "%{version}",
1✔
638
    NULL
639
  };
1✔
640

1✔
641
  jot_ctx = pcalloc(p, sizeof(pr_jot_ctx_t));
642
  text = "%{env:FOOBAR}!";
1✔
643
  parse_on_meta_count = parse_on_unknown_count = parse_on_other_count = 0;
644

645
  mark_point();
1✔
646
  res = pr_jot_parse_logfmt(p, text, jot_ctx, long_on_meta, NULL,
1✔
647
    parse_on_other, 0);
648
  ck_assert_msg(res == 0, "Failed to parse text '%s': %s", text, strerror(errno));
20✔
649
  ck_assert_msg(parse_on_meta_count == 1, "Expected on_meta count 1, got %u",
19✔
650
    parse_on_meta_count);
19✔
651
  ck_assert_msg(parse_on_other_count == 1, "Expected on_other count 1, got %u",
652
    parse_on_other_count);
19✔
653

19✔
654
  text = "%{note:FOOBAR}!";
655
  parse_on_meta_count = parse_on_unknown_count = parse_on_other_count = 0;
19✔
656

657
  mark_point();
658
  res = pr_jot_parse_logfmt(p, text, jot_ctx, long_on_meta, NULL,
659
    parse_on_other, 0);
1✔
660
  ck_assert_msg(res == 0, "Failed to parse text '%s': %s", text, strerror(errno));
661
  ck_assert_msg(parse_on_meta_count == 1, "Expected on_meta count 1, got %u",
1✔
662
    parse_on_meta_count);
663
  ck_assert_msg(parse_on_other_count == 1, "Expected on_other count 1, got %u",
664
    parse_on_other_count);
1✔
665

1✔
666
  text = "%{time:FOOBAR}!";
667
  parse_on_meta_count = parse_on_unknown_count = parse_on_other_count = 0;
1✔
668

1✔
669
  mark_point();
670
  res = pr_jot_parse_logfmt(p, text, jot_ctx, long_on_meta, NULL,
1✔
671
    parse_on_other, 0);
1✔
672
  ck_assert_msg(res == 0, "Failed to parse text '%s': %s", text, strerror(errno));
673
  ck_assert_msg(parse_on_meta_count == 1, "Expected on_meta count 1, got %u",
1✔
674
    parse_on_meta_count);
675
  ck_assert_msg(parse_on_other_count == 1, "Expected on_other count 1, got %u",
676
    parse_on_other_count);
1✔
677

1✔
678
  parse_on_meta_count = parse_on_unknown_count = parse_on_other_count = 0;
679
  text_count = 0;
1✔
680

1✔
681
  for (i = 0; texts[i]; i++) {
682
    text = (const char *) texts[i];
1✔
683
    text_count++;
1✔
684

685
    mark_point();
1✔
686
    res = pr_jot_parse_logfmt(p, text, jot_ctx, parse_on_meta, NULL,
687
      parse_on_other, 0);
688
    ck_assert_msg(res == 0, "Failed to parse text '%s': %s", text,
1✔
689
      strerror(errno));
1✔
690
  }
691

692
  ck_assert_msg(parse_on_meta_count == text_count,
693
    "Expected on_meta count %d, got %u", text_count, parse_on_meta_count);
694
  ck_assert_msg(parse_on_other_count == 0, "Expected on_other count 0, got %u",
695
    parse_on_other_count);
1✔
696

1✔
697
  text = "%{FOOBAR}e";
698
  parse_on_meta_count = parse_on_unknown_count = parse_on_other_count = 0;
1✔
699

1✔
700
  mark_point();
701
  res = pr_jot_parse_logfmt(p, text, jot_ctx, long_on_meta, NULL,
1✔
702
    parse_on_other, 0);
703
  ck_assert_msg(res == 0, "Failed to parse text '%s': %s", text, strerror(errno));
1✔
704
  ck_assert_msg(parse_on_meta_count == 1, "Expected on_meta count 1, got %u",
705
    parse_on_meta_count);
1✔
706
  ck_assert_msg(parse_on_other_count == 0, "Expected on_other count 0, got %u",
707
    parse_on_other_count);
708

1✔
709
  text = "%{FOOBAR}t";
1✔
710
  parse_on_meta_count = parse_on_unknown_count = parse_on_other_count = 0;
1✔
711

1✔
712
  mark_point();
713
  res = pr_jot_parse_logfmt(p, text, jot_ctx, long_on_meta, NULL,
1✔
714
    parse_on_other, 0);
1✔
715
  ck_assert_msg(res == 0, "Failed to parse text '%s': %s", text, strerror(errno));
1✔
716
  ck_assert_msg(parse_on_meta_count == 1, "Expected on_meta count 1, got %u",
717
    parse_on_meta_count);
1✔
718
  ck_assert_msg(parse_on_other_count == 0, "Expected on_other count 0, got %u",
1✔
719
    parse_on_other_count);
720

1✔
721
  text = "%{FOOBAR}T";
1✔
722
  parse_on_meta_count = parse_on_unknown_count = parse_on_other_count = 0;
723

1✔
724
  /* Here we should see 1 unknown for "%{FOOBAR}", and 1 other for the
725
   * trailing "T".
1✔
726
   */
727

728
  mark_point();
1✔
729
  res = pr_jot_parse_logfmt(p, text, jot_ctx, long_on_meta, parse_on_unknown,
730
    parse_on_other, 0);
1✔
731
  ck_assert_msg(res == 0, "Failed to parse text '%s': %s", text, strerror(errno));
1✔
732
  ck_assert_msg(parse_on_meta_count == 0,
733
    "Expected on_meta count 0, got %u", parse_on_meta_count);
1✔
734
  ck_assert_msg(parse_on_unknown_count == 1,
1✔
735
    "Expected on_unknown count 1, got %u", parse_on_unknown_count);
736
  ck_assert_msg(parse_on_other_count == 1,
1✔
737
    "Expected on_other count 1, got %u", parse_on_other_count);
738
}
1✔
739
END_TEST
740

1✔
741
START_TEST (jot_parse_logfmt_custom_vars_test) {
742
  int res;
743
  pr_jot_ctx_t *jot_ctx;
744
  const char *text;
745

746
  jot_ctx = pcalloc(p, sizeof(pr_jot_ctx_t));
747
  text = "%{0}";
27✔
748
  parse_on_meta_count = parse_on_unknown_count = parse_on_other_count = 0;
749

27✔
750
  mark_point();
27✔
751
  res = pr_jot_parse_logfmt(p, text, jot_ctx, parse_on_meta, parse_on_unknown,
752
    parse_on_other, 0);
753
  ck_assert_msg(res == 0, "Failed to parse text '%s': %s", text, strerror(errno));
29✔
754
  ck_assert_msg(parse_on_meta_count == 0,
755
    "Expected on_meta count 0, got %u", parse_on_meta_count);
29✔
756
  ck_assert_msg(parse_on_unknown_count == 1,
29✔
757
    "Expected on_unknown count 1, got %u", parse_on_unknown_count);
758
  ck_assert_msg(parse_on_other_count == 0,
759
    "Expected on_other count 0, got %u", parse_on_other_count);
1✔
760

1✔
761
  parse_on_meta_count = parse_on_unknown_count = parse_on_other_count = 0;
1✔
762

1✔
763
  mark_point();
764
  res = pr_jot_parse_logfmt(p, text, jot_ctx, parse_on_meta, parse_on_unknown,
1✔
765
    parse_on_other, PR_JOT_LOGFMT_PARSE_FL_UNKNOWN_AS_CUSTOM);
1✔
766
  ck_assert_msg(res == 0, "Failed to parse text '%s': %s", text, strerror(errno));
767
  ck_assert_msg(parse_on_meta_count == 1,
1✔
768
    "Expected on_meta count 1, got %u", parse_on_meta_count);
1✔
769
  ck_assert_msg(parse_on_unknown_count == 0,
770
    "Expected on_unknown count 0, got %u", parse_on_unknown_count);
771
  ck_assert_msg(parse_on_other_count == 0,
1✔
772
    "Expected on_other count 0, got %u", parse_on_other_count);
1✔
773
}
1✔
774
END_TEST
1✔
775

776
static unsigned int resolve_on_meta_count = 0;
777
static unsigned int resolve_on_default_count = 0;
1✔
778
static unsigned int resolve_on_other_count = 0;
779

1✔
780
static int resolve_id_on_meta(pool *jot_pool, pr_jot_ctx_t *jot_ctx,
1✔
781
    unsigned char logfmt_id, const char *jot_hint, const void *jot_val) {
1✔
782
  resolve_on_meta_count++;
1✔
783
  return 0;
784
}
785

1✔
786
static int resolve_id_on_default(pool *jot_pool, pr_jot_ctx_t *jot_ctx,
787
    unsigned char logfmt_id) {
1✔
788
  resolve_on_default_count++;
1✔
789
  return 0;
790
}
1✔
791

1✔
792
START_TEST (jot_resolve_logfmt_id_test) {
793
  int res;
794
  cmd_rec *cmd;
1✔
795
  unsigned char logfmt_id;
796

1✔
797
  mark_point();
1✔
798
  res = pr_jot_resolve_logfmt_id(NULL, NULL, NULL, 0, NULL, 0, NULL, NULL,
799
    NULL);
1✔
800
  ck_assert_msg(res < 0, "Failed to handle null pool");
1✔
801
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
802
    strerror(errno), errno);
803

1✔
804
  mark_point();
805
  res = pr_jot_resolve_logfmt_id(p, NULL, NULL, 0, NULL, 0, NULL, NULL, NULL);
1✔
806
  ck_assert_msg(res < 0, "Failed to handle null cmd");
1✔
807
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
808
    strerror(errno), errno);
1✔
809

1✔
810
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
811

1✔
812
  mark_point();
813
  res = pr_jot_resolve_logfmt_id(p, cmd, NULL, 0, NULL, 0, NULL, NULL, NULL);
814
  ck_assert_msg(res < 0, "Failed to handle null on_meta");
1✔
815
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
816
    strerror(errno), errno);
1✔
817

1✔
818
  logfmt_id = 0;
819

1✔
820
  mark_point();
1✔
821
  res = pr_jot_resolve_logfmt_id(p, cmd, NULL, logfmt_id, NULL, 0, NULL,
1✔
822
    resolve_id_on_meta, NULL);
823
  ck_assert_msg(res < 0, "Failed to handle invalid logfmt_id %u", logfmt_id);
1✔
824
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
825
    strerror(errno), errno);
826

1✔
827
  logfmt_id = LOGFMT_META_START;
828

1✔
829
  mark_point();
830
  res = pr_jot_resolve_logfmt_id(p, cmd, NULL, logfmt_id, NULL, 0, NULL,
1✔
831
    resolve_id_on_meta, NULL);
832
  ck_assert_msg(res < 0, "Failed to handle invalid logfmt_id %u", logfmt_id);
1✔
833
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
834
    strerror(errno), errno);
835

1✔
836
  logfmt_id = LOGFMT_META_ARG_END;
1✔
837

1✔
838
  mark_point();
1✔
839
  res = pr_jot_resolve_logfmt_id(p, cmd, NULL, logfmt_id, NULL, 0, NULL,
1✔
840
    resolve_id_on_meta, NULL);
841
  ck_assert_msg(res < 0, "Failed to handle invalid logfmt_id %u", logfmt_id);
1✔
842
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
843
    strerror(errno), errno);
1✔
844
}
845
END_TEST
846

1✔
847
START_TEST (jot_resolve_logfmt_id_on_default_test) {
1✔
848
  int res;
849
  cmd_rec *cmd;
1✔
850
  unsigned char logfmt_id;
1✔
851

852
  mark_point();
1✔
853
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
854
  logfmt_id = LOGFMT_META_BASENAME;
1✔
855
  resolve_on_meta_count = resolve_on_default_count = 0;
856

1✔
857
  mark_point();
858
  res = pr_jot_resolve_logfmt_id(p, cmd, NULL, logfmt_id, NULL, 0, NULL,
859
    resolve_id_on_meta, resolve_id_on_default);
860
  ck_assert_msg(res == 0, "Failed to handle logfmt_id %u: %s", logfmt_id,
1✔
861
    strerror(errno));
1✔
862
  ck_assert_msg(resolve_on_meta_count == 0,
1✔
863
    "Expected on_meta count 0, got %u", resolve_on_meta_count);
1✔
864
  ck_assert_msg(resolve_on_default_count == 1,
865
    "Expected on_default count 1, got %u", resolve_on_default_count);
866
}
1✔
867
END_TEST
1✔
868

869
START_TEST (jot_resolve_logfmt_id_filters_test) {
1✔
870
  int res;
871
  cmd_rec *cmd;
1✔
872
  pr_jot_filters_t *jot_filters;
873
  unsigned char logfmt_id;
1✔
874

875
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
876
  cmd->cmd_class = CL_CONNECT;
877
  logfmt_id = LOGFMT_META_CONNECT;
1✔
878

1✔
879
  /* No filters; should be implicitly jottable. */
1✔
880
  resolve_on_meta_count = resolve_on_default_count = 0;
1✔
881
  jot_filters = NULL;
882

883
  mark_point();
1✔
884
  res = pr_jot_resolve_logfmt_id(p, cmd, jot_filters, logfmt_id, NULL, 0, NULL,
1✔
885
    resolve_id_on_meta, NULL);
886
  ck_assert_msg(res == 0, "Failed to handle logfmt_id %u: %s", logfmt_id,
1✔
887
    strerror(errno));
888
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
889
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
890
  ck_assert_msg(resolve_on_default_count == 0,
1✔
891
    "Expected on_default count 0, got %u", resolve_on_default_count);
892

893
  /* With an ALL filter, and no command class. */
894
  cmd->cmd_class = 0;
1✔
895
  logfmt_id = LOGFMT_META_COMMAND;
1✔
896
  resolve_on_meta_count = resolve_on_default_count = 0;
897
  jot_filters = pr_jot_filters_create(p, "ALL",
898
    PR_JOT_FILTER_TYPE_CLASSES, PR_JOT_FILTER_FL_ALL_INCL_ALL);
1✔
899

1✔
900
  mark_point();
901
  res = pr_jot_resolve_logfmt_id(p, cmd, jot_filters, logfmt_id, NULL, 0, NULL,
1✔
902
    resolve_id_on_meta, NULL);
1✔
903
  ck_assert_msg(res == 0, "Failed to handle logfmt_id %u: %s", logfmt_id,
904
    strerror(errno));
1✔
905
  ck_assert_msg(resolve_on_meta_count == 1,
906
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
907
  ck_assert_msg(resolve_on_default_count == 0,
908
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
909

1✔
910
  /* With explicit filters that allow the class. */
911
  cmd->cmd_class = CL_CONNECT;
912
  logfmt_id = LOGFMT_META_CONNECT;
1✔
913
  resolve_on_meta_count = resolve_on_default_count = 0;
1✔
914
  jot_filters = pr_jot_filters_create(p, "CONNECT",
915
    PR_JOT_FILTER_TYPE_CLASSES, 0);
1✔
916

1✔
917
  mark_point();
918
  res = pr_jot_resolve_logfmt_id(p, cmd, jot_filters, logfmt_id, NULL, 0, NULL,
1✔
919
    resolve_id_on_meta, NULL);
920
  ck_assert_msg(res == 0, "Failed to handle logfmt_id %u: %s", logfmt_id,
921
    strerror(errno));
922
  ck_assert_msg(resolve_on_meta_count == 1,
923
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
924
  ck_assert_msg(resolve_on_default_count == 0,
925
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
926

1✔
927
  /* With explicit filters that ignore the class. */
1✔
928
  resolve_on_meta_count = resolve_on_default_count = 0;
1✔
929
  jot_filters = pr_jot_filters_create(p, "!CONNECT",
930
    PR_JOT_FILTER_TYPE_CLASSES, 0);
931

1✔
932
  mark_point();
1✔
933
  res = pr_jot_resolve_logfmt_id(p, cmd, jot_filters, logfmt_id, NULL, 0, NULL,
934
    resolve_id_on_meta, NULL);
1✔
935
  ck_assert_msg(res < 0, "Failed to handle filtered logfmt_id %u", logfmt_id);
936
  ck_assert_msg(errno == EPERM, "Expected EPERM (%d), got %s (%d)", EPERM,
1✔
937
    strerror(errno), errno);
938
  ck_assert_msg(resolve_on_meta_count == 0,
1✔
939
    "Expected on_meta count 0, got %u", resolve_on_meta_count);
940

941
  /* With explicit filters that do not match the class. */
942
  resolve_on_meta_count = resolve_on_default_count = 0;
1✔
943
  jot_filters = pr_jot_filters_create(p, "DISCONNECT",
1✔
944
    PR_JOT_FILTER_TYPE_CLASSES, 0);
945

946
  mark_point();
1✔
947
  res = pr_jot_resolve_logfmt_id(p, cmd, jot_filters, logfmt_id, NULL, 0, NULL,
1✔
948
    resolve_id_on_meta, NULL);
949
  ck_assert_msg(res < 0, "Failed to handle filtered logfmt_id %u", logfmt_id);
1✔
950
  ck_assert_msg(errno == EPERM, "Expected EPERM (%d), got %s (%d)", EPERM,
1✔
951
    strerror(errno), errno);
952
  ck_assert_msg(resolve_on_meta_count == 0,
1✔
953
    "Expected on_meta count 0, got %u", resolve_on_meta_count);
954

955
  /* With explicit filters that allow the command. Note that this REQUIRES
956
   * that we use a known command, since allowed command comparisons are done
1✔
957
   * by ID.
1✔
958
   */
959
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "RANG"));
960
  cmd->cmd_class = CL_CONNECT;
1✔
961
  resolve_on_meta_count = resolve_on_default_count = 0;
1✔
962
  jot_filters = pr_jot_filters_create(p, "RANG",
963
    PR_JOT_FILTER_TYPE_COMMANDS, 0);
1✔
964

1✔
965
  mark_point();
966
  res = pr_jot_resolve_logfmt_id(p, cmd, jot_filters, logfmt_id, NULL, 0, NULL,
1✔
967
    resolve_id_on_meta, NULL);
968
  ck_assert_msg(res == 0, "Failed to handle logfmt_id %u: %s", logfmt_id,
1✔
969
    strerror(errno));
970
  ck_assert_msg(resolve_on_meta_count == 1,
971
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1✔
972
  ck_assert_msg(resolve_on_default_count == 0,
1✔
973
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
974

1✔
975
  /* With explicit filters that ignore the command. */
976
  resolve_on_meta_count = resolve_on_default_count = 0;
1✔
977
  jot_filters = pr_jot_filters_create(p, "!RANG",
1✔
978
    PR_JOT_FILTER_TYPE_COMMANDS, 0);
1✔
979

980
  mark_point();
1✔
981
  res = pr_jot_resolve_logfmt_id(p, cmd, jot_filters, logfmt_id, NULL, 0, NULL,
982
    resolve_id_on_meta, NULL);
1✔
983
  ck_assert_msg(res < 0, "Failed to handle filtered logfmt_id %u", logfmt_id);
1✔
984
  ck_assert_msg(errno == EPERM, "Expected EPERM (%d), got %s (%d)", EPERM,
985
    strerror(errno), errno);
1✔
986
  ck_assert_msg(resolve_on_meta_count == 0,
987
    "Expected on_meta count 0, got %u", resolve_on_meta_count);
1✔
988

989
  /* With explicit filters that do not match the command. */
1✔
990
  resolve_on_meta_count = resolve_on_default_count = 0;
991
  jot_filters = pr_jot_filters_create(p, "FOO",
992
    PR_JOT_FILTER_TYPE_COMMANDS, 0);
1✔
993

1✔
994
  mark_point();
995
  res = pr_jot_resolve_logfmt_id(p, cmd, jot_filters, logfmt_id, NULL, 0, NULL,
1✔
996
    resolve_id_on_meta, NULL);
1✔
997
  ck_assert_msg(res < 0, "Failed to handle filtered logfmt_id %u", logfmt_id);
998
  ck_assert_msg(errno == EPERM, "Expected EPERM (%d), got %s (%d)", EPERM,
1✔
999
    strerror(errno), errno);
1000
  ck_assert_msg(resolve_on_meta_count == 0,
1✔
1001
    "Expected on_meta count 0, got %u", resolve_on_meta_count);
1002
}
1✔
1003
END_TEST
1004

1✔
1005
START_TEST (jot_resolve_logfmt_id_connect_test) {
1006
  int res;
1007
  cmd_rec *cmd;
1✔
1008
  unsigned char logfmt_id;
1✔
1009

1✔
1010
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
1✔
1011
  cmd->cmd_class = CL_CONNECT;
1012
  logfmt_id = LOGFMT_META_CONNECT;
1✔
1013

1✔
1014
  resolve_on_meta_count = resolve_on_default_count = 0;
1✔
1015

1016
  mark_point();
1✔
1017
  res = pr_jot_resolve_logfmt_id(p, cmd, NULL, logfmt_id, NULL, 0, NULL,
1018
    resolve_id_on_meta, NULL);
1✔
1019
  ck_assert_msg(res == 0, "Failed to handle logfmt_id %u: %s", logfmt_id,
1✔
1020
    strerror(errno));
1021
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
1022
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1023
  ck_assert_msg(resolve_on_default_count == 0,
1✔
1024
    "Expected on_default count 0, got %u", resolve_on_default_count);
1025

1✔
1026
  resolve_on_meta_count = resolve_on_default_count = 0;
1027
  cmd->cmd_class = CL_DISCONNECT;
1028

1✔
1029
  mark_point();
1✔
1030
  res = pr_jot_resolve_logfmt_id(p, cmd, NULL, logfmt_id, NULL, 0, NULL,
1031
    resolve_id_on_meta, NULL);
1✔
1032
  ck_assert_msg(res == 0, "Failed to handle logfmt_id %u: %s", logfmt_id,
1✔
1033
    strerror(errno));
1034
  ck_assert_msg(resolve_on_meta_count == 0,
1✔
1035
    "Expected on_meta count 0, got %u", resolve_on_meta_count);
1036
  ck_assert_msg(resolve_on_default_count == 0,
1✔
1037
    "Expected on_default count 0, got %u", resolve_on_default_count);
1038
}
1✔
1039
END_TEST
1040

1✔
1041
START_TEST (jot_resolve_logfmt_id_disconnect_test) {
1042
  int res;
1043
  cmd_rec *cmd;
1✔
1044
  unsigned char logfmt_id;
1✔
1045

1✔
1046
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
1✔
1047
  cmd->cmd_class = CL_DISCONNECT;
1✔
1048
  logfmt_id = LOGFMT_META_DISCONNECT;
1✔
1049

1050
  resolve_on_meta_count = resolve_on_default_count = 0;
1✔
1051

1✔
1052
  mark_point();
1✔
1053
  res = pr_jot_resolve_logfmt_id(p, cmd, NULL, logfmt_id, NULL, 0, NULL,
1054
    resolve_id_on_meta, NULL);
1✔
1055
  ck_assert_msg(res == 0, "Failed to handle logfmt_id %u: %s", logfmt_id,
1✔
1056
    strerror(errno));
1✔
1057
  ck_assert_msg(resolve_on_meta_count == 1,
1058
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1✔
1059
  ck_assert_msg(resolve_on_default_count == 0,
1✔
1060
    "Expected on_default count 0, got %u", resolve_on_default_count);
1061

1✔
1062
  resolve_on_meta_count = resolve_on_default_count = 0;
1063
  cmd->cmd_class = CL_CONNECT;
1✔
1064

1065
  mark_point();
1✔
1066
  res = pr_jot_resolve_logfmt_id(p, cmd, NULL, logfmt_id, NULL, 0, NULL,
1067
    resolve_id_on_meta, NULL);
1✔
1068
  ck_assert_msg(res == 0, "Failed to handle logfmt_id %u: %s", logfmt_id,
1069
    strerror(errno));
1070
  ck_assert_msg(resolve_on_meta_count == 0,
1✔
1071
    "Expected on_meta count 0, got %u", resolve_on_meta_count);
1✔
1072
  ck_assert_msg(resolve_on_default_count == 0,
1✔
1073
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
1074
}
1✔
1075
END_TEST
1076

1✔
1077
START_TEST (jot_resolve_logfmt_id_custom_test) {
1✔
1078
  int res;
1079
  cmd_rec *cmd;
1080
  unsigned char logfmt_id;
54✔
1081
  const char *custom_data;
53✔
1082
  size_t custom_datalen;
1083

53✔
1084
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
53✔
1085
  cmd->cmd_class = CL_MISC;
1086
  logfmt_id = LOGFMT_META_CUSTOM;
53✔
1087

1088
  resolve_on_meta_count = resolve_on_default_count = 0;
1089
  custom_data = "%{0}";
1090
  custom_datalen = strlen(custom_data);
1✔
1091

1092
  mark_point();
1✔
1093
  res = pr_jot_resolve_logfmt_id(p, cmd, NULL, logfmt_id, custom_data,
1094
    custom_datalen, NULL, resolve_id_on_meta, NULL);
1✔
1095
  ck_assert_msg(res == 0, "Failed to handle logfmt_id %u: %s", logfmt_id,
1096
    strerror(errno));
1097
  ck_assert_msg(resolve_on_meta_count == 1,
178✔
1098
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1099
  ck_assert_msg(resolve_on_default_count == 0,
178✔
1100
    "Expected on_default count 0, got %u", resolve_on_default_count);
178✔
1101
}
1102
END_TEST
1103

74✔
1104
START_TEST (jot_resolve_logfmt_ids_test) {
1105
  register unsigned char i;
74✔
1106
  int res;
74✔
1107
  cmd_rec *cmd;
1108
  unsigned char logfmt_id;
1109

1✔
1110
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
1111
  resolve_on_meta_count = resolve_on_default_count = 0;
1✔
1112

1✔
1113
  /* Currently, the max known LogFormat meta/ID is 53 (DISCONNECT). */
1114
  for (i = 1; i < 54; i++) {
1115
    logfmt_id = i;
1✔
1116

1✔
1117
    mark_point();
1✔
1118
    res = pr_jot_resolve_logfmt_id(p, cmd, NULL, logfmt_id, NULL, 0, NULL,
1✔
1119
      resolve_id_on_meta, resolve_id_on_default);
1120
    ck_assert_msg(res == 0, "Failed to handle logfmt_id %u: %s", logfmt_id,
1✔
1121
      strerror(errno));
1✔
1122
  }
1✔
1123

1✔
1124
  ck_assert_msg(resolve_on_meta_count == 20,
1125
    "Expected on_meta count 20, got %u", resolve_on_meta_count);
1126
  ck_assert_msg(resolve_on_default_count == 28,
1✔
1127
    "Expected on_default count 28, got %u", resolve_on_default_count);
1✔
1128
}
1✔
1129
END_TEST
1✔
1130

1131
static int resolve_on_meta(pool *jot_pool, pr_jot_ctx_t *jot_ctx,
1132
    unsigned char logfmt_id, const char *jot_hint, const void *val) {
1✔
1133
  resolve_on_meta_count++;
1134
  return 0;
1✔
1135
}
1✔
1136

1✔
1137
static int resolve_on_default(pool *jot_pool, pr_jot_ctx_t *jot_ctx,
1✔
1138
    unsigned char logfmt_id) {
1139
  resolve_on_default_count++;
1140
  return 0;
1✔
1141
}
1142

1✔
1143
static int resolve_on_other(pool *jot_pool, pr_jot_ctx_t *jot_ctx,
1✔
1144
    unsigned char *text, size_t text_len) {
1✔
1145
  resolve_on_other_count++;
1✔
1146
  return 0;
1147
}
1148

1✔
1149
START_TEST (jot_resolve_logfmt_invalid_test) {
1✔
1150
  int res;
1151
  cmd_rec *cmd;
1✔
1152
  unsigned char *logfmt;
1✔
1153

1154
  mark_point();
1155
  res = pr_jot_resolve_logfmt(NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
1✔
1156
  ck_assert_msg(res < 0, "Failed to handle null pool");
1✔
1157
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
1158
    strerror(errno), errno);
1✔
1159

1160
  mark_point();
1✔
1161
  res = pr_jot_resolve_logfmt(p, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
1✔
1162
  ck_assert_msg(res < 0, "Failed to handle null cmd");
1✔
1163
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1164
    strerror(errno), errno);
1✔
1165

1✔
1166
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
1✔
1167

1✔
1168
  mark_point();
1✔
1169
  res = pr_jot_resolve_logfmt(p, cmd, NULL, NULL, NULL, NULL, NULL, NULL);
1170
  ck_assert_msg(res < 0, "Failed to handle null logfmt");
1✔
1171
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
1172
    strerror(errno), errno);
1173

1✔
1174
  logfmt = (unsigned char *) "";
1175

1✔
1176
  mark_point();
1177
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL, NULL, NULL, NULL);
1178
  ck_assert_msg(res < 0, "Failed to handle null on_meta");
1✔
1179
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
1180
    strerror(errno), errno);
1✔
1181

1✔
1182
  mark_point();
1✔
1183
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL, resolve_on_meta,
1✔
1184
    NULL, NULL);
1185
  ck_assert_msg(res == 0, "Failed to handle empty logfmt: %s", strerror(errno));
1✔
1186
}
1✔
1187
END_TEST
1188

1✔
1189
START_TEST (jot_resolve_logfmt_basename_test) {
1190
  int res;
1✔
1191
  cmd_rec *cmd;
1192
  unsigned char logfmt[3];
1193

1✔
1194
  logfmt[0] = LOGFMT_META_START;
1✔
1195
  logfmt[1] = LOGFMT_META_BASENAME;
1✔
1196
  logfmt[2] = 0;
1✔
1197

1✔
1198
  mark_point();
1✔
1199
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
1200
  cmd->cmd_class = CL_MISC;
1✔
1201
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
1202
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1203
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
1204
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1205
  ck_assert_msg(resolve_on_meta_count == 0,
1✔
1206
    "Expected on_meta count 0, got %u", resolve_on_meta_count);
1207
  ck_assert_msg(resolve_on_default_count == 1,
1208
    "Expected on_default count 1, got %u", resolve_on_default_count);
1✔
1209
  ck_assert_msg(resolve_on_other_count == 0,
1✔
1210
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
1211

1✔
1212
  mark_point();
1✔
1213
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "RNTO"));
1✔
1214
  cmd->cmd_class = CL_MISC;
1215
  cmd->arg = pstrdup(p, "/foo/bar");
1✔
1216
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
1217
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1218
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
1219
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1220
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
1221
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1222
  ck_assert_msg(resolve_on_default_count == 0,
1223
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
1224
  ck_assert_msg(resolve_on_other_count == 0,
1✔
1225
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
1226

1✔
1227
  mark_point();
1✔
1228
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "RETR"));
1✔
1229
  cmd->cmd_class = CL_MISC;
1230
  pr_table_add_dup(cmd->notes, "mod_xfer.retr-path", "foo", 0);
1✔
1231
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
1232
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1233
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
1234
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1235
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
1236
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1237
  ck_assert_msg(resolve_on_default_count == 0,
1238
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
1239
  ck_assert_msg(resolve_on_other_count == 0,
1✔
1240
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
1241

1✔
1242
  mark_point();
1✔
1243
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "APPE"));
1✔
1244
  cmd->cmd_class = CL_MISC;
1✔
1245
  pr_table_add_dup(cmd->notes, "mod_xfer.store-path", "foo", 0);
1246
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
1247
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
1248
    resolve_on_meta, resolve_on_default, resolve_on_other);
1249
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
1250
  ck_assert_msg(resolve_on_meta_count == 1,
1251
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1✔
1252
  ck_assert_msg(resolve_on_default_count == 0,
1253
    "Expected on_default count 0, got %u", resolve_on_default_count);
1254
  ck_assert_msg(resolve_on_other_count == 0,
1✔
1255
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
1256

1257
  mark_point();
1✔
1258
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "STOR"));
1✔
1259
  cmd->cmd_class = CL_MISC;
1✔
1260
  pr_table_add_dup(cmd->notes, "mod_xfer.store-path", "foo", 0);
1✔
1261
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
1262
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1263
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
1264
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
1265
  ck_assert_msg(resolve_on_meta_count == 1,
1266
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1✔
1267
  ck_assert_msg(resolve_on_default_count == 0,
1268
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
1269
  ck_assert_msg(resolve_on_other_count == 0,
1270
    "Expected on_other count 0, got %u", resolve_on_other_count);
1271

1✔
1272
  mark_point();
1✔
1273
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
1✔
1274
  cmd->cmd_class = CL_MISC;
1✔
1275
  session.xfer.p = p;
1✔
1276
  session.xfer.path = pstrdup(p, "/foo/bar/baz");
1277
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
1278
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
1279
    resolve_on_meta, resolve_on_default, resolve_on_other);
1280
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
1281
  ck_assert_msg(resolve_on_meta_count == 1,
1282
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1✔
1283
  ck_assert_msg(resolve_on_default_count == 0,
1284
    "Expected on_default count 0, got %u", resolve_on_default_count);
1285
  ck_assert_msg(resolve_on_other_count == 0,
1✔
1286
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
1287

1✔
1288
  session.xfer.p = NULL;
1✔
1289
  session.xfer.path = NULL;
1✔
1290

1291
  mark_point();
1✔
1292
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "CDUP"));
1✔
1293
  cmd->cmd_class = CL_MISC;
1294
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
1295
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1296
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
1297
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1298
  ck_assert_msg(resolve_on_meta_count == 1,
1299
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1✔
1300
  ck_assert_msg(resolve_on_default_count == 0,
1✔
1301
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
1302
  ck_assert_msg(resolve_on_other_count == 0,
1✔
1303
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
1304

1305
  mark_point();
1✔
1306
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "XCUP"));
1✔
1307
  cmd->cmd_class = CL_MISC;
1308
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
1309
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1310
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
1311
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1312
  ck_assert_msg(resolve_on_meta_count == 1,
1313
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1✔
1314
  ck_assert_msg(resolve_on_default_count == 0,
1✔
1315
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
1316
  ck_assert_msg(resolve_on_other_count == 0,
1✔
1317
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
1318

1319
  mark_point();
1✔
1320
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "PWD"));
1✔
1321
  cmd->cmd_class = CL_MISC;
1322
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
1323
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1324
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
1325
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1326
  ck_assert_msg(resolve_on_meta_count == 1,
1327
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1✔
1328
  ck_assert_msg(resolve_on_default_count == 0,
1✔
1329
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
1330
  ck_assert_msg(resolve_on_other_count == 0,
1✔
1331
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
1332

1✔
1333
  mark_point();
1334
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "XPWD"));
1✔
1335
  cmd->cmd_class = CL_MISC;
1✔
1336
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1337
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
1338
    resolve_on_meta, resolve_on_default, resolve_on_other);
1339
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
1340
  ck_assert_msg(resolve_on_meta_count == 1,
1341
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1342
  ck_assert_msg(resolve_on_default_count == 0,
1✔
1343
    "Expected on_default count 0, got %u", resolve_on_default_count);
1344
  ck_assert_msg(resolve_on_other_count == 0,
1✔
1345
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
1346

1347
  mark_point();
1✔
1348
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "CWD"));
1✔
1349
  cmd->cmd_class = CL_MISC;
1✔
1350
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1351
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
1352
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
1353
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1354
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
1355
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1356
  ck_assert_msg(resolve_on_default_count == 0,
1✔
1357
    "Expected on_default count 0, got %u", resolve_on_default_count);
1358
  ck_assert_msg(resolve_on_other_count == 0,
1359
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
1360

1✔
1361
  mark_point();
1362
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "XCWD"));
1✔
1363
  cmd->cmd_class = CL_MISC;
1✔
1364
  session.chroot_path = "/foo/bar";
1✔
1365
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1366
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
1367
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
1368
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1369
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
1370
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1371
  ck_assert_msg(resolve_on_default_count == 0,
1✔
1372
    "Expected on_default count 0, got %u", resolve_on_default_count);
1373
  ck_assert_msg(resolve_on_other_count == 0,
1374
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
1375

1✔
1376
  session.chroot_path = NULL;
1377

1✔
1378
  mark_point();
1✔
1379
  cmd = pr_cmd_alloc(p, 4, pstrdup(p, "SITE"), pstrdup(p, "chgrp"),
1✔
1380
    pstrdup(p, "foo"), pstrdup(p, "bar"));
1381
  cmd->cmd_class = CL_MISC;
1✔
1382
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
1383
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1384
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
1385
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1386
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
1387
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1388
  ck_assert_msg(resolve_on_default_count == 0,
1389
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
1390
  ck_assert_msg(resolve_on_other_count == 0,
1✔
1391
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
1392

1✔
1393
  mark_point();
1✔
1394
  cmd = pr_cmd_alloc(p, 4, pstrdup(p, "SITE"), pstrdup(p, "chmod"),
1✔
1395
    pstrdup(p, "foo"), pstrdup(p, "bar"));
1396
  cmd->cmd_class = CL_MISC;
1✔
1397
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
1398
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1399
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
1400
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1401
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
1402
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1403
  ck_assert_msg(resolve_on_default_count == 0,
1404
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
1405
  ck_assert_msg(resolve_on_other_count == 0,
1✔
1406
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
1407

1✔
1408
  mark_point();
1✔
1409
  cmd = pr_cmd_alloc(p, 4, pstrdup(p, "SITE"), pstrdup(p, "UTIME"),
1✔
1410
    pstrdup(p, "foo"), pstrdup(p, "bar"));
1411
  cmd->cmd_class = CL_MISC;
1✔
1412
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
1413
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1414
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
1415
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1416
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
1417
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1418
  ck_assert_msg(resolve_on_default_count == 0,
1419
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
1420
  ck_assert_msg(resolve_on_other_count == 0,
1✔
1421
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
1422

1✔
1423
  mark_point();
1✔
1424
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "DELE"));
1✔
1425
  cmd->cmd_class = CL_MISC;
1426
  cmd->arg = pstrdup(p, "/");
1✔
1427
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
1428
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1429
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
1430
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1431
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
1432
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1433
  ck_assert_msg(resolve_on_default_count == 0,
1434
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
1435
  ck_assert_msg(resolve_on_other_count == 0,
1✔
1436
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
1437

1✔
1438
  mark_point();
1✔
1439
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "LIST"));
1✔
1440
  cmd->cmd_class = CL_MISC;
1441
  cmd->arg = pstrdup(p, "/foo/bar/");
1✔
1442
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
1443
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1444
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
1445
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1446
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
1447
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1448
  ck_assert_msg(resolve_on_default_count == 0,
1449
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
1450
  ck_assert_msg(resolve_on_other_count == 0,
1✔
1451
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
1452

1✔
1453
  mark_point();
1✔
1454
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "MDTM"));
1✔
1455
  cmd->cmd_class = CL_MISC;
1456
  cmd->arg = pstrdup(p, "foo/bar");
1✔
1457
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
1458
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1459
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
1460
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1461
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
1462
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1463
  ck_assert_msg(resolve_on_default_count == 0,
1464
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
1465
  ck_assert_msg(resolve_on_other_count == 0,
1✔
1466
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
1467

1✔
1468
  mark_point();
1✔
1469
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "MKD"));
1✔
1470
  cmd->cmd_class = CL_MISC;
1471
  cmd->arg = pstrdup(p, "foo/bar");
1✔
1472
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
1473
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1474
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
1475
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1476
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
1477
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1478
  ck_assert_msg(resolve_on_default_count == 0,
1479
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
1480
  ck_assert_msg(resolve_on_other_count == 0,
1✔
1481
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
1482

1✔
1483
  mark_point();
1✔
1484
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "MLSD"));
1✔
1485
  cmd->cmd_class = CL_MISC;
1486
  cmd->arg = pstrdup(p, "foo/bar");
1✔
1487
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
1488
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1489
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
1490
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1491
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
1492
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1493
  ck_assert_msg(resolve_on_default_count == 0,
1494
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
1495
  ck_assert_msg(resolve_on_other_count == 0,
1✔
1496
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
1497

1✔
1498
  mark_point();
1✔
1499
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "MLST"));
1✔
1500
  cmd->cmd_class = CL_MISC;
1501
  cmd->arg = pstrdup(p, "foo/bar");
1✔
1502
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
1503
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1504
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
1505
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1506
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
1507
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1508
  ck_assert_msg(resolve_on_default_count == 0,
1509
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
1510
  ck_assert_msg(resolve_on_other_count == 0,
1✔
1511
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
1512

1✔
1513
  mark_point();
1✔
1514
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "NLST"));
1✔
1515
  cmd->cmd_class = CL_MISC;
1516
  cmd->arg = pstrdup(p, "foo/bar");
1✔
1517
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
1518
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1519
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
1520
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1521
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
1522
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1523
  ck_assert_msg(resolve_on_default_count == 0,
1524
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
1525
  ck_assert_msg(resolve_on_other_count == 0,
1✔
1526
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
1527

1✔
1528
  mark_point();
1✔
1529
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "RMD"));
1✔
1530
  cmd->cmd_class = CL_MISC;
1531
  cmd->arg = pstrdup(p, "foo/bar");
1✔
1532
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
1533
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1534
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
1535
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1536
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
1537
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1538
  ck_assert_msg(resolve_on_default_count == 0,
1539
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
1540
  ck_assert_msg(resolve_on_other_count == 0,
1✔
1541
    "Expected on_other count 0, got %u", resolve_on_other_count);
1542

1✔
1543
  mark_point();
1✔
1544
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "XMKD"));
1✔
1545
  cmd->cmd_class = CL_MISC;
1546
  cmd->arg = pstrdup(p, "foo/bar");
1✔
1547
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
1548
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1549
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
1550
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1551
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
1552
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1553
  ck_assert_msg(resolve_on_default_count == 0,
1✔
1554
    "Expected on_default count 0, got %u", resolve_on_default_count);
1555
  ck_assert_msg(resolve_on_other_count == 0,
1556
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
1557

1✔
1558
  mark_point();
1✔
1559
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "XRMD"));
1✔
1560
  cmd->cmd_class = CL_MISC;
1561
  cmd->arg = pstrdup(p, "foo/bar");
1✔
1562
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
1563
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
1564
    resolve_on_meta, resolve_on_default, resolve_on_other);
1565
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
1566
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
1567
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1✔
1568
  ck_assert_msg(resolve_on_default_count == 0,
1✔
1569
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
1570
  ck_assert_msg(resolve_on_other_count == 0,
1571
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
1572

1✔
1573
  mark_point();
1574
  cmd = pr_cmd_alloc(p, 3, pstrdup(p, "MFMT"), pstrdup(p, "foo"),
1✔
1575
    pstrdup(p, "BAR"));
1576
  cmd->cmd_class = CL_MISC;
1✔
1577
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1578
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1579
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
1580
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
1581
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
1582
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1✔
1583
  ck_assert_msg(resolve_on_default_count == 0,
1584
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
1585
  ck_assert_msg(resolve_on_other_count == 0,
1✔
1586
    "Expected on_other count 0, got %u", resolve_on_other_count);
1587
}
1✔
1588
END_TEST
1589

1✔
1590
START_TEST (jot_resolve_logfmt_bytes_sent_test) {
1591
  int res;
1592
  cmd_rec *cmd;
1✔
1593
  unsigned char logfmt[3];
1594

1✔
1595
  logfmt[0] = LOGFMT_META_START;
1✔
1596
  logfmt[1] = LOGFMT_META_BYTES_SENT;
1✔
1597
  logfmt[2] = 0;
1✔
1598

1✔
1599
  mark_point();
1600
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
1✔
1601
  cmd->cmd_class = CL_MISC;
1✔
1602
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1603
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
1604
    resolve_on_meta, resolve_on_default, resolve_on_other);
1605
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
1606
  ck_assert_msg(resolve_on_meta_count == 0,
1607
    "Expected on_meta count 0, got %u", resolve_on_meta_count);
1✔
1608
  ck_assert_msg(resolve_on_default_count == 1,
1609
    "Expected on_default count 1, got %u", resolve_on_default_count);
1610
  ck_assert_msg(resolve_on_other_count == 0,
1✔
1611
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
1612

1✔
1613
  mark_point();
1✔
1614
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1615
  session.xfer.p = p;
1✔
1616
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
1617
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
1618
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1619
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
1620
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1✔
1621
  ck_assert_msg(resolve_on_default_count == 0,
1✔
1622
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
1623
  ck_assert_msg(resolve_on_other_count == 0,
1✔
1624
    "Expected on_other count 0, got %u", resolve_on_other_count);
1625

1✔
1626
  session.xfer.p = NULL;
1✔
1627

1628
  mark_point();
1✔
1629
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1630
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "DELE"));
1✔
1631
  cmd->cmd_class = CL_MISC;
1632
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1633
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
1634
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
1635
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
1636
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1✔
1637
  ck_assert_msg(resolve_on_default_count == 0,
1✔
1638
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
1639
  ck_assert_msg(resolve_on_other_count == 0,
1640
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
1641
}
1✔
1642
END_TEST
1643

1✔
1644
START_TEST (jot_resolve_logfmt_filename_test) {
1645
  int res;
1✔
1646
  cmd_rec *cmd;
1647
  unsigned char logfmt[3];
1648

1✔
1649
  logfmt[0] = LOGFMT_META_START;
1✔
1650
  logfmt[1] = LOGFMT_META_FILENAME;
1✔
1651
  logfmt[2] = 0;
1✔
1652

1✔
1653
  mark_point();
1✔
1654
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1655
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
1✔
1656
  cmd->cmd_class = CL_MISC;
1✔
1657
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1658
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
1659
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1660
  ck_assert_msg(resolve_on_meta_count == 0,
1✔
1661
    "Expected on_meta count 0, got %u", resolve_on_meta_count);
1662
  ck_assert_msg(resolve_on_default_count == 1,
1663
    "Expected on_default count 1, got %u", resolve_on_default_count);
1✔
1664
  ck_assert_msg(resolve_on_other_count == 0,
1✔
1665
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
1666

1✔
1667
  mark_point();
1✔
1668
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
1669
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "RNTO"));
1670
  cmd->cmd_class = CL_MISC;
1✔
1671
  cmd->arg = pstrdup(p, "foo");
1✔
1672
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1673
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
1674
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1675
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
1676
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1677
  ck_assert_msg(resolve_on_default_count == 0,
1678
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
1679
  ck_assert_msg(resolve_on_other_count == 0,
1✔
1680
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
1681

1✔
1682
  mark_point();
1✔
1683
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
1684
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "RETR"));
1685
  cmd->cmd_class = CL_MISC;
1✔
1686
  pr_table_add_dup(cmd->notes, "mod_xfer.retr-path", "foobar", 0);
1✔
1687
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1688
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
1689
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1690
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
1691
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1692
  ck_assert_msg(resolve_on_default_count == 0,
1693
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
1694
  ck_assert_msg(resolve_on_other_count == 0,
1✔
1695
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
1696

1✔
1697
  mark_point();
1✔
1698
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
1699
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "APPE"));
1✔
1700
  cmd->cmd_class = CL_MISC;
1701
  pr_table_add_dup(cmd->notes, "mod_xfer.store-path", "foobar", 0);
1✔
1702
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
1703
    resolve_on_meta, resolve_on_default, resolve_on_other);
1704
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
1705
  ck_assert_msg(resolve_on_meta_count == 1,
1706
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1✔
1707
  ck_assert_msg(resolve_on_default_count == 0,
1708
    "Expected on_default count 0, got %u", resolve_on_default_count);
1709
  ck_assert_msg(resolve_on_other_count == 0,
1✔
1710
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
1711

1712
  mark_point();
1✔
1713
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
1714
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "STOR"));
1✔
1715
  cmd->cmd_class = CL_MISC;
1✔
1716
  pr_table_add_dup(cmd->notes, "mod_xfer.store-path", "foobar", 0);
1✔
1717
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1718
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
1719
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
1720
  ck_assert_msg(resolve_on_meta_count == 1,
1721
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1✔
1722
  ck_assert_msg(resolve_on_default_count == 0,
1723
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
1724
  ck_assert_msg(resolve_on_other_count == 0,
1725
    "Expected on_other count 0, got %u", resolve_on_other_count);
1726

1✔
1727
  mark_point();
1✔
1728
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
1729
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
1✔
1730
  cmd->cmd_class = CL_MISC;
1✔
1731
  session.xfer.p = p;
1732
  session.xfer.path = pstrdup(p, "foobar");
1✔
1733
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
1734
    resolve_on_meta, resolve_on_default, resolve_on_other);
1735
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
1736
  ck_assert_msg(resolve_on_meta_count == 1,
1737
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1✔
1738
  ck_assert_msg(resolve_on_default_count == 0,
1739
    "Expected on_default count 0, got %u", resolve_on_default_count);
1740
  ck_assert_msg(resolve_on_other_count == 0,
1✔
1741
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
1742

1✔
1743
  session.xfer.p = NULL;
1✔
1744
  session.xfer.path = NULL;
1✔
1745

1746
  mark_point();
1✔
1747
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
1748
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "CDUP"));
1749
  cmd->cmd_class = CL_MISC;
1✔
1750
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1751
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
1752
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1753
  ck_assert_msg(resolve_on_meta_count == 1,
1754
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1✔
1755
  ck_assert_msg(resolve_on_default_count == 0,
1✔
1756
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
1757
  ck_assert_msg(resolve_on_other_count == 0,
1✔
1758
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
1759

1760
  mark_point();
1✔
1761
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
1762
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "PWD"));
1763
  cmd->cmd_class = CL_MISC;
1✔
1764
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1765
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
1766
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1767
  ck_assert_msg(resolve_on_meta_count == 1,
1768
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1✔
1769
  ck_assert_msg(resolve_on_default_count == 0,
1✔
1770
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
1771
  ck_assert_msg(resolve_on_other_count == 0,
1✔
1772
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
1773

1774
  mark_point();
1✔
1775
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
1776
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "XCUP"));
1777
  cmd->cmd_class = CL_MISC;
1✔
1778
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1779
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
1780
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1781
  ck_assert_msg(resolve_on_meta_count == 1,
1782
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1✔
1783
  ck_assert_msg(resolve_on_default_count == 0,
1✔
1784
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
1785
  ck_assert_msg(resolve_on_other_count == 0,
1✔
1786
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
1787

1✔
1788
  mark_point();
1789
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
1790
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "XPWD"));
1✔
1791
  cmd->cmd_class = CL_MISC;
1792
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
1793
    resolve_on_meta, resolve_on_default, resolve_on_other);
1794
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
1795
  ck_assert_msg(resolve_on_meta_count == 1,
1796
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1797
  ck_assert_msg(resolve_on_default_count == 0,
1✔
1798
    "Expected on_default count 0, got %u", resolve_on_default_count);
1799
  ck_assert_msg(resolve_on_other_count == 0,
1✔
1800
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
1801

1✔
1802
  mark_point();
1803
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
1804
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "CWD"));
1✔
1805
  cmd->cmd_class = CL_MISC;
1806
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
1807
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
1808
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1809
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
1810
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1811
  ck_assert_msg(resolve_on_default_count == 0,
1✔
1812
    "Expected on_default count 0, got %u", resolve_on_default_count);
1813
  ck_assert_msg(resolve_on_other_count == 0,
1814
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
1815

1✔
1816
  mark_point();
1✔
1817
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1818
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "XCWD"));
1✔
1819
  cmd->cmd_class = CL_MISC;
1✔
1820
  session.chroot_path = "/foo/bar/baz";
1821
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
1822
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
1823
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1824
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
1825
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1826
  ck_assert_msg(resolve_on_default_count == 0,
1✔
1827
    "Expected on_default count 0, got %u", resolve_on_default_count);
1828
  ck_assert_msg(resolve_on_other_count == 0,
1829
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
1830

1✔
1831
  session.chroot_path = NULL;
1✔
1832

1833
  mark_point();
1✔
1834
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
1835
  cmd = pr_cmd_alloc(p, 4, pstrdup(p, "SITE"), pstrdup(p, "CHGRP"),
1836
    pstrdup(p, "foo"), pstrdup(p, "bar"));
1✔
1837
  cmd->cmd_class = CL_MISC;
1✔
1838
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1839
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
1840
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1841
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
1842
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1843
  ck_assert_msg(resolve_on_default_count == 0,
1844
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
1845
  ck_assert_msg(resolve_on_other_count == 0,
1✔
1846
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
1847

1✔
1848
  mark_point();
1✔
1849
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
1850
  cmd = pr_cmd_alloc(p, 4, pstrdup(p, "SITE"), pstrdup(p, "CHMOD"),
1851
    pstrdup(p, "foo"), pstrdup(p, "bar"));
1✔
1852
  cmd->cmd_class = CL_MISC;
1✔
1853
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1854
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
1855
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1856
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
1857
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1858
  ck_assert_msg(resolve_on_default_count == 0,
1859
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
1860
  ck_assert_msg(resolve_on_other_count == 0,
1✔
1861
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
1862

1✔
1863
  mark_point();
1✔
1864
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
1865
  cmd = pr_cmd_alloc(p, 4, pstrdup(p, "SITE"), pstrdup(p, "UTIME"),
1866
    pstrdup(p, "foo"), pstrdup(p, "bar"));
1✔
1867
  cmd->cmd_class = CL_MISC;
1✔
1868
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1869
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
1870
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1871
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
1872
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1873
  ck_assert_msg(resolve_on_default_count == 0,
1874
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
1875
  ck_assert_msg(resolve_on_other_count == 0,
1✔
1876
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
1877

1✔
1878
  mark_point();
1✔
1879
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
1880
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "DELE"));
1881
  cmd->cmd_class = CL_MISC;
1✔
1882
  cmd->arg = pstrdup(p, "foo bar");
1✔
1883
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1884
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
1885
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1886
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
1887
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1888
  ck_assert_msg(resolve_on_default_count == 0,
1889
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
1890
  ck_assert_msg(resolve_on_other_count == 0,
1✔
1891
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
1892

1✔
1893
  mark_point();
1✔
1894
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
1895
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "LIST"));
1896
  cmd->cmd_class = CL_MISC;
1✔
1897
  cmd->arg = pstrdup(p, "foo bar");
1✔
1898
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1899
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
1900
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1901
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
1902
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1903
  ck_assert_msg(resolve_on_default_count == 0,
1904
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
1905
  ck_assert_msg(resolve_on_other_count == 0,
1✔
1906
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
1907

1✔
1908
  mark_point();
1✔
1909
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
1910
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "MDTM"));
1911
  cmd->cmd_class = CL_MISC;
1✔
1912
  cmd->arg = pstrdup(p, "foo bar");
1✔
1913
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1914
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
1915
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1916
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
1917
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1918
  ck_assert_msg(resolve_on_default_count == 0,
1919
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
1920
  ck_assert_msg(resolve_on_other_count == 0,
1✔
1921
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
1922

1✔
1923
  mark_point();
1✔
1924
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
1925
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "MKD"));
1926
  cmd->cmd_class = CL_MISC;
1✔
1927
  cmd->arg = pstrdup(p, "foo bar");
1✔
1928
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1929
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
1930
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1931
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
1932
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1933
  ck_assert_msg(resolve_on_default_count == 0,
1934
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
1935
  ck_assert_msg(resolve_on_other_count == 0,
1✔
1936
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
1937

1✔
1938
  mark_point();
1✔
1939
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
1940
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "MLSD"));
1941
  cmd->cmd_class = CL_MISC;
1✔
1942
  cmd->arg = pstrdup(p, "foo bar");
1✔
1943
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1944
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
1945
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1946
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
1947
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1948
  ck_assert_msg(resolve_on_default_count == 0,
1949
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
1950
  ck_assert_msg(resolve_on_other_count == 0,
1✔
1951
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
1952

1✔
1953
  mark_point();
1✔
1954
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
1955
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "MLST"));
1956
  cmd->cmd_class = CL_MISC;
1✔
1957
  cmd->arg = pstrdup(p, "foo bar");
1✔
1958
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1959
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
1960
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1961
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
1962
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1963
  ck_assert_msg(resolve_on_default_count == 0,
1964
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
1965
  ck_assert_msg(resolve_on_other_count == 0,
1✔
1966
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
1967

1✔
1968
  mark_point();
1✔
1969
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
1970
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "NLST"));
1971
  cmd->cmd_class = CL_MISC;
1✔
1972
  cmd->arg = pstrdup(p, "foo bar");
1✔
1973
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1974
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
1975
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1976
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
1977
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1978
  ck_assert_msg(resolve_on_default_count == 0,
1979
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
1980
  ck_assert_msg(resolve_on_other_count == 0,
1✔
1981
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
1982

1✔
1983
  mark_point();
1✔
1984
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
1985
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "RMD"));
1986
  cmd->cmd_class = CL_MISC;
1✔
1987
  cmd->arg = pstrdup(p, "foo bar");
1✔
1988
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1989
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
1990
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1991
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
1992
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1993
  ck_assert_msg(resolve_on_default_count == 0,
1994
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
1995
  ck_assert_msg(resolve_on_other_count == 0,
1✔
1996
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
1997

1998
  mark_point();
1✔
1999
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
2000
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "XMKD"));
2001
  cmd->cmd_class = CL_MISC;
1✔
2002
  cmd->arg = pstrdup(p, "foo bar");
1✔
2003
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
2004
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
2005
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
2006
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
2007
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
2008
  ck_assert_msg(resolve_on_default_count == 0,
1✔
2009
    "Expected on_default count 0, got %u", resolve_on_default_count);
2010
  ck_assert_msg(resolve_on_other_count == 0,
2011
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
2012

1✔
2013
  mark_point();
1✔
2014
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
2015
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "XRMD"));
1✔
2016
  cmd->cmd_class = CL_MISC;
2017
  cmd->arg = pstrdup(p, "foo bar");
1✔
2018
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
2019
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
2020
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
2021
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
2022
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
2023
  ck_assert_msg(resolve_on_default_count == 0,
2024
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
2025
  ck_assert_msg(resolve_on_other_count == 0,
1✔
2026
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
2027

2028
  mark_point();
1✔
2029
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
2030
  cmd = pr_cmd_alloc(p, 3, pstrdup(p, "MFMT"), pstrdup(p, "foo"),
2031
    pstrdup(p, "BAR"));
1✔
2032
  cmd->cmd_class = CL_MISC;
2033
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
2034
    resolve_on_meta, resolve_on_default, resolve_on_other);
2035
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
2036
  ck_assert_msg(resolve_on_meta_count == 1,
2037
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1✔
2038
  ck_assert_msg(resolve_on_default_count == 0,
1✔
2039
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
2040
  ck_assert_msg(resolve_on_other_count == 0,
1✔
2041
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
2042
}
2043
END_TEST
1✔
2044

1✔
2045
START_TEST (jot_resolve_logfmt_file_modified_test) {
2046
  int res;
1✔
2047
  cmd_rec *cmd;
2048
  unsigned char logfmt[3];
1✔
2049
  char *modified;
2050

1✔
2051
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
2052
  cmd->cmd_class = CL_MISC;
2053
  logfmt[0] = LOGFMT_META_START;
1✔
2054
  logfmt[1] = LOGFMT_META_FILE_MODIFIED;
1✔
2055
  logfmt[2] = 0;
1✔
2056

1✔
2057
  /* First, without the "mod_xfer.file-modified" note. */
1✔
2058
  mark_point();
2059
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
2060
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
2061
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
2062
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
2063
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
2064
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
2065
  ck_assert_msg(resolve_on_default_count == 0,
2066
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
2067
  ck_assert_msg(resolve_on_other_count == 0,
1✔
2068
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
2069

2070
  /* Now, with the "mod_xfer.file-modified" note. */
1✔
2071
  mark_point();
1✔
2072
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
2073
  modified = "true";
1✔
2074
  pr_table_add_dup(cmd->notes, "mod_xfer.file-modified", modified, 0);
2075
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
2076
    resolve_on_meta, resolve_on_default, resolve_on_other);
2077
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
2078
  ck_assert_msg(resolve_on_meta_count == 1,
2079
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1✔
2080
  ck_assert_msg(resolve_on_default_count == 0,
1✔
2081
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
2082
  ck_assert_msg(resolve_on_other_count == 0,
1✔
2083
    "Expected on_other count 0, got %u", resolve_on_other_count);
2084
}
1✔
2085
END_TEST
2086

1✔
2087
START_TEST (jot_resolve_logfmt_file_offset_test) {
1✔
2088
  int res;
2089
  cmd_rec *cmd;
1✔
2090
  unsigned char logfmt[3];
2091
  double file_offset;
1✔
2092

2093
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
1✔
2094
  cmd->cmd_class = CL_MISC;
2095
  logfmt[0] = LOGFMT_META_START;
2096
  logfmt[1] = LOGFMT_META_FILE_OFFSET;
1✔
2097
  logfmt[2] = 0;
1✔
2098

1✔
2099
  /* First, without the "mod_xfer.file-offset" note. */
1✔
2100
  mark_point();
1✔
2101
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
2102
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
2103
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
2104
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
2105
  ck_assert_msg(resolve_on_meta_count == 0,
1✔
2106
    "Expected on_meta count 0, got %u", resolve_on_meta_count);
1✔
2107
  ck_assert_msg(resolve_on_default_count == 1,
2108
    "Expected on_default count 1, got %u", resolve_on_default_count);
2109
  ck_assert_msg(resolve_on_other_count == 0,
1✔
2110
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
2111

1✔
2112
  /* Now, with the "mod_xfer.file-offset" note. */
2113
  mark_point();
1✔
2114
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
2115
  file_offset = 2.0;
2116
  pr_table_add(cmd->notes, "mod_xfer.file-offset", &file_offset,
1✔
2117
    sizeof(file_offset));
2118
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
2119
    resolve_on_meta, resolve_on_default, resolve_on_other);
2120
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
2121
  ck_assert_msg(resolve_on_meta_count == 1,
2122
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1✔
2123
  ck_assert_msg(resolve_on_default_count == 0,
1✔
2124
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
2125
  ck_assert_msg(resolve_on_other_count == 0,
1✔
2126
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
2127
}
2128
END_TEST
1✔
2129

1✔
2130
START_TEST (jot_resolve_logfmt_file_size_test) {
2131
  int res;
1✔
2132
  cmd_rec *cmd;
2133
  unsigned char logfmt[3];
1✔
2134
  off_t file_size;
2135

1✔
2136
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
2137
  cmd->cmd_class = CL_MISC;
2138
  logfmt[0] = LOGFMT_META_START;
1✔
2139
  logfmt[1] = LOGFMT_META_FILE_SIZE;
1✔
2140
  logfmt[2] = 0;
1✔
2141

1✔
2142
  /* First, without the "mod_xfer.file-size" note. */
1✔
2143
  mark_point();
2144
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
2145
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
2146
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
2147
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
2148
  ck_assert_msg(resolve_on_meta_count == 0,
1✔
2149
    "Expected on_meta count 0, got %u", resolve_on_meta_count);
2150
  ck_assert_msg(resolve_on_default_count == 1,
1✔
2151
    "Expected on_default count 1, got %u", resolve_on_default_count);
1✔
2152
  ck_assert_msg(resolve_on_other_count == 0,
1✔
2153
    "Expected on_other count 0, got %u", resolve_on_other_count);
2154

1✔
2155
  /* Now, with the "mod_xfer.file-size" note. */
1✔
2156
  mark_point();
2157
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
2158
  file_size = 2.0;
2159
  pr_table_add(cmd->notes, "mod_xfer.file-size", &file_size, sizeof(file_size));
1✔
2160
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
2161
    resolve_on_meta, resolve_on_default, resolve_on_other);
2162
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
2163
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
2164
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1✔
2165
  ck_assert_msg(resolve_on_default_count == 0,
1✔
2166
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
2167
  ck_assert_msg(resolve_on_other_count == 0,
1✔
2168
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
2169
}
1✔
2170
END_TEST
1✔
2171

1✔
2172
START_TEST (jot_resolve_logfmt_env_var_test) {
1✔
2173
  int res;
1✔
2174
  cmd_rec *cmd;
2175
  unsigned char logfmt[9];
1✔
2176
  const char *key, *val;
1✔
2177

2178
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
1✔
2179
  cmd->cmd_class = CL_MISC;
2180
  logfmt[0] = LOGFMT_META_START;
1✔
2181
  logfmt[1] = LOGFMT_META_ENV_VAR;
2182
  logfmt[2] = 0;
2183

1✔
2184
  mark_point();
1✔
2185
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
2186
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
2187
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
2188
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
2189
  ck_assert_msg(resolve_on_meta_count == 0,
2190
    "Expected on_meta count 0, got %u", resolve_on_meta_count);
1✔
2191
  ck_assert_msg(resolve_on_default_count == 0,
1✔
2192
    "Expected on_default count 0, got %u", resolve_on_default_count);
2193
  ck_assert_msg(resolve_on_other_count == 0,
1✔
2194
    "Expected on_other count 0, got %u", resolve_on_other_count);
2195

1✔
2196
  mark_point();
2197
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
2198
  logfmt[0] = LOGFMT_META_START;
1✔
2199
  logfmt[1] = LOGFMT_META_ENV_VAR;
2200
  logfmt[2] = LOGFMT_META_START;
2201
  logfmt[3] = LOGFMT_META_ARG;
1✔
2202
  logfmt[4] = 'k';
1✔
2203
  logfmt[5] = 'e';
1✔
2204
  logfmt[6] = 'y';
1✔
2205
  logfmt[7] = LOGFMT_META_ARG_END;
1✔
2206
  logfmt[8] = 0;
2207
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
2208
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
2209
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
2210
  ck_assert_msg(resolve_on_meta_count == 0,
1✔
2211
    "Expected on_meta count 0, got %u", resolve_on_meta_count);
1✔
2212
  ck_assert_msg(resolve_on_default_count == 1,
2213
    "Expected on_default count 1, got %u", resolve_on_default_count);
1✔
2214
  ck_assert_msg(resolve_on_other_count == 0,
1✔
2215
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
2216

2217
  mark_point();
1✔
2218
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
2219
  key = "key";
2220
  val = "val";
1✔
2221
  pr_env_set(p, key, val);
2222
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
2223
    resolve_on_meta, resolve_on_default, resolve_on_other);
2224
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
2225
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
2226
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1✔
2227
  ck_assert_msg(resolve_on_default_count == 0,
1✔
2228
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
2229
  ck_assert_msg(resolve_on_other_count == 0,
1✔
2230
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
2231
  pr_env_unset(p, key);
1✔
2232
}
1✔
2233
END_TEST
1✔
2234

1✔
2235
START_TEST (jot_resolve_logfmt_note_test) {
1✔
2236
  int res;
1✔
2237
  cmd_rec *cmd;
2238
  unsigned char logfmt[9];
1✔
2239
  const char *key, *val;
1✔
2240

2241
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
1✔
2242
  cmd->cmd_class = CL_MISC;
2243
  logfmt[0] = LOGFMT_META_START;
1✔
2244
  logfmt[1] = LOGFMT_META_NOTE_VAR;
2245
  logfmt[2] = 0;
2246

1✔
2247
  mark_point();
1✔
2248
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
2249
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
2250
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
2251
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
2252
  ck_assert_msg(resolve_on_meta_count == 0,
1✔
2253
    "Expected on_meta count 0, got %u", resolve_on_meta_count);
2254
  ck_assert_msg(resolve_on_default_count == 0,
1✔
2255
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
2256
  ck_assert_msg(resolve_on_other_count == 0,
2257
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
2258

2259
  mark_point();
1✔
2260
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
2261
  logfmt[0] = LOGFMT_META_START;
2262
  logfmt[1] = LOGFMT_META_NOTE_VAR;
1✔
2263
  logfmt[2] = LOGFMT_META_START;
1✔
2264
  logfmt[3] = LOGFMT_META_ARG;
1✔
2265
  logfmt[4] = 'k';
1✔
2266
  logfmt[5] = 'e';
2267
  logfmt[6] = 'y';
1✔
2268
  logfmt[7] = LOGFMT_META_ARG_END;
1✔
2269
  logfmt[8] = 0;
2270
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
2271
    resolve_on_meta, resolve_on_default, resolve_on_other);
2272
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
2273
  ck_assert_msg(resolve_on_meta_count == 0,
2274
    "Expected on_meta count 0, got %u", resolve_on_meta_count);
2275
  ck_assert_msg(resolve_on_default_count == 1,
1✔
2276
    "Expected on_default count 1, got %u", resolve_on_default_count);
1✔
2277
  ck_assert_msg(resolve_on_other_count == 0,
1✔
2278
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
2279

2280
  mark_point();
2281
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
2282
  key = "key";
1✔
2283
  val = "val";
1✔
2284
  session.notes = pr_table_alloc(p, 0);
1✔
2285
  pr_table_add_dup(session.notes, key, val, 0);
1✔
2286
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
2287
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
2288
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
2289
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
2290
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1✔
2291
  ck_assert_msg(resolve_on_default_count == 0,
1✔
2292
    "Expected on_default count 0, got %u", resolve_on_default_count);
2293
  ck_assert_msg(resolve_on_other_count == 0,
1✔
2294
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
2295

1✔
2296
  mark_point();
2297
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
2298
  pr_table_add_dup(cmd->notes, key, val, 0);
1✔
2299
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
2300
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
2301
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
2302
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
2303
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
2304
  ck_assert_msg(resolve_on_default_count == 0,
2305
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
2306
  ck_assert_msg(resolve_on_other_count == 0,
1✔
2307
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
2308

1✔
2309
  pr_table_empty(session.notes);
1✔
2310
  pr_table_free(session.notes);
1✔
2311
  session.notes = NULL;
1✔
2312
}
1✔
2313
END_TEST
1✔
2314

1✔
2315
START_TEST (jot_resolve_logfmt_var_test) {
1✔
2316
  int res;
1✔
2317
  cmd_rec *cmd;
2318
  unsigned char logfmt[9];
1✔
2319
  const char *key, *val;
1✔
2320

2321
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
1✔
2322
  cmd->cmd_class = CL_MISC;
2323
  logfmt[0] = LOGFMT_META_START;
1✔
2324
  logfmt[1] = LOGFMT_META_VAR_VAR;
2325
  logfmt[2] = 0;
2326

1✔
2327
  mark_point();
1✔
2328
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
2329
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
2330
    resolve_on_meta, resolve_on_default, resolve_on_other);
2331
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
2332
  ck_assert_msg(resolve_on_meta_count == 0,
2333
    "Expected on_meta count 0, got %u", resolve_on_meta_count);
1✔
2334
  ck_assert_msg(resolve_on_default_count == 0,
2335
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
2336
  ck_assert_msg(resolve_on_other_count == 0,
2337
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
2338

1✔
2339
  mark_point();
2340
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
2341
  logfmt[0] = LOGFMT_META_START;
2342
  logfmt[1] = LOGFMT_META_VAR_VAR;
1✔
2343
  logfmt[2] = LOGFMT_META_START;
2344
  logfmt[3] = LOGFMT_META_ARG;
2345
  logfmt[4] = 'k';
1✔
2346
  logfmt[5] = 'e';
1✔
2347
  logfmt[6] = 'y';
1✔
2348
  logfmt[7] = LOGFMT_META_ARG_END;
2349
  logfmt[8] = 0;
2350
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
2351
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
2352
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
2353
  ck_assert_msg(resolve_on_meta_count == 0,
1✔
2354
    "Expected on_meta count 0, got %u", resolve_on_meta_count);
1✔
2355
  ck_assert_msg(resolve_on_default_count == 1,
1✔
2356
    "Expected on_default count 1, got %u", resolve_on_default_count);
2357
  ck_assert_msg(resolve_on_other_count == 0,
1✔
2358
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
2359

1✔
2360
  mark_point();
1✔
2361
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
2362
  key = "%{key}";
2363
  val = "val";
2364

1✔
2365
  res = pr_var_set(p, key, "Jot VAR test", PR_VAR_TYPE_STR, (void *) val,
1✔
2366
    NULL, 0);
1✔
2367
  ck_assert_msg(res == 0, "Failed to set variable: %s", strerror(errno));
2368

1✔
2369
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
2370
    resolve_on_meta, resolve_on_default, resolve_on_other);
2371
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
2372
  ck_assert_msg(resolve_on_meta_count == 1,
2373
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1✔
2374
  ck_assert_msg(resolve_on_default_count == 0,
2375
    "Expected on_default count 0, got %u", resolve_on_default_count);
2376
  ck_assert_msg(resolve_on_other_count == 0,
2377
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
2378

1✔
2379
  res = pr_var_delete(key);
2380
  ck_assert_msg(res == 0, "Failed to delete variable: %s", strerror(errno));
1✔
2381
}
1✔
2382
END_TEST
1✔
2383

1✔
2384
START_TEST (jot_resolve_logfmt_remote_port_test) {
1✔
2385
  int res;
1✔
2386
  cmd_rec *cmd;
1✔
2387
  unsigned char logfmt[3];
1✔
2388
  conn_t *conn;
2389
  const pr_netaddr_t *addr;
1✔
2390

1✔
2391
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
2392
  cmd->cmd_class = CL_MISC;
1✔
2393
  logfmt[0] = LOGFMT_META_START;
1✔
2394
  logfmt[1] = LOGFMT_META_REMOTE_PORT;
2395
  logfmt[2] = 0;
1✔
2396

2397
  /* First, without a session remote address. */
1✔
2398
  mark_point();
2399
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
2400
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
2401
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
2402
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
2403
  ck_assert_msg(resolve_on_meta_count == 0,
2404
    "Expected on_meta count 0, got %u", resolve_on_meta_count);
2405
  ck_assert_msg(resolve_on_default_count == 1,
1✔
2406
    "Expected on_default count 1, got %u", resolve_on_default_count);
1✔
2407
  ck_assert_msg(resolve_on_other_count == 0,
1✔
2408
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
2409

1✔
2410
  /* Now, with a session remote address. */
2411
  mark_point();
1✔
2412
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
2413

1✔
2414
  mark_point();
1✔
2415
  conn = pr_inet_create_conn(p, -1, NULL, INPORT_ANY, FALSE);
1✔
2416
  session.c = conn;
2417
  addr = pr_netaddr_get_addr(p, "127.0.0.1", NULL);
2418
  ck_assert_msg(addr != NULL, "Failed to get address: %s", strerror(errno));
1✔
2419
  pr_netaddr_set_port2((pr_netaddr_t *) addr, 2476);
1✔
2420
  session.c->remote_addr = addr;
1✔
2421
  pr_netaddr_set_sess_addrs();
2422

1✔
2423
  mark_point();
1✔
2424
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
2425
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
2426
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
2427
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
2428
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
2429
  ck_assert_msg(resolve_on_default_count == 0,
2430
    "Expected on_default count 0, got %u", resolve_on_default_count);
2431
  ck_assert_msg(resolve_on_other_count == 0,
1✔
2432
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
2433

1✔
2434
  pr_inet_close(p, session.c);
1✔
2435
  session.c = NULL;
1✔
2436
}
1✔
2437
END_TEST
2438

1✔
2439
START_TEST (jot_resolve_logfmt_rfc1413_ident_test) {
1✔
2440
  int res;
2441
  cmd_rec *cmd;
1✔
2442
  unsigned char logfmt[3];
2443
  char *ident_user;
1✔
2444

2445
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
2446
  cmd->cmd_class = CL_MISC;
1✔
2447
  logfmt[0] = LOGFMT_META_START;
1✔
2448
  logfmt[1] = LOGFMT_META_IDENT_USER;
1✔
2449
  logfmt[2] = 0;
1✔
2450

2451
  /* First, without the "mod_ident.rfc1413-ident" note. */
2452
  mark_point();
1✔
2453
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
2454
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
2455
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
2456
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
2457
  ck_assert_msg(resolve_on_meta_count == 0,
1✔
2458
    "Expected on_meta count 0, got %u", resolve_on_meta_count);
1✔
2459
  ck_assert_msg(resolve_on_default_count == 1,
1✔
2460
    "Expected on_default count 1, got %u", resolve_on_default_count);
1✔
2461
  ck_assert_msg(resolve_on_other_count == 0,
1✔
2462
    "Expected on_other count 0, got %u", resolve_on_other_count);
2463

2464
  /* Now, with the "mod_ident.rfc1413-ident" note. */
1✔
2465
  mark_point();
1✔
2466
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
2467
  ident_user = "FOOBAR";
2468
  session.notes = pr_table_alloc(p, 0);
1✔
2469
  pr_table_add_dup(session.notes, "mod_ident.rfc1413-ident", ident_user, 0);
1✔
2470
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
2471
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
2472
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
2473
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
2474
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
2475
  ck_assert_msg(resolve_on_default_count == 0,
2476
    "Expected on_default count 0, got %u", resolve_on_default_count);
2477
  ck_assert_msg(resolve_on_other_count == 0,
1✔
2478
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
2479

1✔
2480
  pr_table_empty(session.notes);
1✔
2481
  pr_table_free(session.notes);
1✔
2482
  session.notes = NULL;
2483
}
1✔
2484
END_TEST
1✔
2485

2486
START_TEST (jot_resolve_logfmt_xfer_secs_test) {
1✔
2487
  int res;
2488
  cmd_rec *cmd;
1✔
2489
  unsigned char logfmt[3];
2490

2491
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
1✔
2492
  cmd->cmd_class = CL_MISC;
1✔
2493
  logfmt[0] = LOGFMT_META_START;
1✔
2494
  logfmt[1] = LOGFMT_META_SECONDS;
1✔
2495
  logfmt[2] = 0;
1✔
2496

1✔
2497
  /* First, without the sess.xfer.p pool. */
2498
  mark_point();
1✔
2499
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
2500
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
2501
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
2502
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
2503
  ck_assert_msg(resolve_on_meta_count == 0,
1✔
2504
    "Expected on_meta count 0, got %u", resolve_on_meta_count);
2505
  ck_assert_msg(resolve_on_default_count == 1,
2506
    "Expected on_default count 1, got %u", resolve_on_default_count);
1✔
2507
  ck_assert_msg(resolve_on_other_count == 0,
1✔
2508
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
2509

1✔
2510
  /* Now, with the session.xfer.p pool, but no transfer times. */
1✔
2511
  mark_point();
1✔
2512
  session.xfer.p = p;
2513
  session.xfer.start_time.tv_sec = session.xfer.start_time.tv_usec = 0;
1✔
2514
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
2515
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
2516
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
2517
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
2518
  ck_assert_msg(resolve_on_meta_count == 0,
1✔
2519
    "Expected on_meta count 0, got %u", resolve_on_meta_count);
2520
  ck_assert_msg(resolve_on_default_count == 1,
2521
    "Expected on_default count 1, got %u", resolve_on_default_count);
1✔
2522
  ck_assert_msg(resolve_on_other_count == 0,
1✔
2523
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
2524

2525
  mark_point();
2526
  session.xfer.p = p;
1✔
2527
  session.xfer.start_time.tv_sec = 0;
1✔
2528
  session.xfer.start_time.tv_usec = 200000;
1✔
2529
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
2530
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
2531
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
2532
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
2533
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
2534
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1✔
2535
  ck_assert_msg(resolve_on_default_count == 0,
1✔
2536
    "Expected on_default count 0, got %u", resolve_on_default_count);
2537
  ck_assert_msg(resolve_on_other_count == 0,
2538
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
2539

1✔
2540
  mark_point();
1✔
2541
  session.xfer.p = p;
2542
  session.xfer.start_time.tv_sec = 20;
1✔
2543
  session.xfer.start_time.tv_usec = 200;
1✔
2544
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
2545
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
2546
    resolve_on_meta, resolve_on_default, resolve_on_other);
2547
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
2548
  ck_assert_msg(resolve_on_meta_count == 1,
2549
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
2550
  ck_assert_msg(resolve_on_default_count == 0,
2551
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
2552
  ck_assert_msg(resolve_on_other_count == 0,
1✔
2553
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
2554

1✔
2555
  session.xfer.p = NULL;
1✔
2556
  session.xfer.start_time.tv_sec = session.xfer.start_time.tv_usec = 0;
2557
}
1✔
2558
END_TEST
1✔
2559

2560
START_TEST (jot_resolve_logfmt_xfer_ms_test) {
1✔
2561
  int res;
2562
  cmd_rec *cmd;
1✔
2563
  unsigned char logfmt[3];
2564

2565
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
1✔
2566
  cmd->cmd_class = CL_MISC;
1✔
2567
  logfmt[0] = LOGFMT_META_START;
1✔
2568
  logfmt[1] = LOGFMT_META_XFER_MS;
1✔
2569
  logfmt[2] = 0;
1✔
2570

1✔
2571
  /* First, without the sess.xfer.p pool. */
2572
  mark_point();
1✔
2573
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
2574
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
2575
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
2576
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
2577
  ck_assert_msg(resolve_on_meta_count == 0,
1✔
2578
    "Expected on_meta count 0, got %u", resolve_on_meta_count);
2579
  ck_assert_msg(resolve_on_default_count == 1,
2580
    "Expected on_default count 1, got %u", resolve_on_default_count);
1✔
2581
  ck_assert_msg(resolve_on_other_count == 0,
1✔
2582
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
2583

1✔
2584
  /* Now, with the session.xfer.p pool, but no transfer times. */
1✔
2585
  mark_point();
1✔
2586
  session.xfer.p = p;
2587
  session.xfer.start_time.tv_sec = session.xfer.start_time.tv_usec = 0;
1✔
2588
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
2589
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
2590
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
2591
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
2592
  ck_assert_msg(resolve_on_meta_count == 0,
1✔
2593
    "Expected on_meta count 0, got %u", resolve_on_meta_count);
2594
  ck_assert_msg(resolve_on_default_count == 1,
2595
    "Expected on_default count 1, got %u", resolve_on_default_count);
1✔
2596
  ck_assert_msg(resolve_on_other_count == 0,
1✔
2597
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
2598

2599
  mark_point();
2600
  session.xfer.p = p;
1✔
2601
  session.xfer.start_time.tv_sec = 0;
1✔
2602
  session.xfer.start_time.tv_usec = 200000;
1✔
2603
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
2604
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
2605
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
2606
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
2607
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
2608
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1✔
2609
  ck_assert_msg(resolve_on_default_count == 0,
2610
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
2611
  ck_assert_msg(resolve_on_other_count == 0,
1✔
2612
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
2613

1✔
2614
  mark_point();
2615
  session.xfer.p = p;
1✔
2616
  session.xfer.start_time.tv_sec = 20;
1✔
2617
  session.xfer.start_time.tv_usec = 200;
2618
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
2619
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
2620
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
2621
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
2622
  ck_assert_msg(resolve_on_meta_count == 1,
2623
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1✔
2624
  ck_assert_msg(resolve_on_default_count == 0,
1✔
2625
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
2626
  ck_assert_msg(resolve_on_other_count == 0,
1✔
2627
    "Expected on_other count 0, got %u", resolve_on_other_count);
2628

1✔
2629
  session.xfer.p = NULL;
1✔
2630
  session.xfer.start_time.tv_sec = session.xfer.start_time.tv_usec = 0;
2631
}
1✔
2632
END_TEST
2633

1✔
2634
START_TEST (jot_resolve_logfmt_command_test) {
2635
  int res;
2636
  cmd_rec *cmd;
1✔
2637
  unsigned char logfmt[3];
1✔
2638

1✔
2639
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
1✔
2640
  logfmt[0] = LOGFMT_META_START;
1✔
2641
  logfmt[1] = LOGFMT_META_COMMAND;
1✔
2642
  logfmt[2] = 0;
2643

1✔
2644
  mark_point();
1✔
2645
  cmd->cmd_class = CL_CONNECT;
2646
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
2647
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
2648
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
2649
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
2650
  ck_assert_msg(resolve_on_meta_count == 0,
2651
    "Expected on_meta count 0, got %u", resolve_on_meta_count);
1✔
2652
  ck_assert_msg(resolve_on_default_count == 1,
1✔
2653
    "Expected on_default count 1, got %u", resolve_on_default_count);
1✔
2654
  ck_assert_msg(resolve_on_other_count == 0,
1✔
2655
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
2656

1✔
2657
  mark_point();
2658
  cmd->cmd_class = CL_DISCONNECT;
1✔
2659
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
2660
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
2661
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
2662
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
2663
  ck_assert_msg(resolve_on_meta_count == 0,
1✔
2664
    "Expected on_meta count 0, got %u", resolve_on_meta_count);
2665
  ck_assert_msg(resolve_on_default_count == 1,
2666
    "Expected on_default count 1, got %u", resolve_on_default_count);
1✔
2667
  ck_assert_msg(resolve_on_other_count == 0,
1✔
2668
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
2669

1✔
2670
  mark_point();
1✔
2671
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "PASS"));
2672
  cmd->cmd_class = CL_AUTH;
1✔
2673
  session.hide_password = TRUE;
1✔
2674
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
2675
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
2676
    resolve_on_meta, resolve_on_default, resolve_on_other);
2677
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
2678
  ck_assert_msg(resolve_on_meta_count == 1,
2679
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
2680
  ck_assert_msg(resolve_on_default_count == 0,
1✔
2681
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
2682
  ck_assert_msg(resolve_on_other_count == 0,
1✔
2683
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
2684

1✔
2685
  mark_point();
2686
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "PASS"));
1✔
2687
  cmd->cmd_class = CL_AUTH;
1✔
2688
  session.hide_password = FALSE;
2689
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
2690
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
2691
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
2692
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
2693
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
2694
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
2695
  ck_assert_msg(resolve_on_default_count == 0,
2696
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
2697
  ck_assert_msg(resolve_on_other_count == 0,
1✔
2698
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
2699

1✔
2700
  mark_point();
1✔
2701
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "ADAT"));
2702
  cmd->cmd_class = CL_SEC;
1✔
2703
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
2704
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
2705
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
2706
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
2707
  ck_assert_msg(resolve_on_meta_count == 1,
2708
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1✔
2709
  ck_assert_msg(resolve_on_default_count == 0,
1✔
2710
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
2711
  ck_assert_msg(resolve_on_other_count == 0,
2712
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
2713

1✔
2714
  mark_point();
2715
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
1✔
2716
  cmd->cmd_class = CL_MISC;
2717
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
2718
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
2719
    resolve_on_meta, resolve_on_default, resolve_on_other);
2720
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
2721
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
2722
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1✔
2723
  ck_assert_msg(resolve_on_default_count == 0,
1✔
2724
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
2725
  ck_assert_msg(resolve_on_other_count == 0,
1✔
2726
    "Expected on_other count 0, got %u", resolve_on_other_count);
2727
}
1✔
2728
END_TEST
1✔
2729

2730
START_TEST (jot_resolve_logfmt_local_name_test) {
1✔
2731
  int res;
2732
  cmd_rec *cmd;
1✔
2733
  server_rec *server;
2734
  unsigned char logfmt[3];
1✔
2735

2736
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
2737
  cmd->cmd_class = CL_MISC;
1✔
2738
  logfmt[0] = LOGFMT_META_START;
1✔
2739
  logfmt[1] = LOGFMT_META_LOCAL_NAME;
1✔
2740
  logfmt[2] = 0;
1✔
2741

1✔
2742
  mark_point();
2743
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
2744
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
2745
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
2746
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
2747
  ck_assert_msg(resolve_on_meta_count == 0,
1✔
2748
    "Expected on_meta count 0, got %u", resolve_on_meta_count);
2749
  ck_assert_msg(resolve_on_default_count == 1,
1✔
2750
    "Expected on_default count 1, got %u", resolve_on_default_count);
1✔
2751
  ck_assert_msg(resolve_on_other_count == 0,
1✔
2752
    "Expected on_other count 0, got %u", resolve_on_other_count);
2753

1✔
2754
  mark_point();
1✔
2755
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
2756
  server = pcalloc(p, sizeof(server_rec));
1✔
2757
  server->ServerName = "FOOBAR";
2758
  cmd->server = server;
1✔
2759
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
2760
    resolve_on_meta, resolve_on_default, resolve_on_other);
2761
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
2762
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
2763
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1✔
2764
  ck_assert_msg(resolve_on_default_count == 0,
1✔
2765
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
2766
  ck_assert_msg(resolve_on_other_count == 0,
1✔
2767
    "Expected on_other count 0, got %u", resolve_on_other_count);
2768
}
1✔
2769
END_TEST
1✔
2770

2771
START_TEST (jot_resolve_logfmt_local_port_test) {
1✔
2772
  int res;
2773
  cmd_rec *cmd;
1✔
2774
  server_rec *server;
2775
  unsigned char logfmt[3];
1✔
2776

2777
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
2778
  cmd->cmd_class = CL_MISC;
1✔
2779
  logfmt[0] = LOGFMT_META_START;
1✔
2780
  logfmt[1] = LOGFMT_META_LOCAL_PORT;
1✔
2781
  logfmt[2] = 0;
1✔
2782

2783
  mark_point();
1✔
2784
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
2785
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
2786
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
2787
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
2788
  ck_assert_msg(resolve_on_meta_count == 0,
2789
    "Expected on_meta count 0, got %u", resolve_on_meta_count);
1✔
2790
  ck_assert_msg(resolve_on_default_count == 1,
1✔
2791
    "Expected on_default count 1, got %u", resolve_on_default_count);
1✔
2792
  ck_assert_msg(resolve_on_other_count == 0,
2793
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
2794

1✔
2795
  mark_point();
2796
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
2797
  server = pcalloc(p, sizeof(server_rec));
2798
  server->ServerPort = 2121;
1✔
2799
  cmd->server = server;
2800
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
2801
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
2802
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
2803
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
2804
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1✔
2805
  ck_assert_msg(resolve_on_default_count == 0,
2806
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
2807
  ck_assert_msg(resolve_on_other_count == 0,
1✔
2808
    "Expected on_other count 0, got %u", resolve_on_other_count);
2809
}
1✔
2810
END_TEST
2811

1✔
2812
START_TEST (jot_resolve_logfmt_user_test) {
2813
  int res;
2814
  cmd_rec *cmd;
1✔
2815
  unsigned char logfmt[3];
1✔
2816

2817
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
2818
  cmd->cmd_class = CL_MISC;
1✔
2819
  logfmt[0] = LOGFMT_META_START;
1✔
2820
  logfmt[1] = LOGFMT_META_USER;
1✔
2821
  logfmt[2] = 0;
1✔
2822

2823
  mark_point();
1✔
2824
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
2825
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
2826
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
2827
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
2828
  ck_assert_msg(resolve_on_meta_count == 0,
2829
    "Expected on_meta count 0, got %u", resolve_on_meta_count);
1✔
2830
  ck_assert_msg(resolve_on_default_count == 1,
1✔
2831
    "Expected on_default count 1, got %u", resolve_on_default_count);
1✔
2832
  ck_assert_msg(resolve_on_other_count == 0,
2833
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
2834

1✔
2835
  mark_point();
2836
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
2837
  session.user = "FOOBAR";
2838
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
2839
    resolve_on_meta, resolve_on_default, resolve_on_other);
2840
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
2841
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
2842
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1✔
2843
  ck_assert_msg(resolve_on_default_count == 0,
1✔
2844
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
2845
  ck_assert_msg(resolve_on_other_count == 0,
1✔
2846
    "Expected on_other count 0, got %u", resolve_on_other_count);
2847

1✔
2848
  session.user = NULL;
1✔
2849
}
2850
END_TEST
1✔
2851

2852
START_TEST (jot_resolve_logfmt_uid_test) {
1✔
2853
  int res;
2854
  cmd_rec *cmd;
2855
  unsigned char logfmt[3];
1✔
2856

1✔
2857
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
1✔
2858
  cmd->cmd_class = CL_MISC;
2859
  logfmt[0] = LOGFMT_META_START;
2860
  logfmt[1] = LOGFMT_META_UID;
1✔
2861
  logfmt[2] = 0;
1✔
2862

1✔
2863
  mark_point();
1✔
2864
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
2865
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
2866
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
2867
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
2868
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
2869
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1✔
2870
  ck_assert_msg(resolve_on_default_count == 0,
2871
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
2872
  ck_assert_msg(resolve_on_other_count == 0,
1✔
2873
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
2874

2875
  mark_point();
1✔
2876
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
2877
  session.auth_mech = "mod_auth_file.c";
2878
  session.login_uid = 400;
1✔
2879
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
2880
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
2881
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
2882
  ck_assert_msg(resolve_on_meta_count == 1,
2883
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1✔
2884
  ck_assert_msg(resolve_on_default_count == 0,
1✔
2885
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
2886
  ck_assert_msg(resolve_on_other_count == 0,
1✔
2887
    "Expected on_other count 0, got %u", resolve_on_other_count);
2888

1✔
2889
  session.auth_mech = NULL;
1✔
2890
  session.login_uid = 0;
2891
}
1✔
2892
END_TEST
2893

1✔
2894
START_TEST (jot_resolve_logfmt_group_test) {
2895
  int res;
2896
  cmd_rec *cmd;
1✔
2897
  unsigned char logfmt[3];
1✔
2898

2899
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
2900
  cmd->cmd_class = CL_MISC;
1✔
2901
  logfmt[0] = LOGFMT_META_START;
1✔
2902
  logfmt[1] = LOGFMT_META_GROUP;
1✔
2903
  logfmt[2] = 0;
1✔
2904

2905
  mark_point();
1✔
2906
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
2907
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
2908
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
2909
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
2910
  ck_assert_msg(resolve_on_meta_count == 0,
2911
    "Expected on_meta count 0, got %u", resolve_on_meta_count);
1✔
2912
  ck_assert_msg(resolve_on_default_count == 1,
1✔
2913
    "Expected on_default count 1, got %u", resolve_on_default_count);
1✔
2914
  ck_assert_msg(resolve_on_other_count == 0,
2915
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
2916

1✔
2917
  mark_point();
2918
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
2919
  session.group = "FOOBAR";
2920
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
2921
    resolve_on_meta, resolve_on_default, resolve_on_other);
2922
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
2923
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
2924
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1✔
2925
  ck_assert_msg(resolve_on_default_count == 0,
1✔
2926
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
2927
  ck_assert_msg(resolve_on_other_count == 0,
1✔
2928
    "Expected on_other count 0, got %u", resolve_on_other_count);
2929

1✔
2930
  session.group = NULL;
1✔
2931
}
2932
END_TEST
1✔
2933

2934
START_TEST (jot_resolve_logfmt_gid_test) {
1✔
2935
  int res;
2936
  cmd_rec *cmd;
2937
  unsigned char logfmt[3];
1✔
2938

1✔
2939
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
1✔
2940
  cmd->cmd_class = CL_MISC;
2941
  logfmt[0] = LOGFMT_META_START;
2942
  logfmt[1] = LOGFMT_META_GID;
1✔
2943
  logfmt[2] = 0;
1✔
2944

1✔
2945
  mark_point();
1✔
2946
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
2947
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
2948
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
2949
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
2950
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
2951
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1✔
2952
  ck_assert_msg(resolve_on_default_count == 0,
1✔
2953
    "Expected on_default count 0, got %u", resolve_on_default_count);
2954
  ck_assert_msg(resolve_on_other_count == 0,
2955
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
2956

1✔
2957
  mark_point();
1✔
2958
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
2959
  session.auth_mech = "mod_auth_file.c";
1✔
2960
  session.login_gid = 400;
1✔
2961
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
2962
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
2963
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
2964
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
2965
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
2966
  ck_assert_msg(resolve_on_default_count == 0,
2967
    "Expected on_default count 0, got %u", resolve_on_default_count);
2968
  ck_assert_msg(resolve_on_other_count == 0,
1✔
2969
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
2970

1✔
2971
  session.auth_mech = NULL;
1✔
2972
  session.login_gid = 0;
1✔
2973
}
1✔
2974
END_TEST
2975

1✔
2976
START_TEST (jot_resolve_logfmt_original_user_test) {
1✔
2977
  int res;
2978
  cmd_rec *cmd;
1✔
2979
  unsigned char logfmt[3];
2980
  char *orig_user;
1✔
2981

2982
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
2983
  cmd->cmd_class = CL_MISC;
1✔
2984
  logfmt[0] = LOGFMT_META_START;
1✔
2985
  logfmt[1] = LOGFMT_META_ORIGINAL_USER;
1✔
2986
  logfmt[2] = 0;
1✔
2987

2988
  /* First, without the "mod_auth.orig-user" note. */
2989
  mark_point();
1✔
2990
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
2991
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
2992
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
2993
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
2994
  ck_assert_msg(resolve_on_meta_count == 0,
1✔
2995
    "Expected on_meta count 0, got %u", resolve_on_meta_count);
1✔
2996
  ck_assert_msg(resolve_on_default_count == 1,
1✔
2997
    "Expected on_default count 1, got %u", resolve_on_default_count);
1✔
2998
  ck_assert_msg(resolve_on_other_count == 0,
1✔
2999
    "Expected on_other count 0, got %u", resolve_on_other_count);
3000

1✔
3001
  /* Now, with the "mod_auth.orig-user" note. */
1✔
3002
  mark_point();
1✔
3003
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
3004
  orig_user = "FOOBAR";
1✔
3005
  session.notes = pr_table_alloc(p, 0);
1✔
3006
  pr_table_add_dup(session.notes, "mod_auth.orig-user", orig_user, 0);
3007
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
3008
    resolve_on_meta, resolve_on_default, resolve_on_other);
3009
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
3010
  ck_assert_msg(resolve_on_meta_count == 1,
3011
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
3012
  ck_assert_msg(resolve_on_default_count == 0,
1✔
3013
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
3014
  ck_assert_msg(resolve_on_other_count == 0,
1✔
3015
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
3016

1✔
3017
  pr_table_empty(session.notes);
3018
  pr_table_free(session.notes);
1✔
3019
  session.notes = NULL;
1✔
3020
}
3021
END_TEST
1✔
3022

3023
START_TEST (jot_resolve_logfmt_response_code_test) {
1✔
3024
  int res;
3025
  cmd_rec *cmd;
3026
  unsigned char logfmt[3];
1✔
3027

1✔
3028
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
1✔
3029
  cmd->cmd_class = CL_MISC;
1✔
3030
  logfmt[0] = LOGFMT_META_START;
3031
  logfmt[1] = LOGFMT_META_RESPONSE_CODE;
1✔
3032
  logfmt[2] = 0;
1✔
3033

1✔
3034
  mark_point();
3035
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
3036
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
3037
    resolve_on_meta, resolve_on_default, resolve_on_other);
3038
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
3039
  ck_assert_msg(resolve_on_meta_count == 0,
3040
    "Expected on_meta count 0, got %u", resolve_on_meta_count);
1✔
3041
  ck_assert_msg(resolve_on_default_count == 1,
3042
    "Expected on_default count 1, got %u", resolve_on_default_count);
3043
  ck_assert_msg(resolve_on_other_count == 0,
1✔
3044
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
3045

1✔
3046
  mark_point();
3047
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "QUIT"));
3048
  cmd->cmd_class = CL_MISC;
1✔
3049
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
3050
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
3051
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
3052
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
3053
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
3054
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1✔
3055
  ck_assert_msg(resolve_on_default_count == 0,
1✔
3056
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
3057
  ck_assert_msg(resolve_on_other_count == 0,
1✔
3058
    "Expected on_other count 0, got %u", resolve_on_other_count);
3059

1✔
3060
  mark_point();
1✔
3061
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
3062
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
3063
  cmd->cmd_class = CL_MISC;
1✔
3064

1✔
3065
  pr_response_set_pool(p);
3066
  pr_response_add("200", "foo %s", "bar");
1✔
3067
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
3068
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
3069
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
3070
  ck_assert_msg(resolve_on_meta_count == 1,
3071
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1✔
3072
  ck_assert_msg(resolve_on_default_count == 0,
1✔
3073
    "Expected on_default count 0, got %u", resolve_on_default_count);
3074
  ck_assert_msg(resolve_on_other_count == 0,
1✔
3075
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
3076

1✔
3077
  pr_response_clear(&resp_list);
3078
  pr_response_set_pool(NULL);
1✔
3079
}
1✔
3080
END_TEST
3081

1✔
3082
START_TEST (jot_resolve_logfmt_response_text_test) {
3083
  int res;
1✔
3084
  cmd_rec *cmd;
3085
  unsigned char logfmt[3];
3086

1✔
3087
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
1✔
3088
  cmd->cmd_class = CL_MISC;
1✔
3089
  logfmt[0] = LOGFMT_META_START;
3090
  logfmt[1] = LOGFMT_META_RESPONSE_STR;
3091
  logfmt[2] = 0;
1✔
3092

1✔
3093
  mark_point();
1✔
3094
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
3095
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
3096
    resolve_on_meta, resolve_on_default, resolve_on_other);
3097
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
3098
  ck_assert_msg(resolve_on_meta_count == 0,
1✔
3099
    "Expected on_meta count 0, got %u", resolve_on_meta_count);
1✔
3100
  ck_assert_msg(resolve_on_default_count == 1,
1✔
3101
    "Expected on_default count 1, got %u", resolve_on_default_count);
1✔
3102
  ck_assert_msg(resolve_on_other_count == 0,
3103
    "Expected on_other count 0, got %u", resolve_on_other_count);
3104

1✔
3105
  mark_point();
1✔
3106
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
3107

3108
  pr_response_set_pool(p);
1✔
3109
  pr_response_add("200", "foo %s", "bar");
1✔
3110
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
3111
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
3112
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
3113
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
3114
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
3115
  ck_assert_msg(resolve_on_default_count == 0,
3116
    "Expected on_default count 0, got %u", resolve_on_default_count);
3117
  ck_assert_msg(resolve_on_other_count == 0,
1✔
3118
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
3119

1✔
3120
  pr_response_clear(&resp_list);
1✔
3121
  pr_response_set_pool(NULL);
1✔
3122
}
3123
END_TEST
1✔
3124

1✔
3125
START_TEST (jot_resolve_logfmt_response_ms_test) {
3126
  int res;
1✔
3127
  cmd_rec *cmd;
3128
  unsigned char logfmt[3];
1✔
3129
  uint64_t start_ms;
3130

1✔
3131
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
3132
  cmd->cmd_class = CL_MISC;
3133
  logfmt[0] = LOGFMT_META_START;
1✔
3134
  logfmt[1] = LOGFMT_META_RESPONSE_MS;
1✔
3135
  logfmt[2] = 0;
1✔
3136

1✔
3137
  /* First, without the "start_ms" note. */
3138
  mark_point();
1✔
3139
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
3140
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
3141
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
3142
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
3143
  ck_assert_msg(resolve_on_meta_count == 0,
3144
    "Expected on_meta count 0, got %u", resolve_on_meta_count);
1✔
3145
  ck_assert_msg(resolve_on_default_count == 1,
1✔
3146
    "Expected on_default count 1, got %u", resolve_on_default_count);
1✔
3147
  ck_assert_msg(resolve_on_other_count == 0,
3148
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
3149

1✔
3150
  /* Now, with the "start_ms" note. */
3151
  mark_point();
1✔
3152
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
3153
  start_ms = 123456;
1✔
3154
  pr_table_add(cmd->notes, "start_ms", &start_ms, sizeof(start_ms));
3155
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
3156
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
3157
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
3158
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
3159
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1✔
3160
  ck_assert_msg(resolve_on_default_count == 0,
3161
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
3162
  ck_assert_msg(resolve_on_other_count == 0,
1✔
3163
    "Expected on_other count 0, got %u", resolve_on_other_count);
3164
}
1✔
3165
END_TEST
3166

1✔
3167
START_TEST (jot_resolve_logfmt_class_test) {
3168
  int res;
3169
  cmd_rec *cmd;
1✔
3170
  unsigned char logfmt[3];
1✔
3171

3172
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
3173
  cmd->cmd_class = CL_MISC;
1✔
3174
  logfmt[0] = LOGFMT_META_START;
1✔
3175
  logfmt[1] = LOGFMT_META_CLASS;
1✔
3176
  logfmt[2] = 0;
1✔
3177

1✔
3178
  mark_point();
3179
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
3180
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
3181
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
3182
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
3183
  ck_assert_msg(resolve_on_meta_count == 0,
1✔
3184
    "Expected on_meta count 0, got %u", resolve_on_meta_count);
3185
  ck_assert_msg(resolve_on_default_count == 1,
3186
    "Expected on_default count 1, got %u", resolve_on_default_count);
1✔
3187
  ck_assert_msg(resolve_on_other_count == 0,
1✔
3188
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
3189

3190
  mark_point();
1✔
3191
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
3192
  session.conn_class = pcalloc(p, sizeof(pr_class_t));
3193
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
3194
    resolve_on_meta, resolve_on_default, resolve_on_other);
3195
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
3196
  ck_assert_msg(resolve_on_meta_count == 1,
3197
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
3198
  ck_assert_msg(resolve_on_default_count == 0,
3199
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
3200
  ck_assert_msg(resolve_on_other_count == 0,
1✔
3201
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
3202

1✔
3203
  session.conn_class = NULL;
1✔
3204
}
1✔
3205
END_TEST
3206

1✔
3207
START_TEST (jot_resolve_logfmt_anon_passwd_test) {
1✔
3208
  int res;
3209
  cmd_rec *cmd;
1✔
3210
  unsigned char logfmt[3];
3211
  char *anon_passwd;
1✔
3212

3213
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
3214
  cmd->cmd_class = CL_MISC;
1✔
3215
  logfmt[0] = LOGFMT_META_START;
1✔
3216
  logfmt[1] = LOGFMT_META_ANON_PASS;
1✔
3217
  logfmt[2] = 0;
1✔
3218

3219
  /* First, without the "mod_auth.anon-passwd" note. */
3220
  mark_point();
1✔
3221
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
3222
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
3223
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
3224
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
3225
  ck_assert_msg(resolve_on_meta_count == 0,
1✔
3226
    "Expected on_meta count 0, got %u", resolve_on_meta_count);
1✔
3227
  ck_assert_msg(resolve_on_default_count == 1,
1✔
3228
    "Expected on_default count 1, got %u", resolve_on_default_count);
1✔
3229
  ck_assert_msg(resolve_on_other_count == 0,
1✔
3230
    "Expected on_other count 0, got %u", resolve_on_other_count);
3231

1✔
3232
  /* Now, with the "mod_auth.anon-passwd" note. */
1✔
3233
  mark_point();
1✔
3234
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
3235
  anon_passwd = "FOOBAR";
1✔
3236
  session.notes = pr_table_alloc(p, 0);
1✔
3237
  pr_table_add_dup(session.notes, "mod_auth.anon-passwd", anon_passwd, 0);
3238
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
3239
    resolve_on_meta, resolve_on_default, resolve_on_other);
3240
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
3241
  ck_assert_msg(resolve_on_meta_count == 1,
3242
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
3243
  ck_assert_msg(resolve_on_default_count == 0,
1✔
3244
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
3245
  ck_assert_msg(resolve_on_other_count == 0,
1✔
3246
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
3247

3248
  pr_table_empty(session.notes);
1✔
3249
  pr_table_free(session.notes);
1✔
3250
  session.notes = NULL;
3251
}
1✔
3252
END_TEST
3253

1✔
3254
START_TEST (jot_resolve_logfmt_method_test) {
3255
  int res;
3256
  cmd_rec *cmd;
1✔
3257
  unsigned char logfmt[3];
1✔
3258

1✔
3259
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
1✔
3260
  cmd->cmd_class = CL_CONNECT;
1✔
3261
  logfmt[0] = LOGFMT_META_START;
3262
  logfmt[1] = LOGFMT_META_METHOD;
1✔
3263
  logfmt[2] = 0;
1✔
3264

3265
  mark_point();
1✔
3266
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
3267
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
3268
    resolve_on_meta, resolve_on_default, resolve_on_other);
3269
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
3270
  ck_assert_msg(resolve_on_meta_count == 0,
1✔
3271
    "Expected on_meta count 0, got %u", resolve_on_meta_count);
1✔
3272
  ck_assert_msg(resolve_on_default_count == 1,
1✔
3273
    "Expected on_default count 1, got %u", resolve_on_default_count);
1✔
3274
  ck_assert_msg(resolve_on_other_count == 0,
1✔
3275
    "Expected on_other count 0, got %u", resolve_on_other_count);
3276

1✔
3277
  mark_point();
1✔
3278
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
3279
  cmd->cmd_class = CL_MISC;
1✔
3280
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
3281
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
3282
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
3283
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
3284
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
3285
  ck_assert_msg(resolve_on_default_count == 0,
3286
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
3287
  ck_assert_msg(resolve_on_other_count == 0,
1✔
3288
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
3289

1✔
3290
  mark_point();
3291
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
3292
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "SITE"));
1✔
3293
  cmd->cmd_class = CL_MISC;
1✔
3294
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
3295
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
3296
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
3297
  ck_assert_msg(resolve_on_meta_count == 0,
1✔
3298
    "Expected on_meta count 0, got %u", resolve_on_meta_count);
1✔
3299
  ck_assert_msg(resolve_on_default_count == 1,
1✔
3300
    "Expected on_default count 1, got %u", resolve_on_default_count);
3301
  ck_assert_msg(resolve_on_other_count == 0,
1✔
3302
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
3303

3304
  mark_point();
1✔
3305
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
3306
  cmd = pr_cmd_alloc(p, 2, pstrdup(p, "SITE"), pstrdup(p, "foobar"));
1✔
3307
  cmd->cmd_class = CL_MISC;
3308
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
3309
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
3310
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
3311
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
3312
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1✔
3313
  ck_assert_msg(resolve_on_default_count == 0,
1✔
3314
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
3315
  ck_assert_msg(resolve_on_other_count == 0,
3316
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
3317
}
1✔
3318
END_TEST
3319

1✔
3320
START_TEST (jot_resolve_logfmt_xfer_path_test) {
3321
  int res;
1✔
3322
  cmd_rec *cmd;
3323
  unsigned char logfmt[3];
3324

1✔
3325
  logfmt[0] = LOGFMT_META_START;
1✔
3326
  logfmt[1] = LOGFMT_META_XFER_PATH;
1✔
3327
  logfmt[2] = 0;
1✔
3328

1✔
3329
  mark_point();
1✔
3330
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
3331
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
3332
  cmd->cmd_class = CL_MISC;
1✔
3333
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
3334
    resolve_on_meta, resolve_on_default, resolve_on_other);
3335
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
3336
  ck_assert_msg(resolve_on_meta_count == 0,
3337
    "Expected on_meta count 0, got %u", resolve_on_meta_count);
1✔
3338
  ck_assert_msg(resolve_on_default_count == 1,
3339
    "Expected on_default count 1, got %u", resolve_on_default_count);
3340
  ck_assert_msg(resolve_on_other_count == 0,
1✔
3341
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
3342

3343
  mark_point();
1✔
3344
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
3345
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "RNTO"));
1✔
3346
  cmd->cmd_class = CL_MISC;
1✔
3347
  cmd->arg = pstrdup(p, "foo");
1✔
3348
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
3349
    resolve_on_meta, resolve_on_default, resolve_on_other);
3350
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
3351
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
3352
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
3353
  ck_assert_msg(resolve_on_default_count == 0,
1✔
3354
    "Expected on_default count 0, got %u", resolve_on_default_count);
3355
  ck_assert_msg(resolve_on_other_count == 0,
1✔
3356
    "Expected on_other count 0, got %u", resolve_on_other_count);
3357

3358
  mark_point();
1✔
3359
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
3360
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
1✔
3361
  cmd->cmd_class = CL_MISC;
1✔
3362
  session.xfer.p = p;
1✔
3363
  session.xfer.path = pstrdup(p, "foo/bar");
1✔
3364
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
3365
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
3366
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
3367
  ck_assert_msg(resolve_on_meta_count == 1,
3368
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1✔
3369
  ck_assert_msg(resolve_on_default_count == 0,
3370
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
3371
  ck_assert_msg(resolve_on_other_count == 0,
3372
    "Expected on_other count 0, got %u", resolve_on_other_count);
3373

1✔
3374
  session.xfer.p = NULL;
1✔
3375
  session.xfer.path = NULL;
1✔
3376

1✔
3377
  mark_point();
1✔
3378
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
3379
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "DELE"));
3380
  cmd->cmd_class = CL_MISC;
1✔
3381
  cmd->arg = pstrdup(p, "foo/bar");
1✔
3382
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
3383
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
3384
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
3385
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
3386
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
3387
  ck_assert_msg(resolve_on_default_count == 0,
3388
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
3389
  ck_assert_msg(resolve_on_other_count == 0,
1✔
3390
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
3391

1✔
3392
  mark_point();
1✔
3393
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
3394
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "MKD"));
3395
  cmd->cmd_class = CL_MISC;
1✔
3396
  cmd->arg = pstrdup(p, "foo/bar");
1✔
3397
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
3398
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
3399
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
3400
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
3401
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
3402
  ck_assert_msg(resolve_on_default_count == 0,
3403
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
3404
  ck_assert_msg(resolve_on_other_count == 0,
1✔
3405
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
3406

1✔
3407
  mark_point();
1✔
3408
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
3409
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "XMKD"));
3410
  cmd->cmd_class = CL_MISC;
1✔
3411
  cmd->arg = pstrdup(p, "foo/bar");
1✔
3412
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
3413
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
3414
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
3415
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
3416
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
3417
  ck_assert_msg(resolve_on_default_count == 0,
1✔
3418
    "Expected on_default count 0, got %u", resolve_on_default_count);
3419
  ck_assert_msg(resolve_on_other_count == 0,
3420
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
3421

1✔
3422
  mark_point();
1✔
3423
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
3424
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "RMD"));
3425
  cmd->cmd_class = CL_MISC;
1✔
3426
  cmd->arg = pstrdup(p, "foo/bar");
1✔
3427
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
3428
    resolve_on_meta, resolve_on_default, resolve_on_other);
3429
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
3430
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
3431
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1✔
3432
  ck_assert_msg(resolve_on_default_count == 0,
1✔
3433
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
3434
  ck_assert_msg(resolve_on_other_count == 0,
3435
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
3436

1✔
3437
  mark_point();
3438
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
3439
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "XRMD"));
3440
  cmd->cmd_class = CL_MISC;
1✔
3441
  cmd->arg = pstrdup(p, "foo/bar");
3442
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
3443
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
3444
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
3445
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
3446
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1✔
3447
  ck_assert_msg(resolve_on_default_count == 0,
1✔
3448
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
3449
  ck_assert_msg(resolve_on_other_count == 0,
3450
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
3451
}
1✔
3452
END_TEST
3453

1✔
3454
START_TEST (jot_resolve_logfmt_xfer_port_test) {
3455
  int res;
1✔
3456
  cmd_rec *cmd;
3457
  unsigned char logfmt[3];
3458

1✔
3459
  logfmt[0] = LOGFMT_META_START;
1✔
3460
  logfmt[1] = LOGFMT_META_XFER_PORT;
1✔
3461
  logfmt[2] = 0;
1✔
3462

1✔
3463
  mark_point();
1✔
3464
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
3465
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
1✔
3466
  cmd->cmd_class = CL_MISC;
1✔
3467
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
3468
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
3469
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
3470
  ck_assert_msg(resolve_on_meta_count == 0,
1✔
3471
    "Expected on_meta count 0, got %u", resolve_on_meta_count);
3472
  ck_assert_msg(resolve_on_default_count == 1,
3473
    "Expected on_default count 1, got %u", resolve_on_default_count);
1✔
3474
  ck_assert_msg(resolve_on_other_count == 0,
1✔
3475
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
3476

1✔
3477
  mark_point();
1✔
3478
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
3479
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "PASV"));
3480
  cmd->cmd_class = CL_MISC;
1✔
3481
  session.data_port = 7777;
1✔
3482
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
3483
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
3484
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
3485
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
3486
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
3487
  ck_assert_msg(resolve_on_default_count == 0,
3488
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
3489
  ck_assert_msg(resolve_on_other_count == 0,
1✔
3490
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
3491

1✔
3492
  mark_point();
1✔
3493
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
3494
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "PORT"));
3495
  cmd->cmd_class = CL_MISC;
1✔
3496
  session.data_port = 7777;
1✔
3497
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
3498
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
3499
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
3500
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
3501
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
3502
  ck_assert_msg(resolve_on_default_count == 0,
3503
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
3504
  ck_assert_msg(resolve_on_other_count == 0,
1✔
3505
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
3506

1✔
3507
  mark_point();
1✔
3508
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
3509
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "EPRT"));
3510
  cmd->cmd_class = CL_MISC;
1✔
3511
  session.data_port = 7777;
1✔
3512
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
3513
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
3514
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
3515
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
3516
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
3517
  ck_assert_msg(resolve_on_default_count == 0,
3518
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
3519
  ck_assert_msg(resolve_on_other_count == 0,
1✔
3520
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
3521

1✔
3522
  mark_point();
1✔
3523
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
3524
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "EPSV"));
3525
  cmd->cmd_class = CL_MISC;
1✔
3526
  session.data_port = 7777;
1✔
3527
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
3528
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
3529
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
3530
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
3531
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
3532
  ck_assert_msg(resolve_on_default_count == 0,
3533
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
3534
  ck_assert_msg(resolve_on_other_count == 0,
1✔
3535
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
3536

1✔
3537
  mark_point();
1✔
3538
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
3539
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "APPE"));
3540
  cmd->cmd_class = CL_MISC;
1✔
3541
  session.data_port = 7777;
1✔
3542
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
3543
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
3544
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
3545
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
3546
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
3547
  ck_assert_msg(resolve_on_default_count == 0,
3548
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
3549
  ck_assert_msg(resolve_on_other_count == 0,
1✔
3550
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
3551

1✔
3552
  mark_point();
1✔
3553
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
3554
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "LIST"));
3555
  cmd->cmd_class = CL_MISC;
1✔
3556
  session.data_port = 7777;
1✔
3557
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
3558
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
3559
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
3560
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
3561
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
3562
  ck_assert_msg(resolve_on_default_count == 0,
3563
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
3564
  ck_assert_msg(resolve_on_other_count == 0,
1✔
3565
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
3566

1✔
3567
  mark_point();
1✔
3568
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
3569
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "MLSD"));
3570
  cmd->cmd_class = CL_MISC;
1✔
3571
  session.data_port = 7777;
1✔
3572
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
3573
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
3574
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
3575
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
3576
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
3577
  ck_assert_msg(resolve_on_default_count == 0,
3578
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
3579
  ck_assert_msg(resolve_on_other_count == 0,
1✔
3580
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
3581

1✔
3582
  mark_point();
1✔
3583
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
3584
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "NLST"));
3585
  cmd->cmd_class = CL_MISC;
1✔
3586
  session.data_port = 7777;
1✔
3587
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
3588
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
3589
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
3590
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
3591
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
3592
  ck_assert_msg(resolve_on_default_count == 0,
3593
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
3594
  ck_assert_msg(resolve_on_other_count == 0,
1✔
3595
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
3596

1✔
3597
  mark_point();
1✔
3598
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
3599
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "RETR"));
3600
  cmd->cmd_class = CL_MISC;
1✔
3601
  session.data_port = 7777;
1✔
3602
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
3603
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
3604
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
3605
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
3606
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
3607
  ck_assert_msg(resolve_on_default_count == 0,
3608
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
3609
  ck_assert_msg(resolve_on_other_count == 0,
1✔
3610
    "Expected on_other count 0, got %u", resolve_on_other_count);
3611

3612
  mark_point();
1✔
3613
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
3614
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "STOR"));
1✔
3615
  cmd->cmd_class = CL_MISC;
1✔
3616
  session.data_port = 7777;
3617
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
3618
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
3619
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
3620
  ck_assert_msg(resolve_on_meta_count == 1,
3621
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1✔
3622
  ck_assert_msg(resolve_on_default_count == 0,
1✔
3623
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
3624
  ck_assert_msg(resolve_on_other_count == 0,
1✔
3625
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
3626

3627
  mark_point();
1✔
3628
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
3629
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "STOU"));
3630
  cmd->cmd_class = CL_MISC;
1✔
3631
  session.data_port = 7777;
3632
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
3633
    resolve_on_meta, resolve_on_default, resolve_on_other);
3634
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
3635
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
3636
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1✔
3637
  ck_assert_msg(resolve_on_default_count == 0,
1✔
3638
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
3639
  ck_assert_msg(resolve_on_other_count == 0,
1✔
3640
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
3641

3642
  session.data_port = 0;
1✔
3643
}
1✔
3644
END_TEST
3645

1✔
3646
START_TEST (jot_resolve_logfmt_xfer_type_test) {
3647
  int res;
1✔
3648
  cmd_rec *cmd;
3649
  unsigned char logfmt[3];
3650

1✔
3651
  logfmt[0] = LOGFMT_META_START;
1✔
3652
  logfmt[1] = LOGFMT_META_XFER_TYPE;
1✔
3653
  logfmt[2] = 0;
1✔
3654

1✔
3655
  mark_point();
1✔
3656
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
3657
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
1✔
3658
  cmd->cmd_class = CL_MISC;
1✔
3659
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
3660
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
3661
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
3662
  ck_assert_msg(resolve_on_meta_count == 0,
1✔
3663
    "Expected on_meta count 0, got %u", resolve_on_meta_count);
3664
  ck_assert_msg(resolve_on_default_count == 1,
3665
    "Expected on_default count 1, got %u", resolve_on_default_count);
1✔
3666
  ck_assert_msg(resolve_on_other_count == 0,
3667
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
3668

1✔
3669
  mark_point();
1✔
3670
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
3671
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "APPE"));
1✔
3672
  cmd->cmd_class = CL_MISC;
3673
  session.sf_flags = SF_ASCII;
1✔
3674
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
3675
    resolve_on_meta, resolve_on_default, resolve_on_other);
3676
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
3677
  ck_assert_msg(resolve_on_meta_count == 1,
3678
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1✔
3679
  ck_assert_msg(resolve_on_default_count == 0,
3680
    "Expected on_default count 0, got %u", resolve_on_default_count);
3681
  ck_assert_msg(resolve_on_other_count == 0,
1✔
3682
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
3683

1✔
3684
  mark_point();
1✔
3685
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
3686
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "LIST"));
1✔
3687
  cmd->cmd_class = CL_MISC;
3688
  session.sf_flags = SF_ASCII_OVERRIDE;
1✔
3689
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
3690
    resolve_on_meta, resolve_on_default, resolve_on_other);
3691
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
3692
  ck_assert_msg(resolve_on_meta_count == 1,
3693
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1✔
3694
  ck_assert_msg(resolve_on_default_count == 0,
3695
    "Expected on_default count 0, got %u", resolve_on_default_count);
3696
  ck_assert_msg(resolve_on_other_count == 0,
1✔
3697
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
3698

1✔
3699
  session.sf_flags = 0;
1✔
3700

1✔
3701
  mark_point();
1✔
3702
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
3703
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "MLSD"));
1✔
3704
  cmd->cmd_class = CL_MISC;
1✔
3705
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
3706
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
3707
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
3708
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
3709
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
3710
  ck_assert_msg(resolve_on_default_count == 0,
3711
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
3712
  ck_assert_msg(resolve_on_other_count == 0,
1✔
3713
    "Expected on_other count 0, got %u", resolve_on_other_count);
3714

3715
  mark_point();
1✔
3716
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
3717
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "RETR"));
1✔
3718
  cmd->cmd_class = CL_MISC;
1✔
3719
  tests_stubs_set_protocol("sftp");
3720
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
3721
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
3722
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
3723
  ck_assert_msg(resolve_on_meta_count == 1,
3724
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1✔
3725
  ck_assert_msg(resolve_on_default_count == 0,
1✔
3726
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
3727
  ck_assert_msg(resolve_on_other_count == 0,
1✔
3728
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
3729

3730
  mark_point();
1✔
3731
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
3732
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "STOR"));
3733
  cmd->cmd_class = CL_MISC;
1✔
3734
  tests_stubs_set_protocol("scp");
3735
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
3736
    resolve_on_meta, resolve_on_default, resolve_on_other);
3737
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
3738
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
3739
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1✔
3740
  ck_assert_msg(resolve_on_default_count == 0,
1✔
3741
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
3742
  ck_assert_msg(resolve_on_other_count == 0,
1✔
3743
    "Expected on_other count 0, got %u", resolve_on_other_count);
3744

1✔
3745
  tests_stubs_set_protocol(NULL);
1✔
3746
}
3747
END_TEST
1✔
3748

3749
START_TEST (jot_resolve_logfmt_xfer_status_test) {
1✔
3750
  int res;
3751
  cmd_rec *cmd;
3752
  unsigned char logfmt[3];
1✔
3753

1✔
3754
  logfmt[0] = LOGFMT_META_START;
1✔
3755
  logfmt[1] = LOGFMT_META_XFER_STATUS;
1✔
3756
  logfmt[2] = 0;
1✔
3757

1✔
3758
  mark_point();
3759
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
3760
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
1✔
3761
  cmd->cmd_class = CL_MISC;
3762
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
3763
    resolve_on_meta, resolve_on_default, resolve_on_other);
3764
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
3765
  ck_assert_msg(resolve_on_meta_count == 0,
3766
    "Expected on_meta count 0, got %u", resolve_on_meta_count);
3767
  ck_assert_msg(resolve_on_default_count == 1,
1✔
3768
    "Expected on_default count 1, got %u", resolve_on_default_count);
3769
  ck_assert_msg(resolve_on_other_count == 0,
3770
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
3771

1✔
3772
  mark_point();
1✔
3773
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
3774
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "RETR"));
1✔
3775
  cmd->cmd_class = CL_MISC;
1✔
3776
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
3777
    resolve_on_meta, resolve_on_default, resolve_on_other);
3778
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
3779
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
3780
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
3781
  ck_assert_msg(resolve_on_default_count == 0,
1✔
3782
    "Expected on_default count 0, got %u", resolve_on_default_count);
3783
  ck_assert_msg(resolve_on_other_count == 0,
1✔
3784
    "Expected on_other count 0, got %u", resolve_on_other_count);
3785

3786
  mark_point();
1✔
3787
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
3788
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "RETR"));
3789
  cmd->cmd_class = CL_MISC;
1✔
3790
  tests_stubs_set_protocol("ftps");
1✔
3791
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
3792
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
3793
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
3794
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
3795
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1✔
3796
  ck_assert_msg(resolve_on_default_count == 0,
3797
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
3798
  ck_assert_msg(resolve_on_other_count == 0,
1✔
3799
    "Expected on_other count 0, got %u", resolve_on_other_count);
3800

1✔
3801
  tests_stubs_set_protocol(NULL);
3802

1✔
3803
  /* 5xx response */
3804
  mark_point();
3805
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
3806
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "RETR"));
3807
  cmd->cmd_class = CL_MISC;
3808
  pr_response_set_pool(p);
1✔
3809
  pr_response_add("500", "foo %s", "bar");
1✔
3810
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
3811
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
3812
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
3813
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
3814
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1✔
3815
  ck_assert_msg(resolve_on_default_count == 0,
3816
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
3817
  ck_assert_msg(resolve_on_other_count == 0,
1✔
3818
    "Expected on_other count 0, got %u", resolve_on_other_count);
3819

1✔
3820
  pr_response_clear(&resp_list);
3821

1✔
3822
  /* 1xx response */
3823
  mark_point();
3824
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
3825
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "RETR"));
3826
  cmd->cmd_class = CL_MISC;
3827
  pr_response_set_pool(p);
1✔
3828
  pr_response_add("123", "foo %s", "bar");
1✔
3829
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
3830
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
3831
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
3832
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
3833
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1✔
3834
  ck_assert_msg(resolve_on_default_count == 0,
3835
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
3836
  ck_assert_msg(resolve_on_other_count == 0,
1✔
3837
    "Expected on_other count 0, got %u", resolve_on_other_count);
3838

1✔
3839
  pr_response_clear(&resp_list);
3840

1✔
3841
  /* 2xx response */
3842
  mark_point();
3843
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
3844
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "RETR"));
3845
  cmd->cmd_class = CL_MISC;
3846
  pr_response_set_pool(p);
1✔
3847
  pr_response_add("234", "foo %s", "bar");
1✔
3848
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
3849
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
3850
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
3851
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
3852
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
3853
  ck_assert_msg(resolve_on_default_count == 0,
1✔
3854
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
3855
  ck_assert_msg(resolve_on_other_count == 0,
3856
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
3857

3858
  pr_response_clear(&resp_list);
1✔
3859

3860
  /* ABOR */
3861
  mark_point();
1✔
3862
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
3863
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "ABOR"));
1✔
3864
  cmd->cmd_class = CL_MISC;
3865
  pr_response_set_pool(p);
1✔
3866
  pr_response_add("234", "foo %s", "bar");
1✔
3867
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
3868
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
3869
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
3870
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
3871
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
3872
  ck_assert_msg(resolve_on_default_count == 0,
1✔
3873
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
3874
  ck_assert_msg(resolve_on_other_count == 0,
3875
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
3876

3877
  pr_response_clear(&resp_list);
1✔
3878

3879
  /* SF_ABORT */
3880
  mark_point();
1✔
3881
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
3882
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "RETR"));
1✔
3883
  cmd->cmd_class = CL_MISC;
1✔
3884
  session.sf_flags = SF_ABORT;
1✔
3885
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
3886
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
3887
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
3888
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
3889
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1✔
3890
  ck_assert_msg(resolve_on_default_count == 0,
3891
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
3892
  ck_assert_msg(resolve_on_other_count == 0,
3893
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
3894

3895
  session.sf_flags = 0;
3896
  pr_response_clear(&resp_list);
1✔
3897
  pr_response_set_pool(NULL);
1✔
3898

3899
  mark_point();
3900
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
3901
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "RETR"));
1✔
3902
  cmd->cmd_class = CL_MISC;
1✔
3903
  tests_stubs_set_protocol("sftp");
1✔
3904
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
3905
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
3906
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
3907
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
3908
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
3909
  ck_assert_msg(resolve_on_default_count == 0,
1✔
3910
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
3911
  ck_assert_msg(resolve_on_other_count == 0,
1✔
3912
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
3913

1✔
3914
  mark_point();
3915
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
3916
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "STOR"));
1✔
3917
  cmd->cmd_class = CL_MISC;
3918
  pr_table_add_dup(cmd->notes, "mod_sftp.file-status", "FOO!", 0);
1✔
3919
  tests_stubs_set_protocol("sftp");
3920
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
3921
    resolve_on_meta, resolve_on_default, resolve_on_other);
3922
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
3923
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
3924
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1✔
3925
  ck_assert_msg(resolve_on_default_count == 0,
1✔
3926
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
3927
  ck_assert_msg(resolve_on_other_count == 0,
1✔
3928
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
3929

3930
  tests_stubs_set_protocol(NULL);
1✔
3931
}
1✔
3932
END_TEST
3933

1✔
3934
START_TEST (jot_resolve_logfmt_xfer_failure_test) {
3935
  int res;
1✔
3936
  cmd_rec *cmd;
3937
  unsigned char logfmt[3];
3938

1✔
3939
  logfmt[0] = LOGFMT_META_START;
3940
  logfmt[1] = LOGFMT_META_XFER_FAILURE;
3941
  logfmt[2] = 0;
1✔
3942

1✔
3943
  mark_point();
1✔
3944
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
3945
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
1✔
3946
  cmd->cmd_class = CL_MISC;
1✔
3947
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
3948
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
3949
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
3950
  ck_assert_msg(resolve_on_meta_count == 0,
3951
    "Expected on_meta count 0, got %u", resolve_on_meta_count);
1✔
3952
  ck_assert_msg(resolve_on_default_count == 1,
3953
    "Expected on_default count 1, got %u", resolve_on_default_count);
1✔
3954
  ck_assert_msg(resolve_on_other_count == 0,
3955
    "Expected on_other count 0, got %u", resolve_on_other_count);
3956

1✔
3957
  mark_point();
3958
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
3959
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "RETR"));
1✔
3960
  cmd->cmd_class = CL_MISC;
1✔
3961
  tests_stubs_set_protocol("ftps");
1✔
3962
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
3963
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
3964
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
3965
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
3966
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
3967
  ck_assert_msg(resolve_on_default_count == 0,
1✔
3968
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
3969
  ck_assert_msg(resolve_on_other_count == 0,
3970
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
3971

3972
  tests_stubs_set_protocol(NULL);
1✔
3973

3974
  /* SF_ABORT */
3975
  mark_point();
1✔
3976
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
3977
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "RETR"));
3978
  cmd->cmd_class = CL_MISC;
3979
  session.sf_flags = SF_ABORT;
1✔
3980
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
3981
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
3982
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
3983
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
3984
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1✔
3985
  ck_assert_msg(resolve_on_default_count == 0,
1✔
3986
    "Expected on_default count 0, got %u", resolve_on_default_count);
3987
  ck_assert_msg(resolve_on_other_count == 0,
1✔
3988
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
3989

3990
  session.sf_flags = 0;
1✔
3991

3992
  /* 5xx response */
1✔
3993
  mark_point();
3994
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
3995
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "RETR"));
1✔
3996
  cmd->cmd_class = CL_MISC;
1✔
3997
  pr_response_set_pool(p);
3998
  pr_response_add("543", "foo %s", "BAR BAZ");
3999
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
4000
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
4001
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
4002
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
4003
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1✔
4004
  ck_assert_msg(resolve_on_default_count == 0,
1✔
4005
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
4006
  ck_assert_msg(resolve_on_other_count == 0,
4007
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
4008

1✔
4009
  pr_response_clear(&resp_list);
4010
  pr_response_set_pool(NULL);
1✔
4011

4012
  /* 1xx response */
1✔
4013
  mark_point();
4014
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
4015
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "RETR"));
1✔
4016
  cmd->cmd_class = CL_MISC;
1✔
4017
  pr_response_set_pool(p);
4018
  pr_response_add("123", "foo %s", "BAR BAZ");
1✔
4019
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
4020
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
4021
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
4022
  ck_assert_msg(resolve_on_meta_count == 0,
1✔
4023
    "Expected on_meta count 0, got %u", resolve_on_meta_count);
1✔
4024
  ck_assert_msg(resolve_on_default_count == 1,
4025
    "Expected on_default count 1, got %u", resolve_on_default_count);
1✔
4026
  ck_assert_msg(resolve_on_other_count == 0,
1✔
4027
    "Expected on_other count 0, got %u", resolve_on_other_count);
4028

1✔
4029
  pr_response_clear(&resp_list);
4030
  pr_response_set_pool(NULL);
1✔
4031

4032
  /* 2xx response */
4033
  mark_point();
1✔
4034
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
4035
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "RETR"));
4036
  cmd->cmd_class = CL_MISC;
4037
  pr_response_set_pool(p);
1✔
4038
  pr_response_add("234", "foo %s", "BAR BAZ");
1✔
4039
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
4040
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
4041
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
4042
  ck_assert_msg(resolve_on_meta_count == 0,
1✔
4043
    "Expected on_meta count 0, got %u", resolve_on_meta_count);
1✔
4044
  ck_assert_msg(resolve_on_default_count == 1,
1✔
4045
    "Expected on_default count 1, got %u", resolve_on_default_count);
4046
  ck_assert_msg(resolve_on_other_count == 0,
1✔
4047
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
4048

1✔
4049
  pr_response_clear(&resp_list);
1✔
4050
  pr_response_set_pool(NULL);
1✔
4051

4052
  mark_point();
1✔
4053
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
4054
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "RETR"));
4055
  cmd->cmd_class = CL_MISC;
1✔
4056
  tests_stubs_set_protocol("sftp");
4057
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
4058
    resolve_on_meta, resolve_on_default, resolve_on_other);
4059
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
4060
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
4061
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1✔
4062
  ck_assert_msg(resolve_on_default_count == 0,
1✔
4063
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
4064
  ck_assert_msg(resolve_on_other_count == 0,
1✔
4065
    "Expected on_other count 0, got %u", resolve_on_other_count);
4066

1✔
4067
  tests_stubs_set_protocol(NULL);
1✔
4068
}
4069
END_TEST
1✔
4070

4071
START_TEST (jot_resolve_logfmt_dir_name_test) {
1✔
4072
  int res;
4073
  cmd_rec *cmd;
4074
  unsigned char logfmt[3];
1✔
4075

1✔
4076
  logfmt[0] = LOGFMT_META_START;
1✔
4077
  logfmt[1] = LOGFMT_META_DIR_NAME;
1✔
4078
  logfmt[2] = 0;
1✔
4079

1✔
4080
  mark_point();
4081
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
4082
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
1✔
4083
  cmd->cmd_class = CL_MISC;
4084
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
4085
    resolve_on_meta, resolve_on_default, resolve_on_other);
4086
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
4087
  ck_assert_msg(resolve_on_meta_count == 1,
4088
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
4089
  ck_assert_msg(resolve_on_default_count == 0,
1✔
4090
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
4091
  ck_assert_msg(resolve_on_other_count == 0,
1✔
4092
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
4093

1✔
4094
  mark_point();
1✔
4095
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
4096
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "CDUP"));
1✔
4097
  cmd->cmd_class = CL_MISC;
1✔
4098
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
4099
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
4100
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
4101
  ck_assert_msg(resolve_on_meta_count == 0,
1✔
4102
    "Expected on_meta count 0, got %u", resolve_on_meta_count);
4103
  ck_assert_msg(resolve_on_default_count == 1,
4104
    "Expected on_default count 1, got %u", resolve_on_default_count);
1✔
4105
  ck_assert_msg(resolve_on_other_count == 0,
1✔
4106
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
4107

1✔
4108
  mark_point();
1✔
4109
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
4110
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "CWD"));
4111
  cmd->cmd_class = CL_MISC;
1✔
4112
  cmd->arg = pstrdup(p, "foo");
1✔
4113
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
4114
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
4115
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
4116
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
4117
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
4118
  ck_assert_msg(resolve_on_default_count == 0,
4119
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
4120
  ck_assert_msg(resolve_on_other_count == 0,
1✔
4121
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
4122

1✔
4123
  mark_point();
1✔
4124
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
4125
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "LIST"));
4126
  cmd->cmd_class = CL_MISC;
1✔
4127
  cmd->arg = pstrdup(p, "/foo");
1✔
4128
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
4129
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
4130
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
4131
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
4132
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
4133
  ck_assert_msg(resolve_on_default_count == 0,
4134
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
4135
  ck_assert_msg(resolve_on_other_count == 0,
1✔
4136
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
4137

1✔
4138
  mark_point();
1✔
4139
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
4140
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "MLSD"));
4141
  cmd->cmd_class = CL_MISC;
1✔
4142
  cmd->arg = pstrdup(p, "/foo/");
1✔
4143
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
4144
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
4145
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
4146
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
4147
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
4148
  ck_assert_msg(resolve_on_default_count == 0,
4149
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
4150
  ck_assert_msg(resolve_on_other_count == 0,
1✔
4151
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
4152

1✔
4153
  mark_point();
1✔
4154
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
4155
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "MKD"));
4156
  cmd->cmd_class = CL_MISC;
1✔
4157
  cmd->arg = pstrdup(p, "foo/");
1✔
4158
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
4159
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
4160
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
4161
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
4162
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
4163
  ck_assert_msg(resolve_on_default_count == 0,
4164
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
4165
  ck_assert_msg(resolve_on_other_count == 0,
1✔
4166
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
4167

1✔
4168
  mark_point();
1✔
4169
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
4170
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "NLST"));
4171
  cmd->cmd_class = CL_MISC;
1✔
4172
  cmd->arg = pstrdup(p, "foo/");
1✔
4173
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
4174
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
4175
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
4176
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
4177
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
4178
  ck_assert_msg(resolve_on_default_count == 0,
4179
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
4180
  ck_assert_msg(resolve_on_other_count == 0,
1✔
4181
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
4182

1✔
4183
  mark_point();
1✔
4184
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
4185
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "RMD"));
4186
  cmd->cmd_class = CL_MISC;
1✔
4187
  cmd->arg = pstrdup(p, "foo/");
1✔
4188
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
4189
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
4190
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
4191
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
4192
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
4193
  ck_assert_msg(resolve_on_default_count == 0,
4194
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
4195
  ck_assert_msg(resolve_on_other_count == 0,
1✔
4196
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
4197

1✔
4198
  mark_point();
1✔
4199
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
4200
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "XCWD"));
4201
  cmd->cmd_class = CL_MISC;
1✔
4202
  cmd->arg = pstrdup(p, "foo/");
1✔
4203
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
4204
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
4205
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
4206
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
4207
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
4208
  ck_assert_msg(resolve_on_default_count == 0,
4209
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
4210
  ck_assert_msg(resolve_on_other_count == 0,
1✔
4211
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
4212

1✔
4213
  mark_point();
1✔
4214
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
4215
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "XCUP"));
4216
  cmd->cmd_class = CL_MISC;
1✔
4217
  cmd->arg = pstrdup(p, "foo/");
1✔
4218
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
4219
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
4220
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
4221
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
4222
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
4223
  ck_assert_msg(resolve_on_default_count == 0,
1✔
4224
    "Expected on_default count 0, got %u", resolve_on_default_count);
4225
  ck_assert_msg(resolve_on_other_count == 0,
4226
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
4227

1✔
4228
  mark_point();
1✔
4229
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
4230
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "XMKD"));
4231
  cmd->cmd_class = CL_MISC;
1✔
4232
  cmd->arg = pstrdup(p, "foo/");
1✔
4233
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
4234
    resolve_on_meta, resolve_on_default, resolve_on_other);
4235
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
4236
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
4237
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1✔
4238
  ck_assert_msg(resolve_on_default_count == 0,
1✔
4239
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
4240
  ck_assert_msg(resolve_on_other_count == 0,
4241
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
4242

1✔
4243
  mark_point();
4244
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
4245
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "XRMD"));
4246
  cmd->cmd_class = CL_MISC;
1✔
4247
  cmd->arg = pstrdup(p, "foo/");
4248
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
4249
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
4250
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
4251
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
4252
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1✔
4253
  ck_assert_msg(resolve_on_default_count == 0,
1✔
4254
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
4255
  ck_assert_msg(resolve_on_other_count == 0,
4256
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
4257
}
1✔
4258
END_TEST
4259

1✔
4260
START_TEST (jot_resolve_logfmt_dir_path_test) {
4261
  int res;
1✔
4262
  cmd_rec *cmd;
4263
  unsigned char logfmt[3];
4264

1✔
4265
  logfmt[0] = LOGFMT_META_START;
1✔
4266
  logfmt[1] = LOGFMT_META_DIR_PATH;
1✔
4267
  logfmt[2] = 0;
1✔
4268

1✔
4269
  mark_point();
1✔
4270
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
4271
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
1✔
4272
  cmd->cmd_class = CL_MISC;
1✔
4273
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
4274
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
4275
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
4276
  ck_assert_msg(resolve_on_meta_count == 0,
1✔
4277
    "Expected on_meta count 0, got %u", resolve_on_meta_count);
4278
  ck_assert_msg(resolve_on_default_count == 1,
4279
    "Expected on_default count 1, got %u", resolve_on_default_count);
1✔
4280
  ck_assert_msg(resolve_on_other_count == 0,
1✔
4281
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
4282

1✔
4283
  mark_point();
1✔
4284
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
4285
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "CDUP"));
4286
  cmd->cmd_class = CL_MISC;
1✔
4287
  cmd->arg = pstrdup(p, "/foo/bar/baz");
1✔
4288
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
4289
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
4290
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
4291
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
4292
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
4293
  ck_assert_msg(resolve_on_default_count == 0,
4294
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
4295
  ck_assert_msg(resolve_on_other_count == 0,
1✔
4296
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
4297

1✔
4298
  mark_point();
1✔
4299
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
4300
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "LIST"));
4301
  cmd->cmd_class = CL_MISC;
1✔
4302
  cmd->arg = pstrdup(p, "/foo/bar/baz");
1✔
4303
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
4304
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
4305
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
4306
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
4307
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
4308
  ck_assert_msg(resolve_on_default_count == 0,
4309
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
4310
  ck_assert_msg(resolve_on_other_count == 0,
1✔
4311
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
4312

1✔
4313
  mark_point();
1✔
4314
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
4315
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "MKD"));
4316
  cmd->cmd_class = CL_MISC;
1✔
4317
  cmd->arg = pstrdup(p, "/foo/bar/baz");
1✔
4318
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
4319
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
4320
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
4321
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
4322
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
4323
  ck_assert_msg(resolve_on_default_count == 0,
4324
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
4325
  ck_assert_msg(resolve_on_other_count == 0,
1✔
4326
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
4327

1✔
4328
  mark_point();
1✔
4329
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
4330
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "MLSD"));
4331
  cmd->cmd_class = CL_MISC;
1✔
4332
  cmd->arg = pstrdup(p, "/foo/bar/baz");
1✔
4333
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
4334
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
4335
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
4336
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
4337
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
4338
  ck_assert_msg(resolve_on_default_count == 0,
4339
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
4340
  ck_assert_msg(resolve_on_other_count == 0,
1✔
4341
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
4342

1✔
4343
  mark_point();
1✔
4344
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
4345
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "NLST"));
4346
  cmd->cmd_class = CL_MISC;
1✔
4347
  cmd->arg = pstrdup(p, "/foo/bar/baz");
1✔
4348
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
4349
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
4350
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
4351
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
4352
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
4353
  ck_assert_msg(resolve_on_default_count == 0,
4354
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
4355
  ck_assert_msg(resolve_on_other_count == 0,
1✔
4356
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
4357

1✔
4358
  mark_point();
1✔
4359
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
4360
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "RMD"));
4361
  cmd->cmd_class = CL_MISC;
1✔
4362
  cmd->arg = pstrdup(p, "/foo/bar/baz");
1✔
4363
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
4364
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
4365
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
4366
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
4367
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
4368
  ck_assert_msg(resolve_on_default_count == 0,
4369
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
4370
  ck_assert_msg(resolve_on_other_count == 0,
1✔
4371
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
4372

1✔
4373
  mark_point();
1✔
4374
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
4375
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "XCUP"));
4376
  cmd->cmd_class = CL_MISC;
1✔
4377
  cmd->arg = pstrdup(p, "/foo/bar/baz");
1✔
4378
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
4379
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
4380
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
4381
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
4382
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
4383
  ck_assert_msg(resolve_on_default_count == 0,
4384
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
4385
  ck_assert_msg(resolve_on_other_count == 0,
1✔
4386
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
4387

1✔
4388
  mark_point();
1✔
4389
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
4390
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "XMKD"));
1✔
4391
  cmd->cmd_class = CL_MISC;
1✔
4392
  cmd->arg = pstrdup(p, "/foo/bar/baz");
4393
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
4394
    resolve_on_meta, resolve_on_default, resolve_on_other);
4395
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
4396
  ck_assert_msg(resolve_on_meta_count == 1,
4397
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
4398
  ck_assert_msg(resolve_on_default_count == 0,
1✔
4399
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
4400
  ck_assert_msg(resolve_on_other_count == 0,
1✔
4401
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
4402

1✔
4403
  mark_point();
1✔
4404
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
4405
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "XRMD"));
1✔
4406
  cmd->cmd_class = CL_MISC;
1✔
4407
  cmd->arg = pstrdup(p, "/foo/bar/baz");
4408
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
4409
    resolve_on_meta, resolve_on_default, resolve_on_other);
4410
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
4411
  ck_assert_msg(resolve_on_meta_count == 1,
4412
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
4413
  ck_assert_msg(resolve_on_default_count == 0,
1✔
4414
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
4415
  ck_assert_msg(resolve_on_other_count == 0,
4416
    "Expected on_other count 0, got %u", resolve_on_other_count);
4417

1✔
4418
  mark_point();
1✔
4419
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
4420
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "CWD"));
1✔
4421
  cmd->cmd_class = CL_MISC;
4422
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
4423
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
4424
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
4425
  ck_assert_msg(resolve_on_meta_count == 1,
4426
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1✔
4427
  ck_assert_msg(resolve_on_default_count == 0,
1✔
4428
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
4429
  ck_assert_msg(resolve_on_other_count == 0,
1✔
4430
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
4431

4432
  mark_point();
1✔
4433
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
4434
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "CWD"));
4435
  cmd->cmd_class = CL_MISC;
1✔
4436
  session.chroot_path = "/foo/bar/baz/";
4437
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
4438
    resolve_on_meta, resolve_on_default, resolve_on_other);
4439
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
4440
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
4441
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1✔
4442
  ck_assert_msg(resolve_on_default_count == 0,
1✔
4443
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
4444
  ck_assert_msg(resolve_on_other_count == 0,
4445
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
4446

1✔
4447
  session.chroot_path = NULL;
4448
}
1✔
4449
END_TEST
4450

1✔
4451
START_TEST (jot_resolve_logfmt_cmd_params_test) {
4452
  int res;
4453
  cmd_rec *cmd;
1✔
4454
  unsigned char logfmt[3];
1✔
4455

1✔
4456
  logfmt[0] = LOGFMT_META_START;
1✔
4457
  logfmt[1] = LOGFMT_META_CMD_PARAMS;
4458
  logfmt[2] = 0;
1✔
4459

1✔
4460
  mark_point();
4461
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
1✔
4462
  cmd->cmd_class = CL_CONNECT;
4463
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
4464
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
4465
    resolve_on_meta, resolve_on_default, resolve_on_other);
4466
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
4467
  ck_assert_msg(resolve_on_meta_count == 0,
1✔
4468
    "Expected on_meta count 0, got %u", resolve_on_meta_count);
1✔
4469
  ck_assert_msg(resolve_on_default_count == 1,
1✔
4470
    "Expected on_default count 1, got %u", resolve_on_default_count);
1✔
4471
  ck_assert_msg(resolve_on_other_count == 0,
1✔
4472
    "Expected on_other count 0, got %u", resolve_on_other_count);
4473

1✔
4474
  mark_point();
1✔
4475
  cmd->cmd_class = CL_DISCONNECT;
4476
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
4477
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
4478
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
4479
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
4480
  ck_assert_msg(resolve_on_meta_count == 0,
4481
    "Expected on_meta count 0, got %u", resolve_on_meta_count);
1✔
4482
  ck_assert_msg(resolve_on_default_count == 1,
1✔
4483
    "Expected on_default count 1, got %u", resolve_on_default_count);
1✔
4484
  ck_assert_msg(resolve_on_other_count == 0,
1✔
4485
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
4486

4487
  mark_point();
1✔
4488
  cmd->cmd_class = CL_MISC;
1✔
4489
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
4490
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
4491
    resolve_on_meta, resolve_on_default, resolve_on_other);
4492
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
4493
  ck_assert_msg(resolve_on_meta_count == 0,
4494
    "Expected on_meta count 0, got %u", resolve_on_meta_count);
4495
  ck_assert_msg(resolve_on_default_count == 1,
1✔
4496
    "Expected on_default count 1, got %u", resolve_on_default_count);
1✔
4497
  ck_assert_msg(resolve_on_other_count == 0,
1✔
4498
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
4499

1✔
4500
  mark_point();
4501
  cmd = pr_cmd_alloc(p, 2, pstrdup(p, "FOO"), pstrdup(p, "bar"));
1✔
4502
  cmd->arg = pstrdup(p, "baz");
1✔
4503
  cmd->cmd_class = CL_MISC;
4504
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
4505
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
4506
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
4507
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
4508
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
4509
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
4510
  ck_assert_msg(resolve_on_default_count == 0,
4511
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
4512
  ck_assert_msg(resolve_on_other_count == 0,
1✔
4513
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
4514

1✔
4515
  mark_point();
1✔
4516
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "ADAT"));
4517
  cmd->cmd_class = CL_SEC;
1✔
4518
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
4519
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
4520
    resolve_on_meta, resolve_on_default, resolve_on_other);
4521
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
4522
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
4523
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1✔
4524
  ck_assert_msg(resolve_on_default_count == 0,
1✔
4525
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
4526
  ck_assert_msg(resolve_on_other_count == 0,
4527
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
4528

1✔
4529
  mark_point();
4530
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "PASS"));
1✔
4531
  cmd->cmd_class = CL_AUTH;
4532
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
4533
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
4534
    resolve_on_meta, resolve_on_default, resolve_on_other);
4535
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
4536
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
4537
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1✔
4538
  ck_assert_msg(resolve_on_default_count == 0,
1✔
4539
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
4540
  ck_assert_msg(resolve_on_other_count == 0,
4541
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
4542
}
1✔
4543
END_TEST
4544

1✔
4545
START_TEST (jot_resolve_logfmt_rename_from_test) {
4546
  int res;
1✔
4547
  cmd_rec *cmd;
4548
  unsigned char logfmt[3];
4549
  char *rnfr_path;
1✔
4550

1✔
4551
  logfmt[0] = LOGFMT_META_START;
1✔
4552
  logfmt[1] = LOGFMT_META_RENAME_FROM;
1✔
4553
  logfmt[2] = 0;
1✔
4554

1✔
4555
  mark_point();
4556
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
1✔
4557
  cmd->cmd_class = CL_MISC;
1✔
4558
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
4559
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
4560
    resolve_on_meta, resolve_on_default, resolve_on_other);
4561
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
4562
  ck_assert_msg(resolve_on_meta_count == 0,
4563
    "Expected on_meta count 0, got %u", resolve_on_meta_count);
4564
  ck_assert_msg(resolve_on_default_count == 1,
1✔
4565
    "Expected on_default count 1, got %u", resolve_on_default_count);
1✔
4566
  ck_assert_msg(resolve_on_other_count == 0,
1✔
4567
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
4568

4569
  mark_point();
4570
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "RNTO"));
1✔
4571
  cmd->cmd_class = CL_MISC;
1✔
4572
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
4573
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
4574
    resolve_on_meta, resolve_on_default, resolve_on_other);
4575
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
4576
  ck_assert_msg(resolve_on_meta_count == 0,
1✔
4577
    "Expected on_meta count 0, got %u", resolve_on_meta_count);
1✔
4578
  ck_assert_msg(resolve_on_default_count == 1,
1✔
4579
    "Expected on_default count 1, got %u", resolve_on_default_count);
1✔
4580
  ck_assert_msg(resolve_on_other_count == 0,
4581
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
4582

1✔
4583
  mark_point();
1✔
4584
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
4585
  rnfr_path = "FOOBAR";
1✔
4586
  session.notes = pr_table_alloc(p, 0);
1✔
4587
  pr_table_add_dup(session.notes, "mod_core.rnfr-path", rnfr_path, 0);
4588
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
4589
    resolve_on_meta, resolve_on_default, resolve_on_other);
4590
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
4591
  ck_assert_msg(resolve_on_meta_count == 1,
4592
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
4593
  ck_assert_msg(resolve_on_default_count == 0,
1✔
4594
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
4595
  ck_assert_msg(resolve_on_other_count == 0,
1✔
4596
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
4597

4598
  pr_table_empty(session.notes);
1✔
4599
  pr_table_free(session.notes);
1✔
4600
  session.notes = NULL;
4601
}
1✔
4602
END_TEST
4603

1✔
4604
START_TEST (jot_resolve_logfmt_eos_reason_test) {
4605
  int res;
4606
  cmd_rec *cmd;
1✔
4607
  unsigned char logfmt[3];
1✔
4608

1✔
4609
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
1✔
4610
  cmd->cmd_class = CL_MISC;
4611
  logfmt[0] = LOGFMT_META_START;
1✔
4612
  logfmt[1] = LOGFMT_META_EOS_REASON;
1✔
4613
  logfmt[2] = 0;
4614

1✔
4615
  mark_point();
4616
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
4617
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
4618
    resolve_on_meta, resolve_on_default, resolve_on_other);
4619
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
4620
  ck_assert_msg(resolve_on_meta_count == 0,
1✔
4621
    "Expected on_meta count 0, got %u", resolve_on_meta_count);
4622
  ck_assert_msg(resolve_on_default_count == 1,
4623
    "Expected on_default count 1, got %u", resolve_on_default_count);
1✔
4624
  ck_assert_msg(resolve_on_other_count == 0,
1✔
4625
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
4626

1✔
4627
  mark_point();
1✔
4628
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
4629
  session.disconnect_reason = -1;
1✔
4630
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
4631
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
4632
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
4633
  ck_assert_msg(resolve_on_meta_count == 0,
1✔
4634
    "Expected on_meta count 0, got %u", resolve_on_meta_count);
4635
  ck_assert_msg(resolve_on_default_count == 1,
1✔
4636
    "Expected on_default count 1, got %u", resolve_on_default_count);
1✔
4637
  ck_assert_msg(resolve_on_other_count == 0,
1✔
4638
    "Expected on_other count 0, got %u", resolve_on_other_count);
4639

1✔
4640
  mark_point();
1✔
4641
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
4642
  session.disconnect_reason = PR_SESS_DISCONNECT_BANNED;
1✔
4643
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
4644
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
4645
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
4646
  ck_assert_msg(resolve_on_meta_count == 1,
4647
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1✔
4648
  ck_assert_msg(resolve_on_default_count == 0,
1✔
4649
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
4650
  ck_assert_msg(resolve_on_other_count == 0,
1✔
4651
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
4652

1✔
4653
  session.disconnect_reason = 0;
4654
}
1✔
4655
END_TEST
1✔
4656

4657
START_TEST (jot_resolve_logfmt_vhost_ip_test) {
1✔
4658
  int res;
4659
  cmd_rec *cmd;
1✔
4660
  server_rec *server;
4661
  unsigned char logfmt[3];
1✔
4662

4663
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
4664
  cmd->cmd_class = CL_MISC;
1✔
4665
  logfmt[0] = LOGFMT_META_START;
1✔
4666
  logfmt[1] = LOGFMT_META_VHOST_IP;
1✔
4667
  logfmt[2] = 0;
1✔
4668

1✔
4669
  mark_point();
4670
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
4671
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
4672
    resolve_on_meta, resolve_on_default, resolve_on_other);
4673
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
4674
  ck_assert_msg(resolve_on_meta_count == 0,
1✔
4675
    "Expected on_meta count 0, got %u", resolve_on_meta_count);
1✔
4676
  ck_assert_msg(resolve_on_default_count == 1,
1✔
4677
    "Expected on_default count 1, got %u", resolve_on_default_count);
1✔
4678
  ck_assert_msg(resolve_on_other_count == 0,
1✔
4679
    "Expected on_other count 0, got %u", resolve_on_other_count);
4680

1✔
4681
  mark_point();
1✔
4682
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
4683
  server = pcalloc(p, sizeof(server_rec));
1✔
4684
  server->ServerAddress = "FOOBAR";
1✔
4685
  cmd->server = server;
4686
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
4687
    resolve_on_meta, resolve_on_default, resolve_on_other);
4688
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
4689
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
4690
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1✔
4691
  ck_assert_msg(resolve_on_default_count == 0,
1✔
4692
    "Expected on_default count 0, got %u", resolve_on_default_count);
4693
  ck_assert_msg(resolve_on_other_count == 0,
4694
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
4695
}
1✔
4696
END_TEST
4697

1✔
4698
START_TEST (jot_resolve_logfmt_filters_test) {
1✔
4699
  int res;
4700
  cmd_rec *cmd;
4701
  pr_jot_filters_t *jot_filters;
4702
  unsigned char logfmt[3];
1✔
4703

1✔
4704
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
1✔
4705
  cmd->cmd_class = CL_CONNECT;
1✔
4706

4707
  /* No filters; should be implicitly jottable. */
4708
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
4709
  jot_filters = NULL;
1✔
4710
  logfmt[0] = LOGFMT_META_START;
4711
  logfmt[1] = LOGFMT_META_CONNECT;
1✔
4712
  logfmt[2] = 0;
1✔
4713

4714
  mark_point();
4715
  res = pr_jot_resolve_logfmt(p, cmd, jot_filters, logfmt, NULL,
4716
    resolve_on_meta, NULL, NULL);
1✔
4717
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
4718
  ck_assert_msg(resolve_on_meta_count == 1,
4719
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
4720

1✔
4721
  /* With an ALL filter, and no command class. */
1✔
4722
  cmd->cmd_class = 0;
4723
  logfmt[1] = LOGFMT_META_COMMAND;
1✔
4724
  resolve_on_meta_count = resolve_on_default_count = 0;
1✔
4725
  jot_filters = pr_jot_filters_create(p, "ALL",
4726
    PR_JOT_FILTER_TYPE_CLASSES, PR_JOT_FILTER_FL_ALL_INCL_ALL);
1✔
4727

4728
  mark_point();
4729
  res = pr_jot_resolve_logfmt(p, cmd, jot_filters, logfmt, NULL,
4730
    resolve_on_meta, NULL, NULL);
1✔
4731
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
4732
  ck_assert_msg(resolve_on_meta_count == 1,
4733
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
4734

1✔
4735
  /* With explicit filters that allow the class. */
1✔
4736
  cmd->cmd_class = CL_CONNECT;
4737
  logfmt[1] = LOGFMT_META_CONNECT;
1✔
4738
  resolve_on_meta_count = resolve_on_default_count = 0;
1✔
4739
  jot_filters = pr_jot_filters_create(p, "CONNECT",
4740
    PR_JOT_FILTER_TYPE_CLASSES, 0);
1✔
4741

4742
  mark_point();
4743
  res = pr_jot_resolve_logfmt(p, cmd, jot_filters, logfmt, NULL,
4744
    resolve_on_meta, NULL, NULL);
4745
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
4746
  ck_assert_msg(resolve_on_meta_count == 1,
4747
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1✔
4748

1✔
4749
  /* With explicit filters that ignore the class. */
1✔
4750
  resolve_on_meta_count = resolve_on_default_count = 0;
1✔
4751
  jot_filters = pr_jot_filters_create(p, "!CONNECT",
4752
    PR_JOT_FILTER_TYPE_CLASSES, 0);
4753

1✔
4754
  mark_point();
1✔
4755
  res = pr_jot_resolve_logfmt(p, cmd, jot_filters, logfmt, NULL,
4756
    resolve_on_meta, NULL, NULL);
1✔
4757
  ck_assert_msg(res < 0, "Failed to handle filtered logfmt");
1✔
4758
  ck_assert_msg(errno == EPERM, "Expected EPERM (%d), got %s (%d)", EPERM,
4759
    strerror(errno), errno);
4760
  ck_assert_msg(resolve_on_meta_count == 0,
4761
    "Expected on_meta count 0, got %u", resolve_on_meta_count);
1✔
4762

1✔
4763
  /* With explicit filters that do not match the class. */
4764
  resolve_on_meta_count = resolve_on_default_count = 0;
4765
  jot_filters = pr_jot_filters_create(p, "DISCONNECT",
1✔
4766
    PR_JOT_FILTER_TYPE_CLASSES, 0);
1✔
4767

4768
  mark_point();
1✔
4769
  res = pr_jot_resolve_logfmt(p, cmd, jot_filters, logfmt, NULL,
1✔
4770
    resolve_on_meta, NULL, NULL);
4771
  ck_assert_msg(res < 0, "Failed to handle filtered logfmt");
1✔
4772
  ck_assert_msg(errno == EPERM, "Expected EPERM (%d), got %s (%d)", EPERM,
4773
    strerror(errno), errno);
4774
  ck_assert_msg(resolve_on_meta_count == 0,
4775
    "Expected on_meta count 0, got %u", resolve_on_meta_count);
1✔
4776

1✔
4777
  /* With explicit filters that allow the command. Note that this REQUIRES
4778
   * that we use a known command, since allowed command comparisons are done
4779
   * by ID.
1✔
4780
   */
1✔
4781
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "RANG"));
4782
  cmd->cmd_class = CL_CONNECT;
1✔
4783
  resolve_on_meta_count = resolve_on_default_count = 0;
1✔
4784
  jot_filters = pr_jot_filters_create(p, "RANG",
4785
    PR_JOT_FILTER_TYPE_COMMANDS, 0);
1✔
4786

4787
  mark_point();
1✔
4788
  res = pr_jot_resolve_logfmt(p, cmd, jot_filters, logfmt, NULL,
4789
    resolve_on_meta, NULL, NULL);
4790
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
4791
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
4792
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1✔
4793

1✔
4794
  /* With explicit filters that ignore the command. */
4795
  resolve_on_meta_count = resolve_on_default_count = 0;
1✔
4796
  jot_filters = pr_jot_filters_create(p, "!RANG",
1✔
4797
    PR_JOT_FILTER_TYPE_COMMANDS, 0);
1✔
4798

1✔
4799
  mark_point();
1✔
4800
  res = pr_jot_resolve_logfmt(p, cmd, jot_filters, logfmt, NULL,
4801
    resolve_on_meta, NULL, NULL);
1✔
4802
  ck_assert_msg(res < 0, "Failed to handle filtered logfmt");
1✔
4803
  ck_assert_msg(errno == EPERM, "Expected EPERM (%d), got %s (%d)", EPERM,
4804
    strerror(errno), errno);
1✔
4805
  ck_assert_msg(resolve_on_meta_count == 0,
1✔
4806
    "Expected on_meta count 0, got %u", resolve_on_meta_count);
4807

1✔
4808
  /* With explicit filters that do not match the command. */
4809
  resolve_on_meta_count = resolve_on_default_count = 0;
1✔
4810
  jot_filters = pr_jot_filters_create(p, "FOO",
4811
    PR_JOT_FILTER_TYPE_COMMANDS, 0);
4812

1✔
4813
  mark_point();
1✔
4814
  res = pr_jot_resolve_logfmt(p, cmd, jot_filters, logfmt, NULL,
1✔
4815
    resolve_on_meta, NULL, NULL);
1✔
4816
  ck_assert_msg(res < 0, "Failed to handle filtered logfmt");
4817
  ck_assert_msg(errno == EPERM, "Expected EPERM (%d), got %s (%d)", EPERM,
1✔
4818
    strerror(errno), errno);
1✔
4819
  ck_assert_msg(resolve_on_meta_count == 0,
1✔
4820
    "Expected on_meta count 0, got %u", resolve_on_meta_count);
1✔
4821
}
1✔
4822
END_TEST
4823

1✔
4824
START_TEST (jot_resolve_logfmt_on_default_test) {
1✔
4825
  int res;
4826
  cmd_rec *cmd;
1✔
4827
  unsigned char logfmt[3];
1✔
4828

4829
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
1✔
4830
  logfmt[0] = LOGFMT_META_START;
4831
  logfmt[1] = LOGFMT_META_BASENAME;
1✔
4832
  logfmt[2] = 0;
4833
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
4834

4835
  mark_point();
4836
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
4837
    resolve_on_meta, resolve_on_default, NULL);
1✔
4838
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
4839
  ck_assert_msg(resolve_on_meta_count == 0,
1✔
4840
    "Expected on_meta count 0, got %u", resolve_on_meta_count);
4841
  ck_assert_msg(resolve_on_default_count == 1,
1✔
4842
    "Expected on_default count 1, got %u", resolve_on_default_count);
1✔
4843
}
1✔
4844
END_TEST
1✔
4845

1✔
4846
START_TEST (jot_resolve_logfmt_on_other_test) {
4847
  int res;
1✔
4848
  cmd_rec *cmd;
4849
  unsigned char logfmt[3];
1✔
4850

1✔
4851
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
4852
  logfmt[0] = 'A';
1✔
4853
  logfmt[1] = '!';
1✔
4854
  logfmt[2] = 0;
4855
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
4856

4857
  mark_point();
1✔
4858
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
4859
    resolve_on_meta, resolve_on_default, resolve_on_other);
4860
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
4861
  ck_assert_msg(resolve_on_meta_count == 0,
1✔
4862
    "Expected on_meta count 0, got %u", resolve_on_meta_count);
4863
  ck_assert_msg(resolve_on_default_count == 0,
1✔
4864
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
4865
  ck_assert_msg(resolve_on_other_count == 1,
4866
    "Expected on_other count 1, got %u", resolve_on_other_count);
1✔
4867
}
1✔
4868
END_TEST
4869

1✔
4870
START_TEST (jot_resolve_logfmt_connect_test) {
4871
  int res;
1✔
4872
  cmd_rec *cmd;
4873
  unsigned char logfmt[3];
1✔
4874

4875
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
4876
  cmd->cmd_class = CL_CONNECT;
1✔
4877
  logfmt[0] = LOGFMT_META_START;
1✔
4878
  logfmt[1] = LOGFMT_META_CONNECT;
1✔
4879
  logfmt[2] = 0;
1✔
4880

4881
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
4882

1✔
4883
  mark_point();
1✔
4884
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
4885
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
4886
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
4887
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
4888
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
4889
  ck_assert_msg(resolve_on_default_count == 0,
1✔
4890
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
4891
  ck_assert_msg(resolve_on_other_count == 0,
4892
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
4893

1✔
4894
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
4895
  cmd->cmd_class = CL_DISCONNECT;
1✔
4896

4897
  mark_point();
1✔
4898
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
4899
    resolve_on_meta, resolve_on_default, resolve_on_other);
4900
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
4901
  ck_assert_msg(resolve_on_meta_count == 0,
1✔
4902
    "Expected on_meta count 0, got %u", resolve_on_meta_count);
4903
  ck_assert_msg(resolve_on_default_count == 0,
1✔
4904
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
4905
  ck_assert_msg(resolve_on_other_count == 0,
4906
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
4907
}
1✔
4908
END_TEST
4909

1✔
4910
START_TEST (jot_resolve_logfmt_disconnect_test) {
4911
  int res;
1✔
4912
  cmd_rec *cmd;
4913
  unsigned char logfmt[3];
1✔
4914

4915
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
4916
  cmd->cmd_class = CL_DISCONNECT;
1✔
4917
  logfmt[0] = LOGFMT_META_START;
1✔
4918
  logfmt[1] = LOGFMT_META_DISCONNECT;
1✔
4919
  logfmt[2] = 0;
1✔
4920

4921
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
4922

1✔
4923
  mark_point();
1✔
4924
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
4925
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
4926
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
4927
  ck_assert_msg(resolve_on_meta_count == 1,
1✔
4928
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1✔
4929
  ck_assert_msg(resolve_on_default_count == 0,
1✔
4930
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
4931
  ck_assert_msg(resolve_on_other_count == 0,
1✔
4932
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
4933

4934
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
4935
  cmd->cmd_class = CL_CONNECT;
4936

1✔
4937
  mark_point();
1✔
4938
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
4939
    resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
4940
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
4941
  ck_assert_msg(resolve_on_meta_count == 0,
4942
    "Expected on_meta count 0, got %u", resolve_on_meta_count);
1✔
4943
  ck_assert_msg(resolve_on_default_count == 0,
4944
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
4945
  ck_assert_msg(resolve_on_other_count == 0,
4946
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
4947
}
4948
END_TEST
4949

1✔
4950
START_TEST (jot_resolve_logfmt_custom_test) {
1✔
4951
  int res;
1✔
4952
  cmd_rec *cmd;
1✔
4953
  unsigned char logfmt[10];
1✔
4954

4955
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
1✔
4956
  cmd->cmd_class = CL_MISC;
1✔
4957
  logfmt[0] = LOGFMT_META_START;
1✔
4958
  logfmt[1] = LOGFMT_META_CUSTOM;
1✔
4959
  logfmt[2] = LOGFMT_META_START;
4960
  logfmt[3] = LOGFMT_META_ARG;
4961
  logfmt[4] = '%';
54✔
4962
  logfmt[5] = '{';
53✔
4963
  logfmt[6] = '0';
4964
  logfmt[7] = '}';
53✔
4965
  logfmt[8] = LOGFMT_META_ARG_END;
53✔
4966
  logfmt[9] = 0;
4967

53✔
4968
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
4969

4970
  mark_point();
4971
  res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
4972
    resolve_on_meta, resolve_on_default, resolve_on_other);
4973
  ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1✔
4974
  ck_assert_msg(resolve_on_meta_count == 1,
4975
    "Expected on_meta count 1, got %u", resolve_on_meta_count);
1✔
4976
  ck_assert_msg(resolve_on_default_count == 0,
4977
    "Expected on_default count 0, got %u", resolve_on_default_count);
1✔
4978
  ck_assert_msg(resolve_on_other_count == 0,
4979
    "Expected on_other count 0, got %u", resolve_on_other_count);
4980
}
4981
END_TEST
4982

1✔
4983
START_TEST (jot_resolve_logfmts_test) {
4984
  register unsigned char i;
1✔
4985
  int res;
1✔
4986
  cmd_rec *cmd;
4987
  unsigned char logfmt[3];
4988

1✔
4989
  cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
1✔
4990
  logfmt[0] = LOGFMT_META_START;
1✔
4991
  logfmt[2] = 0;
4992
  resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1✔
4993

1✔
4994
  /* Currently, the max known LogFormat meta/ID is 53 (DISCONNECT). */
1✔
4995
  for (i = 1; i < 54; i++) {
1✔
4996
    logfmt[1] = i;
4997

4998
    mark_point();
1✔
4999
    res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1✔
5000
      resolve_on_meta, resolve_on_default, resolve_on_other);
1✔
5001
    ck_assert_msg(res == 0, "Failed to handle logfmt_id %u: %s", logfmt[1],
1✔
5002
      strerror(errno));
5003
  }
5004

1✔
5005
  ck_assert_msg(resolve_on_meta_count == 20,
1✔
5006
    "Expected on_meta count 20, got %u", resolve_on_meta_count);
1✔
5007
  ck_assert_msg(resolve_on_default_count == 28,
1✔
5008
    "Expected on_default count 28, got %u", resolve_on_default_count);
1✔
5009
  ck_assert_msg(resolve_on_other_count == 0,
1✔
5010
    "Expected on_other count 0, got %u", resolve_on_other_count);
1✔
5011
}
1✔
5012
END_TEST
1✔
5013

1✔
5014
static unsigned int scan_on_meta_count = 0;
1✔
5015

1✔
5016
static int scan_on_meta(pool *jot_pool, pr_jot_ctx_t *jot_ctx,
5017
    unsigned char logfmt_id, const char *logfmt_data, size_t logfmt_datalen) {
1✔
5018
  scan_on_meta_count++;
1✔
5019
  return 0;
1✔
5020
}
1✔
5021

5022
START_TEST (jot_scan_logfmt_test) {
5023
  int res;
1✔
5024
  unsigned char logfmt[12];
1✔
5025

1✔
5026
  mark_point();
1✔
5027
  res = pr_jot_scan_logfmt(NULL, NULL, 0, NULL, NULL, 0);
5028
  ck_assert_msg(res < 0, "Failed to handle null pool");
5029
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
5030
    strerror(errno), errno);
5031

1✔
5032
  mark_point();
1✔
5033
  res = pr_jot_scan_logfmt(p, NULL, 0, NULL, NULL, 0);
5034
  ck_assert_msg(res < 0, "Failed to handle null logfmt");
1✔
5035
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
5036
    strerror(errno), errno);
1✔
5037

5038
  logfmt[0] = LOGFMT_META_START;
5039
  logfmt[1] = LOGFMT_META_CUSTOM;
1✔
5040
  logfmt[2] = LOGFMT_META_START;
5041
  logfmt[3] = LOGFMT_META_ARG;
1✔
5042
  logfmt[4] = '%';
1✔
5043
  logfmt[5] = '{';
5044
  logfmt[6] = 'f';
1✔
5045
  logfmt[7] = 'o';
5046
  logfmt[8] = 'o';
1✔
5047
  logfmt[9] = '}';
5048
  logfmt[10] = LOGFMT_META_ARG_END;
1✔
5049
  logfmt[11] = 0;
5050

5051
  mark_point();
1✔
5052
  res = pr_jot_scan_logfmt(p, logfmt, 0, NULL, NULL, 0);
1✔
5053
  ck_assert_msg(res < 0, "Failed to handle null on_meta");
1✔
5054
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
5055
    strerror(errno), errno);
1✔
5056

1✔
5057
  mark_point();
5058
  res = pr_jot_scan_logfmt(p, logfmt, 0, NULL, scan_on_meta, 0);
1✔
5059
  ck_assert_msg(res < 0, "Failed to handle invalid LogFormat ID");
1✔
5060
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
5061
    strerror(errno), errno);
1✔
5062

5063
  scan_on_meta_count = 0;
5064

1✔
5065
  mark_point();
1✔
5066
  res = pr_jot_scan_logfmt(p, logfmt, LOGFMT_META_ENV_VAR, NULL, scan_on_meta,
1✔
5067
    0);
1✔
5068
  ck_assert_msg(res == 0, "Failed to scan logmt for ENV_VAR: %s",
5069
    strerror(errno));
5070
  ck_assert_msg(scan_on_meta_count == 0, "Expected scan_on_meta 0, got %u",
1✔
5071
    scan_on_meta_count);
5072

1✔
5073
  scan_on_meta_count = 0;
1✔
5074

1✔
5075
  mark_point();
1✔
5076
  res = pr_jot_scan_logfmt(p, logfmt, LOGFMT_META_CUSTOM, NULL, scan_on_meta,
5077
    0);
5078
  ck_assert_msg(res == 0, "Failed to scan logmt for CUSTOM: %s",
1✔
5079
    strerror(errno));
1✔
5080
  ck_assert_msg(scan_on_meta_count == 1, "Expected scan_on_meta 1, got %u",
1✔
5081
    scan_on_meta_count);
1✔
5082
}
5083
END_TEST
5084

1✔
5085
START_TEST (jot_on_json_test) {
1✔
5086
  pr_jot_ctx_t *ctx;
5087
  pr_json_object_t *json;
1✔
5088
  double num;
1✔
5089
  int res, truth;
1✔
5090
  const char *text;
1✔
5091

5092
  mark_point();
5093
  res = pr_jot_on_json(NULL, NULL, 0, NULL, NULL);
1✔
5094
  ck_assert_msg(res < 0, "Failed to handle null pool");
5095
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
5096
    strerror(errno), errno);
1✔
5097

1✔
5098
  mark_point();
1✔
5099
  res = pr_jot_on_json(p, NULL, 0, NULL, NULL);
5100
  ck_assert_msg(res < 0, "Failed to handle null ctx");
5101
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
5102
    strerror(errno), errno);
5103

1✔
5104
  ctx = pcalloc(p, sizeof(pr_jot_ctx_t));
1✔
5105

1✔
5106
  mark_point();
1✔
5107
  res = pr_jot_on_json(p, ctx, 0, NULL, NULL);
5108
  ck_assert_msg(res < 0, "Failed to handle null val");
5109
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
5110
    strerror(errno), errno);
1✔
5111

1✔
5112
  mark_point();
1✔
5113
  res = pr_jot_on_json(p, ctx, 0, NULL, &num);
5114
  ck_assert_msg(res < 0, "Failed to handle null ctx->log");
5115
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
5116
    strerror(errno), errno);
1✔
5117

1✔
5118
  json = pr_json_object_alloc(p);
1✔
5119
  ctx->log = json;
5120

5121
  mark_point();
1✔
5122
  res = pr_jot_on_json(p, ctx, 0, NULL, &num);
1✔
5123
  ck_assert_msg(res < 0, "Failed to handle null ctx->user_data");
1✔
5124
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
5125
    strerror(errno), errno);
5126

5127
  ctx->user_data = pr_table_alloc(p, 0);
1✔
5128

1✔
5129
  mark_point();
5130
  res = pr_jot_on_json(p, ctx, 0, NULL, &num);
5131
  ck_assert_msg(res < 0, "Failed to handle null JSON info");
1✔
5132
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
5133
    strerror(errno), errno);
5134

1✔
5135
  ctx->user_data = pr_jot_get_logfmt2json(p);
1✔
5136

1✔
5137
  mark_point();
1✔
5138
  truth = FALSE;
5139
  res = pr_jot_on_json(p, ctx, LOGFMT_META_CONNECT, NULL, &truth);
5140
  ck_assert_msg(res == 0, "Failed to handle LOGFMT_META_CONNECT: %s",
1✔
5141
    strerror(errno));
1✔
5142

1✔
5143
  mark_point();
1✔
5144
  num = 2476;
5145
  res = pr_jot_on_json(p, ctx, LOGFMT_META_PID, NULL, &num);
5146
  ck_assert_msg(res == 0, "Failed to handle LOGFMT_META_PID: %s",
1✔
5147
    strerror(errno));
1✔
5148

1✔
5149
  mark_point();
5150
  text = "lorem ipsum";
1✔
5151
  res = pr_jot_on_json(p, ctx, LOGFMT_META_IDENT_USER, NULL, text);
1✔
5152
  ck_assert_msg(res == 0, "Failed to handle LOGFMT_META_IDENT_USER: %s",
1✔
5153
    strerror(errno));
1✔
5154

5155
  mark_point();
5156
  text = "alef bet vet";
5157
  res = pr_jot_on_json(p, ctx, LOGFMT_META_USER, "USER_KEY", text);
55✔
5158
  ck_assert_msg(res == 0, "Failed to handle LOGFMT_META_USER: %s",
53✔
5159
    strerror(errno));
53✔
5160

53✔
5161
  (void) pr_json_object_free(json);
5162
}
5163
END_TEST
5164

1✔
5165
START_TEST (jot_get_logfmt2json_test) {
1✔
5166
  pr_table_t *res;
5167

1✔
5168
  mark_point();
5169
  res = pr_jot_get_logfmt2json(NULL);
5170
  ck_assert_msg(res == NULL, "Failed to handle null pool");
890✔
5171
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
890✔
5172
    strerror(errno), errno);
890✔
5173

5174
  mark_point();
890✔
5175
  res = pr_jot_get_logfmt2json(p);
890✔
5176
  ck_assert_msg(res != NULL, "Failed to get map: %s", strerror(errno));
890✔
5177
}
5178
END_TEST
890✔
5179

890✔
5180
START_TEST (jot_get_logfmt_id_name_test) {
890✔
5181
  register unsigned char i;
5182
  const char *res;
890✔
5183

890✔
5184
  mark_point();
890✔
5185
  res = pr_jot_get_logfmt_id_name(0);
890✔
5186
  ck_assert_msg(res == NULL, "Failed to handle invalid logfmt_id");
890✔
5187
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
890✔
5188
    strerror(errno), errno);
890✔
5189

5190
  /* Currently, the max known LogFormat meta/ID is 54 (XFER_PORT). */
890✔
5191
  for (i = 2; i < 55; i++) {
890✔
5192
    mark_point();
890✔
5193
    res = pr_jot_get_logfmt_id_name(i);
890✔
5194
    ck_assert_msg(res != NULL, "Failed to get name for LogFormat ID %u: %s",
890✔
5195
      i, strerror(errno));
890✔
5196
  }
890✔
5197

890✔
5198
  res = pr_jot_get_logfmt_id_name(LOGFMT_META_CUSTOM);
890✔
5199
  ck_assert_msg(res != NULL, "Failed to get name for LogFormat ID %u: %s",
890✔
5200
    LOGFMT_META_CUSTOM, strerror(errno));
890✔
5201
}
890✔
5202
END_TEST
890✔
5203

890✔
5204
Suite *tests_get_jot_suite(void) {
890✔
5205
  Suite *suite;
890✔
5206
  TCase *testcase;
890✔
5207

890✔
5208
  suite = suite_create("jot");
890✔
5209
  testcase = tcase_create("base");
890✔
5210
  tcase_add_checked_fixture(testcase, set_up, tear_down);
890✔
5211

890✔
5212
  tcase_add_test(testcase, jot_filters_create_test);
890✔
5213
  tcase_add_test(testcase, jot_filters_destroy_test);
890✔
5214
  tcase_add_test(testcase, jot_filters_include_classes_test);
890✔
5215
  tcase_add_test(testcase, jot_filters_parse_sifts_test);
890✔
5216

890✔
5217
  tcase_add_test(testcase, jot_parse_on_meta_test);
890✔
5218
  tcase_add_test(testcase, jot_parse_on_unknown_test);
890✔
5219
  tcase_add_test(testcase, jot_parse_on_other_test);
890✔
5220
  tcase_add_test(testcase, jot_parse_logfmt_test);
890✔
5221
  tcase_add_test(testcase, jot_parse_logfmt_short_vars_test);
890✔
5222
  tcase_add_test(testcase, jot_parse_logfmt_long_vars_test);
890✔
5223
  tcase_add_test(testcase, jot_parse_logfmt_custom_vars_test);
890✔
5224

890✔
5225
  tcase_add_test(testcase, jot_resolve_logfmt_id_test);
890✔
5226
  tcase_add_test(testcase, jot_resolve_logfmt_id_on_default_test);
890✔
5227
  tcase_add_test(testcase, jot_resolve_logfmt_id_filters_test);
890✔
5228
  tcase_add_test(testcase, jot_resolve_logfmt_id_connect_test);
890✔
5229
  tcase_add_test(testcase, jot_resolve_logfmt_id_disconnect_test);
890✔
5230
  tcase_add_test(testcase, jot_resolve_logfmt_id_custom_test);
890✔
5231
  tcase_add_test(testcase, jot_resolve_logfmt_ids_test);
890✔
5232
  tcase_add_test(testcase, jot_resolve_logfmt_invalid_test);
890✔
5233
  tcase_add_test(testcase, jot_resolve_logfmt_basename_test);
890✔
5234
  tcase_add_test(testcase, jot_resolve_logfmt_bytes_sent_test);
890✔
5235
  tcase_add_test(testcase, jot_resolve_logfmt_filename_test);
890✔
5236
  tcase_add_test(testcase, jot_resolve_logfmt_file_modified_test);
890✔
5237
  tcase_add_test(testcase, jot_resolve_logfmt_file_offset_test);
890✔
5238
  tcase_add_test(testcase, jot_resolve_logfmt_file_size_test);
890✔
5239
  tcase_add_test(testcase, jot_resolve_logfmt_env_var_test);
890✔
5240
  tcase_add_test(testcase, jot_resolve_logfmt_note_test);
890✔
5241
  tcase_add_test(testcase, jot_resolve_logfmt_var_test);
890✔
5242
  tcase_add_test(testcase, jot_resolve_logfmt_remote_port_test);
890✔
5243
  tcase_add_test(testcase, jot_resolve_logfmt_rfc1413_ident_test);
5244
  tcase_add_test(testcase, jot_resolve_logfmt_xfer_secs_test);
890✔
5245
  tcase_add_test(testcase, jot_resolve_logfmt_xfer_ms_test);
890✔
5246
  tcase_add_test(testcase, jot_resolve_logfmt_command_test);
890✔
5247
  tcase_add_test(testcase, jot_resolve_logfmt_local_name_test);
890✔
5248
  tcase_add_test(testcase, jot_resolve_logfmt_local_port_test);
5249
  tcase_add_test(testcase, jot_resolve_logfmt_user_test);
890✔
5250
  tcase_add_test(testcase, jot_resolve_logfmt_uid_test);
890✔
5251
  tcase_add_test(testcase, jot_resolve_logfmt_group_test);
5252
  tcase_add_test(testcase, jot_resolve_logfmt_gid_test);
5253
  tcase_add_test(testcase, jot_resolve_logfmt_original_user_test);
5254
  tcase_add_test(testcase, jot_resolve_logfmt_response_code_test);
5255
  tcase_add_test(testcase, jot_resolve_logfmt_response_text_test);
5256
  tcase_add_test(testcase, jot_resolve_logfmt_response_ms_test);
5257
  tcase_add_test(testcase, jot_resolve_logfmt_class_test);
5258
  tcase_add_test(testcase, jot_resolve_logfmt_anon_passwd_test);
5259
  tcase_add_test(testcase, jot_resolve_logfmt_method_test);
5260
  tcase_add_test(testcase, jot_resolve_logfmt_xfer_path_test);
5261
  tcase_add_test(testcase, jot_resolve_logfmt_xfer_port_test);
5262
  tcase_add_test(testcase, jot_resolve_logfmt_xfer_type_test);
5263
  tcase_add_test(testcase, jot_resolve_logfmt_xfer_status_test);
5264
  tcase_add_test(testcase, jot_resolve_logfmt_xfer_failure_test);
5265
  tcase_add_test(testcase, jot_resolve_logfmt_dir_name_test);
5266
  tcase_add_test(testcase, jot_resolve_logfmt_dir_path_test);
5267
  tcase_add_test(testcase, jot_resolve_logfmt_cmd_params_test);
5268
  tcase_add_test(testcase, jot_resolve_logfmt_rename_from_test);
5269
  tcase_add_test(testcase, jot_resolve_logfmt_eos_reason_test);
5270
  tcase_add_test(testcase, jot_resolve_logfmt_vhost_ip_test);
5271
  tcase_add_test(testcase, jot_resolve_logfmt_filters_test);
5272
  tcase_add_test(testcase, jot_resolve_logfmt_on_default_test);
5273
  tcase_add_test(testcase, jot_resolve_logfmt_on_other_test);
5274
  tcase_add_test(testcase, jot_resolve_logfmt_connect_test);
5275
  tcase_add_test(testcase, jot_resolve_logfmt_disconnect_test);
5276
  tcase_add_test(testcase, jot_resolve_logfmt_custom_test);
5277
  tcase_add_test(testcase, jot_resolve_logfmts_test);
5278

5279
  tcase_add_test(testcase, jot_scan_logfmt_test);
5280
  tcase_add_test(testcase, jot_on_json_test);
5281
  tcase_add_test(testcase, jot_get_logfmt2json_test);
5282
  tcase_add_test(testcase, jot_get_logfmt_id_name_test);
5283

5284
  suite_add_tcase(suite, testcase);
5285
  return suite;
5286
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc