2016-08-30 16:05:18 +02:00
|
|
|
// Copyright 2015, 2016 Ethcore (UK) Ltd.
|
|
|
|
// This file is part of Parity.
|
|
|
|
|
|
|
|
// Parity is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
|
|
|
// Parity 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 General Public License for more details.
|
|
|
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2016-10-19 11:02:21 +02:00
|
|
|
use tests::helpers::{serve, serve_with_registrar, request, assert_security_headers};
|
2016-08-30 16:05:18 +02:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn should_return_error() {
|
|
|
|
// given
|
|
|
|
let server = serve();
|
|
|
|
|
|
|
|
// when
|
|
|
|
let response = request(server,
|
|
|
|
"\
|
|
|
|
GET /api/empty HTTP/1.1\r\n\
|
|
|
|
Host: 127.0.0.1:8080\r\n\
|
|
|
|
Connection: close\r\n\
|
|
|
|
\r\n\
|
|
|
|
{}
|
|
|
|
"
|
|
|
|
);
|
|
|
|
|
|
|
|
// then
|
|
|
|
assert_eq!(response.status, "HTTP/1.1 404 Not Found".to_owned());
|
2016-10-22 15:21:41 +02:00
|
|
|
assert_eq!(response.headers.get(3).unwrap(), "Content-Type: application/json");
|
2016-08-30 16:05:18 +02:00
|
|
|
assert_eq!(response.body, format!("58\n{}\n0\n\n", r#"{"code":"404","title":"Not Found","detail":"Resource you requested has not been found."}"#));
|
2016-10-19 11:02:21 +02:00
|
|
|
assert_security_headers(&response.headers);
|
2016-08-30 16:05:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn should_serve_apps() {
|
|
|
|
// given
|
|
|
|
let server = serve();
|
|
|
|
|
|
|
|
// when
|
|
|
|
let response = request(server,
|
|
|
|
"\
|
|
|
|
GET /api/apps HTTP/1.1\r\n\
|
|
|
|
Host: 127.0.0.1:8080\r\n\
|
|
|
|
Connection: close\r\n\
|
|
|
|
\r\n\
|
|
|
|
{}
|
|
|
|
"
|
|
|
|
);
|
|
|
|
|
|
|
|
// then
|
|
|
|
assert_eq!(response.status, "HTTP/1.1 200 OK".to_owned());
|
2016-10-22 15:21:41 +02:00
|
|
|
assert_eq!(response.headers.get(3).unwrap(), "Content-Type: application/json");
|
|
|
|
assert!(response.body.contains("Parity UI"), response.body);
|
2016-10-19 11:02:21 +02:00
|
|
|
assert_security_headers(&response.headers);
|
2016-08-30 16:05:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn should_handle_ping() {
|
|
|
|
// given
|
|
|
|
let server = serve();
|
|
|
|
|
|
|
|
// when
|
|
|
|
let response = request(server,
|
|
|
|
"\
|
|
|
|
POST /api/ping HTTP/1.1\r\n\
|
|
|
|
Host: home.parity\r\n\
|
|
|
|
Connection: close\r\n\
|
|
|
|
\r\n\
|
|
|
|
{}
|
|
|
|
"
|
|
|
|
);
|
|
|
|
|
|
|
|
// then
|
|
|
|
assert_eq!(response.status, "HTTP/1.1 200 OK".to_owned());
|
2016-10-22 15:21:41 +02:00
|
|
|
assert_eq!(response.headers.get(3).unwrap(), "Content-Type: application/json");
|
2016-08-30 16:05:18 +02:00
|
|
|
assert_eq!(response.body, "0\n\n".to_owned());
|
2016-10-19 11:02:21 +02:00
|
|
|
assert_security_headers(&response.headers);
|
2016-08-30 16:05:18 +02:00
|
|
|
}
|
|
|
|
|
2016-09-22 18:05:36 +02:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn should_try_to_resolve_dapp() {
|
|
|
|
// given
|
|
|
|
let (server, registrar) = serve_with_registrar();
|
|
|
|
|
|
|
|
// when
|
|
|
|
let response = request(server,
|
|
|
|
"\
|
|
|
|
GET /api/content/1472a9e190620cdf6b31f383373e45efcfe869a820c91f9ccd7eb9fb45e4985d HTTP/1.1\r\n\
|
|
|
|
Host: home.parity\r\n\
|
|
|
|
Connection: close\r\n\
|
|
|
|
\r\n\
|
|
|
|
"
|
|
|
|
);
|
|
|
|
|
|
|
|
// then
|
|
|
|
assert_eq!(response.status, "HTTP/1.1 404 Not Found".to_owned());
|
|
|
|
assert_eq!(registrar.calls.lock().len(), 2);
|
2016-10-19 11:02:21 +02:00
|
|
|
assert_security_headers(&response.headers);
|
2016-09-22 18:05:36 +02:00
|
|
|
}
|
|
|
|
|
2016-10-22 15:21:41 +02:00
|
|
|
#[test]
|
|
|
|
fn should_return_signer_port_cors_headers() {
|
|
|
|
// given
|
|
|
|
let server = serve();
|
|
|
|
|
|
|
|
// when
|
|
|
|
let response = request(server,
|
|
|
|
"\
|
|
|
|
POST /api/ping HTTP/1.1\r\n\
|
|
|
|
Host: localhost:8080\r\n\
|
|
|
|
Origin: http://127.0.0.1:18180\r\n\
|
|
|
|
Connection: close\r\n\
|
|
|
|
\r\n\
|
|
|
|
{}
|
|
|
|
"
|
|
|
|
);
|
|
|
|
|
|
|
|
// then
|
|
|
|
assert_eq!(response.status, "HTTP/1.1 200 OK".to_owned());
|
|
|
|
assert!(
|
|
|
|
response.headers_raw.contains("Access-Control-Allow-Origin: http://127.0.0.1:18180"),
|
|
|
|
"CORS header for signer missing: {:?}",
|
|
|
|
response.headers
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn should_return_signer_port_cors_headers_for_home_parity() {
|
|
|
|
// given
|
|
|
|
let server = serve();
|
|
|
|
|
|
|
|
// when
|
|
|
|
let response = request(server,
|
|
|
|
"\
|
|
|
|
POST /api/ping HTTP/1.1\r\n\
|
|
|
|
Host: localhost:8080\r\n\
|
|
|
|
Origin: http://home.parity\r\n\
|
|
|
|
Connection: close\r\n\
|
|
|
|
\r\n\
|
|
|
|
{}
|
|
|
|
"
|
|
|
|
);
|
|
|
|
|
|
|
|
// then
|
|
|
|
assert_eq!(response.status, "HTTP/1.1 200 OK".to_owned());
|
|
|
|
assert!(
|
|
|
|
response.headers_raw.contains("Access-Control-Allow-Origin: http://home.parity"),
|
|
|
|
"CORS header for home.parity missing: {:?}",
|
|
|
|
response.headers
|
|
|
|
);
|
|
|
|
}
|