micro_http: check arithmetic operations
Signed-off-by: Ioana Chirca <chioana@amazon.com> Signed-off-by: YUAN LYU <lyuyuan92@gmail.com>
This commit is contained in:
committed by
Adrian Catangiu
parent
9830b66a09
commit
17ead39d82
@@ -28,6 +28,10 @@ pub enum RequestError {
|
||||
InvalidHeader,
|
||||
/// The Request is invalid and cannot be served.
|
||||
InvalidRequest,
|
||||
/// Overflow occurred when parsing a request.
|
||||
Overflow,
|
||||
/// Underflow occurred when parsing a request.
|
||||
Underflow,
|
||||
}
|
||||
|
||||
impl Display for RequestError {
|
||||
@@ -39,6 +43,8 @@ impl Display for RequestError {
|
||||
Self::UnsupportedHeader => write!(f, "Unsupported header."),
|
||||
Self::InvalidHeader => write!(f, "Invalid header."),
|
||||
Self::InvalidRequest => write!(f, "Invalid request."),
|
||||
Self::Overflow => write!(f, "Overflow occurred when parsing a request."),
|
||||
Self::Underflow => write!(f, "Underflow occurred when parsing a request."),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -91,6 +97,10 @@ pub enum ServerError {
|
||||
ConnectionError(ConnectionError),
|
||||
/// Server maximum capacity has been reached.
|
||||
ServerFull,
|
||||
/// Overflow occured while processing messages.
|
||||
Overflow,
|
||||
/// Underflow occured while processing mesagges.
|
||||
Underflow,
|
||||
}
|
||||
|
||||
impl Display for ServerError {
|
||||
@@ -99,6 +109,8 @@ impl Display for ServerError {
|
||||
Self::IOError(inner) => write!(f, "IO error: {}", inner),
|
||||
Self::ConnectionError(inner) => write!(f, "Connection error: {}", inner),
|
||||
Self::ServerFull => write!(f, "Server is full."),
|
||||
Self::Overflow => write!(f, "Overflow occured while processing messages."),
|
||||
Self::Underflow => write!(f, "Underflow occured while processing messages."),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -250,9 +262,11 @@ mod tests {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
use self::ConnectionError::*;
|
||||
match (self, other) {
|
||||
(ParseError(_), ParseError(_)) => true,
|
||||
(ParseError(ref e), ParseError(ref other_e)) => e.eq(other_e),
|
||||
(ConnectionClosed, ConnectionClosed) => true,
|
||||
(StreamError(_), StreamError(_)) => true,
|
||||
(StreamError(ref e), StreamError(ref other_e)) => {
|
||||
format!("{}", e).eq(&format!("{}", other_e))
|
||||
}
|
||||
(InvalidWrite, InvalidWrite) => true,
|
||||
_ => false,
|
||||
}
|
||||
@@ -309,29 +323,37 @@ mod tests {
|
||||
#[test]
|
||||
fn test_display_request_error() {
|
||||
assert_eq!(
|
||||
format!("{}", RequestError::InvalidHttpMethod("test")),
|
||||
"Invalid HTTP Method: test"
|
||||
format!("{}", RequestError::InvalidHeader),
|
||||
"Invalid header."
|
||||
);
|
||||
assert_eq!(
|
||||
format!("{}", RequestError::InvalidUri("test")),
|
||||
"Invalid URI: test"
|
||||
format!("{}", RequestError::InvalidHttpMethod("test")),
|
||||
"Invalid HTTP Method: test"
|
||||
);
|
||||
assert_eq!(
|
||||
format!("{}", RequestError::InvalidHttpVersion("test")),
|
||||
"Invalid HTTP Version: test"
|
||||
);
|
||||
assert_eq!(
|
||||
format!("{}", RequestError::InvalidHeader),
|
||||
"Invalid header."
|
||||
format!("{}", RequestError::InvalidRequest),
|
||||
"Invalid request."
|
||||
);
|
||||
assert_eq!(
|
||||
format!("{}", RequestError::InvalidUri("test")),
|
||||
"Invalid URI: test"
|
||||
);
|
||||
assert_eq!(
|
||||
format!("{}", RequestError::Overflow),
|
||||
"Overflow occurred when parsing a request."
|
||||
);
|
||||
assert_eq!(
|
||||
format!("{}", RequestError::Underflow),
|
||||
"Underflow occurred when parsing a request."
|
||||
);
|
||||
assert_eq!(
|
||||
format!("{}", RequestError::UnsupportedHeader),
|
||||
"Unsupported header."
|
||||
);
|
||||
assert_eq!(
|
||||
format!("{}", RequestError::InvalidRequest),
|
||||
"Invalid request."
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -377,6 +399,14 @@ mod tests {
|
||||
),
|
||||
"IO error: Resource temporarily unavailable (os error 11)"
|
||||
);
|
||||
assert_eq!(
|
||||
format!("{}", ServerError::Overflow),
|
||||
"Overflow occured while processing messages."
|
||||
);
|
||||
assert_eq!(
|
||||
format!("{}", ServerError::Underflow),
|
||||
"Underflow occured while processing messages."
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user