2018-05-04 19:14:49 +04:00
|
|
|
#! /usr/bin/env bash
|
|
|
|
|
|
|
|
## from genesis to demo
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
test_dir="$(cd "$(dirname "$0")" && echo "$(pwd -P)")"
|
|
|
|
source $test_dir/test_lib.inc.sh "$@"
|
|
|
|
|
|
|
|
start_node 1 --cors-origin "*"
|
|
|
|
|
|
|
|
show_logs="no"
|
|
|
|
|
|
|
|
sleep 2
|
|
|
|
|
|
|
|
run_preflight() {
|
|
|
|
local origin="$1"
|
|
|
|
local method="$2"
|
|
|
|
local cors_method="$3"
|
|
|
|
local header="$4"
|
|
|
|
curl -H "Origin: $origin" \
|
|
|
|
-H "Access-Control-Request-Method: $cors_method" \
|
|
|
|
-H "Access-Control-Request-Headers: $header" \
|
|
|
|
-X $method \
|
2018-04-16 02:44:24 +04:00
|
|
|
-I -s http://localhost:18731/chains/main/blocks/head/header/shell > CURL.$id 2>&1
|
2018-05-04 19:14:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
run_request() {
|
|
|
|
local origin="$1"
|
|
|
|
curl -H "Origin: $origin" \
|
|
|
|
-H "Content-Type: application/json" \
|
|
|
|
-D CURL.$id \
|
2018-04-16 02:44:24 +04:00
|
|
|
-s http://localhost:18731/chains/main/blocks/head/header/shell 2>&1 > /dev/null
|
2018-05-04 19:14:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
# Preflight
|
2018-04-16 02:44:24 +04:00
|
|
|
run_preflight "localhost" "OPTIONS" "GET" "Content-Type"
|
2018-05-04 19:14:49 +04:00
|
|
|
cat CURL.$id
|
|
|
|
grep -q "access-control-allow-origin" CURL.$id
|
|
|
|
grep -q "access-control-allow-methods" CURL.$id
|
|
|
|
grep -q "access-control-allow-headers" CURL.$id
|
|
|
|
|
|
|
|
# Request
|
|
|
|
run_request "localhost"
|
|
|
|
cat CURL.$id
|
|
|
|
grep -q "access-control-allow-origin" CURL.$id
|
|
|
|
|
|
|
|
echo
|
|
|
|
echo End of test
|
|
|
|
echo
|