Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make TLS configurable, improve test coverage and add redirect support (…
…#14)
- Loading branch information
1 parent
9c2f9a6
commit 1102ed9
Showing
39 changed files
with
586 additions
and
334 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ target/ | |
.*/target/ | ||
**/*.rs.bk | ||
*.tar | ||
.gdb_history |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
//! The cbor tests | ||
|
||
#![cfg(test)] | ||
|
||
use actix_web::{test::TestRequest, HttpRequest, HttpResponse}; | ||
use cbor::{CborRequest, CborResponseBuilder}; | ||
use failure::Fail; | ||
use futures::Future; | ||
use serde_cbor::to_vec; | ||
use webapp::protocol::{request, response}; | ||
|
||
fn build_request() -> TestRequest<()> { | ||
TestRequest::with_header("content-type", "application/cbor") | ||
} | ||
|
||
#[test] | ||
fn succeed_to_decode_request() { | ||
let login = request::LoginCredentials { | ||
username: "username".to_owned(), | ||
password: "password".to_owned(), | ||
}; | ||
let payload = to_vec(&login).unwrap(); | ||
let request: HttpRequest<()> = build_request().set_payload(payload).finish(); | ||
let result: request::LoginCredentials = CborRequest::new(&request).wait().unwrap(); | ||
assert_eq!(result, login); | ||
} | ||
|
||
#[test] | ||
fn fail_to_decode_empty_request() { | ||
let request: HttpRequest<()> = build_request().finish(); | ||
let result: Result<(), _> = CborRequest::new(&request).wait(); | ||
assert!( | ||
&result | ||
.unwrap_err() | ||
.cause() | ||
.unwrap() | ||
.to_string() | ||
.contains("EOF") | ||
); | ||
} | ||
|
||
#[test] | ||
fn fail_to_decode_wrong_request() { | ||
let payload: Vec<u8> = (1..10).collect(); | ||
let request: HttpRequest<()> = build_request().set_payload(payload).finish(); | ||
let result: Result<(), _> = CborRequest::new(&request).wait(); | ||
assert!( | ||
&result | ||
.unwrap_err() | ||
.cause() | ||
.unwrap() | ||
.to_string() | ||
.contains("invalid type") | ||
); | ||
} | ||
|
||
#[test] | ||
fn fail_to_decode_wrong_typed_request() { | ||
let login = request::LoginCredentials { | ||
username: "username".to_owned(), | ||
password: "password".to_owned(), | ||
}; | ||
let payload = to_vec(&login).unwrap(); | ||
let request: HttpRequest<()> = build_request().set_payload(payload).finish(); | ||
let result: Result<request::Logout, _> = CborRequest::new(&request).wait(); | ||
assert!( | ||
&result | ||
.unwrap_err() | ||
.cause() | ||
.unwrap() | ||
.to_string() | ||
.contains("missing field") | ||
); | ||
} | ||
|
||
#[test] | ||
fn succeed_to_encode_response() { | ||
let response = HttpResponse::Ok().cbor(response::Logout); | ||
assert!(response.is_ok()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.