github.com/keltia/go-ipfs@v0.3.8-0.20150909044612-210793031c63/test/sharness/t0110-gateway.sh (about) 1 #!/bin/sh 2 # 3 # Copyright (c) 2015 Matt Bell 4 # MIT Licensed; see the LICENSE file in this repository. 5 # 6 7 test_description="Test HTTP Gateway" 8 9 . lib/test-lib.sh 10 11 test_init_ipfs 12 test_config_ipfs_gateway_readonly $ADDR_GWAY 13 test_launch_ipfs_daemon 14 15 port=$PORT_GWAY 16 apiport=$PORT_API 17 18 # TODO check both 5001 and 5002. 19 # 5001 should have a readable gateway (part of the API) 20 # 5002 should have a readable gateway (using ipfs config Addresses.Gateway) 21 # but ideally we should only write the tests once. so maybe we need to 22 # define a function to test a gateway, and do so for each port. 23 # for now we check 5001 here as 5002 will be checked in gateway-writable. 24 25 test_expect_success "GET IPFS path succeeds" ' 26 echo "Hello Worlds!" >expected && 27 HASH=$(ipfs add -q expected) && 28 curl -sfo actual "http://127.0.0.1:$port/ipfs/$HASH" 29 ' 30 31 test_expect_success "GET IPFS path output looks good" ' 32 test_cmp expected actual && 33 rm actual 34 ' 35 36 test_expect_success "GET IPFS path on API forbidden" ' 37 test_curl_resp_http_code "http://127.0.0.1:$apiport/ipfs/$HASH" "HTTP/1.1 403 Forbidden" 38 ' 39 40 test_expect_success "GET IPFS directory path succeeds" ' 41 mkdir dir && 42 echo "12345" >dir/test && 43 ipfs add -r -q dir >actual && 44 HASH2=$(tail -n 1 actual) && 45 curl -sf "http://127.0.0.1:$port/ipfs/$HASH2" 46 ' 47 48 test_expect_success "GET IPFS directory file succeeds" ' 49 curl -sfo actual "http://127.0.0.1:$port/ipfs/$HASH2/test" 50 ' 51 52 test_expect_success "GET IPFS directory file output looks good" ' 53 test_cmp dir/test actual 54 ' 55 56 test_expect_success "GET IPFS non existent file returns code expected (404)" ' 57 test_curl_resp_http_code "http://127.0.0.1:$port/ipfs/$HASH2/pleaseDontAddMe" "HTTP/1.1 404 Not Found" 58 ' 59 60 test_expect_failure "GET IPNS path succeeds" ' 61 ipfs name publish "$HASH" && 62 NAME=$(ipfs config Identity.PeerID) && 63 curl -sfo actual "http://127.0.0.1:$port/ipns/$NAME" 64 ' 65 66 test_expect_failure "GET IPNS path output looks good" ' 67 test_cmp expected actual 68 ' 69 70 test_expect_success "GET invalid IPFS path errors" ' 71 test_must_fail curl -sf "http://127.0.0.1:$port/ipfs/12345" 72 ' 73 74 test_expect_success "GET invalid path errors" ' 75 test_must_fail curl -sf "http://127.0.0.1:$port/12345" 76 ' 77 78 test_expect_success "GET /webui returns code expected" ' 79 test_curl_resp_http_code "http://127.0.0.1:$apiport/webui" "HTTP/1.1 302 Found" "HTTP/1.1 301 Moved Permanently" 80 ' 81 82 test_expect_success "GET /webui/ returns code expected" ' 83 test_curl_resp_http_code "http://127.0.0.1:$apiport/webui/" "HTTP/1.1 302 Found" "HTTP/1.1 301 Moved Permanently" 84 ' 85 86 test_expect_success "GET /logs returns logs" ' 87 test_expect_code 28 curl http://127.0.0.1:$apiport/logs -m1 > log_out 88 ' 89 90 test_expect_success "log output looks good" ' 91 grep "log API client connected" log_out 92 ' 93 94 # test ipfs readonly api 95 96 test_curl_gateway_api() { 97 curl -sfo actual "http://127.0.0.1:$port/api/v0/$1" 98 } 99 100 test_expect_success "get IPFS directory file through readonly API succeeds" ' 101 test_curl_gateway_api "cat?arg=$HASH2/test" 102 ' 103 104 test_expect_success "get IPFS directory file through readonly API output looks good" ' 105 test_cmp dir/test actual 106 ' 107 108 test_expect_success "refs IPFS directory file through readonly API succeeds" ' 109 test_curl_gateway_api "refs?arg=$HASH2/test" 110 ' 111 112 test_expect_success "test gateway api is sanitized" ' 113 for cmd in "add" "block/put" "bootstrap" "config" "dht" "diag" "dns" "get" "id" "mount" "name/publish" "object/put" "object/new" "object/patch" "pin" "ping" "refs/local" "repo" "resolve" "stats" "swarm" "tour" "file" "update" "version" "bitswap"; do 114 test_curl_resp_http_code "http://127.0.0.1:$port/api/v0/$cmd" "HTTP/1.1 404 Not Found" 115 done 116 ' 117 118 test_kill_ipfs_daemon 119 120 test_done