1
0
mirror of https://github.com/moparisthebest/curl synced 2024-12-22 08:08:50 -05:00

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
parent cd3aba1a5c
commit 60c86297bf
16 changed files with 111 additions and 30 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -951,6 +951,8 @@ static int do_tftp(struct testcase *test, struct tftphdr *tp, ssize_t size)
#ifdef USE_WINSOCK #ifdef USE_WINSOCK
DWORD recvtimeout, recvtimeoutbak; DWORD recvtimeout, recvtimeoutbak;
#endif #endif
char *option = (char *)"mode"; /* mode is implicit */
int toggle = 1;
/* Open request dump file. */ /* Open request dump file. */
server = fopen(REQUEST_DUMP, "ab"); 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; cp = (char *)&tp->th_stuff;
filename = cp; filename = cp;
again: do {
bool endofit = true;
while (cp < &buf.storage[size]) { while (cp < &buf.storage[size]) {
if (*cp == '\0') if (*cp == '\0') {
endofit = false;
break; break;
}
cp++; 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) { if (*cp) {
nak(EBADOP); nak(EBADOP);
fclose(server); fclose(server);
return 3; return 3;
} }
if (first) {
mode = ++cp;
first = 0;
goto again;
}
/* store input protocol */ /* store input protocol */
fprintf(server, "filename: %s\n", filename); fprintf(server, "filename: %s\n", filename);
@ -990,7 +1018,6 @@ again:
*cp = (char)tolower((int)*cp); *cp = (char)tolower((int)*cp);
/* store input protocol */ /* store input protocol */
fprintf(server, "mode: %s\n", mode);
fclose(server); fclose(server);
for (pf = formata; pf->f_mode; pf++) for (pf = formata; pf->f_mode; pf++)