File: sshd_parser.t

package info (click to toggle)
libconfig-model-openssh-perl 2.9.9.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 640 kB
  • sloc: perl: 4,596; makefile: 12
file content (61 lines) | stat: -rw-r--r-- 2,025 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
use strict;
use warnings;
use lib qw(contrib/lib);
use 5.22.0;

use ParseMan;

use Test::More;
use Test::Differences;
use Path::Tiny;
use experimental qw/postderef signatures/ ;

my $html = path('xt/sshd_config.html')->slurp;

my $data = parse_html_man_page($html);

subtest "man page transformation" => sub {
    # test some data items
    is($data->{element_list}[0],'AcceptEnv', "first element name");
    is($data->{element_list}[5],'AllowTcpForwarding', "5th element name");
};

subtest "test generation of model string" => sub {
    my @unilines = qw/AuthorizedKeysCommand/;
    my $boolean = sub {
        return "type=leaf value_type=boolean write_as=no,yes upstream_default=$_[0]";
    };
    my $enum = sub ($set,$def = undef) {
        my $str = "type=leaf value_type=enum choice=$set";
        $str .= " upstream_default=$def" if defined $def;
        return $str;
    };

    my %expected_load = (
        # AddKeysToAgent => $enum->('yes,confirm,ask,no', 'no'),
        AddressFamily => $enum->('any,inet,inet6', 'any'),
        AllowStreamLocalForwarding => $enum->('yes,all,no,local,remote','yes'),
        AllowGroups => 'type=list cargo type=leaf value_type=uniline',
        AllowUsers => 'type=list cargo type=leaf value_type=uniline',
        AuthorizedKeysFile => 'type=list cargo type=leaf value_type=uniline',
        MaxStartups => 'type=leaf value_type=uniline upstream_default=10',
        X11Forwarding => $boolean->('no'),
    );

    foreach my $p (@unilines) {
        $expected_load{$p} = 'type=leaf value_type=uniline';
    }

    foreach my $param ($data->{element_list}->@*) {
        my @desc = $data->{element_data}{$param}->@*;
        my $load = create_load_data(sshd => $param => @desc);

        # check only some of the parameters
        if (defined  $expected_load{$param}) {
            note("test failed with @desc") unless $load eq $expected_load{$param};
            is($load, $expected_load{$param}, "check generated load string of $param");
        }
    }
};

done_testing;