tests for protocol version negotiation
This commit is contained in:
parent
62701affb9
commit
1d7f733aaf
|
@ -0,0 +1,21 @@
|
|||
package Utils;
|
||||
|
||||
use strict;
|
||||
|
||||
|
||||
sub harnessTypeToCmd {
|
||||
my $harnessType = shift;
|
||||
|
||||
if ($harnessType eq 'cpp') {
|
||||
return './cpp/harness';
|
||||
} elsif ($harnessType eq 'js') {
|
||||
return 'node js/harness.js';
|
||||
} elsif ($harnessType eq 'rust') {
|
||||
return '../../rust-negentropy/target/debug/harness';
|
||||
}
|
||||
|
||||
die "unknown harness type: $harnessType";
|
||||
}
|
||||
|
||||
|
||||
1;
|
21
test/fuzz.pl
21
test/fuzz.pl
|
@ -5,26 +5,15 @@ $|++;
|
|||
|
||||
use IPC::Open2;
|
||||
use Session::Token;
|
||||
use FindBin;
|
||||
use lib "$FindBin::Bin";
|
||||
use Utils;
|
||||
|
||||
die "usage: $0 <lang1> <lang2>" if @ARGV < 2;
|
||||
my $harnessCmd1 = harnessTypeToCmd(shift) || die "please provide harness type (cpp, js, etc)";
|
||||
my $harnessCmd2 = harnessTypeToCmd(shift) || die "please provide harness type (cpp, js, etc)";
|
||||
my $harnessCmd1 = Utils::harnessTypeToCmd(shift) || die "please provide harness type (cpp, js, etc)";
|
||||
my $harnessCmd2 = Utils::harnessTypeToCmd(shift) || die "please provide harness type (cpp, js, etc)";
|
||||
my $idSize = shift || 16;
|
||||
|
||||
sub harnessTypeToCmd {
|
||||
my $harnessType = shift;
|
||||
|
||||
if ($harnessType eq 'cpp') {
|
||||
return './cpp/harness';
|
||||
} elsif ($harnessType eq 'js') {
|
||||
return 'node js/harness.js';
|
||||
} elsif ($harnessType eq 'rust') {
|
||||
return '../../rust-negentropy/target/debug/harness';
|
||||
}
|
||||
|
||||
die "unknown harness type: $harnessType";
|
||||
}
|
||||
|
||||
|
||||
srand($ENV{SEED} || 0);
|
||||
my $stgen = Session::Token->new(seed => "\x00" x 1024, alphabet => '0123456789abcdef', length => $idSize * 2);
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
#!/usr/bin/env perl
|
||||
|
||||
use strict;
|
||||
$|++;
|
||||
|
||||
use IPC::Open2;
|
||||
use Session::Token;
|
||||
use FindBin;
|
||||
use lib "$FindBin::Bin";
|
||||
use Utils;
|
||||
|
||||
die "usage: $0 <lang>" if @ARGV < 1;
|
||||
my $harnessCmd = Utils::harnessTypeToCmd(shift) || die "please provide harness type (cpp, js, etc)";
|
||||
my $idSize = shift || 16;
|
||||
|
||||
|
||||
my $expectedResp;
|
||||
|
||||
## Get expected response using protocol version 0
|
||||
|
||||
{
|
||||
my ($infile, $outfile);
|
||||
my $pid = open2($outfile, $infile, $harnessCmd);
|
||||
|
||||
print $infile "item,12345,eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee\n";
|
||||
print $infile "seal\n";
|
||||
print $infile "msg,6000000200\n"; ## full range bound, empty IdList
|
||||
|
||||
my $resp = <$outfile>;
|
||||
chomp $resp;
|
||||
|
||||
$expectedResp = $resp;
|
||||
}
|
||||
|
||||
## Client tries to use some hypothetical newer version, but falls back to version 0
|
||||
|
||||
{
|
||||
my ($infile, $outfile);
|
||||
my $pid = open2($outfile, $infile, $harnessCmd);
|
||||
|
||||
print $infile "item,12345,eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee\n";
|
||||
print $infile "seal\n";
|
||||
|
||||
print $infile "msg,61aabbccddeeff\n"; ## some new protocol message
|
||||
|
||||
my $resp = <$outfile>;
|
||||
chomp $resp;
|
||||
|
||||
## 61: The bound timestamp, as varint. The value is 0x60 (preferred protocol version), but 1 is added as per timestamp protocol
|
||||
## 00: The following ID has length 0
|
||||
## 04: UnsupportedProtocolVersion mode
|
||||
die "bad upgrade response: $resp" unless $resp eq "msg,610004";
|
||||
|
||||
## Try again with protocol version 0
|
||||
print $infile "msg,6000000200\n"; ## full range bound, empty IdList
|
||||
|
||||
$resp = <$outfile>;
|
||||
chomp $resp;
|
||||
die "didn't fall back to protocol version 0: $resp" unless $resp eq $expectedResp;
|
||||
}
|
||||
|
||||
print "OK\n";
|
|
@ -63,6 +63,13 @@ if (@langs >= 2) {
|
|||
|
||||
|
||||
|
||||
## Protocol upgrade tests
|
||||
|
||||
foreach my $lang (@langs) {
|
||||
note("------- PROTO UPGRADE $lang -------");
|
||||
run("perl protoversion.pl $lang");
|
||||
}
|
||||
|
||||
|
||||
|
||||
########
|
||||
|
|
Loading…
Reference in New Issue