commit a0f90d4946e03e433ff014f4d8ab4ea34a97603a
parent 2e3520a205f3cd644d8c714d1e8437446ca03573
Author: kyle <kyle@getaddrinfo.net>
Date: Tue, 17 Nov 2015 23:19:39 -0700
tests: add new test for two lists with the same name
- two lists with the same name was an early design decision
- looks like it works, with a small tweak to sl
- sl tweak was to sha256 random bytes instead of "$msg . time"
- this wouldn't provide unique hashes for lists created less than 1 second
apart
- this is the first bug fixed by the testsuite I think :)
Diffstat:
4 files changed, 50 insertions(+), 1 deletion(-)
diff --git a/sl b/sl
@@ -299,7 +299,7 @@ sub msg_new_list
print "$addr: adding first list member devid = '$devid_fp'\n";
my $time = time;
- my $list_id = sha256_base64($msg . $time);
+ my $list_id = sha256_base64(arc4random_bytes(32));
print "$addr: list fingerprint = '" .fingerprint($list_id). "'\n";
# add new list with single list member
diff --git a/tests/two_lists_same_name/Makefile b/tests/two_lists_same_name/Makefile
@@ -0,0 +1,4 @@
+test:
+ perl test.pl
+
+.include "../test.mk"
diff --git a/tests/two_lists_same_name/server.log.good b/tests/two_lists_same_name/server.log.good
@@ -0,0 +1,9 @@
+new connection
+added new device <phone_num> <base64>
+'this is a new list'
+adding first list member devid = <base64>
+list fingerprint = <base64>
+'this is a new list'
+adding first list member devid = <base64>
+list fingerprint = <base64>
+disconnected!
diff --git a/tests/two_lists_same_name/test.pl b/tests/two_lists_same_name/test.pl
@@ -0,0 +1,36 @@
+#!/usr/bin/perl -I../
+
+use strict;
+use warnings;
+
+use testlib;
+
+# this test:
+# - gets a new device id
+# - creates a new list
+# - receives new list response
+# - verifies received information is congruent with what was sent
+
+my $sock = new_socket();
+send_msg($sock, 0, "4038675309");
+my ($type, $device_id, $length) = recv_msg($sock);
+
+fail "got response type $type, expected 0" if ($type != 0);
+fail "expected response length of 43, got $length" if ($length != 43);
+
+my $list_name = "this is a new list";
+send_msg($sock, 1, "$device_id\0$list_name");
+my ($type2, $list_data, $length2) = recv_msg($sock);
+
+fail "got response type $type, expected 1" if ($type2 != 1);
+
+my ($id, $name, @members) = split("\0", $list_data);
+my $id_length = length($id);
+
+fail "bad id length $id_length != 43" if ($id_length != 43);
+fail "recv'd name '$name' not equal to '$list_name'" if ($name ne $list_name);
+fail "list does not have exactly 1 member" if (@members != 1);
+
+# add the same list again
+send_msg($sock, 1, "$device_id\0$list_name");
+($type2, $list_data, $length2) = recv_msg($sock);