-
Notifications
You must be signed in to change notification settings - Fork 2
/
init-mockserver
executable file
·105 lines (95 loc) · 3.64 KB
/
init-mockserver
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/bin/sh
if [ -z "$MOCKSERVER" ]; then
MOCKSERVER=localhost:1080
fi
while ! curl -f -v -X PUT "http://$MOCKSERVER/mockserver/expectation" -d '{
"httpRequest" : {"headers": {"Host": ["mockserver.*"]}},
"httpResponseTemplate": {
"templateType": "JAVASCRIPT",
"template": "return {
statusCode: 200,
cookies: {session: request.headers[\"Session-Id\"] && request.headers[\"Session-Id\"][0]},
headers: {
\"Content-Type\": [\"application/json\"],
Date: [Date()]},
body: JSON.stringify(request)};"},
"priority": -100}' ; do
sleep 1
done
curl -f -v -X PUT "http://$MOCKSERVER/mockserver/expectation" -d '{
"httpRequest" : {"path": "/bytes/.*"},
"httpResponseTemplate": {
"templateType": "JAVASCRIPT",
"template": "return {
statusCode: 200,
cookies: {session: request.headers[\"Session-Id\"] && request.headers[\"Session-Id\"][0]},
headers: {Date: [Date()]},
body: \"#\".repeat(parseInt(request.path.split(\"/\")[2]))};"}}'
curl -f -v -X PUT "http://$MOCKSERVER/mockserver/expectation" -d '{
"httpRequest" : {"path": "/delay/.*"},
"httpResponseTemplate": {
"templateType": "JAVASCRIPT",
"template": "return {
delay: {timeUnit: \"SECONDS\", value: parseInt(request.path.split(\"/\")[2])},
statusCode: 200,
cookies: {session: request.headers[\"Session-Id\"] && request.headers[\"Session-Id\"][0]},
headers: {
\"Content-Type\": [\"application/json\"],
Date: [Date()]},
body: JSON.stringify(request)};"}}'
curl -f -v -X PUT "http://$MOCKSERVER/mockserver/expectation" -d '{
"httpRequest" : {"path": "/ip"},
"httpResponseTemplate": {
"templateType": "JAVASCRIPT",
"template": "return {
statusCode: 200,
cookies: {session: request.headers[\"Session-Id\"] && request.headers[\"Session-Id\"][0]},
headers: {
\"Content-Type\": [\"application/json\"],
Date: [Date()]},
body: JSON.stringify({origin: function() {
var forwarded = request.headers[\"X-Forwarded-For\"] || request.headers[\"x-forwarded-for\"];
return forwarded[0].split(\",\")[0]
}()})
};"
}
}'
curl -f -v -X PUT "http://$MOCKSERVER/mockserver/expectation" -d '{
"httpRequest" : {"path": "/redirect-to"},
"httpResponseTemplate": {
"templateType": "JAVASCRIPT",
"template": "return {
statusCode: 302,
cookies: {session: request.headers[\"Session-Id\"] && request.headers[\"Session-Id\"][0]},
headers: {Location: request.queryStringParameters[\"url\"]}};"}}'
curl -f -v -X PUT "http://$MOCKSERVER/mockserver/expectation" -d '{
"httpRequest" : {"path": "/response-headers"},
"httpResponseTemplate": {
"templateType": "JAVASCRIPT",
"template": "return {
statusCode: 200,
cookies: {session: request.headers[\"Session-Id\"] && request.headers[\"Session-Id\"][0]},
headers: request.queryStringParameters,
body: JSON.stringify(request)};"}}'
curl -f -v -X PUT "http://$MOCKSERVER/mockserver/expectation" -d '{
"httpRequest" : {"path": "/status/.*"},
"httpResponseTemplate": {
"templateType": "JAVASCRIPT",
"template": "return {
statusCode: parseInt(request.path.split(\"/\")[2]),
cookies: {session: request.headers[\"Session-Id\"] && request.headers[\"Session-Id\"][0]},
headers: {
\"Content-Type\": [\"application/json\"],
Date: [Date()]},
body: JSON.stringify(request)};"}}'
curl -f -v -X PUT "http://$MOCKSERVER/mockserver/expectation" -d '{
"httpRequest" : {"path": "/uuid"},
"httpResponseTemplate": {
"templateType": "JAVASCRIPT",
"template": "return {
statusCode: 200,
cookies: {session: request.headers[\"Session-Id\"] && request.headers[\"Session-Id\"][0]},
headers: {
\"Content-Type\": [\"application/json\"],
Date: [Date()]},
body: JSON.stringify({\"uuid\": uuid})};"}}'