Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vlc
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Redmine
Redmine
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
videolan
vlc
Commits
4c06a2be
Commit
4c06a2be
authored
Dec 19, 2015
by
Rémi Denis-Courmont
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
https: HTTP 1 connection handling unit test
parent
3ac615a7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
231 additions
and
2 deletions
+231
-2
modules/access/http/Makefile.am
modules/access/http/Makefile.am
+4
-2
modules/access/http/h1conn_test.c
modules/access/http/h1conn_test.c
+227
-0
No files found.
modules/access/http/Makefile.am
View file @
4c06a2be
...
...
@@ -32,6 +32,8 @@ h2output_test_SOURCES = access/http/h2output_test.c
h2output_test_LDADD
=
libvlc_http.la
$(LIBPTHREAD)
h2conn_test_SOURCES
=
access/http/h2conn_test.c
h2conn_test_LDADD
=
libvlc_http.la
$(LIBPTHREAD)
h1conn_test_SOURCES
=
access/http/h1conn_test.c
h1conn_test_LDADD
=
libvlc_http.la
h1chunked_test_SOURCES
=
access/http/chunked_test.c
h1chunked_test_LDADD
=
libvlc_http.la
http_msg_test_SOURCES
=
access/http/message_test.c
\
...
...
@@ -40,8 +42,8 @@ http_file_test_SOURCES = access/http/file_test.c \
access/http/message.c access/http/message.h
\
access/http/file.c access/http/file.h
check_PROGRAMS
+=
hpack_test hpackenc_test
\
h2frame_test h2output_test h2conn_test h1chunked_test
\
h2frame_test h2output_test h2conn_test h1c
onn_test h1c
hunked_test
\
http_msg_test http_file_test
TESTS
+=
hpack_test hpackenc_test
\
h2frame_test h2output_test h2conn_test h1chunked_test
\
h2frame_test h2output_test h2conn_test h1c
onn_test h1c
hunked_test
\
http_msg_test http_file_test
modules/access/http/h1conn_test.c
0 → 100644
View file @
4c06a2be
/*****************************************************************************
* h1conn_test.c: HTTP/1 connection tests
*****************************************************************************
* Copyright (C) 2015 Rémi Denis-Courmont
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#undef NDEBUG
#include <assert.h>
#include <stddef.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/socket.h>
#ifndef SOCK_CLOEXEC
# define SOCK_CLOEXEC 0
#endif
#include <vlc_common.h>
#include <vlc_block.h>
#include <vlc_tls.h>
#include "conn.h"
#include "message.h"
static
struct
vlc_http_conn
*
conn
;
static
int
external_fd
;
static
void
conn_create
(
void
)
{
int
fds
[
2
];
if
(
socketpair
(
PF_LOCAL
,
SOCK_STREAM
|
SOCK_CLOEXEC
,
0
,
fds
))
assert
(
!
"socketpair"
);
struct
vlc_tls
*
tls
=
vlc_tls_DummyCreate
(
NULL
,
fds
[
1
]);
assert
(
tls
!=
NULL
);
external_fd
=
fds
[
0
];
conn
=
vlc_h1_conn_create
(
tls
);
assert
(
conn
!=
NULL
);
}
static
void
conn_send_raw
(
const
void
*
buf
,
size_t
len
)
{
ssize_t
val
=
write
(
external_fd
,
buf
,
len
);
assert
((
size_t
)
val
==
len
);
}
static
void
conn_send
(
const
char
*
str
)
{
return
conn_send_raw
(
str
,
strlen
(
str
));
}
static
void
conn_shutdown
(
int
how
)
{
shutdown
(
external_fd
,
how
);
}
static
void
conn_destroy
(
void
)
{
conn_shutdown
(
SHUT_WR
);
vlc_http_conn_release
(
conn
);
close
(
external_fd
);
}
static
struct
vlc_http_stream
*
stream_open
(
void
)
{
struct
vlc_http_msg
*
m
=
vlc_http_req_create
(
"GET"
,
"https"
,
"www.example.com"
,
"/"
);
assert
(
m
!=
NULL
);
struct
vlc_http_stream
*
s
=
vlc_http_stream_open
(
conn
,
m
);
vlc_http_msg_destroy
(
m
);
return
s
;
}
int
main
(
void
)
{
struct
vlc_http_stream
*
s
;
struct
vlc_http_msg
*
m
;
struct
block_t
*
b
;
/* Dummy */
conn_create
();
conn_destroy
();
/* Test rejected connection */
conn_create
();
conn_shutdown
(
SHUT_RD
);
s
=
stream_open
();
assert
(
s
==
NULL
);
conn_destroy
();
/* Test rejected stream */
conn_create
();
s
=
stream_open
();
assert
(
s
!=
NULL
);
conn_shutdown
(
SHUT_WR
);
m
=
vlc_http_stream_read_headers
(
s
);
assert
(
m
==
NULL
);
b
=
vlc_http_stream_read
(
s
);
assert
(
b
==
NULL
);
m
=
vlc_http_stream_read_headers
(
s
);
assert
(
m
==
NULL
);
b
=
vlc_http_stream_read
(
s
);
assert
(
b
==
NULL
);
vlc_http_stream_close
(
s
,
true
);
s
=
stream_open
();
assert
(
s
==
NULL
);
conn_destroy
();
/* Test garbage */
conn_create
();
s
=
stream_open
();
assert
(
s
!=
NULL
);
conn_send
(
"Go away!
\r\n\r\n
"
);
conn_shutdown
(
SHUT_WR
);
m
=
vlc_http_stream_read_headers
(
s
);
assert
(
m
==
NULL
);
b
=
vlc_http_stream_read
(
s
);
assert
(
b
==
NULL
);
conn_destroy
();
vlc_http_stream_close
(
s
,
false
);
/* Test HTTP/1.0 stream */
conn_create
();
s
=
stream_open
();
assert
(
s
!=
NULL
);
conn_send
(
"HTTP/1.0 200 OK
\r\n\r\n
"
);
m
=
vlc_http_stream_read_headers
(
s
);
assert
(
m
!=
NULL
);
conn_send
(
"Hello world!"
);
conn_shutdown
(
SHUT_WR
);
b
=
vlc_http_msg_read
(
m
);
assert
(
b
!=
NULL
);
assert
(
b
->
i_buffer
==
12
);
assert
(
!
memcmp
(
b
->
p_buffer
,
"Hello world!"
,
12
));
block_Release
(
b
);
b
=
vlc_http_msg_read
(
m
);
assert
(
b
==
NULL
);
vlc_http_msg_destroy
(
m
);
conn_destroy
();
/* Test HTTP/1.1 with closed connection */
conn_create
();
s
=
stream_open
();
assert
(
s
!=
NULL
);
conn_send
(
"HTTP/1.1 200 OK
\r\n
Connection: close
\r\n\r\n
"
);
m
=
vlc_http_stream_read_headers
(
s
);
assert
(
m
!=
NULL
);
conn_send
(
"Hello again!"
);
conn_shutdown
(
SHUT_WR
);
b
=
vlc_http_msg_read
(
m
);
assert
(
b
!=
NULL
);
assert
(
b
->
i_buffer
==
12
);
assert
(
!
memcmp
(
b
->
p_buffer
,
"Hello again!"
,
12
));
block_Release
(
b
);
b
=
vlc_http_msg_read
(
m
);
assert
(
b
==
NULL
);
vlc_http_msg_destroy
(
m
);
conn_destroy
();
/* Test HTTP/1.1 with chunked transfer encoding */
conn_create
();
s
=
stream_open
();
assert
(
s
!=
NULL
);
conn_send
(
"HTTP/1.1 200 OK
\r\n
Transfer-Encoding: chunked
\r\n
"
"Content-Length: 1000000
\r\n\r\n
"
);
/* length must be ignored */
m
=
vlc_http_stream_read_headers
(
s
);
assert
(
m
!=
NULL
);
conn_send
(
"C
\r\n
Hello there!
\r\n
0
\r\n\r\n
"
);
b
=
vlc_http_msg_read
(
m
);
assert
(
b
!=
NULL
);
assert
(
b
->
i_buffer
==
12
);
assert
(
!
memcmp
(
b
->
p_buffer
,
"Hello there!"
,
12
));
block_Release
(
b
);
conn_destroy
();
/* test connection release before closing stream */
b
=
vlc_http_msg_read
(
m
);
assert
(
b
==
NULL
);
vlc_http_msg_destroy
(
m
);
/* Test HTTP/1.1 with content length */
conn_create
();
s
=
stream_open
();
assert
(
s
!=
NULL
);
conn_send
(
"HTTP/1.1 200 OK
\r\n
Content-Length: 8
\r\n\r\n
"
);
m
=
vlc_http_stream_read_headers
(
s
);
assert
(
m
!=
NULL
);
conn_send
(
"Bye bye!"
);
b
=
vlc_http_msg_read
(
m
);
assert
(
b
!=
NULL
);
assert
(
b
->
i_buffer
==
8
);
assert
(
!
memcmp
(
b
->
p_buffer
,
"Bye bye!"
,
8
));
block_Release
(
b
);
b
=
vlc_http_msg_read
(
m
);
assert
(
b
==
NULL
);
vlc_http_msg_destroy
(
m
);
conn_destroy
();
return
0
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment