#!/bin/sh
#
# Copyright (C) 2011-2013 Cesnet z.s.p.o
# Use of this source is governed by a 3-clause BSD-style license, see LICENSE file.

keyfile='key.pem'
certfile='cert.pem'
cafile='tcs-ca-bundle.pem'
url="$1"
client="$2"

#    --fail \
#    --show-error \
#

echo "Test  404"
curl \
    --key $keyfile \
    --cert $certfile \
    --cacert $cafile \
    --connect-timeout 3 \
    --request POST \
    "$url/blefub?client=$2"
echo

echo "Test  404"
curl \
    --key $keyfile \
    --cert $certfile \
    --cacert $cafile \
    --connect-timeout 3 \
    --request POST \
    "$url/?client=$2"
echo

echo "Test  403 - no client"
curl \
    --key $keyfile \
    --cert $certfile \
    --cacert $cafile \
    --connect-timeout 3 \
    --request POST \
    "$url/getEvents"
echo

echo "Test  403 - wrong client"
curl \
    --key $keyfile \
    --cert $certfile \
    --cacert $cafile \
    --connect-timeout 3 \
    --request POST \
    "$url/getEvents?client=asdf.blefub"
echo

echo "Test  Deserialization"
curl \
    --key $keyfile \
    --cert $certfile \
    --cacert $cafile \
    --connect-timeout 3 \
    --request POST \
    --data '{#$%^' \
    "$url/getEvents?client=$2"
echo

echo "Test  Called with unknown category"
curl \
    --key $keyfile \
    --cert $certfile \
    --cacert $cafile \
    --connect-timeout 3 \
    --request POST \
    "$url/getEvents?client=$2&cat=bflm"
echo

echo "Test  Called with both cat and nocat"
curl \
    --key $keyfile \
    --cert $certfile \
    --cacert $cafile \
    --connect-timeout 3 \
    --request POST \
    "$url/getEvents?client=$2&cat=Other&nocat=Test"
echo

echo "Test  Invalid data for getEvents - silently discarded"
curl \
    --key $keyfile \
    --cert $certfile \
    --cacert $cafile \
    --connect-timeout 3 \
    --request POST \
    --data '[1]' \
    "$url/getEvents?client=$2"
echo

echo "Test  Called with internal args - just in log"
curl \
    --key $keyfile \
    --cert $certfile \
    --cacert $cafile \
    --connect-timeout 3 \
    --request POST \
    "$url/getEvents?client=$2&self=test"
echo

echo "Test  Called with superfluous args - just in log"
curl \
    --key $keyfile \
    --cert $certfile \
    --cacert $cafile \
    --connect-timeout 3 \
    --request POST \
    "$url/getEvents?client=$2&bad=guy"
echo

echo "Test  getEvents with no args - should be OK"
curl \
    --key $keyfile \
    --cert $certfile \
    --cacert $cafile \
    --connect-timeout 3 \
    --request POST \
    "$url/getEvents?client=$2"
echo

echo "Test  getEvents - should be OK"
curl \
    --key $keyfile \
    --cert $certfile \
    --cacert $cafile \
    --connect-timeout 3 \
    --request POST \
    "$url/getEvents?client=$2&count=3&id=10"
echo

echo "Test  getDebug"
curl \
    --key $keyfile \
    --cert $certfile \
    --cacert $cafile \
    --connect-timeout 3 \
    --request POST \
    "$url/getDebug?client=$2"
echo

echo "Test  getInfo"
curl \
    --key $keyfile \
    --cert $certfile \
    --cacert $cafile \
    --connect-timeout 3 \
    --request POST \
    "$url/getInfo?client=$2"
echo

#curl \
#    --fail \
#    --connect-timeout 3 \
#    --request POST \
#    $url/getEvents
