File: import-modsec-unit-tests.pl

package info (click to toggle)
modsecurity 3.0.3-1%2Bdeb10u2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 42,032 kB
  • sloc: cpp: 25,953; ansic: 15,785; sh: 5,357; python: 3,556; yacc: 2,896; makefile: 1,394; lex: 1,344; perl: 464; ruby: 69; javascript: 53; php: 42
file content (49 lines) | stat: -rwxr-xr-x 1,092 bytes parent folder | download | duplicates (4)
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
#!/usr/bin/perl -w
#
#

use strict;
use warnings;
use JSON;

my $dir = $ARGV[0];
my $out = $ARGV[1];

if (!($dir && $out))
{
    die "Use: ./mport-modsec-unit-tests.pl /path/to/modsec/tests /path/to/dest\n\n";
}


opendir(DIR, $dir) or die "Failed to open: \"$!\"";

while (my $file = readdir(DIR)) 
{
    my $orig_file = $file;
    $file = $dir . "/" . $file;
    next if not ($file =~ m/\.t$/);

    open(CFG, "<$file") || die "Failed to open \"$file\": $!";
    my @data = <CFG>;
    my @C;
    my $edata = q/@C = (/ . join("", @data) . q/)/;
    eval $edata;
    die "Failed to read test data \"$file\": $@" if ($@);
    unless (@C) {
        print "No tests defined for $file\n";
        next;
    }

    print "Loaded ".@C." tests from $file\n";
    my $json = to_json(\@C, {utf8 => 1, pretty => 1});
    my ($new_file) = $orig_file =~ m/(.*)\.t$/;
    $new_file = $out . "/" . $new_file . ".json";
    open (DFG, ">$new_file" ) || die "Failed to open: \"$file\": $!";

    print " Saving at: " . $new_file . "\n";
    print DFG $json;
    close(DFG);
    close(CFG);
}

closedir(DIR);