forked from Azure/autorest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathazureSpecials.js
261 lines (240 loc) · 11 KB
/
azureSpecials.js
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
var express = require('express');
var router = express.Router();
var util = require('util');
var constants = require('../util/constants');
var utils = require('../util/utils')
var specials = function (coverage) {
coverage['AzureSubscriptionMethodLocalValid'] = 0;
coverage['AzureSubscriptionMethodGlobalValid'] = 0;
coverage['AzureSubscriptionMethodGlobalNotProvidedValid'] = 0;
coverage['AzureSubscriptionPathLocalValid'] = 0;
coverage['AzureSubscriptionPathGlobalValid'] = 0;
coverage['AzureSubscriptionSwaggerLocalValid'] = 0;
coverage['AzureSubscriptionSwaggerGlobalValid'] = 0;
coverage['AzureApiVersionMethodLocalNull'] = 0;
coverage['AzureApiVersionMethodLocalValid'] = 0;
coverage['AzureApiVersionMethodGlobalValid'] = 0;
coverage['AzureApiVersionMethodGlobalNotProvidedValid'] = 0;
coverage['AzureApiVersionPathLocalValid'] = 0;
coverage['AzureApiVersionPathGlobalValid'] = 0;
coverage['AzureApiVersionSwaggerLocalValid'] = 0;
coverage['AzureApiVersionSwaggerGlobalValid'] = 0;
coverage['AzureMethodPathUrlEncoding'] = 0;
coverage['AzurePathPathUrlEncoding'] = 0;
coverage['AzureSwaggerPathUrlEncoding'] = 0;
coverage['AzureMethodQueryUrlEncoding'] = 0;
coverage['AzurePathQueryUrlEncoding'] = 0;
coverage['AzureSwaggerQueryUrlEncoding'] = 0;
coverage['AzureMethodQueryUrlEncodingNull'] = 0;
coverage['AzureXmsRequestClientOverwrite'] = 0;
coverage['AzureXmsRequestClientOverwriteViaParameter'] = 0;
coverage['AzureXmsRequestClientIdNull'] = 0;
coverage['AzureXmsCustomNamedRequestId'] = 0;
coverage['AzureXmsCustomNamedRequestIdParameterGroup'] = 0;
coverage['AzureRequestClientIdInError'] = 0;
coverage['AzureODataFilter'] = 0;
router.post('/subscriptionId/:location/string/none/path/:scope/:scenario/:subscription', function (req, res, next) {
var location = req.params.location;
var scope = req.params.scope;
var scenario = req.params.scenario;
var subscription = req.params.subscription;
var coverageScenario = '';
if (!req.get("x-ms-client-request-id")) {
utils.send400(res, next, "Header x-ms-client-request-id must be provided in each request.");
}
if (location === 'method') {
coverageScenario = 'AzureSubscriptionMethod';
if (scope === 'local') {
coverageScenario += 'LocalValid';
} else if (scope === 'global') {
coverageScenario += 'GlobalValid';
} else if (scope === 'globalNotProvided') {
coverageScenario += 'GlobalNotProvidedValid';
} else {
utils.send400(res, next, 'Unable to parse location: "' + util.inspect(location) + '"');
}
} else if (location === 'path') {
coverageScenario = 'AzureSubscriptionPath';
if (scope === 'local') {
coverageScenario += 'LocalValid';
} else if (scope === 'global') {
coverageScenario += 'GlobalValid';
} else {
utils.send400(res, next, 'Unable to parse location: "' + util.inspect(location) + '"');
}
} else if (location === 'swagger') {
coverageScenario = 'AzureSubscriptionSwagger';
if (scope === 'local') {
coverageScenario += 'LocalValid';
} else if (scope === 'global') {
coverageScenario += 'GlobalValid';
} else {
utils.send400(res, next, 'Unable to parse location: "' + util.inspect(location) + '"');
}
} else {
utils.send400(res, next, 'Unable to parse definition location: "' + util.inspect(location) + '"');
}
if (scenario === subscription) {
coverage[coverageScenario]++;
res.send(200).end();
} else {
utils.send400(res, next, 'Expected subscription: "' + util.inspect(scenario) + '" did not match actual "' + subscription + '"');
}
});
router.get('/apiVersion/:location/string/none/query/:scope/:scenario', function (req, res, next) {
var location = req.params.location;
var scope = req.params.scope;
var scenario = req.params.scenario;
var apiVersion = req.query['api-version'];
var coverageScenario = 'AzureApiVersion';
if (location === 'method') {
coverageScenario += 'Method';
if (scope === 'local' && scenario === '2.0') {
coverageScenario += 'LocalValid';
} else if (scope === 'local' && scenario === 'null') {
coverageScenario += 'LocalNull';
} else if (scope === 'global') {
coverageScenario += 'GlobalValid';
} else if (scope === 'globalNotProvided') {
coverageScenario += 'GlobalNotProvidedValid';
} else {
utils.send400(res, next, 'Unable to parse location: "' + util.inspect(location) + '"');
}
} else if (location === 'path') {
coverageScenario += 'Path';
if (scope === 'local') {
coverageScenario += 'LocalValid';
} else if (scope === 'global') {
coverageScenario += 'GlobalValid';
} else {
utils.send400(res, next, 'Unable to parse location: "' + util.inspect(location) + '"');
}
} else if (location === 'swagger') {
coverageScenario += 'Swagger';
if (scope === 'local') {
coverageScenario += 'LocalValid';
} else if (scope === 'global') {
coverageScenario += 'GlobalValid';
} else {
utils.send400(res, next, 'Unable to parse location: "' + util.inspect(location) + '"');
}
} else {
utils.send400(res, next, 'Unable to parse definition location: "' + util.inspect(location) + '"');
}
if (scenario === apiVersion || (scenario === 'null' && Object.keys(req.query).length === 0)) {
coverage[coverageScenario]++;
res.send(200).end();
} else {
utils.send400(res, next, 'Expected api-version: "' + util.inspect(scenario) + '" did not match actual "' + apiVersion + '"');
}
});
router.get('/skipUrlEncoding/:location/path/valid/path1/path2/path3', function (req, res, next) {
var location = req.params.location;
if (location === 'method' || location === 'path' || location === 'swagger') {
var scenario = 'Azure' + utils.toPascalCase(location) + 'PathUrlEncoding';
coverage[scenario]++;
res.status(200).end();
} else {
utils.send400(res, next, 'Unable to determine location "' + util.inspect(location) + '" for AzurePathUrlEncoding scenario');
}
});
router.get('/skipUrlEncoding/:location/query/valid', function (req, res, next) {
var location = req.params.location;
if (location === 'method' || location === 'path' || location === 'swagger') {
var scenario = 'Azure' + utils.toPascalCase(location) + 'QueryUrlEncoding';
if (Object.keys(req.query).length > 2 && req.query['q1'] === 'value1' &&
req.query['q2'] === 'value2' && req.query['q3'] === 'value3') {
coverage[scenario]++;
res.status(200).end();
} else {
utils.send400(res, next, 'Unexpected query values for scenario "' + scenario + '": "' + util.inspect(req.query) + '"');
}
} else {
utils.send400(res, next, 'Unable to determine location "' + util.inspect(location) + '" for AzurePathUrlEncoding scenario');
}
});
router.get('/skipUrlEncoding/method/query/null', function (req, res, next) {
var scenario = 'AzureMethodQueryUrlEncodingNull';
if (Object.keys(req.query).length <= 1 && (req.query['q1'] === undefined || req.query['q1'] === null)) {
coverage[scenario]++;
res.status(200).end();
} else {
utils.send400(res, next, 'Unexpected query values for scenario "' + scenario + '": "' + util.inspect(req.query) + '"');
}
});
router.get('/odata/filter', function (req, res, next) {
var scenario = 'AzureODataFilter';
if (req.query['$filter'] !== "id gt 5 and name eq 'foo'") {
utils.send400(res, next, 'Unexpected $filter value for "' + scenario + '": expect "id gt 5 and name eq \'foo\'" actual "' + req.query['$filter'] + '"');
}
if (req.query['$top'] !== "10") {
utils.send400(res, next, 'Unexpected $top value for "' + scenario + '": expect "10" actual "' + req.query['$top'] + '"');
}
if (req.query['$orderby'] !== "id") {
utils.send400(res, next, 'Unexpected $top value for "' + scenario + '": expect "id" actual "' + req.query['$orderby'] + '"');
}
coverage[scenario]++;
res.status(200).end();
});
router.get('/overwrite/x-ms-client-request-id/method/', function (req, res, next) {
var headers = {
'x-ms-request-id': '123'
};
if (!req.headers["x-ms-client-request-id"]) {
coverage['AzureXmsRequestClientIdNull']++;
res.set(headers).status(200).end();
} else if (req.headers["x-ms-client-request-id"] !== '9C4D50EE-2D56-4CD3-8152-34347DC9F2B0') {
coverage['AzureRequestClientIdInError']++;
res.set(headers).status(400).end();
} else {
coverage['AzureXmsRequestClientOverwrite']++;
res.set(headers).status(200).end();
}
});
router.get('/overwrite/x-ms-client-request-id/via-param/method/', function (req, res, next) {
var headers = {
'x-ms-request-id': '123'
};
if (req.get("x-ms-client-request-id") !== '9C4D50EE-2D56-4CD3-8152-34347DC9F2B0') {
utils.send400(res, next, "Header x-ms-client-request-id must be set to 9C4D50EE-2D56-4CD3-8152-34347DC9F2B0.");
} else {
coverage['AzureXmsRequestClientOverwriteViaParameter']++;
res.set(headers).status(200).end();
}
});
router.post('/customNamedRequestId', function (req, res, next) {
var headers = {
'foo-request-id': '123'
};
if (req.get("foo-client-request-id") !== '9C4D50EE-2D56-4CD3-8152-34347DC9F2B0') {
utils.send400(res, next, "Header foo-client-request-id must be set to 9C4D50EE-2D56-4CD3-8152-34347DC9F2B0.");
} else {
coverage['AzureXmsCustomNamedRequestId']++;
res.set(headers).status(200).end();
}
});
router.post('/customNamedRequestIdParamGrouping', function (req, res, next) {
var headers = {
'foo-request-id': '123'
};
if (req.get("foo-client-request-id") !== '9C4D50EE-2D56-4CD3-8152-34347DC9F2B0') {
utils.send400(res, next, "Header foo-client-request-id must be set to 9C4D50EE-2D56-4CD3-8152-34347DC9F2B0.");
} else {
coverage['AzureXmsCustomNamedRequestIdParameterGroup']++;
res.set(headers).status(200).end();
}
});
router.head('/customNamedRequestIdHead', function (req, res, next) {
var headers = {
'foo-request-id': '123'
};
if (req.get("foo-client-request-id") !== '9C4D50EE-2D56-4CD3-8152-34347DC9F2B0') {
utils.send400(res, next, "Header foo-client-request-id must be set to 9C4D50EE-2D56-4CD3-8152-34347DC9F2B0.");
} else {
coverage['AzureXmsCustomNamedRequestId']++;
res.set(headers).status(200).end();
}
});
}
specials.prototype.router = router;
module.exports = specials;