52 lines
1.1 KiB
Bash
Executable File
52 lines
1.1 KiB
Bash
Executable File
#! /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 \
|
|
-I -s http://localhost:18731/blocks/head/protocol > CURL.$id 2>&1
|
|
}
|
|
|
|
run_request() {
|
|
local origin="$1"
|
|
curl -H "Origin: $origin" \
|
|
-H "Content-Type: application/json" \
|
|
--data-binary "{}" \
|
|
-D CURL.$id \
|
|
-s http://localhost:18731/blocks/head/protocol 2>&1 > /dev/null
|
|
}
|
|
|
|
# Preflight
|
|
run_preflight "localhost" "OPTIONS" "POST" "Content-Type"
|
|
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
|