/[cwmp]/google/trunk/t/30-server.t
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /google/trunk/t/30-server.t

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 233 by dpavlin, Sat Nov 24 02:17:40 2007 UTC revision 234 by dpavlin, Sun Nov 25 23:26:42 2007 UTC
# Line 4  use warnings; Line 4  use warnings;
4    
5  my $debug = shift @ARGV;  my $debug = shift @ARGV;
6    
7  use Test::More tests => 20;  use Test::More tests => 135;
8  use Data::Dump qw/dump/;  use Data::Dump qw/dump/;
9  use Cwd qw/abs_path/;  use Cwd qw/abs_path/;
10    use File::Find;
11    use File::Slurp;
12    use File::Path qw/rmtree mkpath/;
13    use YAML::Syck;
14  use blib;  use blib;
15    
16  BEGIN {  BEGIN {
17          use_ok('Net::HTTP');          use_ok('Net::HTTP');
18          use_ok('CWMP::Server');          use_ok('CWMP::Server');
19          use_ok('CWMP::Store');          use_ok('CWMP::Store');
20            use_ok('CWMP::Request');
21  }  }
22    
23  my $port = 4242;  my $port = 4242;
# Line 26  ok(my $abs_path = abs_path($0), "abs_pat Line 31  ok(my $abs_path = abs_path($0), "abs_pat
31  $abs_path =~ s!/[^/]*$!/!;      #!fix-vim  $abs_path =~ s!/[^/]*$!/!;      #!fix-vim
32    
33  my $store_path = "$abs_path/var/";  my $store_path = "$abs_path/var/";
 #my $store_module = 'DBMDeep';  
34  my $store_module = 'YAML';  my $store_module = 'YAML';
35    
36    rmtree $store_path if -e $store_path;
37    ok( mkpath $store_path, "mkpath $store_path" );
38    
39  ok( my $server = CWMP::Server->new({  ok( my $server = CWMP::Server->new({
40          debug => $debug,          debug => $debug,
41          port => $port,          port => $port,
# Line 36  ok( my $server = CWMP::Server->new({ Line 43  ok( my $server = CWMP::Server->new({
43                  store => {                  store => {
44                          module => $store_module,                          module => $store_module,
45                          path => $store_path,                          path => $store_path,
46                          clean => 1,  #                       clean => 1,
47                  },                  },
48                  create_dump => 0,                  create_dump => 0,
49          }          }
# Line 58  if ( $pid = fork ) { Line 65  if ( $pid = fork ) {
65    
66  sleep 1;        # so server can start  sleep 1;        # so server can start
67    
68  ok( my $s = Net::HTTP->new(Host => "localhost:$port"), 'client' );  my $s;
 $s->keep_alive( 1 );  
69    
70  ok( $s->write_request(  sub cpe_connect {
71          POST => '/',          return $s if $s;
72          'Transfer-Encoding' => 'chunked',          diag "CPE connect";
73          'SOAPAction' => '',          ok( $s = Net::HTTP->new(Host => "localhost:$port"), 'CPE client' );
74          'Content-Type' => 'text/xml',          $s->keep_alive( 1 );
 ), 'write_request' );  
   
 foreach my $chunk (qq{  
   
 <soapenv:Envelope soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soap="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cwmp="urn:dslforum-org:cwmp-1-0">  
  <soapenv:Header>  
 <cwmp:ID soapenv:mustUnderstand="1">1_THOM_TR69_ID</cwmp:ID>  
  </soapenv:Header>  
  <soapenv:Body>  
 <cwmp:Inform>  
 <DeviceId>  
  <Manufacturer>THOMSON</Manufacturer>  
  <OUI>00147F</OUI>  
  <ProductClass>SpeedTouch 780</ProductClass>  
  <SerialNumber>CP0644JTHJ4</SerialNumber>  
 </DeviceId>  
 <Event soap:arrayType="cwmp:EventStruct[03]">  
 <EventStruct>  
  <EventCode>0 BOOTSTRAP</EventCode>  
  <CommandKey></CommandKey>  
 </EventStruct>  
 <EventStruct>  
  <Event},qq{Code>1 BOOT</EventCode>  
  <CommandKey></CommandKey>  
 </EventStruct>  
 <EventStruct>  
  <EventCode>4 VALUE CHANGE</EventCode>  
  <CommandKey></CommandKey>  
 </EventStruct>  
 </Event>  
 <MaxEnvelopes>2</MaxEnvelopes>  
 <CurrentTime>1970-01-01T00:04:33Z</CurrentTime>  
 <RetryCount>01</RetryCount>},qq{  
 <ParameterList soap:arrayType="cwmp:ParameterValueStruct[12]">  
 <ParameterValueStruct>  
  <Name>InternetGatewayDevice.DeviceSummary</Name>  
  <Value xsi:type="xsd:string">InternetGatewayDevice:1.1[] (Baseline:1, EthernetLAN:1, ADSLWAN:1, Bridging:1, Time:1, WiFiLAN:1)</Value>  
 </ParameterValueStruct>  
 <ParameterValueStruct>  
  <Name>}, qq{  
 InternetGatewayDevice.DeviceInfo.SpecVersion</Name>  
  <Value xsi:type="xsd:string">1.1</Value>  
 </ParameterValueStruct>  
 <ParameterValueStruct>  
  <Name>InternetGatewayDevice.DeviceInfo.HardwareVersion</Name>  
  <Value xsi:type="xsd:string">BANT-R</Value>  
 </ParameterValueStruct>  
 <ParameterValueStruct>  
  <Name>InternetGatewayDevice.DeviceInfo.SoftwareVersion</Name>  
  <Value xsi:type="xsd:string">6.2.15.5</Value>  
 </ParameterValueStruct>  
 <ParameterValueStruct>  
  <Name>InternetGatewayDevice.DeviceInfo.ProvisioningCode</Name>  
  <Value xsi:type="xsd:string"></Value>  
 </ParameterValueStruct>  
 <ParameterValueStruct>  
  <Name>InternetGatewayDevice.DeviceInfo.VendorConfigFile.1.Name</Name>  
  <Value xsi:type="xsd:string">Routed PPPoE on 0/35 and 8/35</Value>  
 </ParameterValueStruct>  
 <ParameterValueStruct>  
  <Name>InternetGatewayDevice.DeviceInfo.VendorConfigFile.1.Version</Name>  
  <Value xsi:type="xsd:string"></Value>  
 </ParameterValueStruct>  
 <ParameterValueStruct>  
  <Name>InternetGatewayDevice.DeviceInfo.VendorConfigFile.1.Date</Name>  
  <Value xsi:type="xsd:dateTime">0000-00-00T00:00:00</Value>  
 </ParameterValueStruct>  
 <ParameterValueStruct>  
  <Name>InternetGatewayDevice.DeviceInfo.VendorConfigFile.1.Description</Name>  
  <Value xsi:type="xsd:string">Factory Defaults</Value>  
 </ParameterValueStruct>  
 <ParameterValueStruct>  
  <Name>InternetGatewayDevice.ManagementServer.ConnectionRequestURL</Name>  
  <Value}, qq{ xsi:type="xsd:string">http://192.168.1.254:51005/</Value>  
 </ParameterValueStruct>  
 <ParameterValueStruct>  
  <Name>InternetGatewayDevice.ManagementServer.ParameterKey</Name>  
  <Value xsi:type="xsd:string"></Value>  
 </ParameterValueStruct>  
 <ParameterValueStruct>  
  <Name>.ExternalIPAddress</Name>  
  <Value xsi:type="xsd:string">192.168.1.254</Value>  
 </ParameterValueStruct>  
 </ParameterList>  
 </cwmp:Inform>  
  </soapenv:Body>  
 </soapenv:Envelope>  
 } ) {  
         ok( $s->write_chunk( $chunk ), "chunk " . length($chunk) . " bytes" );  
75  }  }
 ok( $s->write_chunk_eof, 'write_chunk_eof' );  
76    
77  sleep 1;  sub cpe_disconnect {
78            return unless $s;
79            diag "CPE disconnect";
80            $s->keep_alive( 0 );
81            ok( $s->write_request(
82                    POST => '/',
83                    'SOAPAction' => '',
84                    'Content-Type' => 'text/xml',
85            ), 'write_request' );
86            my ($code, $mess, %h) = $s->read_response_headers;
87            undef $s;
88            diag "$code $mess";
89            return $code == 200 ? 1 : 0;
90    }
91    
92  ok( my $store = CWMP::Store->new({ module => $store_module, path => $store_path, debug => $debug }), 'another store' );  sub test_request {
93            my $path = shift;
94    
95  my $state = {          ok( -e $path, $path );
96    CurrentTime    => "1970-01-01T00:04:33Z",  
97    DeviceID       => {          cpe_disconnect if $path =~ m/Inform/;
98                        Manufacturer => "THOMSON",          cpe_connect;
99                        OUI => "00147F",  
100                        ProductClass => "SpeedTouch 780",          ok( $s->write_request(
101                        SerialNumber => "CP0644JTHJ4",                  POST => '/',
102                      },                  'Transfer-Encoding' => 'chunked',
103    EventStruct    => ["0 BOOTSTRAP", "1 BOOT", "4 VALUE CHANGE"],                  'SOAPAction' => '',
104    ID             => "1_THOM_TR69_ID",                  'Content-Type' => 'text/xml',
105    MaxEnvelopes   => 2,          ), 'write_request' );
106  #  NoMoreRequests => undef,  
107    Parameter      => {          my $xml = read_file( $path );
108                        "\nInternetGatewayDevice.DeviceInfo.SpecVersion"                  => "1.1",          $xml =~ s/^.+?</</s;
109                        ".ExternalIPAddress"                                              => "192.168.1.254",  
110                        "InternetGatewayDevice.DeviceInfo.HardwareVersion"                => "BANT-R",          my $chunk_size = 5000;
111                        "InternetGatewayDevice.DeviceInfo.ProvisioningCode"               => undef,  
112                        "InternetGatewayDevice.DeviceInfo.SoftwareVersion"                => "6.2.15.5",          foreach my $part ( 0 .. int( length($xml) / $chunk_size ) ) {
113                        "InternetGatewayDevice.DeviceInfo.VendorConfigFile.1.Date"        => "0000-00-00T00:00:00",                  my $chunk = substr( $xml, $part * $chunk_size, $chunk_size );
114                        "InternetGatewayDevice.DeviceInfo.VendorConfigFile.1.Description" => "Factory Defaults",                  ok( $s->write_chunk( $chunk ), "chunk $part " . length($chunk) . " bytes" );
115                        "InternetGatewayDevice.DeviceInfo.VendorConfigFile.1.Name"        => "Routed PPPoE on 0/35 and 8/35",          }
116                        "InternetGatewayDevice.DeviceInfo.VendorConfigFile.1.Version"     => undef,          ok( $s->write_chunk_eof, 'write_chunk_eof' );
117                        "InternetGatewayDevice.DeviceSummary"                             => "InternetGatewayDevice:1.1[] (Baseline:1, EthernetLAN:1, ADSLWAN:1, Bridging:1, Time:1, WiFiLAN:1)",  
118                        "InternetGatewayDevice.ManagementServer.ConnectionRequestURL"     => "http://192.168.1.254:51005/",          my($code, $mess, %h) = $s->read_response_headers;
119                        "InternetGatewayDevice.ManagementServer.ParameterKey"             => undef,          diag "$code $mess";
120                      },          while (1) {
121    RetryCount     => "01",                  my $buf;
122    _dispatch      => "InformResponse",                  my $n = $s->read_entity_body($buf, 1024);
123  };                  die "read failed: $!" unless defined $n;
124                    last unless $n;
125                    diag $buf;
126            }
127    
128  ok( my $store_state = $store->current_store->get_state( 'CP0644JTHJ4' ), 'get_state' );          ok( my $store = CWMP::Store->new({ module => $store_module, path => $store_path, debug => $debug }), 'another store' );
129    
130            my $state = LoadFile( "$path.yml" );
131    
132            $path =~ s!/[^/]+$!!; #!vim
133            ok( my $uid = $store->state_to_uid( LoadFile( "$path/Inform.yml" ) ), 'state_to_uid' );
134    
135            ok( my $store_state = $store->current_store->get_state( $uid ), 'get_state' );
136    
137            my $s;
138    
139            # ignore
140            foreach my $k ( keys %$state ) {
141                    if ( defined( $store_state->{$k} ) ) {
142                            $s->{$k} = $store_state->{$k};
143                    } else {
144                            die "store_state doesn't have $k: ",dump( $store_state );
145                    }
146            }
147    
148            is_deeply( $s, $state, 'store->current_store->get_state' );
149    
150    }
151    
152    find({
153            no_chdir => 1,
154            wanted => sub {
155                    my $path = $File::Find::name;
156                    return unless -f $path;
157                    return if $path =~ m/\.yml$/;
158                    eval {
159                            test_request( $path );
160                    };
161                    ok( ! $@, "request $path" );
162            }
163    },'t/dump/');
164    
165  is_deeply( $store_state, $state, 'store->current_store->get_state' );  ok( cpe_disconnect, 'cpe_disconnect' );
166    
167  diag "shutdown server";  diag "shutdown server";
168    

Legend:
Removed from v.233  
changed lines
  Added in v.234

  ViewVC Help
Powered by ViewVC 1.1.26