2018-06-04 10:19:50 +02:00
|
|
|
// Copyright 2015-2018 Parity Technologies (UK) Ltd.
|
2016-08-30 16:05:18 +02:00
|
|
|
// 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-11-03 12:22:28 +01:00
|
|
|
use tests::helpers::{serve, request, assert_security_headers, assert_security_headers_for_embed};
|
2016-08-30 16:05:18 +02:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn should_redirect_to_home() {
|
|
|
|
// given
|
|
|
|
let server = serve();
|
|
|
|
|
|
|
|
// when
|
|
|
|
let response = request(server,
|
|
|
|
"\
|
|
|
|
GET / HTTP/1.1\r\n\
|
|
|
|
Host: 127.0.0.1:8080\r\n\
|
|
|
|
Connection: close\r\n\
|
|
|
|
\r\n\
|
|
|
|
"
|
|
|
|
);
|
|
|
|
|
|
|
|
// then
|
2017-03-22 07:02:14 +01:00
|
|
|
response.assert_status("HTTP/1.1 302 Found");
|
2016-10-22 15:21:41 +02:00
|
|
|
assert_eq!(response.headers.get(0).unwrap(), "Location: http://127.0.0.1:18180");
|
2016-08-30 16:05:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2017-05-24 12:24:07 +02:00
|
|
|
fn should_redirect_to_home_with_domain() {
|
2016-08-30 16:05:18 +02:00
|
|
|
// given
|
|
|
|
let server = serve();
|
|
|
|
|
|
|
|
// when
|
|
|
|
let response = request(server,
|
|
|
|
"\
|
2017-05-24 12:24:07 +02:00
|
|
|
GET / HTTP/1.1\r\n\
|
|
|
|
Host: home.web3.site\r\n\
|
2016-08-30 16:05:18 +02:00
|
|
|
Connection: close\r\n\
|
|
|
|
\r\n\
|
|
|
|
"
|
|
|
|
);
|
|
|
|
|
|
|
|
// then
|
2017-03-22 07:02:14 +01:00
|
|
|
response.assert_status("HTTP/1.1 302 Found");
|
2016-10-22 15:21:41 +02:00
|
|
|
assert_eq!(response.headers.get(0).unwrap(), "Location: http://127.0.0.1:18180");
|
2016-08-30 16:05:18 +02:00
|
|
|
}
|
|
|
|
|
2016-11-02 11:29:18 +01:00
|
|
|
#[test]
|
2017-05-24 12:24:07 +02:00
|
|
|
fn should_redirect_to_home_when_trailing_slash_is_missing() {
|
2016-11-02 11:29:18 +01:00
|
|
|
// given
|
|
|
|
let server = serve();
|
|
|
|
|
|
|
|
// when
|
|
|
|
let response = request(server,
|
|
|
|
"\
|
2017-05-24 12:24:07 +02:00
|
|
|
GET /app HTTP/1.1\r\n\
|
2016-11-02 11:29:18 +01:00
|
|
|
Host: 127.0.0.1:8080\r\n\
|
|
|
|
Connection: close\r\n\
|
|
|
|
\r\n\
|
|
|
|
"
|
|
|
|
);
|
|
|
|
|
|
|
|
// then
|
2017-03-22 07:02:14 +01:00
|
|
|
response.assert_status("HTTP/1.1 302 Found");
|
2016-11-02 11:29:18 +01:00
|
|
|
assert_eq!(response.headers.get(0).unwrap(), "Location: http://127.0.0.1:18180");
|
|
|
|
}
|
|
|
|
|
2016-08-30 16:05:18 +02:00
|
|
|
#[test]
|
2016-09-01 11:16:19 +02:00
|
|
|
fn should_display_404_on_invalid_dapp() {
|
2016-08-30 16:05:18 +02:00
|
|
|
// given
|
|
|
|
let server = serve();
|
|
|
|
|
|
|
|
// when
|
|
|
|
let response = request(server,
|
|
|
|
"\
|
|
|
|
GET /invaliddapp/ HTTP/1.1\r\n\
|
|
|
|
Host: 127.0.0.1:8080\r\n\
|
|
|
|
Connection: close\r\n\
|
|
|
|
\r\n\
|
|
|
|
"
|
|
|
|
);
|
|
|
|
|
|
|
|
// then
|
2017-03-22 07:02:14 +01:00
|
|
|
response.assert_status("HTTP/1.1 404 Not Found");
|
2016-11-03 12:22:28 +01:00
|
|
|
assert_security_headers_for_embed(&response.headers);
|
2016-08-30 16:05:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2016-09-01 11:16:19 +02:00
|
|
|
fn should_display_404_on_invalid_dapp_with_domain() {
|
2016-08-30 16:05:18 +02:00
|
|
|
// given
|
|
|
|
let server = serve();
|
|
|
|
|
|
|
|
// when
|
|
|
|
let response = request(server,
|
|
|
|
"\
|
|
|
|
GET / HTTP/1.1\r\n\
|
2017-02-04 09:52:14 +01:00
|
|
|
Host: invaliddapp.web3.site\r\n\
|
2016-08-30 16:05:18 +02:00
|
|
|
Connection: close\r\n\
|
|
|
|
\r\n\
|
|
|
|
"
|
|
|
|
);
|
|
|
|
|
|
|
|
// then
|
2017-03-22 07:02:14 +01:00
|
|
|
response.assert_status("HTTP/1.1 404 Not Found");
|
2016-11-03 12:22:28 +01:00
|
|
|
assert_security_headers_for_embed(&response.headers);
|
2016-08-30 16:05:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn should_serve_rpc() {
|
|
|
|
// given
|
|
|
|
let server = serve();
|
|
|
|
|
|
|
|
// when
|
|
|
|
let response = request(server,
|
|
|
|
"\
|
|
|
|
POST / HTTP/1.1\r\n\
|
|
|
|
Host: 127.0.0.1:8080\r\n\
|
|
|
|
Connection: close\r\n\
|
|
|
|
Content-Type: application/json\r\n
|
|
|
|
\r\n\
|
|
|
|
{}
|
|
|
|
"
|
|
|
|
);
|
|
|
|
|
|
|
|
// then
|
2017-03-22 07:02:14 +01:00
|
|
|
response.assert_status("HTTP/1.1 200 OK");
|
|
|
|
assert_eq!(response.body, format!("4C\n{}\n\n0\n\n", r#"{"jsonrpc":"2.0","error":{"code":-32700,"message":"Parse error"},"id":null}"#));
|
2016-08-30 16:05:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn should_serve_rpc_at_slash_rpc() {
|
|
|
|
// given
|
|
|
|
let server = serve();
|
|
|
|
|
|
|
|
// when
|
|
|
|
let response = request(server,
|
|
|
|
"\
|
|
|
|
POST /rpc HTTP/1.1\r\n\
|
|
|
|
Host: 127.0.0.1:8080\r\n\
|
|
|
|
Connection: close\r\n\
|
|
|
|
Content-Type: application/json\r\n
|
|
|
|
\r\n\
|
|
|
|
{}
|
|
|
|
"
|
|
|
|
);
|
|
|
|
|
|
|
|
// then
|
2017-03-22 07:02:14 +01:00
|
|
|
response.assert_status("HTTP/1.1 200 OK");
|
|
|
|
assert_eq!(response.body, format!("4C\n{}\n\n0\n\n", r#"{"jsonrpc":"2.0","error":{"code":-32700,"message":"Parse error"},"id":null}"#));
|
2016-08-30 16:05:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn should_serve_proxy_pac() {
|
|
|
|
// given
|
|
|
|
let server = serve();
|
|
|
|
|
|
|
|
// when
|
|
|
|
let response = request(server,
|
|
|
|
"\
|
|
|
|
GET /proxy/proxy.pac HTTP/1.1\r\n\
|
|
|
|
Host: 127.0.0.1:8080\r\n\
|
|
|
|
Connection: close\r\n\
|
|
|
|
\r\n\
|
|
|
|
{}
|
|
|
|
"
|
|
|
|
);
|
|
|
|
|
|
|
|
// then
|
2017-03-22 07:02:14 +01:00
|
|
|
response.assert_status("HTTP/1.1 200 OK");
|
2017-05-24 12:24:07 +02:00
|
|
|
assert_eq!(response.body, "DB\n\nfunction FindProxyForURL(url, host) {\n\tif (shExpMatch(host, \"home.web3.site\"))\n\t{\n\t\treturn \"PROXY 127.0.0.1:18180\";\n\t}\n\n\tif (shExpMatch(host, \"*.web3.site\"))\n\t{\n\t\treturn \"PROXY 127.0.0.1:8080\";\n\t}\n\n\treturn \"DIRECT\";\n}\n\n0\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
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn should_serve_utils() {
|
|
|
|
// given
|
|
|
|
let server = serve();
|
|
|
|
|
|
|
|
// when
|
|
|
|
let response = request(server,
|
|
|
|
"\
|
|
|
|
GET /parity-utils/inject.js HTTP/1.1\r\n\
|
|
|
|
Host: 127.0.0.1:8080\r\n\
|
|
|
|
Connection: close\r\n\
|
|
|
|
\r\n\
|
|
|
|
{}
|
|
|
|
"
|
|
|
|
);
|
|
|
|
|
|
|
|
// then
|
2017-03-22 07:02:14 +01:00
|
|
|
response.assert_status("HTTP/1.1 200 OK");
|
2017-10-05 12:35:01 +02:00
|
|
|
response.assert_header("Content-Type", "application/javascript");
|
|
|
|
assert_eq!(response.body.contains("function(){"), true, "Expected function in: {}", response.body);
|
2016-10-19 11:02:21 +02:00
|
|
|
assert_security_headers(&response.headers);
|
2016-08-30 16:05:18 +02:00
|
|
|
}
|