-
Notifications
You must be signed in to change notification settings - Fork 9
/
api.feeds.upload.feeds-method.apikey-auth.url.js
334 lines (314 loc) · 15.6 KB
/
api.feeds.upload.feeds-method.apikey-auth.url.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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
const should = require('should');
const flow = require('nimble');
const httpStatus = require('http-status');
const requireNew = require('require-new');
const wipe = require('./fixture-helpers/wipe');
const setup = require('./fixture-helpers/setup');
const executeUploadTest = require('./fixture-helpers/test-utils').executeUploadTest;
const config = require('../config');
const ESDR_API_ROOT_URL = config.get("esdr:apiRootUrl");
const ESDR_FEEDS_API_URL = ESDR_API_ROOT_URL + "/feeds";
const UNKNOWN_FEED_API_KEY = "012345678901234567890123456789012345678901234567890123456789abcd";
describe("REST API", function() {
const user1 = requireNew('./fixtures/user1.json');
const user2 = requireNew('./fixtures/user2.json');
const product1 = requireNew('./fixtures/product1.json');
const device1 = requireNew('./fixtures/device1.json');
const feed1 = requireNew('./fixtures/feed1.json'); // public, user 1, product 1, device 1
const feed2 = requireNew('./fixtures/feed2.json'); // private, user 1, product 1, device 1
const feedUpload1 = {
request : requireNew('./fixtures/feed-upload1-request.json'),
response : requireNew('./fixtures/feed-upload1-response.json')
};
const feedUpload2 = {
request : requireNew('./fixtures/feed-upload2-request.json'),
response : requireNew('./fixtures/feed-upload2-response.json')
};
const feedUpload3 = {
request : requireNew('./fixtures/feed-upload3-request.json'),
response : requireNew('./fixtures/feed-upload3-response.json')
};
const feedUpload4 = {
request : requireNew('./fixtures/feed-upload4-request.json'),
response : requireNew('./fixtures/feed-upload4-response.json')
};
const feedUpload5 = {
request : requireNew('./fixtures/feed-upload5-request.json'),
response : requireNew('./fixtures/feed-upload5-response.json')
};
const feedUpload6 = {
request : requireNew('./fixtures/feed-upload6-request.json'),
response : requireNew('./fixtures/feed-upload6-response.json')
};
const feedUpload7 = {
request : requireNew('./fixtures/feed-upload7-request.json'),
response : requireNew('./fixtures/feed-upload7-response.json')
};
const feedUpload8 = {
request : requireNew('./fixtures/feed-upload8-request.json'),
response : requireNew('./fixtures/feed-upload8-response.json')
};
const invalidChannelName1 = {
request : requireNew('./fixtures/feed-upload-invalid-channel-name-1-request.json'),
response : requireNew('./fixtures/feed-upload-invalid-channel-name-1-response.json')
}
const invalidChannelName2 = {
request : requireNew('./fixtures/feed-upload-invalid-channel-name-2-request.json'),
response : requireNew('./fixtures/feed-upload-invalid-channel-name-2-response.json')
}
const invalidChannelName3 = {
request : requireNew('./fixtures/feed-upload-invalid-channel-name-3-request.json'),
response : requireNew('./fixtures/feed-upload-invalid-channel-name-3-response.json')
}
const invalidChannelName4 = {
request : requireNew('./fixtures/feed-upload-invalid-channel-name-4-request.json'),
response : requireNew('./fixtures/feed-upload-invalid-channel-name-4-response.json')
}
before(function(initDone) {
flow.series(
[
wipe.wipeAllData,
function(done) {
setup.createUser(user1, done);
},
function(done) {
setup.verifyUser(user1, done);
},
function(done) {
setup.authenticateUser(user1, done);
},
function(done) {
setup.createUser(user2, done);
},
function(done) {
setup.verifyUser(user2, done);
},
function(done) {
setup.authenticateUser(user2, done);
},
function(done) {
product1.creatorUserId = user1.id;
setup.createProduct(product1, done);
},
function(done) {
device1.userId = user1.id;
device1.productId = product1.id;
setup.createDevice(device1, done);
},
function(done) {
feed1.userId = user1.id;
feed1.deviceId = device1.id;
feed1.productId = product1.id;
feed1.channelSpecs = product1.defaultChannelSpecs;
setup.createFeed(feed1, done);
},
function(done) {
feed2.userId = user1.id;
feed2.deviceId = device1.id;
feed2.productId = product1.id;
feed2.channelSpecs = product1.defaultChannelSpecs;
setup.createFeed(feed2, done);
}
],
initDone
);
});
describe("Feeds", function() {
describe("Upload", function() {
describe("To /feeds method", function() {
describe("API Key Authentication", function() {
describe("Feed API Key in the URL", function() {
[
{
description : "Should be able to upload empty data to a public feed using the feed's apiKey to authenticate",
url : function() {
return ESDR_FEEDS_API_URL + "/" + feed1.apiKey;
},
dataToUpload : {},
expectedHttpStatus : httpStatus.OK,
expectedStatusText : 'success',
expectedResponseData : {
channelBounds : {},
importedBounds : {}
}
},
{
description : "Should be able to upload empty data to a private feed using the feed's apiKey to authenticate",
url : function() {
return ESDR_FEEDS_API_URL + "/" + feed2.apiKey;
},
dataToUpload : {},
expectedHttpStatus : httpStatus.OK,
expectedStatusText : 'success',
expectedResponseData : {
channelBounds : {},
importedBounds : {}
}
},
{
description : "Should be able to upload to a public feed using the feed's apiKey to authenticate",
url : function() {
return ESDR_FEEDS_API_URL + "/" + feed1.apiKey;
},
dataToUpload : feedUpload1.request,
expectedHttpStatus : httpStatus.OK,
expectedStatusText : 'success',
expectedResponseData : feedUpload1.response.data
},
{
description : "Should be able to upload to a private feed using the feed's apiKey to authenticate",
url : function() {
return ESDR_FEEDS_API_URL + "/" + feed2.apiKey;
},
dataToUpload : feedUpload5.request,
expectedHttpStatus : httpStatus.OK,
expectedStatusText : 'success',
expectedResponseData : feedUpload5.response.data
},
{
description : "Should be able to upload more data to a public feed using the feed's apiKey to authenticate",
url : function() {
return ESDR_FEEDS_API_URL + "/" + feed1.apiKey;
},
dataToUpload : feedUpload2.request,
expectedHttpStatus : httpStatus.OK,
expectedStatusText : 'success',
expectedResponseData : feedUpload2.response.data
},
{
description : "Should be able to upload more data to a private feed using the feed's apiKey to authenticate",
url : function() {
return ESDR_FEEDS_API_URL + "/" + feed2.apiKey;
},
dataToUpload : feedUpload6.request,
expectedHttpStatus : httpStatus.OK,
expectedStatusText : 'success',
expectedResponseData : feedUpload6.response.data
},
{
description : "Should be able to upload data for a single channel to a public feed (this one will affect the min/max times)",
url : function() {
return ESDR_FEEDS_API_URL + "/" + feed1.apiKey;
},
dataToUpload : feedUpload3.request,
expectedHttpStatus : httpStatus.OK,
expectedStatusText : 'success',
expectedResponseData : feedUpload3.response.data
},
{
description : "Should be able to upload data for a single channel to a private feed (this one will affect the min/max times)",
url : function() {
return ESDR_FEEDS_API_URL + "/" + feed2.apiKey;
},
dataToUpload : feedUpload7.request,
expectedHttpStatus : httpStatus.OK,
expectedStatusText : 'success',
expectedResponseData : feedUpload7.response.data
},
{
description : "Should be able to upload data for a single channel to a public feed (this one won't affect the min/max times)",
url : function() {
return ESDR_FEEDS_API_URL + "/" + feed1.apiKey;
},
dataToUpload : feedUpload4.request,
expectedHttpStatus : httpStatus.OK,
expectedStatusText : 'success',
expectedResponseData : feedUpload4.response.data
},
{
description : "Should be able to upload data for a single channel to a private feed (this one won't affect the min/max times)",
url : function() {
return ESDR_FEEDS_API_URL + "/" + feed2.apiKey;
},
dataToUpload : feedUpload8.request,
expectedHttpStatus : httpStatus.OK,
expectedStatusText : 'success',
expectedResponseData : feedUpload8.response.data
},
{
description : "Should fail to upload to a public feed using the read-only apiKey to authenticate",
url : function() {
return ESDR_FEEDS_API_URL + "/" + feed1.apiKeyReadOnly;
},
dataToUpload : {},
expectedHttpStatus : httpStatus.FORBIDDEN,
expectedStatusText : 'error',
expectedResponseData : null
},
{
description : "Should fail to upload to a private feed using the read-only apiKey to authenticate",
url : function() {
return ESDR_FEEDS_API_URL + "/" + feed2.apiKeyReadOnly;
},
dataToUpload : {},
expectedHttpStatus : httpStatus.FORBIDDEN,
expectedStatusText : 'error',
expectedResponseData : null
},
{
description : "Should fail to upload using an invalid feed apiKey to authenticate",
url : function() {
return ESDR_FEEDS_API_URL + "/" + "bogus";
},
dataToUpload : {},
expectedHttpStatus : httpStatus.NOT_FOUND,
expectedStatusText : 'error',
expectedResponseData : null
},
{
description : "Should fail to upload using a valid but unknown feed apiKey to authenticate",
url : function() {
return ESDR_FEEDS_API_URL + "/" + UNKNOWN_FEED_API_KEY;
},
dataToUpload : {},
expectedHttpStatus : httpStatus.NOT_FOUND,
expectedStatusText : 'error',
expectedResponseData : null
},
{
description : "Should fail to upload to a feed if one or more channel names is invalid",
url : function() {
return ESDR_FEEDS_API_URL + "/" + feed1.apiKey;
},
dataToUpload : invalidChannelName1.request,
expectedHttpStatus : httpStatus.UNPROCESSABLE_ENTITY,
expectedStatusText : 'error',
expectedResponseData : invalidChannelName1.response,
},
{
description : "Should fail to upload to a feed if one or more channel names is invalid",
url : function() {
return ESDR_FEEDS_API_URL + "/" + feed1.apiKey;
},
dataToUpload : invalidChannelName2.request,
expectedHttpStatus : httpStatus.UNPROCESSABLE_ENTITY,
expectedStatusText : 'error',
expectedResponseData : invalidChannelName2.response,
},
{
description : "Should fail to upload to a feed if one or more channel names is invalid",
url : function() {
return ESDR_FEEDS_API_URL + "/" + feed1.apiKey;
},
dataToUpload : invalidChannelName3.request,
expectedHttpStatus : httpStatus.UNPROCESSABLE_ENTITY,
expectedStatusText : 'error',
expectedResponseData : invalidChannelName3.response,
},
{
description : "Should fail to upload to a feed if one or more channel names is invalid",
url : function() {
return ESDR_FEEDS_API_URL + "/" + feed1.apiKey;
},
dataToUpload : invalidChannelName4.request,
expectedHttpStatus : httpStatus.UNPROCESSABLE_ENTITY,
expectedStatusText : 'error',
expectedResponseData : invalidChannelName4.response,
}
].forEach(executeUploadTest);
}); // End Feed API Key in the URL
}); // End API Key Authentication
}); // End To /feeds method
}); // End Upload
}); // End Feeds
}); // End REST API