summaryrefslogtreecommitdiff
path: root/tools/test_relay_api.sh
blob: 4a830826f9a9ae35cfe1e7460e5764ad49edcfab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/bin/sh
#
# Copyright (C) 2024 Sébastien Helleu <flashcode@flashtux.org>
#
# This file is part of WeeChat, the extensible chat client.
#
# WeeChat 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.
#
# WeeChat 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 WeeChat.  If not, see <https://www.gnu.org/licenses/>.
#

#
# Test WeeChat relay HTTP REST API.
#
# Environment variables that can be used:
#
#   RELAY_PASSWORD  Password for WeeChat relay
#

set -o errexit

# default values for options from environment variables
default_relay_password="test"

usage ()
{
    rc=$1
    cat <<-EOF

Syntax: $0 url

  url  URL of the running WeeChat with relay api (without "/api")

Environment variables used:

  RELAY_PASSWORD  password for the relay (default: "${default_relay_password}")

Example:

  RELAY_PASSWORD="test" $0 http://localhost:9000

EOF
    exit "${rc}"
}

error_usage ()
{
    echo >&2 "ERROR: $*"
    usage 1
}

# ================================== START ==================================

# relay password
[ -z "${RELAY_PASSWORD}" ] && RELAY_PASSWORD="${default_relay_password}"

# check command line arguments
if [ $# -eq 0 ]; then
    usage 0
fi
if [ $# -lt 1 ]; then
    error_usage "missing arguments"
fi

# command line arguments
url="$1"

schemathesis run \
    --checks all \
    --validate-schema=true \
    --experimental=openapi-3.1 \
    --base-url "${url}/api" \
    --auth "plain:${RELAY_PASSWORD}" \
    ./src/plugins/relay/api/weechat-relay-api.yaml \
    ;

exit 0