k2hr3-api 1.0.24 → 1.0.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/ChangeLog +12 -0
  2. package/app.js +63 -30
  3. package/bin/run.sh +14 -0
  4. package/config/default.json +3 -2
  5. package/lib/k2hr3config.js +12 -0
  6. package/lib/k2hr3dkc.js +903 -13
  7. package/lib/k2hr3keys.js +1 -0
  8. package/lib/k2hr3tokens.js +147 -60
  9. package/package.json +10 -5
  10. package/routes/tenant.js +1014 -0
  11. package/routes/userTokens.js +77 -126
  12. package/tests/auto_all_spec.js +4 -0
  13. package/tests/auto_tenant.js +989 -0
  14. package/tests/auto_tenant_spec.js +79 -0
  15. package/tests/auto_usertokens.js +6 -6
  16. package/tests/manual_acr_delete.js +1 -0
  17. package/tests/manual_acr_get.js +1 -0
  18. package/tests/manual_acr_postput.js +1 -0
  19. package/tests/manual_allusertenant_get.js +58 -3
  20. package/tests/manual_extdata_get.js +1 -0
  21. package/tests/manual_list_gethead.js +1 -0
  22. package/tests/manual_policy_delete.js +1 -0
  23. package/tests/manual_policy_gethead.js +3 -1
  24. package/tests/manual_policy_postput.js +1 -0
  25. package/tests/manual_resource_delete.js +1 -0
  26. package/tests/manual_resource_gethead.js +1 -0
  27. package/tests/manual_resource_postput.js +1 -0
  28. package/tests/manual_role_delete.js +2 -0
  29. package/tests/manual_role_gethead.js +4 -0
  30. package/tests/manual_role_postput.js +2 -0
  31. package/tests/manual_service_delete.js +1 -0
  32. package/tests/manual_service_gethead.js +1 -0
  33. package/tests/manual_service_postput.js +1 -0
  34. package/tests/manual_tenant_delete.js +152 -0
  35. package/tests/manual_tenant_gethead.js +268 -0
  36. package/tests/manual_tenant_postput.js +293 -0
  37. package/tests/manual_test.sh +21 -7
  38. package/tests/manual_userdata_get.js +1 -0
  39. package/tests/manual_usertoken_gethead.js +1 -0
  40. package/tests/manual_usertoken_postput.js +1 -0
  41. package/tests/manual_version_get.js +1 -0
  42. package/tests/test.sh +2 -0
@@ -50,13 +50,10 @@ function rawCommonGetUserToken(req, res, unscopedToken, otherToken, username, pa
50
50
  // Get token from User Credentials
51
51
  //
52
52
  if(!apiutil.isSafeString(username)){
53
- /* eslint-disable indent, no-mixed-spaces-and-tabs */
54
53
  error = {
55
- result: false,
56
- message: 'Some parameter(user name or unscoped token) is wrong.'
57
- };
58
- /* eslint-enable indent, no-mixed-spaces-and-tabs */
59
-
54
+ result: false,
55
+ message: 'Some parameter(user name or unscoped token) is wrong.'
56
+ };
60
57
  r3logger.elog(error.message);
61
58
  resutil.errResponse(req, res, 400, error); // 400: Bad Request
62
59
  return;
@@ -65,27 +62,21 @@ function rawCommonGetUserToken(req, res, unscopedToken, otherToken, username, pa
65
62
  r3token.getUserToken(_username, _passwd, _tenant, function(err, token)
66
63
  {
67
64
  if(null !== err){
68
- /* eslint-disable indent, no-mixed-spaces-and-tabs */
69
65
  var error = {
70
- result: false,
71
- message: 'could not get scoped user token for user=' + _username + ', tenant=' + _tenant + ' by ' + err.message
72
- };
73
- /* eslint-enable indent, no-mixed-spaces-and-tabs */
74
-
66
+ result: false,
67
+ message: 'could not get scoped user token for user=' + _username + ', tenant=' + _tenant + ' by ' + err.message
68
+ };
75
69
  r3logger.elog(error.message);
76
70
  resutil.errResponse(_req, _res, 404, error); // 404: Not Found
77
71
  return;
78
72
  }
79
73
  r3logger.dlog('get user token jsonres = ' + JSON.stringify(token));
80
74
 
81
- /* eslint-disable indent, no-mixed-spaces-and-tabs */
82
75
  var result = { result: true,
83
- message: 'succeed',
84
- scoped: apiutil.isSafeString(_tenant),
85
- token: token
86
- };
87
- /* eslint-enable indent, no-mixed-spaces-and-tabs */
88
-
76
+ message: 'succeed',
77
+ scoped: apiutil.isSafeString(_tenant),
78
+ token: token
79
+ };
89
80
  _res.status(201); // 201: Created
90
81
  _res.send(JSON.stringify(result));
91
82
  });
@@ -95,13 +86,10 @@ function rawCommonGetUserToken(req, res, unscopedToken, otherToken, username, pa
95
86
  // Get Scoped token from Unscoped token
96
87
  //
97
88
  if(!apiutil.isSafeString(username)){
98
- /* eslint-disable indent, no-mixed-spaces-and-tabs */
99
89
  error = {
100
- result: false,
101
- message: 'Some parameter(user name or unscoped token) is wrong.'
102
- };
103
- /* eslint-enable indent, no-mixed-spaces-and-tabs */
104
-
90
+ result: false,
91
+ message: 'Some parameter(user name or unscoped token) is wrong.'
92
+ };
105
93
  r3logger.elog(error.message);
106
94
  resutil.errResponse(req, res, 400, error); // 400: Bad Request
107
95
  return;
@@ -110,27 +98,22 @@ function rawCommonGetUserToken(req, res, unscopedToken, otherToken, username, pa
110
98
  r3token.getScopedUserToken(_unscopedToken, _username, _tenant, function(err, token)
111
99
  {
112
100
  if(null !== err){
113
- /* eslint-disable indent, no-mixed-spaces-and-tabs */
114
101
  var error = {
115
- result: false,
116
- message: 'could not get scoped user token for user=' + _username + ', tenant=' + _tenant + ' by ' + err.message
117
- };
118
- /* eslint-enable indent, no-mixed-spaces-and-tabs */
119
-
102
+ result: false,
103
+ message: 'could not get scoped user token for user=' + _username + ', tenant=' + _tenant + ' by ' + err.message
104
+ };
120
105
  r3logger.elog(error.message);
121
106
  resutil.errResponse(_req, _res, 404, error); // 404: Not Found
122
107
  return;
123
108
  }
124
109
  r3logger.dlog('get user token jsonres = ' + JSON.stringify(token));
125
110
 
126
- /* eslint-disable indent, no-mixed-spaces-and-tabs */
127
111
  var result = {
128
- result: true,
129
- message: 'succeed',
130
- scoped: apiutil.isSafeString(_tenant),
131
- token: token
132
- };
133
- /* eslint-enable indent, no-mixed-spaces-and-tabs */
112
+ result: true,
113
+ message: 'succeed',
114
+ scoped: apiutil.isSafeString(_tenant),
115
+ token: token
116
+ };
134
117
 
135
118
  _res.status(201); // 201: Created
136
119
  _res.send(JSON.stringify(result));
@@ -143,28 +126,22 @@ function rawCommonGetUserToken(req, res, unscopedToken, otherToken, username, pa
143
126
  r3token.getUserTokenByToken(_otherToken, _tenant, function(err, token)
144
127
  {
145
128
  if(null !== err){
146
- /* eslint-disable indent, no-mixed-spaces-and-tabs */
147
129
  var error = {
148
- result: false,
149
- message: 'could not get scoped user token for other token, tenant=' + _tenant + ' by ' + err.message
150
- };
151
- /* eslint-enable indent, no-mixed-spaces-and-tabs */
152
-
130
+ result: false,
131
+ message: 'could not get scoped user token for other token, tenant=' + _tenant + ' by ' + err.message
132
+ };
153
133
  r3logger.elog(error.message);
154
134
  resutil.errResponse(_req, _res, 404, error); // 404: Not Found
155
135
  return;
156
136
  }
157
137
  r3logger.dlog('get user token jsonres = ' + JSON.stringify(token));
158
138
 
159
- /* eslint-disable indent, no-mixed-spaces-and-tabs */
160
139
  var result = {
161
- result: true,
162
- message: 'succeed',
163
- scoped: apiutil.isSafeString(_tenant),
164
- token: token
165
- };
166
- /* eslint-enable indent, no-mixed-spaces-and-tabs */
167
-
140
+ result: true,
141
+ message: 'succeed',
142
+ scoped: apiutil.isSafeString(_tenant),
143
+ token: token
144
+ };
168
145
  _res.status(201); // 201: Created
169
146
  _res.send(JSON.stringify(result));
170
147
  });
@@ -188,13 +165,11 @@ function rawGetUnscopedUserToken(req)
188
165
  !apiutil.isSafeString(resobj.token_info.user) ||
189
166
  false !== resobj.token_info.scoped )
190
167
  {
191
- /* eslint-disable indent, no-mixed-spaces-and-tabs */
192
168
  return {
193
169
  result: false,
194
170
  status: 400, // 400: Bad Request
195
171
  message: 'could not get unscoped user token in request.'
196
172
  };
197
- /* eslint-enable indent, no-mixed-spaces-and-tabs */
198
173
  }
199
174
 
200
175
  return {
@@ -223,13 +198,10 @@ router.post('/', function(req, res, next) // eslint-disable-line no-unused-
223
198
  if( !apiutil.isSafeEntity(req) ||
224
199
  !apiutil.isSafeEntity(req.body) )
225
200
  {
226
- /* eslint-disable indent, no-mixed-spaces-and-tabs */
227
201
  error = {
228
- result: false,
229
- message: 'POST body does not have auth key'
230
- };
231
- /* eslint-enable indent, no-mixed-spaces-and-tabs */
232
-
202
+ result: false,
203
+ message: 'POST body does not have auth key'
204
+ };
233
205
  r3logger.elog(error.message);
234
206
  resutil.errResponse(req, res, 400, error); // 400: Bad Request
235
207
  return;
@@ -260,13 +232,10 @@ router.post('/', function(req, res, next) // eslint-disable-line no-unused-
260
232
  // (1) case of unscoped token registered in k2hr3
261
233
  //
262
234
  if(!apiutil.isSafeEntity(req.body.auth) || !apiutil.isSafeString(req.body.auth.tenantName)){
263
- /* eslint-disable indent, no-mixed-spaces-and-tabs */
264
235
  error = {
265
- result: false,
266
- message: 'POST body does not have tenant name(or user credentials)'
267
- };
268
- /* eslint-enable indent, no-mixed-spaces-and-tabs */
269
-
236
+ result: false,
237
+ message: 'POST body does not have tenant name(or user credentials)'
238
+ };
270
239
  r3logger.elog(error.message);
271
240
  resutil.errResponse(req, res, 400, error); // 400: Bad Request
272
241
  return;
@@ -280,13 +249,10 @@ router.post('/', function(req, res, next) // eslint-disable-line no-unused-
280
249
  //
281
250
  otherToken = r3token.getAuthTokenHeader(req, false);
282
251
  if(!apiutil.isSafeString(otherToken)){
283
- /* eslint-disable indent, no-mixed-spaces-and-tabs */
284
252
  error = {
285
- result: false,
286
- message: resobj.message
287
- };
288
- /* eslint-enable indent, no-mixed-spaces-and-tabs */
289
-
253
+ result: false,
254
+ message: resobj.message
255
+ };
290
256
  r3logger.elog(resobj.message);
291
257
  resutil.errResponse(req, res, resobj.status, error); // 40X
292
258
  return;
@@ -320,13 +286,10 @@ router.put('/', function(req, res, next) // eslint-disable-line no-unused-v
320
286
  if( !apiutil.isSafeEntity(req) ||
321
287
  !apiutil.isSafeEntity(req.query) )
322
288
  {
323
- /* eslint-disable indent, no-mixed-spaces-and-tabs */
324
289
  error = {
325
- result: false,
326
- message: 'PUT argument does not have any data'
327
- };
328
- /* eslint-enable indent, no-mixed-spaces-and-tabs */
329
-
290
+ result: false,
291
+ message: 'PUT argument does not have any data'
292
+ };
330
293
  r3logger.elog(error.message);
331
294
  resutil.errResponse(req, res, 400, error); // 400: Bad Request
332
295
  return;
@@ -357,13 +320,10 @@ router.put('/', function(req, res, next) // eslint-disable-line no-unused-v
357
320
  // (1) case of unscoped token registered in k2hr3
358
321
  //
359
322
  if(!apiutil.isSafeString(req.query.tenantname)){
360
- /* eslint-disable indent, no-mixed-spaces-and-tabs */
361
323
  error = {
362
- result: false,
363
- message: 'POST body does not have tenant name(or user credentials)'
364
- };
365
- /* eslint-enable indent, no-mixed-spaces-and-tabs */
366
-
324
+ result: false,
325
+ message: 'POST body does not have tenant name(or user credentials)'
326
+ };
367
327
  r3logger.elog(error.message);
368
328
  resutil.errResponse(req, res, 400, error); // 400: Bad Request
369
329
  return;
@@ -378,13 +338,10 @@ router.put('/', function(req, res, next) // eslint-disable-line no-unused-v
378
338
  //
379
339
  otherToken = r3token.getAuthTokenHeader(req, false);
380
340
  if(!apiutil.isSafeString(otherToken)){
381
- /* eslint-disable indent, no-mixed-spaces-and-tabs */
382
341
  error = {
383
- result: false,
384
- message: resobj.message
385
- };
386
- /* eslint-enable indent, no-mixed-spaces-and-tabs */
387
-
342
+ result: false,
343
+ message: resobj.message
344
+ };
388
345
  r3logger.elog(resobj.message);
389
346
  resutil.errResponse(req, res, resobj.status, error); // 40X
390
347
  return;
@@ -411,8 +368,10 @@ router.put('/', function(req, res, next) // eslint-disable-line no-unused-v
411
368
  // user => user name
412
369
  // tenants => [
413
370
  // {
414
- // name: "tenant name"
415
- // display: "display name"
371
+ // name: "tenant name"
372
+ // display: "display name"
373
+ // id: "tenant id"
374
+ // description: "tenant description"
416
375
  // },
417
376
  // ...
418
377
  // ]
@@ -453,21 +412,20 @@ router.get('/', function(req, res, next) // eslint-disable-line no-unused-v
453
412
  // build response body
454
413
  if(token_info.scoped){
455
414
  // scoped token
456
- /* eslint-disable indent, no-mixed-spaces-and-tabs */
457
415
  result = {
458
- result: true,
459
- message: 'succeed',
460
- scoped: true,
461
- user: token_info.user,
462
- tenants: [
463
- {
464
- name: token_info.tenant,
465
- display: token_info.tenant // [NOTE] this is not real display name.
466
- }
467
- ]
468
- };
469
- /* eslint-enable indent, no-mixed-spaces-and-tabs */
470
-
416
+ result: true,
417
+ message: 'succeed',
418
+ scoped: true,
419
+ user: token_info.user,
420
+ tenants: [
421
+ {
422
+ name: token_info.tenant,
423
+ display: token_info.display,
424
+ id: token_info.id,
425
+ description: token_info.description
426
+ }
427
+ ]
428
+ };
471
429
  _res.status(200); // 200: OK
472
430
  _res.send(JSON.stringify(result));
473
431
 
@@ -476,13 +434,10 @@ router.get('/', function(req, res, next) // eslint-disable-line no-unused-v
476
434
  r3token.initializeTenantList(token_result.token, token_info.user, function(error, tenant_list)
477
435
  {
478
436
  if(null !== error){
479
- /* eslint-disable indent, no-mixed-spaces-and-tabs */
480
437
  var result = {
481
- result: false,
482
- message: 'failed to get tenant list for user (' + token_info.user + ') by unscoped token(' + token_result.token + ')'
483
- };
484
- /* eslint-enable indent, no-mixed-spaces-and-tabs */
485
-
438
+ result: false,
439
+ message: 'failed to get tenant list for user (' + token_info.user + ') by unscoped token(' + token_result.token + ')'
440
+ };
486
441
  r3logger.elog(result.message);
487
442
  resutil.errResponse(_req, _res, 404, result); // 404: Not Found
488
443
  return;
@@ -491,26 +446,22 @@ router.get('/', function(req, res, next) // eslint-disable-line no-unused-v
491
446
  // reget tenant list
492
447
  tenant_list = r3token.getTenantList(token_info.user);
493
448
  if(null === tenant_list || apiutil.isEmptyArray(tenant_list)){
494
- /* eslint-disable indent, no-mixed-spaces-and-tabs */
495
449
  result = {
496
- result: false,
497
- message: 'token(' + token_result.token + ') for user (' + token_info.user + ') does not have any tenant.'
498
- };
499
- /* eslint-enable indent, no-mixed-spaces-and-tabs */
500
-
450
+ result: false,
451
+ message: 'token(' + token_result.token + ') for user (' + token_info.user + ') does not have any tenant.'
452
+ };
501
453
  r3logger.elog(result.message);
502
454
  resutil.errResponse(_req, _res, 404, result); // 404: Not Found
503
455
  return;
504
456
  }
505
457
 
506
- /* eslint-disable indent, no-mixed-spaces-and-tabs */
507
- result = { result: true,
508
- message: 'succeed',
509
- scoped: false,
510
- user: token_info.user,
511
- tenants: tenant_list };
512
- /* eslint-enable indent, no-mixed-spaces-and-tabs */
513
-
458
+ result = {
459
+ result: true,
460
+ message: 'succeed',
461
+ scoped: false,
462
+ user: token_info.user,
463
+ tenants: tenant_list
464
+ };
514
465
  _res.status(200); // 200: OK
515
466
  _res.send(JSON.stringify(result));
516
467
  });
@@ -107,6 +107,10 @@ describe('ALL K2HR3 API TEST', function(){ // eslint-disable-line no-undef
107
107
  require('./auto_role');
108
108
  });
109
109
 
110
+ describe('SUB API TEST: TENANT', function(){ // eslint-disable-line no-undef
111
+ require('./auto_tenant');
112
+ });
113
+
110
114
  describe('SUB API TEST: ACR', function(){ // eslint-disable-line no-undef
111
115
  require('./auto_acr');
112
116
  });