tftp tests: verify sent options too

The tftpd test server now logs all received options and thus all TFTP
test cases need to match them exactly.

Extended test 283 to use and verify --tftp-blksize.
This commit is contained in:
Daniel Stenberg 2015-11-06 10:52:19 +01:00
Родитель cd3aba1a5c
Коммит 60c86297bf
16 изменённых файлов: 111 добавлений и 30 удалений

Просмотреть файл

@ -32,8 +32,11 @@ This data will not be sent
</errorcode>
<protocol>
opcode: 2
filename: /invalid-file
mode: octet
tsize: 27
blksize: 512
timeout: 6
filename: /invalid-file
</protocol>
</verify>
</testcase>

Просмотреть файл

@ -37,8 +37,11 @@ tftp://%HOSTIP:%TFTPPORT//1009 --local-port 44444-45444
<verify>
<protocol>
opcode: 1
filename: /1009
mode: octet
tsize: 0
blksize: 512
timeout: 6
filename: /1009
</protocol>
</verify>
</testcase>

Просмотреть файл

@ -37,8 +37,11 @@ tftp://%HOSTIP:%TFTPPORT//1049 --trace-ascii log/traceit --interface %CLIENTIP
<verify>
<protocol>
opcode: 1
filename: /1049
mode: octet
tsize: 0
blksize: 512
timeout: 6
filename: /1049
</protocol>
</verify>
</testcase>

Просмотреть файл

@ -37,8 +37,11 @@ TFTP retrieve with mode=i
<verify>
<protocol>
opcode: 1
filename: /1093
mode: octet
tsize: 0
blksize: 512
timeout: 6
filename: /1093
</protocol>
</verify>
</testcase>

Просмотреть файл

@ -43,8 +43,11 @@ TFTP retrieve with mode=netascii
<verify>
<protocol>
opcode: 1
filename: /1094
mode: netascii
tsize: 0
blksize: 512
timeout: 6
filename: /1094
</protocol>
</verify>
</testcase>

Просмотреть файл

@ -32,11 +32,17 @@ tftp://%HOSTIP:%TFTPPORT/an/invalid-file tftp://%HOSTIP:%TFTPPORT//1099 --trace-
<verify>
<protocol>
opcode: 1
mode: octet
tsize: 0
blksize: 512
timeout: 6
filename: an/invalid-file
mode: octet
opcode: 1
filename: /1099
mode: octet
tsize: 0
blksize: 512
timeout: 6
filename: /1099
</protocol>
<stdout>
data for 1099

Просмотреть файл

@ -38,8 +38,11 @@ tftp://%HOSTIP:%TFTPPORT//1238 -Y1000 -y2
<verify>
<protocol>
opcode: 1
filename: /1238
mode: octet
tsize: 0
blksize: 512
timeout: 6
filename: /1238
</protocol>
# 28 = CURLE_OPERATION_TIMEDOUT
<errorcode>

Просмотреть файл

@ -88,8 +88,11 @@ TYPE I
SIZE 20020002
RETR 20020002
opcode: 1
filename: /20020003
mode: octet
tsize: 0
blksize: 512
timeout: 6
filename: /20020003
QUIT
</protocol>
<stdout>

Просмотреть файл

@ -88,11 +88,17 @@ TYPE I
SIZE 20030002
RETR 20030002
opcode: 1
filename: /20030003
mode: octet
tsize: 0
blksize: 512
timeout: 6
filename: /20030003
opcode: 1
filename: /20030003
mode: octet
tsize: 0
blksize: 512
timeout: 6
filename: /20030003
EPSV
SIZE 20030002
RETR 20030002

Просмотреть файл

@ -43,11 +43,17 @@ for several protocols
<verify>
<protocol>
opcode: 1
filename: /2004
mode: octet
tsize: 0
blksize: 512
timeout: 6
filename: /2004
opcode: 1
filename: /2004
mode: octet
tsize: 0
blksize: 512
timeout: 6
filename: /2004
</protocol>
<stdout>
Test data file

Просмотреть файл

@ -36,8 +36,11 @@ tftp://%HOSTIP:%TFTPPORT//271 --trace-ascii log/traceit
<verify>
<protocol>
opcode: 1
filename: /271
mode: octet
tsize: 0
blksize: 512
timeout: 6
filename: /271
</protocol>
</verify>
</testcase>

Просмотреть файл

@ -17,7 +17,7 @@ tftp
TFTP retrieve on invalid file
</name>
<command>
tftp://%HOSTIP:%TFTPPORT//invalid-file --trace-ascii log/traceit
tftp://%HOSTIP:%TFTPPORT//invalid-file --trace-ascii log/traceit --tftp-blksize 1024
</command>
</client>
@ -29,8 +29,11 @@ tftp://%HOSTIP:%TFTPPORT//invalid-file --trace-ascii log/traceit
</errorcode>
<protocol>
opcode: 1
filename: /invalid-file
mode: octet
tsize: 0
blksize: 1024
timeout: 6
filename: /invalid-file
</protocol>
</verify>
</testcase>

Просмотреть файл

@ -60,8 +60,11 @@ tftp://%HOSTIP:%TFTPPORT//284 --trace-ascii log/traceit
<verify>
<protocol>
opcode: 1
filename: /284
mode: octet
tsize: 0
blksize: 512
timeout: 6
filename: /284
</protocol>
</verify>
</testcase>

Просмотреть файл

@ -37,8 +37,11 @@ sent
</upload>
<protocol>
opcode: 2
filename: /test285.txt
mode: octet
tsize: 32
blksize: 512
timeout: 6
filename: /test285.txt
</protocol>
</verify>
</testcase>

Просмотреть файл

@ -85,8 +85,11 @@ condition in the TFTP transmit code.
</upload>
<protocol>
opcode: 2
filename: /test286.txt
mode: octet
tsize: 512
blksize: 512
timeout: 6
filename: /test286.txt
</protocol>
</verify>
</testcase>

Просмотреть файл

@ -951,6 +951,8 @@ static int do_tftp(struct testcase *test, struct tftphdr *tp, ssize_t size)
#ifdef USE_WINSOCK
DWORD recvtimeout, recvtimeoutbak;
#endif
char *option = (char *)"mode"; /* mode is implicit */
int toggle = 1;
/* Open request dump file. */
server = fopen(REQUEST_DUMP, "ab");
@ -966,22 +968,48 @@ static int do_tftp(struct testcase *test, struct tftphdr *tp, ssize_t size)
cp = (char *)&tp->th_stuff;
filename = cp;
again:
do {
bool endofit = true;
while (cp < &buf.storage[size]) {
if (*cp == '\0')
if (*cp == '\0') {
endofit = false;
break;
}
cp++;
}
if(endofit)
/* no more options */
break;
/* before increasing pointer, make sure it is still within the legal
space */
if((cp+1) < &buf.storage[size]) {
++cp;
if(first) {
/* store the mode since we need it later */
mode = cp;
first = 0;
}
if(toggle)
/* name/value pair: */
fprintf(server, "%s: %s\n", option, cp);
else {
/* store the name pointer */
option = cp;
}
toggle ^= 1;
}
else
/* No more options */
break;
} while(1);
if (*cp) {
nak(EBADOP);
fclose(server);
return 3;
}
if (first) {
mode = ++cp;
first = 0;
goto again;
}
/* store input protocol */
fprintf(server, "filename: %s\n", filename);
@ -990,7 +1018,6 @@ again:
*cp = (char)tolower((int)*cp);
/* store input protocol */
fprintf(server, "mode: %s\n", mode);
fclose(server);
for (pf = formata; pf->f_mode; pf++)