1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-11-27 17:22:57 +01:00

update multipart tests

This commit is contained in:
Nikolay Kim 2017-10-22 22:23:38 -07:00
parent f737a3eb3e
commit e8936fe081
2 changed files with 46 additions and 8 deletions

View File

@ -239,12 +239,17 @@ impl InnerMultipart {
//ValueError("Could not find starting boundary %r"
//% (self._boundary))
}
if chunk.len() < boundary.len() {
continue
}
if &chunk[..2] == b"--" && &chunk[2..chunk.len()-2] == boundary.as_bytes() {
break;
} else {
if chunk.len() < boundary.len() + 2{
continue
}
let b: &[u8] = boundary.as_ref();
if chunk.len() <= boundary.len() + 2 &&
&chunk[..boundary.len()] == b &&
if &chunk[..boundary.len()] == b &&
&chunk[boundary.len()..boundary.len()+2] == b"--" {
eof = true;
break;
@ -746,9 +751,13 @@ mod tests {
let (mut sender, payload) = Payload::new(false);
let bytes = Bytes::from(
"--abbc761f78ff4d7cb7573b5a23f96ef0\r\n\
"testasdadsad\r\n\
--abbc761f78ff4d7cb7573b5a23f96ef0\r\n\
Content-Type: text/plain; charset=utf-8\r\nContent-Length: 4\r\n\r\n\
test\r\n\
--abbc761f78ff4d7cb7573b5a23f96ef0\r\n\
Content-Type: text/plain; charset=utf-8\r\nContent-Length: 4\r\n\r\n\
data\r\n\
--abbc761f78ff4d7cb7573b5a23f96ef0--\r\n");
sender.feed_data(bytes);
@ -777,6 +786,30 @@ mod tests {
}
_ => unreachable!()
}
match multipart.poll() {
Ok(Async::Ready(Some(item))) => {
match item {
MultipartItem::Field(mut field) => {
assert_eq!(field.content_type().type_(), mime::TEXT);
assert_eq!(field.content_type().subtype(), mime::PLAIN);
match field.poll() {
Ok(Async::Ready(Some(chunk))) =>
assert_eq!(chunk.0, "data"),
_ => unreachable!()
}
match field.poll() {
Ok(Async::Ready(None)) => (),
_ => unreachable!()
}
},
_ => unreachable!()
}
}
_ => unreachable!()
}
match multipart.poll() {
Ok(Async::Ready(None)) => (),
_ => unreachable!()

View File

@ -4,7 +4,6 @@ extern crate tokio_core;
extern crate reqwest;
use std::{net, thread};
use std::str::FromStr;
use std::sync::Arc;
use std::sync::atomic::{AtomicUsize, Ordering};
use tokio_core::net::TcpListener;
@ -35,18 +34,24 @@ fn test_serve() {
#[test]
fn test_serve_incoming() {
thread::spawn(|| {
let loopback = net::Ipv4Addr::new(127, 0, 0, 1);
let socket = net::SocketAddrV4::new(loopback, 0);
let tcp = net::TcpListener::bind(socket).unwrap();
let addr1 = tcp.local_addr().unwrap();
let addr2 = tcp.local_addr().unwrap();
thread::spawn(move || {
let sys = System::new("test");
let srv = create_server();
let addr = net::SocketAddr::from_str("127.0.0.1:58903").unwrap();
let tcp = TcpListener::bind(&addr, Arbiter::handle()).unwrap();
let tcp = TcpListener::from_listener(tcp, &addr2, Arbiter::handle()).unwrap();
srv.serve_incoming::<_, ()>(tcp.incoming()).unwrap();
sys.run();
});
assert!(reqwest::get("http://localhost:58903/").unwrap().status().is_success());
assert!(reqwest::get(&format!("http://{}/", addr1))
.unwrap().status().is_success());
}
struct MiddlewareTest {