12-save-changed-conf.t 3.61 KB
Newer Older
1 2 3 4
#!/usr/bin/env perl -I pl/lib

use Test::More;
use strict;
5
use JSON::MaybeXS;
6
use Data::Dumper;
Xavier Guimard's avatar
Xavier Guimard committed
7
require 't/test-lib.pm';
8

Xavier Guimard's avatar
Xavier Guimard committed
9 10
my $struct = 't/jsonfiles/12-modified.json';
my $confFiles = [ 't/conf/lmConf-1.js', 't/conf/lmConf-2.js' ];
11 12 13 14 15 16 17 18 19

sub body {
    return IO::File->new( $struct, 'r' );
}

# Delete lmConf-2.js if exists
eval { unlink $confFiles->[1]; };

my ( $res, $resBody );
20
ok( $res = &client->post( '/confs/', 'cfgNum=1', &body, 'application/json' ),
21 22 23 24 25 26 27 28 29
    "Request succeed" );
ok( $res->[0] == 200, "Result code is 200" );
ok( $resBody = decode_json( $res->[2]->[0] ),
    "Result body contains JSON text" );
ok( $resBody->{result} == 1, "JSON response contains \"result:1\"" )
  or print STDERR Dumper($resBody);
ok( -f $confFiles->[1], 'File is created' );

my @changes = @{&changes};
Xavier Guimard's avatar
Xavier Guimard committed
30
my @cmsg    = @{ $resBody->{details}->{__changes__} };
31
ok( @changes == @cmsg, 'Same changes count' );
Xavier Guimard's avatar
Xavier Guimard committed
32
while ( my $c = shift @{ $resBody->{details}->{__changes__} } ) {
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
    @changes = grep { $_->{key} ne $c->{key} } @changes;
    @cmsg    = grep { $_->{key} ne $c->{key} } @cmsg;
}
ok( !@changes, 'All changes detected' );

#print STDERR Dumper(\@changes,\@cmsg);

count(7);

unlink $confFiles->[1];
done_testing( count() );

sub changes {
    return [
        {
            'key' => 'portal',
            'new' => 'http://auth2.example.com/',
            'old' => 'http://auth.example.com/'
        },
        {
            'new' => 0,
            'old' => 1,
            'key' => 'portalDisplayLogout'
        },
        {
            'key' =>
              'applicationList, Sample applications, Application Test 1, uri',
            'old' => 'http://test1.example.com/',
            'new' => 'http://testex.example.com/'
        },
        {
            'new' => 'Application Test 3',
            'key' => 'applicationList, Sample applications'
        },
        {
            'key' => 'userDB',
            'new' => 'LDAP',
            'old' => 'Demo'
        },
        {
            'key' => 'passwordDB',
            'new' => 'LDAP',
            'old' => 'Demo'
        },
        {
            'key' => 'openIdSPList',
            'new' => '1;bad.com'
        },
        {
            'key' => 'exportedVars',
            'new' => 'User-Agent'
        },
        {
            'new' => 'Uid',
            'key' => 'exportedVars'
        },
        {
            'key' => 'exportedVars',
            'old' => 'UA'
        },
        {
            'key' =>
              'locationRules, test1.example.com, (?#Logout comment)^/logout',
            'new' => 'logout_sso',
            'old' => undef
        },
        {
            'old' => '^/logout',
            'key' => 'locationRules, test1.example.com'
        },
        {
            'key' => 'locationRules, test3.example.com, ^/logout',
            'new' => 'logout_sso',
            'old' => undef
        },
        {
            'key' => 'locationRules, test3.example.com, default',
            'old' => undef,
            'new' => 'accept'
        },
        {
            'key' => 'locationRules',
            'new' => 'test3.example.com'
        },
        {
            'key' => 'exportedHeaders, test3.example.com, Auth-User',
            'old' => undef,
            'new' => '$uid'
        },
        {
            'new' => 'test3.example.com',
            'key' => 'exportedHeaders'
        },
        {
            'key' => 'locationRules, test.ex.com, default',
            'old' => undef,
            'new' => 'deny'
        },
        {
            'key' => 'locationRules',
            'new' => 'test.ex.com'
        },
        {
            'key' => 'virtualHosts',
            'old' => 'test2.example.com'
        }
    ];
}