blob: fd6b1d096df2fcca09117b13b5448817ae59482b [file] [log] [blame]
BjornMagnussonXA37d37852019-10-15 08:42:08 +02001#!/bin/bash
2
3#Script for basic testing of the A1 simulator API
4#Note: policy is reset before test
5
6HOST_PORT="localhost:8080"
7
8echo "Usage: populate.sh [<host:port>]"
9
10HOST_PORT="localhost:8080"
11
12if [ $# == 1 ]; then
13 echo "Setting host and port from cmd line: "$1
14 HOST_PORT=$1
15fi
16
17echo "======================================="
18echo "Using host and port:" $HOST_PORT
19echo "======================================="
20
21echo "======================================="
22echo "Resetting db"
23curl 'http://'$HOST_PORT'/reset'
24echo "======================================="
25
26#Create a policy type
27create_pt() {
28 PATTERN="s/XXXX/${1}/g"
29 sed $PATTERN pt-template.json > .tmp.json
30 res=$(curl -sw "%{http_code}" -X PUT --header 'Content-Type: application/json' --header 'Accept: */*' -d @.tmp.json 'http://'${HOST_PORT}'/a1-p/policytypes/'$1)
31 http_code="${res:${#res}-3}"
32 echo "Response code: " $http_code
33}
34
35get_pt() {
36 res=$(curl -sw "%{http_code}" --header 'Accept: application/json' 'http://'${HOST_PORT}'/a1-p/policytypes/'$1)
37 http_code="${res:${#res}-3}"
38 echo "Response code: " $http_code
39 echo "Response: " ${res:0:${#res}-3}
40}
41
42get_pts() {
43 res=$(curl -sw "%{http_code}" --header 'Accept: application/json' 'http://'${HOST_PORT}'/a1-p/policytypes/')
44 http_code="${res:${#res}-3}"
45 echo "Response code: " $http_code
46 echo "Response: " ${res:0:${#res}-3}
47}
48
49del_pt() {
50 res=$(curl -sw "%{http_code}" -X DELETE --header 'Accept: */*' 'http://'${HOST_PORT}'/a1-p/policytypes/'$1)
51 http_code="${res:${#res}-3}"
52 echo "Response code: " $http_code
53}
54
55get_pis() {
56 res=$(curl -sw "%{http_code}" --header 'Accept: application/json' 'http://'${HOST_PORT}'/a1-p/policytypes/'${1}'/policies')
57 http_code="${res:${#res}-3}"
58 echo "Response code: " $http_code
59 echo "Response: " ${res:0:${#res}-3}
60}
61
62create_pi() {
63 PATTERN="s/XXXX/${2}/g"
64 sed $PATTERN pi-template.json > .tmp.json
65 res=$(curl -sw "%{http_code}" -X PUT --header 'Content-Type: application/json' --header 'Accept: */*' -d @.tmp.json 'http://'${HOST_PORT}'/a1-p/policytypes/'$1'/policies/'$2)
66 http_code="${res:${#res}-3}"
67 echo "Response code: " $http_code
68}
69
70get_pi() {
71 res=$(curl -sw "%{http_code}" --header 'Accept: application/json' 'http://'${HOST_PORT}'/a1-p/policytypes/'${1}'/policies/'$2)
72 http_code="${res:${#res}-3}"
73 echo "Response code: " $http_code
74 echo "Response: " ${res:0:${#res}-3}
75}
76
77del_pi() {
78 res=$(curl -sw "%{http_code}" -X DELETE --header 'Accept: application/json' 'http://'${HOST_PORT}'/a1-p/policytypes/'${1}'/policies/'$2)
79 http_code="${res:${#res}-3}"
80 echo "Response code: " $http_code
81}
82
83stat_pi() {
84 res=$(curl -sw "%{http_code}" --header 'Accept: application/json' 'http://'${HOST_PORT}'/a1-p/policytypes/'${1}'/policies/'$2'/status')
85 http_code="${res:${#res}-3}"
86 echo "Response code: " $http_code
87 echo "Response: " ${res:0:${#res}-3}
88}
89
90
91echo "== Create policy type 23"
92create_pt 23
93echo "== Get policy type 23"
94get_pt 23
95echo "== Create policy type 23 again"
96create_pt 23
97echo "== Create policy type 24"
98create_pt 24
99echo "== Get all policy types"
100get_pts
101echo "== Delete policy type 24"
102del_pt 24
103echo "== Delete policy type 24 again"
104del_pt 24
105echo "== Get all policy types"
106get_pts
107echo "== Get all policy instancess for type 23"
108get_pis 23
109echo "== Create policy instance 16 for type 23"
110create_pi 23 16
111echo "== Create policy instance 16 for type 23 again"
112create_pi 23 16
113echo "== Get policy instance 16 for type 23"
114get_pi 23 16
115echo "== Get missing policy instance 17 for type 23"
116get_pi 23 17
117echo "== Create policy instance 18 for type 23"
118create_pi 23 18
119echo "== Get all policy instances for type 23"
120get_pis 23
121echo "== Delete policy instance 18 for type 23"
122del_pi 23 18
123echo "== Get all policy instances for type 23"
124get_pis 23
125echo "== Get status for policy instance 16 for type 23"
126stat_pi 23 16