k2hr3-api 1.0.42 → 2.0.1

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 (149) hide show
  1. package/config/k2hr3-init.sh.templ +4 -4
  2. package/dist/.gitkeep +0 -0
  3. package/dist/src/app.js +262 -0
  4. package/{bin → dist/src/bin}/run.sh +1 -1
  5. package/dist/src/bin/watcher.js +113 -0
  6. package/dist/src/bin/www.js +217 -0
  7. package/dist/src/lib/basicipcheck.js +392 -0
  8. package/dist/src/lib/cacerts.js +106 -0
  9. package/dist/src/lib/dbglogging.js +190 -0
  10. package/dist/src/lib/dummyuserapi.js +719 -0
  11. package/dist/src/lib/ipwatch.js +354 -0
  12. package/dist/src/lib/k2hr3acrutil.js +532 -0
  13. package/dist/src/lib/k2hr3apiutil.js +1444 -0
  14. package/dist/src/lib/k2hr3cliutil.js +183 -0
  15. package/dist/src/lib/k2hr3config.js +832 -0
  16. package/dist/src/lib/k2hr3cryptutil.js +258 -0
  17. package/dist/src/lib/k2hr3dkc.js +12121 -0
  18. package/dist/src/lib/k2hr3extdata.js +198 -0
  19. package/dist/src/lib/k2hr3keys.js +207 -0
  20. package/dist/src/lib/k2hr3resutil.js +111 -0
  21. package/dist/src/lib/k2hr3template.js +6546 -0
  22. package/dist/src/lib/k2hr3tokens.js +2643 -0
  23. package/dist/src/lib/k2hr3userdata.js +296 -0
  24. package/dist/src/lib/k8soidc.js +1000 -0
  25. package/dist/src/lib/openstackapiv2.js +695 -0
  26. package/dist/src/lib/openstackapiv3.js +932 -0
  27. package/dist/src/lib/openstackep.js +667 -0
  28. package/{tests/auto_common.js → dist/src/lib/types.js} +4 -38
  29. package/dist/src/routes/acr.js +704 -0
  30. package/dist/src/routes/debugVerify.js +294 -0
  31. package/dist/src/routes/extdata.js +219 -0
  32. package/dist/src/routes/list.js +264 -0
  33. package/dist/src/routes/policy.js +840 -0
  34. package/dist/src/routes/resource.js +1489 -0
  35. package/dist/src/routes/role.js +2627 -0
  36. package/dist/src/routes/service.js +908 -0
  37. package/dist/src/routes/tenant.js +1141 -0
  38. package/dist/src/routes/userTokens.js +482 -0
  39. package/dist/src/routes/userdata.js +212 -0
  40. package/dist/src/routes/version.js +103 -0
  41. package/package.json +152 -121
  42. package/ChangeLog +0 -378
  43. package/app.js +0 -292
  44. package/bin/watcher +0 -122
  45. package/bin/www +0 -180
  46. package/eslint.config.mjs +0 -68
  47. package/lib/basicipcheck.js +0 -376
  48. package/lib/cacerts.js +0 -71
  49. package/lib/dbglogging.js +0 -151
  50. package/lib/dummyuserapi.js +0 -766
  51. package/lib/ipwatch.js +0 -379
  52. package/lib/k2hr3acrutil.js +0 -516
  53. package/lib/k2hr3apiutil.js +0 -1494
  54. package/lib/k2hr3cliutil.js +0 -191
  55. package/lib/k2hr3config.js +0 -826
  56. package/lib/k2hr3cryptutil.js +0 -254
  57. package/lib/k2hr3dkc.js +0 -12632
  58. package/lib/k2hr3extdata.js +0 -198
  59. package/lib/k2hr3keys.js +0 -234
  60. package/lib/k2hr3resutil.js +0 -100
  61. package/lib/k2hr3template.js +0 -6925
  62. package/lib/k2hr3tokens.js +0 -2799
  63. package/lib/k2hr3userdata.js +0 -312
  64. package/lib/k8soidc.js +0 -1012
  65. package/lib/openstackapiv2.js +0 -764
  66. package/lib/openstackapiv3.js +0 -1032
  67. package/lib/openstackep.js +0 -553
  68. package/routes/acr.js +0 -738
  69. package/routes/debugVerify.js +0 -263
  70. package/routes/extdata.js +0 -232
  71. package/routes/list.js +0 -270
  72. package/routes/policy.js +0 -869
  73. package/routes/resource.js +0 -1441
  74. package/routes/role.js +0 -2664
  75. package/routes/service.js +0 -894
  76. package/routes/tenant.js +0 -1095
  77. package/routes/userTokens.js +0 -511
  78. package/routes/userdata.js +0 -218
  79. package/routes/version.js +0 -108
  80. package/templ/Dockerfile.templ +0 -71
  81. package/tests/auto_acr.js +0 -1101
  82. package/tests/auto_acr_spec.js +0 -79
  83. package/tests/auto_all_spec.js +0 -142
  84. package/tests/auto_control_subprocess.sh +0 -243
  85. package/tests/auto_extdata.js +0 -220
  86. package/tests/auto_extdata_spec.js +0 -79
  87. package/tests/auto_init_config_json.sh +0 -275
  88. package/tests/auto_k2hdkc_server.ini +0 -109
  89. package/tests/auto_k2hdkc_slave.ini +0 -83
  90. package/tests/auto_list.js +0 -439
  91. package/tests/auto_list_spec.js +0 -79
  92. package/tests/auto_policy.js +0 -1579
  93. package/tests/auto_policy_spec.js +0 -79
  94. package/tests/auto_resource.js +0 -10956
  95. package/tests/auto_resource_spec.js +0 -79
  96. package/tests/auto_role.js +0 -6150
  97. package/tests/auto_role_spec.js +0 -79
  98. package/tests/auto_service.js +0 -770
  99. package/tests/auto_service_spec.js +0 -79
  100. package/tests/auto_subprocesses.js +0 -114
  101. package/tests/auto_template.sh +0 -126
  102. package/tests/auto_tenant.js +0 -1100
  103. package/tests/auto_tenant_spec.js +0 -79
  104. package/tests/auto_token_util.js +0 -219
  105. package/tests/auto_userdata.js +0 -292
  106. package/tests/auto_userdata_spec.js +0 -79
  107. package/tests/auto_usertokens.js +0 -565
  108. package/tests/auto_usertokens_spec.js +0 -79
  109. package/tests/auto_version.js +0 -127
  110. package/tests/auto_version_spec.js +0 -79
  111. package/tests/auto_watcher.js +0 -157
  112. package/tests/auto_watcher_spec.js +0 -79
  113. package/tests/k2hdkc_test.data +0 -986
  114. package/tests/k2hdkc_test_load.sh +0 -255
  115. package/tests/k2hr3template_test.js +0 -187
  116. package/tests/k2hr3template_test.sh +0 -339
  117. package/tests/k2hr3template_test_async.js +0 -216
  118. package/tests/k2hr3template_test_template.result +0 -7117
  119. package/tests/k2hr3template_test_template.txt +0 -3608
  120. package/tests/k2hr3template_test_vars.js +0 -194
  121. package/tests/manual_acr_delete.js +0 -143
  122. package/tests/manual_acr_get.js +0 -297
  123. package/tests/manual_acr_postput.js +0 -215
  124. package/tests/manual_allusertenant_get.js +0 -113
  125. package/tests/manual_extdata_get.js +0 -191
  126. package/tests/manual_k2hr3keys_get.js +0 -84
  127. package/tests/manual_list_gethead.js +0 -230
  128. package/tests/manual_policy_delete.js +0 -132
  129. package/tests/manual_policy_gethead.js +0 -275
  130. package/tests/manual_policy_postput.js +0 -297
  131. package/tests/manual_resource_delete.js +0 -433
  132. package/tests/manual_resource_gethead.js +0 -423
  133. package/tests/manual_resource_postput.js +0 -487
  134. package/tests/manual_role_delete.js +0 -404
  135. package/tests/manual_role_gethead.js +0 -547
  136. package/tests/manual_role_postput.js +0 -544
  137. package/tests/manual_service_delete.js +0 -153
  138. package/tests/manual_service_gethead.js +0 -178
  139. package/tests/manual_service_postput.js +0 -348
  140. package/tests/manual_tenant_delete.js +0 -186
  141. package/tests/manual_tenant_gethead.js +0 -268
  142. package/tests/manual_tenant_postput.js +0 -293
  143. package/tests/manual_test.sh +0 -352
  144. package/tests/manual_userdata_get.js +0 -173
  145. package/tests/manual_usertoken_gethead.js +0 -136
  146. package/tests/manual_usertoken_postput.js +0 -310
  147. package/tests/manual_version_get.js +0 -127
  148. package/tests/run_local_test_k2hdkc.sh +0 -174
  149. package/tests/test.sh +0 -333
package/tests/auto_acr.js DELETED
@@ -1,1101 +0,0 @@
1
- /*
2
- * K2HR3 REST API
3
- *
4
- * Copyright 2017 Yahoo Japan Corporation.
5
- *
6
- * K2HR3 is K2hdkc based Resource and Roles and policy Rules, gathers
7
- * common management information for the cloud.
8
- * K2HR3 can dynamically manage information as "who", "what", "operate".
9
- * These are stored as roles, resources, policies in K2hdkc, and the
10
- * client system can dynamically read and modify these information.
11
- *
12
- * For the full copyright and license information, please view
13
- * the license file that was distributed with this source code.
14
- *
15
- * AUTHOR: Takeshi Nakatani
16
- * CREATE: Tue Dec 19 2017
17
- * REVISION:
18
- *
19
- */
20
-
21
- 'use strict';
22
-
23
- var common = require('./auto_common'); // Common objects for Chai
24
- var chai = common.chai;
25
- var chaiHttp = common.chaiHttp; // eslint-disable-line no-unused-vars
26
- var app = common.app;
27
- var assert = common.assert; // eslint-disable-line no-unused-vars
28
- var expect = common.expect;
29
- var tokenutil = require('./auto_token_util'); // Token utility
30
-
31
- //--------------------------------------------------------------
32
- // Main describe section
33
- //--------------------------------------------------------------
34
- describe('API : ACR', function(){ // eslint-disable-line no-undef
35
- var alltokens = {};
36
- var parentobj = this; // for calling tokenutil.before
37
-
38
- //
39
- // Before in describe section
40
- //
41
- before(function(done){ // eslint-disable-line no-undef
42
- // Nothing to do
43
- tokenutil.before(parentobj, alltokens, done);
44
- });
45
-
46
- //
47
- // After in describe section
48
- //
49
- after(function(){ // eslint-disable-line no-undef
50
- // Nothing to do
51
- });
52
-
53
- //
54
- // Run Test(GET - SCOPED TOKEN INFO - SUCCESS/FAILURE)
55
- //
56
- it('GET /v1/acr : failure get user token information for service(not_exist_service) in tenant0 by scoped token with status 403', function(done){ // eslint-disable-line no-undef
57
- var uri = '/v1/acr';
58
- uri += '/not_exist_service'; // path: yrn:yahoo:not_exist_service::tenant0
59
-
60
- chai.request(app)
61
- .get(uri)
62
- .set('content-type', 'application/json')
63
- .set('x-auth-token', alltokens.scopedtoken.tenant0) // tenant0
64
- .end(function(err, res){
65
- expect(res).to.have.status(403);
66
- expect(res).to.be.json;
67
- expect(res.body).to.be.an('object');
68
- expect(res.body.result).to.be.a('boolean').to.be.false;
69
- expect(res.body.message).to.be.a('string').to.equal('Not found yrn:yahoo::::service:not_exist_service subkey under yrn:yahoo::::service key(there is no master service key)');
70
-
71
- //
72
- // Check removing token
73
- //
74
- chai.request(app)
75
- .get(uri)
76
- .set('content-type', 'application/json')
77
- .set('x-auth-token', alltokens.scopedtoken.tenant0) // tenant0
78
- .end(function(err, res){
79
- expect(res).to.have.status(401);
80
- expect(res).to.be.json;
81
- expect(res.body).to.be.an('object');
82
- expect(res.body.result).to.be.a('boolean').to.be.false;
83
- expect(res.body.message).to.have.string('token(');
84
- expect(res.body.message).to.have.string(') is not existed, because it is expired or not set yet.');
85
-
86
- // reset all token
87
- tokenutil.before(parentobj, alltokens, done);
88
- });
89
- });
90
- });
91
-
92
- it('GET /v1/acr : failure get user token information for service(testservice) in tenant0 by invalid scoped token with status 401', function(done){ // eslint-disable-line no-undef
93
- var uri = '/v1/acr';
94
- uri += '/testservice'; // path: yrn:yahoo:testservice::tenant0
95
-
96
- chai.request(app)
97
- .get(uri)
98
- .set('content-type', 'application/json')
99
- .set('x-auth-token', 'U=invalid_user_token') // invalid token
100
- .end(function(err, res){
101
- expect(res).to.have.status(401);
102
- expect(res).to.be.json;
103
- expect(res.body).to.be.an('object');
104
- expect(res.body.result).to.be.a('boolean').to.be.false;
105
- expect(res.body.message).to.be.a('string').to.equal('token(invalid_user_token) is not existed, because it is expired or not set yet.');
106
-
107
- done();
108
- });
109
- });
110
-
111
- //
112
- // This case is not run now.
113
- //
114
- // [NOTE]
115
- // Now our test data does not have "tenant2" which is not included testservice member.
116
- // (tenant0/tenant1 are testservice member(owner), then those scoped token could not occur error.)
117
- //
118
- // it('GET /v1/acr : failure get user token information for service(testservice) in tenant0 by another scoped token with status 403', function(done){ // eslint-disable-line no-undef
119
- // var uri = '/v1/acr';
120
- // uri += '/testservice'; // path: yrn:yahoo:testservice::tenant0
121
- //
122
- // chai.request(app)
123
- // .get(uri)
124
- // .set('content-type', 'application/json')
125
- // .set('x-auth-token', alltokens.scopedtoken.tenant2) // tenant2
126
- // .end(function(err, res){
127
- // expect(res).to.have.status(403);
128
- // expect(res).to.be.json;
129
- // expect(res.body).to.be.an('object');
130
- // expect(res.body.result).to.be.a('boolean').to.be.false;
131
- // expect(res.body.message).to.be.a('string').to.equal('Not found yrn:yahoo:::32834 key under yrn:yahoo::::service:testservice key');
132
- //
133
- // //
134
- // // Check removing token
135
- // //
136
- // chai.request(app)
137
- // .get(uri)
138
- // .set('content-type', 'application/json')
139
- // .set('x-auth-token', alltokens.scopedtoken.tenant2) // tenant2
140
- // .end(function(err, res){
141
- // expect(res).to.have.status(401);
142
- // expect(res).to.be.json;
143
- // expect(res.body).to.be.an('object');
144
- // expect(res.body.result).to.be.a('boolean').to.be.false;
145
- // expect(res.body.message).to.have.string('token(')
146
- // expect(res.body.message).to.have.string(') is not existed, because it is expired or not set yet.')
147
- //
148
- // // reset all token
149
- // tokenutil.before(parentobj, alltokens, done);
150
- // });
151
- // });
152
- // });
153
-
154
- it('GET /v1/acr : get user token information for service(testservice) in tenant0 by member scoped token with status 200', function(done){ // eslint-disable-line no-undef
155
- var uri = '/v1/acr';
156
- uri += '/testservice'; // path: yrn:yahoo:testservice::tenant0
157
-
158
- chai.request(app)
159
- .get(uri)
160
- .set('content-type', 'application/json')
161
- .set('x-auth-token', alltokens.scopedtoken.tenant0) // tenant0
162
- .end(function(err, res){
163
- expect(res).to.have.status(200);
164
- expect(res).to.be.json;
165
- expect(res.body).to.be.an('object');
166
- expect(res.body.result).to.be.a('boolean').to.be.true;
167
- expect(res.body.message).to.be.a('null');
168
- expect(res.body.tokeninfo).to.be.an('object');
169
- expect(res.body.tokeninfo.user).to.be.a('string').to.equal('dummyuser');
170
- expect(res.body.tokeninfo.tenant).to.be.a('string').to.equal('tenant0');
171
- expect(res.body.tokeninfo.service).to.be.a('string').to.equal('testservice');
172
-
173
- //
174
- // Check removing token
175
- //
176
- chai.request(app)
177
- .get(uri)
178
- .set('content-type', 'application/json')
179
- .set('x-auth-token', alltokens.scopedtoken.tenant0) // tenant0
180
- .end(function(err, res){
181
- expect(res).to.have.status(401);
182
- expect(res).to.be.json;
183
- expect(res.body).to.be.an('object');
184
- expect(res.body.result).to.be.a('boolean').to.be.false;
185
- expect(res.body.message).to.have.string('token(');
186
- expect(res.body.message).to.have.string(') is not existed, because it is expired or not set yet.');
187
-
188
- // reset all token
189
- tokenutil.before(parentobj, alltokens, done);
190
- });
191
- });
192
- });
193
-
194
- it('GET /v1/acr : get user token information for service(testservice) in tenant1 by owner scoped token with status 200', function(done){ // eslint-disable-line no-undef
195
- var uri = '/v1/acr';
196
- uri += '/testservice'; // path: yrn:yahoo:testservice::tenant1
197
-
198
- chai.request(app)
199
- .get(uri)
200
- .set('content-type', 'application/json')
201
- .set('x-auth-token', alltokens.scopedtoken.tenant1) // tenant1
202
- .end(function(err, res){
203
- expect(res).to.have.status(200);
204
- expect(res).to.be.json;
205
- expect(res.body).to.be.an('object');
206
- expect(res.body.result).to.be.a('boolean').to.be.true;
207
- expect(res.body.message).to.be.a('null');
208
- expect(res.body.tokeninfo).to.be.an('object');
209
- expect(res.body.tokeninfo.user).to.be.a('string').to.equal('dummyuser');
210
- expect(res.body.tokeninfo.tenant).to.be.a('string').to.equal('tenant1');
211
- expect(res.body.tokeninfo.service).to.be.a('string').to.equal('testservice');
212
-
213
- //
214
- // Check removing token
215
- //
216
- chai.request(app)
217
- .get(uri)
218
- .set('content-type', 'application/json')
219
- .set('x-auth-token', alltokens.scopedtoken.tenant1) // tenant1
220
- .end(function(err, res){
221
- expect(res).to.have.status(401);
222
- expect(res).to.be.json;
223
- expect(res.body).to.be.an('object');
224
- expect(res.body.result).to.be.a('boolean').to.be.false;
225
- expect(res.body.message).to.have.string('token(');
226
- expect(res.body.message).to.have.string(') is not existed, because it is expired or not set yet.');
227
-
228
- // reset all token
229
- tokenutil.before(parentobj, alltokens, done);
230
- });
231
- });
232
- });
233
-
234
- //
235
- // Run Test(GET - ALL SERVICE RESOURCE - SUCCESS/FAILURE)
236
- //
237
- it('GET /v1/acr : failure get all resource for service(testservice) in tenant0 by not allowed client ip with status 403', function(done){ // eslint-disable-line no-undef
238
- var uri = '/v1/acr';
239
- uri += '/testservice'; // path: yrn:yahoo:testservice::tenant0
240
- uri += '?cip=127.0.0.1'; // cip: 127.0.0.1(not allowed ip)
241
- uri += '&cport=8000'; // cport: 8000
242
- uri += '&crole=yrn:yahoo:::tenant0:role:test_service_tenant'; // crole: yrn:yahoo:::tenant0:role:test_service_tenant
243
- uri += '&ccuk='; // ccuk: null
244
- uri += '&sport=8000'; // sport: 8000
245
- uri += '&srole=yrn:yahoo:::tenant1:role:test_service_owner'; // srole: yrn:yahoo:::tenant1:role:test_service_owner
246
- uri += '&scuk='; // scuk: null
247
-
248
- chai.request(app)
249
- .get(uri)
250
- .set('content-type', 'application/json')
251
- .end(function(err, res){
252
- expect(res).to.have.status(403);
253
- expect(res).to.be.json;
254
- expect(res.body).to.be.an('object');
255
- expect(res.body.result).to.be.a('boolean').to.be.false;
256
- expect(res.body.message).to.be.a('string').to.equal('client ip(127.0.0.1) and port(8000) and cuk(null) is not client role(yrn:yahoo:::tenant0:role:test_service_tenant) member.');
257
-
258
- done();
259
- });
260
- });
261
-
262
- it('GET /v1/acr : failure get all resource for service(testservice) in tenant0 without parameter(cip) with status 400', function(done){ // eslint-disable-line no-undef
263
- var uri = '/v1/acr';
264
- uri += '/testservice'; // path: yrn:yahoo:testservice::tenant0
265
- // // cip: not set
266
- uri += '?cport=8000'; // cport: 8000
267
- uri += '&crole=yrn:yahoo:::tenant0:role:test_service_tenant'; // crole: yrn:yahoo:::tenant0:role:test_service_tenant
268
- uri += '&ccuk='; // ccuk: null
269
- uri += '&sport=8000'; // sport: 8000
270
- uri += '&srole=yrn:yahoo:::tenant1:role:test_service_owner'; // srole: yrn:yahoo:::tenant1:role:test_service_owner
271
- uri += '&scuk='; // scuk: null
272
-
273
- chai.request(app)
274
- .get(uri)
275
- .set('content-type', 'application/json')
276
- .end(function(err, res){
277
- expect(res).to.have.status(400);
278
- expect(res).to.be.json;
279
- expect(res.body).to.be.an('object');
280
- expect(res.body.result).to.be.a('boolean').to.be.false;
281
- expect(res.body.message).to.be.a('string').to.equal('GET request or parameters are wrong');
282
-
283
- done();
284
- });
285
- });
286
-
287
- it('GET /v1/acr : failure get all resource for service(testservice) in tenant0 without parameter(crole) with status 400', function(done){ // eslint-disable-line no-undef
288
- var uri = '/v1/acr';
289
- uri += '/testservice'; // path: yrn:yahoo:testservice::tenant0
290
- uri += '?cip=127.1.0.1'; // cip: 127.1.0.1
291
- uri += '&cport=8000'; // cport: 8000
292
- // // crole: not set
293
- uri += '&ccuk='; // ccuk: null
294
- uri += '&sport=8000'; // sport: 8000
295
- uri += '&srole=yrn:yahoo:::tenant1:role:test_service_owner'; // srole: yrn:yahoo:::tenant1:role:test_service_owner
296
- uri += '&scuk='; // scuk: null
297
-
298
- chai.request(app)
299
- .get(uri)
300
- .set('content-type', 'application/json')
301
- .end(function(err, res){
302
- expect(res).to.have.status(400);
303
- expect(res).to.be.json;
304
- expect(res.body).to.be.an('object');
305
- expect(res.body.result).to.be.a('boolean').to.be.false;
306
- expect(res.body.message).to.be.a('string').to.equal('GET request or parameters are wrong');
307
-
308
- done();
309
- });
310
- });
311
-
312
- it('GET /v1/acr : failure get all resource for service(testservice) in tenant0 without parameter(srole) with status 400', function(done){ // eslint-disable-line no-undef
313
- var uri = '/v1/acr';
314
- uri += '/testservice'; // path: yrn:yahoo:testservice::tenant0
315
- uri += '?cip=127.1.0.1'; // cip: 127.1.0.1
316
- uri += '&cport=8000'; // cport: 8000
317
- uri += '&crole=yrn:yahoo:::tenant0:role:test_service_tenant'; // crole: yrn:yahoo:::tenant0:role:test_service_tenant
318
- uri += '&ccuk='; // ccuk: null
319
- uri += '&sport=8000'; // sport: 8000
320
- // // srole: not set
321
- uri += '&scuk='; // scuk: null
322
-
323
- chai.request(app)
324
- .get(uri)
325
- .set('content-type', 'application/json')
326
- .end(function(err, res){
327
- expect(res).to.have.status(400);
328
- expect(res).to.be.json;
329
- expect(res.body).to.be.an('object');
330
- expect(res.body.result).to.be.a('boolean').to.be.false;
331
- expect(res.body.message).to.be.a('string').to.equal('GET request or parameters are wrong');
332
-
333
- done();
334
- });
335
- });
336
-
337
- it('GET /v1/acr : get all resource for service(testservice) in tenant0 with status 200', function(done){ // eslint-disable-line no-undef
338
- var uri = '/v1/acr';
339
- uri += '/testservice'; // path: yrn:yahoo:testservice::tenant0
340
- uri += '?cip=127.1.0.1'; // cip: 127.1.0.1
341
- uri += '&cport=8000'; // cport: 8000
342
- uri += '&crole=yrn:yahoo:::tenant0:role:test_service_tenant'; // crole: yrn:yahoo:::tenant0:role:test_service_tenant
343
- uri += '&ccuk='; // ccuk: null
344
- uri += '&sport=8000'; // sport: 8000
345
- uri += '&srole=yrn:yahoo:::tenant1:role:test_service_owner'; // srole: yrn:yahoo:::tenant1:role:test_service_owner
346
- uri += '&scuk='; // scuk: null
347
-
348
- chai.request(app)
349
- .get(uri)
350
- .set('content-type', 'application/json')
351
- .end(function(err, res){
352
- expect(res).to.have.status(200);
353
- expect(res).to.be.json;
354
- expect(res.body).to.be.an('object');
355
- expect(res.body.result).to.be.a('boolean').to.be.true;
356
- expect(res.body.message).to.be.a('null');
357
- expect(res.body.resources).to.be.an.instanceof(Array).to.have.lengthOf(1);
358
- expect(res.body.resources[0]).to.be.an('object');
359
- expect(res.body.resources[0].name).to.be.a('string').to.equal('test_service_resource');
360
- expect(res.body.resources[0].type).to.be.a('string').to.equal('string');
361
- expect(res.body.resources[0].data).to.be.a('string').to.equal('test service in tenant resource data for debug');
362
- expect(res.body.resources[0].keys).to.be.an('object');
363
- expect(res.body.resources[0].keys.test_service_key).to.equal('test_service_value');
364
-
365
- done();
366
- });
367
- });
368
-
369
- it('GET /v1/acr : get all resource for service(testservice) in tenant0 without parameter(cport,ccuk) with status 200', function(done){ // eslint-disable-line no-undef
370
- var uri = '/v1/acr';
371
- uri += '/testservice'; // path: yrn:yahoo:testservice::tenant0
372
- uri += '?cip=127.1.0.1'; // cip: 127.1.0.1
373
- // // cport: not set
374
- uri += '&crole=yrn:yahoo:::tenant0:role:test_service_tenant'; // crole: yrn:yahoo:::tenant0:role:test_service_tenant
375
- // // ccuk: not set
376
- uri += '&sport=8000'; // sport: 8000
377
- uri += '&srole=yrn:yahoo:::tenant1:role:test_service_owner'; // srole: yrn:yahoo:::tenant1:role:test_service_owner
378
- uri += '&scuk='; // scuk: null
379
-
380
- chai.request(app)
381
- .get(uri)
382
- .set('content-type', 'application/json')
383
- .end(function(err, res){
384
- expect(res).to.have.status(200);
385
- expect(res).to.be.json;
386
- expect(res.body).to.be.an('object');
387
- expect(res.body.result).to.be.a('boolean').to.be.true;
388
- expect(res.body.message).to.be.a('null');
389
- expect(res.body.resources).to.be.an.instanceof(Array).to.have.lengthOf(1);
390
- expect(res.body.resources[0]).to.be.an('object');
391
- expect(res.body.resources[0].name).to.be.a('string').to.equal('test_service_resource');
392
- expect(res.body.resources[0].type).to.be.a('string').to.equal('string');
393
- expect(res.body.resources[0].data).to.be.a('string').to.equal('test service in tenant resource data for debug');
394
- expect(res.body.resources[0].keys).to.be.an('object');
395
- expect(res.body.resources[0].keys.test_service_key).to.equal('test_service_value');
396
-
397
- done();
398
- });
399
- });
400
-
401
- it('GET /v1/acr : get all resource for service(testservice) in tenant0 without parameter(sport,scuk) with status 200', function(done){ // eslint-disable-line no-undef
402
- var uri = '/v1/acr';
403
- uri += '/testservice'; // path: yrn:yahoo:testservice::tenant0
404
- uri += '?cip=127.1.0.1'; // cip: 127.1.0.1
405
- uri += '&cport=8000'; // cport: 8000
406
- uri += '&crole=yrn:yahoo:::tenant0:role:test_service_tenant'; // crole: yrn:yahoo:::tenant0:role:test_service_tenant
407
- uri += '&ccuk='; // ccuk: null
408
- // // sport: not set
409
- uri += '&srole=yrn:yahoo:::tenant1:role:test_service_owner'; // srole: yrn:yahoo:::tenant1:role:test_service_owner
410
- // // scuk: not set
411
-
412
- chai.request(app)
413
- .get(uri)
414
- .set('content-type', 'application/json')
415
- .end(function(err, res){
416
- expect(res).to.have.status(200);
417
- expect(res).to.be.json;
418
- expect(res.body).to.be.an('object');
419
- expect(res.body.result).to.be.a('boolean').to.be.true;
420
- expect(res.body.message).to.be.a('null');
421
- expect(res.body.resources).to.be.an.instanceof(Array).to.have.lengthOf(1);
422
- expect(res.body.resources[0]).to.be.an('object');
423
- expect(res.body.resources[0].name).to.be.a('string').to.equal('test_service_resource');
424
- expect(res.body.resources[0].type).to.be.a('string').to.equal('string');
425
- expect(res.body.resources[0].data).to.be.a('string').to.equal('test service in tenant resource data for debug');
426
- expect(res.body.resources[0].keys).to.be.an('object');
427
- expect(res.body.resources[0].keys.test_service_key).to.equal('test_service_value');
428
-
429
- done();
430
- });
431
- });
432
-
433
- //
434
- // Run Test(DELETE - SUCCESS/FAILURE)
435
- //
436
- it('DELETE /v1/acr : delete not exist service(not_exist_service) in tenant0 by scoped token with status 204', function(done){ // eslint-disable-line no-undef
437
- var uri = '/v1/acr';
438
- uri += '/not_exist_service'; // path: yrn:yahoo:not_exist_service::tenant0
439
-
440
- chai.request(app)
441
- .delete(uri)
442
- .set('content-type', 'application/json')
443
- .set('x-auth-token', alltokens.scopedtoken.tenant0) // tenant0
444
- .end(function(err, res){
445
- expect(res).to.have.status(204);
446
-
447
- done();
448
- });
449
- });
450
-
451
- it('DELETE /v1/acr : delete service(testservice) in tenant0 by another tenant scoped token with status 204', function(done){ // eslint-disable-line no-undef
452
- var uri = '/v1/acr';
453
- uri += '/testservice'; // path: yrn:yahoo:testservice::tenant0
454
-
455
- chai.request(app)
456
- .delete(uri)
457
- .set('content-type', 'application/json')
458
- .set('x-auth-token', alltokens.scopedtoken.tenant1) // tenant1
459
- .end(function(err, res){
460
- expect(res).to.have.status(204);
461
-
462
- //
463
- // Check resource under service
464
- //
465
- chai.request(app)
466
- .get('/v1/resource/test_service_resource?service=testservice&expand=false')
467
- .set('content-type', 'application/json')
468
- .set('x-auth-token', alltokens.scopedtoken.tenant0) // tenant0
469
- .end(function(err, res){
470
- expect(res).to.have.status(200);
471
- expect(res).to.be.json;
472
- expect(res.body).to.be.an('object');
473
- expect(res.body.result).to.be.a('boolean').to.be.true;
474
- expect(res.body.message).to.be.a('null');
475
- expect(res.body.resource).to.be.an('object');
476
- expect(res.body.resource.string).to.be.a('string').to.equal('test service in tenant resource data for debug');
477
- expect(res.body.resource.object).to.be.a('null');
478
- expect(res.body.resource.expire).to.be.a('null');
479
- expect(res.body.resource.keys).to.be.an('object').to.deep.equal({test_service_key: 'test_service_value'});
480
- expect(res.body.resource.aliases).to.be.an.instanceof(Array).to.have.lengthOf(0);
481
-
482
- done();
483
- });
484
- });
485
- });
486
-
487
- it('DELETE /v1/acr : delete service(testservice) in tenant0 by invalid scoped token with status 204', function(done){ // eslint-disable-line no-undef
488
- var uri = '/v1/acr';
489
- uri += '/testservice'; // path: yrn:yahoo:testservice::tenant0
490
-
491
- chai.request(app)
492
- .delete(uri)
493
- .set('content-type', 'application/json')
494
- .set('x-auth-token', 'U=invalid_user_token') // invalid user token
495
- .end(function(err, res){
496
- expect(res).to.have.status(401);
497
-
498
- done();
499
- });
500
- });
501
-
502
- it('DELETE /v1/acr : delete service(testservice) in tenant0 by scoped token with status 204', function(done){ // eslint-disable-line no-undef
503
- var uri = '/v1/acr';
504
- uri += '/testservice'; // path: yrn:yahoo:testservice::tenant0
505
-
506
- chai.request(app)
507
- .delete(uri)
508
- .set('content-type', 'application/json')
509
- .set('x-auth-token', alltokens.scopedtoken.tenant0) // tenant0
510
- .end(function(err, res){
511
- expect(res).to.have.status(204);
512
-
513
- //
514
- // Check resource under service
515
- //
516
- chai.request(app)
517
- .get('/v1/resource/test_service_resource?service=testservice&expand=false')
518
- .set('content-type', 'application/json')
519
- .set('x-auth-token', alltokens.scopedtoken.tenant0) // tenant0
520
- .end(function(err, res){
521
- expect(res).to.have.status(404);
522
- expect(res).to.be.json;
523
- expect(res.body).to.be.an('object');
524
- expect(res.body.result).to.be.a('boolean').to.be.false;
525
- expect(res.body.message).to.be.a('string').to.equal('Could not get resource data for resource yrn: yrn:yahoo:testservice::tenant0:resource:test_service_resource');
526
-
527
- done();
528
- });
529
- });
530
- });
531
-
532
- //
533
- // Run Test(POST - SUCCESS/FAILURE)
534
- //
535
- it('(SERVICE POST FOR ACR TEST) /v1/service : create new service(acr_test_service) in tenant1 by scoped token with status 201', function(done){ // eslint-disable-line no-undef
536
- //
537
- // Create service with tenant1 owner
538
- //
539
- chai.request(app)
540
- .post('/v1/service')
541
- .set('content-type', 'application/json')
542
- .set('x-auth-token', alltokens.scopedtoken.tenant1) // tenant1
543
- .send({
544
- name: 'acr_test_service',
545
- verify: { // verify = static resource
546
- name: 'acr_test_service_resource',
547
- expire: null,
548
- type: 'string',
549
- data: 'test service resource data for acr test in tenant0 owner',
550
- keys: {
551
- foo: 'bar'
552
- }
553
- }
554
- })
555
- .end(function(err, res){
556
- expect(res).to.have.status(201);
557
- expect(res).to.be.json;
558
- expect(res.body).to.be.an('object');
559
- expect(res.body.result).to.be.a('boolean').to.be.true;
560
- expect(res.body.message).to.be.a('null');
561
-
562
- //
563
- // Added tenant0 to service member
564
- //
565
- chai.request(app)
566
- .post('/v1/service/acr_test_service')
567
- .set('content-type', 'application/json')
568
- .set('x-auth-token', alltokens.scopedtoken.tenant1) // tenant1
569
- .send({
570
- tenant: 'yrn:yahoo:::tenant0', // tenant0
571
- clear_tenant: false,
572
- verify: { // verify = static resource
573
- name: 'acr_test_service_resource',
574
- expire: null,
575
- type: 'string',
576
- data: 'test service resource data for acr test in tenant0 owner',
577
- keys: {
578
- foo: 'bar'
579
- }
580
- }
581
- })
582
- .end(function(err, res){
583
- expect(res).to.have.status(201);
584
- expect(res).to.be.json;
585
- expect(res.body).to.be.an('object');
586
- expect(res.body.result).to.be.a('boolean').to.be.true;
587
- expect(res.body.message).to.be.a('null');
588
-
589
- done();
590
- });
591
- });
592
- });
593
-
594
- it('POST /v1/acr : failure create service(acr_test_service) in tenant0 by invalid scoped token with status 401', function(done){ // eslint-disable-line no-undef
595
- var uri = '/v1/acr';
596
- uri += '/acr_test_service'; // path: yrn:yahoo:acr_test_service::tenant0
597
-
598
- chai.request(app)
599
- .post(uri)
600
- .set('content-type', 'application/json')
601
- .set('x-auth-token', 'U=invalid_scoped_token') // invalid token
602
- .send('') // body is empty
603
- .end(function(err, res){
604
- expect(res).to.have.status(401);
605
- expect(res).to.be.json;
606
- expect(res.body).to.be.an('object');
607
- expect(res.body.result).to.be.a('boolean').to.be.false;
608
- expect(res.body.message).to.be.a('string').to.equal('token(invalid_scoped_token) is not existed, because it is expired or not set yet.');
609
-
610
- done();
611
- });
612
- });
613
-
614
- it('POST /v1/acr : failure create service(not_exist_service) in tenant0 by scoped token with status 403', function(done){ // eslint-disable-line no-undef
615
- var uri = '/v1/acr';
616
- uri += '/not_exist_service'; // path: yrn:yahoo:not_exist_service::tenant0
617
-
618
- chai.request(app)
619
- .post(uri)
620
- .set('content-type', 'application/json')
621
- .set('x-auth-token', alltokens.scopedtoken.tenant0) // tenant0
622
- .send('') // body is empty
623
- .end(function(err, res){
624
- expect(res).to.have.status(403);
625
- expect(res).to.be.json;
626
- expect(res.body).to.be.an('object');
627
- expect(res.body.result).to.be.a('boolean').to.be.false;
628
- expect(res.body.message).to.be.a('string').to.equal('key(yrn:yahoo::::service:not_exist_service:verify) does not have safe verify url nor JSON string : null');
629
-
630
- done();
631
- });
632
- });
633
-
634
- it('POST /v1/acr : create service(acr_test_service) in tenant0 by scoped token with status 201', function(done){ // eslint-disable-line no-undef
635
- var uri = '/v1/acr';
636
- uri += '/acr_test_service'; // path: yrn:yahoo:acr_test_service::tenant0
637
-
638
- chai.request(app)
639
- .post(uri)
640
- .set('content-type', 'application/json')
641
- .set('x-auth-token', alltokens.scopedtoken.tenant0) // tenant0
642
- .send('') // body is empty
643
- .end(function(err, res){
644
- expect(res).to.have.status(201);
645
- expect(res).to.be.json;
646
- expect(res.body).to.be.an('object');
647
- expect(res.body.result).to.be.a('boolean').to.be.true;
648
- expect(res.body.message).to.be.a('null');
649
-
650
- //
651
- // Check resource under service
652
- //
653
- chai.request(app)
654
- .get('/v1/resource/acr_test_service_resource?service=acr_test_service&expand=false')
655
- .set('content-type', 'application/json')
656
- .set('x-auth-token', alltokens.scopedtoken.tenant0) // tenant0
657
- .end(function(err, res){
658
- expect(res).to.have.status(200);
659
- expect(res).to.be.json;
660
- expect(res.body).to.be.an('object');
661
- expect(res.body.result).to.be.a('boolean').to.be.true;
662
- expect(res.body.message).to.be.a('null');
663
- expect(res.body.resource).to.be.an('object');
664
- expect(res.body.resource.string).to.be.a('string').to.equal('test service resource data for acr test in tenant0 owner');
665
- expect(res.body.resource.object).to.be.a('null');
666
- expect(res.body.resource.expire).to.be.a('null');
667
- expect(res.body.resource.keys).to.be.an('object').to.deep.equal({foo: 'bar'});
668
- expect(res.body.resource.aliases).to.be.an.instanceof(Array).to.have.lengthOf(0);
669
-
670
- done();
671
- });
672
- });
673
- });
674
-
675
- it('POST /v1/acr : failure create service(acr_test_service) in tenant0 by invalid unscoped scoped token with status 401', function(done){ // eslint-disable-line no-undef
676
- var uri = '/v1/acr';
677
- uri += '/acr_test_service'; // path: yrn:yahoo:acr_test_service::tenant0
678
-
679
- chai.request(app)
680
- .post(uri)
681
- .set('content-type', 'application/json')
682
- .set('x-auth-token', 'U=invalid_scoped_token') // invalid token
683
- .send({ // tenant0
684
- tenant: 'tenant0'
685
- })
686
- .end(function(err, res){
687
- expect(res).to.have.status(401);
688
- expect(res).to.be.json;
689
- expect(res.body).to.be.an('object');
690
- expect(res.body.result).to.be.a('boolean').to.be.false;
691
- expect(res.body.message).to.be.a('string').to.equal('token(invalid_scoped_token) is not existed, because it is expired or not set yet.');
692
-
693
- done();
694
- });
695
- });
696
-
697
- it('POST /v1/acr : failure create service(not_exist_service) in tenant0 by unscoped scoped token with status 403', function(done){ // eslint-disable-line no-undef
698
- var uri = '/v1/acr';
699
- uri += '/not_exist_service'; // path: yrn:yahoo:not_exist_service::tenant0
700
-
701
- chai.request(app)
702
- .post(uri)
703
- .set('content-type', 'application/json')
704
- .set('x-auth-token', alltokens.unscopedtoken) // unscoped user token
705
- .send({ // tenant0
706
- tenant: 'tenant0'
707
- })
708
- .end(function(err, res){
709
- expect(res).to.have.status(403);
710
- expect(res).to.be.json;
711
- expect(res.body).to.be.an('object');
712
- expect(res.body.result).to.be.a('boolean').to.be.false;
713
- expect(res.body.message).to.be.a('string').to.equal('key(yrn:yahoo::::service:not_exist_service:verify) does not have safe verify url nor JSON string : null');
714
-
715
- done();
716
- });
717
- });
718
-
719
- it('POST /v1/acr : failure create service(acr_test_service) in invalid tenant by unscoped scoped token with status 400', function(done){ // eslint-disable-line no-undef
720
- var uri = '/v1/acr';
721
- uri += '/acr_test_service'; // path: yrn:yahoo:acr_test_service::invalid_tenant
722
-
723
- chai.request(app)
724
- .post(uri)
725
- .set('content-type', 'application/json')
726
- .set('x-auth-token', alltokens.unscopedtoken) // unscoped user token
727
- .send({ // invalid tenant
728
- tenant: 'invalid_tenant'
729
- })
730
- .end(function(err, res){
731
- expect(res).to.have.status(400);
732
- expect(res).to.be.json;
733
- expect(res.body).to.be.an('object');
734
- expect(res.body.result).to.be.a('boolean').to.be.false;
735
- expect(res.body.message).to.be.a('string').to.equal('user (dummyuser) is not member of tenant(invalid_tenant).');
736
-
737
- done();
738
- });
739
- });
740
-
741
- it('POST /v1/acr : create service(acr_test_service) in tenant0 by unscoped scoped token with status 201', function(done){ // eslint-disable-line no-undef
742
- var uri = '/v1/acr';
743
- uri += '/acr_test_service'; // path: yrn:yahoo:acr_test_service::tenant0
744
-
745
- chai.request(app)
746
- .post(uri)
747
- .set('content-type', 'application/json')
748
- .set('x-auth-token', alltokens.unscopedtoken) // unscoped user token
749
- .send({ // tenant0
750
- tenant: 'tenant0'
751
- })
752
- .end(function(err, res){
753
- expect(res).to.have.status(201);
754
- expect(res).to.be.json;
755
- expect(res.body).to.be.an('object');
756
- expect(res.body.result).to.be.a('boolean').to.be.true;
757
- expect(res.body.message).to.be.a('null');
758
-
759
- //
760
- // Check resource under service
761
- //
762
- chai.request(app)
763
- .get('/v1/resource/acr_test_service_resource?service=acr_test_service&expand=false')
764
- .set('content-type', 'application/json')
765
- .set('x-auth-token', alltokens.scopedtoken.tenant0) // tenant0
766
- .end(function(err, res){
767
- expect(res).to.have.status(200);
768
- expect(res).to.be.json;
769
- expect(res.body).to.be.an('object');
770
- expect(res.body.result).to.be.a('boolean').to.be.true;
771
- expect(res.body.message).to.be.a('null');
772
- expect(res.body.resource).to.be.an('object');
773
- expect(res.body.resource.string).to.be.a('string').to.equal('test service resource data for acr test in tenant0 owner');
774
- expect(res.body.resource.object).to.be.a('null');
775
- expect(res.body.resource.expire).to.be.a('null');
776
- expect(res.body.resource.keys).to.be.an('object').to.deep.equal({foo: 'bar'});
777
- expect(res.body.resource.aliases).to.be.an.instanceof(Array).to.have.lengthOf(0);
778
-
779
- done();
780
- });
781
- });
782
- });
783
-
784
- it('POST /v1/acr : create service(testservice) in tenant0 by scoped token with status 200(but error 401/403 in mocha)', function(done){ // eslint-disable-line no-undef
785
- var uri = '/v1/acr';
786
- uri += '/testservice'; // path: yrn:yahoo:testservice::tenant0
787
-
788
- chai.request(app)
789
- .post(uri)
790
- .set('content-type', 'application/json')
791
- .set('x-auth-token', alltokens.scopedtoken.tenant0) // tenant0
792
- .send('') // body is empty
793
- .end(function(err, res){
794
- //
795
- // [NOTE]
796
- // We could not check create service for tenant with mocha.
797
- // Because we could not get listening port before start test at loading test data
798
- // which had verify url.
799
- // Then we got connect error here.
800
- //
801
- expect(res.status).to.satisfy(function(status){
802
- return (status == 403 || status == 401);
803
- });
804
- expect(res).to.be.json;
805
- expect(res.body).to.be.an('object');
806
- expect(res.body.result).to.be.a('boolean').to.be.false;
807
- expect(res.body.message).to.be.a('string');
808
- expect(res.body.message).to.satisfy(function(message){
809
- return (-1 != message.indexOf('connect ECONNREFUSED') || -1 != message.indexOf('got error response for verify request by status=401') || -1 != message.indexOf('parameter is wrong : verifyurl='));
810
- });
811
-
812
- done();
813
-
814
- //
815
- // We expect following when it works.
816
- //
817
- // expect(res).to.have.status(200);
818
- // expect(res).to.be.json;
819
- // expect(res.body).to.be.an('object');
820
- // expect(res.body.result).to.be.a('boolean').to.be.true;
821
- // expect(res.body.message).to.be.a('null');
822
- //
823
- // //
824
- // // Check resource under service
825
- // //
826
- // chai.request(app)
827
- // .get('/v1/resource/test_service_resource?service=testservice&expand=false')
828
- // .set('content-type', 'application/json')
829
- // .set('x-auth-token', alltokens.scopedtoken.tenant0) // tenant0
830
- // .end(function(err, res){
831
- // expect(res).to.have.status(200);
832
- // expect(res).to.be.json;
833
- // expect(res.body).to.be.an('object');
834
- // expect(res.body.result).to.be.a('boolean').to.be.true;
835
- // expect(res.body.message).to.be.a('null');
836
- // expect(res.body.resource).to.be.an('object');
837
- // expect(res.body.resource.string).to.be.a('string').to.equal('test service in tenant resource data for debug');
838
- // expect(res.body.resource.object).to.be.a('null');
839
- // expect(res.body.resource.expire).to.be.a('null');
840
- // expect(res.body.resource.keys).to.be.an('object').to.deep.equal({test_service_key: 'test_service_value'});
841
- // expect(res.body.resource.aliases).to.be.an.instanceof(Array).to.have.lengthOf(0);
842
- //
843
- // done();
844
- // });
845
- });
846
- });
847
-
848
- //
849
- // Run Test(PUT - SUCCESS/FAILURE)
850
- //
851
- it('PUT /v1/acr : failure create service(acr_test_service) in tenant0 by invalid scoped token with status 401', function(done){ // eslint-disable-line no-undef
852
- var uri = '/v1/acr';
853
- uri += '/acr_test_service'; // path: yrn:yahoo:acr_test_service::tenant0
854
-
855
- chai.request(app)
856
- .put(uri)
857
- .set('content-type', 'application/json')
858
- .set('x-auth-token', 'U=invalid_scoped_token') // invalid token
859
- .end(function(err, res){
860
- expect(res).to.have.status(401);
861
- expect(res).to.be.json;
862
- expect(res.body).to.be.an('object');
863
- expect(res.body.result).to.be.a('boolean').to.be.false;
864
- expect(res.body.message).to.be.a('string').to.equal('token(invalid_scoped_token) is not existed, because it is expired or not set yet.');
865
-
866
- done();
867
- });
868
- });
869
-
870
- it('PUT /v1/acr : failure create service(not_exist_service) in tenant0 by scoped token with status 403', function(done){ // eslint-disable-line no-undef
871
- var uri = '/v1/acr';
872
- uri += '/not_exist_service'; // path: yrn:yahoo:not_exist_service::tenant0
873
-
874
- chai.request(app)
875
- .put(uri)
876
- .set('content-type', 'application/json')
877
- .set('x-auth-token', alltokens.scopedtoken.tenant0) // tenant0
878
- .end(function(err, res){
879
- expect(res).to.have.status(403);
880
- expect(res).to.be.json;
881
- expect(res.body).to.be.an('object');
882
- expect(res.body.result).to.be.a('boolean').to.be.false;
883
- expect(res.body.message).to.be.a('string').to.equal('key(yrn:yahoo::::service:not_exist_service:verify) does not have safe verify url nor JSON string : null');
884
-
885
- done();
886
- });
887
- });
888
-
889
- it('PUT /v1/acr : create service(acr_test_service) in tenant0 by scoped token with status 201', function(done){ // eslint-disable-line no-undef
890
- var uri = '/v1/acr';
891
- uri += '/acr_test_service'; // path: yrn:yahoo:acr_test_service::tenant0
892
-
893
- chai.request(app)
894
- .put(uri)
895
- .set('content-type', 'application/json')
896
- .set('x-auth-token', alltokens.scopedtoken.tenant0) // tenant0
897
- .end(function(err, res){
898
- expect(res).to.have.status(201);
899
- expect(res).to.be.json;
900
- expect(res.body).to.be.an('object');
901
- expect(res.body.result).to.be.a('boolean').to.be.true;
902
- expect(res.body.message).to.be.a('null');
903
-
904
- //
905
- // Check resource under service
906
- //
907
- chai.request(app)
908
- .get('/v1/resource/acr_test_service_resource?service=acr_test_service&expand=false')
909
- .set('content-type', 'application/json')
910
- .set('x-auth-token', alltokens.scopedtoken.tenant0) // tenant0
911
- .end(function(err, res){
912
- expect(res).to.have.status(200);
913
- expect(res).to.be.json;
914
- expect(res.body).to.be.an('object');
915
- expect(res.body.result).to.be.a('boolean').to.be.true;
916
- expect(res.body.message).to.be.a('null');
917
- expect(res.body.resource).to.be.an('object');
918
- expect(res.body.resource.string).to.be.a('string').to.equal('test service resource data for acr test in tenant0 owner');
919
- expect(res.body.resource.object).to.be.a('null');
920
- expect(res.body.resource.expire).to.be.a('null');
921
- expect(res.body.resource.keys).to.be.an('object').to.deep.equal({foo: 'bar'});
922
- expect(res.body.resource.aliases).to.be.an.instanceof(Array).to.have.lengthOf(0);
923
-
924
- done();
925
- });
926
- });
927
- });
928
-
929
- it('PUT /v1/acr : failure create service(acr_test_service) in tenant0 by invalid unscoped scoped token with status 401', function(done){ // eslint-disable-line no-undef
930
- var uri = '/v1/acr';
931
- uri += '/acr_test_service'; // path: yrn:yahoo:acr_test_service::tenant0
932
- uri += '?tenant=tenant0'; // tenant0
933
-
934
- chai.request(app)
935
- .put(uri)
936
- .set('content-type', 'application/json')
937
- .set('x-auth-token', 'U=invalid_scoped_token') // invalid token
938
- .end(function(err, res){
939
- expect(res).to.have.status(401);
940
- expect(res).to.be.json;
941
- expect(res.body).to.be.an('object');
942
- expect(res.body.result).to.be.a('boolean').to.be.false;
943
- expect(res.body.message).to.be.a('string').to.equal('token(invalid_scoped_token) is not existed, because it is expired or not set yet.');
944
-
945
- done();
946
- });
947
- });
948
-
949
- it('PUT /v1/acr : failure create service(not_exist_service) in tenant0 by unscoped scoped token with status 403', function(done){ // eslint-disable-line no-undef
950
- var uri = '/v1/acr';
951
- uri += '/not_exist_service'; // path: yrn:yahoo:not_exist_service::tenant0
952
- uri += '?tenant=tenant0'; // tenant0
953
-
954
- chai.request(app)
955
- .put(uri)
956
- .set('content-type', 'application/json')
957
- .set('x-auth-token', alltokens.unscopedtoken) // unscoped user token
958
- .end(function(err, res){
959
- expect(res).to.have.status(403);
960
- expect(res).to.be.json;
961
- expect(res.body).to.be.an('object');
962
- expect(res.body.result).to.be.a('boolean').to.be.false;
963
- expect(res.body.message).to.be.a('string').to.equal('key(yrn:yahoo::::service:not_exist_service:verify) does not have safe verify url nor JSON string : null');
964
-
965
- done();
966
- });
967
- });
968
-
969
- it('PUT /v1/acr : failure create service(acr_test_service) in invalid tenant by unscoped scoped token with status 400', function(done){ // eslint-disable-line no-undef
970
- var uri = '/v1/acr';
971
- uri += '/acr_test_service'; // path: yrn:yahoo:acr_test_service::invalid_tenant
972
- uri += '?tenant=invalid_tenant'; // invalid tenant
973
-
974
- chai.request(app)
975
- .put(uri)
976
- .set('content-type', 'application/json')
977
- .set('x-auth-token', alltokens.unscopedtoken) // unscoped user token
978
- .end(function(err, res){
979
- expect(res).to.have.status(400);
980
- expect(res).to.be.json;
981
- expect(res.body).to.be.an('object');
982
- expect(res.body.result).to.be.a('boolean').to.be.false;
983
- expect(res.body.message).to.be.a('string').to.equal('user (dummyuser) is not member of tenant(invalid_tenant).');
984
-
985
- done();
986
- });
987
- });
988
-
989
- it('PUT /v1/acr : create service(acr_test_service) in tenant0 by unscoped scoped token with status 201', function(done){ // eslint-disable-line no-undef
990
- var uri = '/v1/acr';
991
- uri += '/acr_test_service'; // path: yrn:yahoo:acr_test_service::tenant0
992
- uri += '?tenant=tenant0'; // tenant0
993
-
994
- chai.request(app)
995
- .put(uri)
996
- .set('content-type', 'application/json')
997
- .set('x-auth-token', alltokens.unscopedtoken) // unscoped user token
998
- .end(function(err, res){
999
- expect(res).to.have.status(201);
1000
- expect(res).to.be.json;
1001
- expect(res.body).to.be.an('object');
1002
- expect(res.body.result).to.be.a('boolean').to.be.true;
1003
- expect(res.body.message).to.be.a('null');
1004
-
1005
- //
1006
- // Check resource under service
1007
- //
1008
- chai.request(app)
1009
- .get('/v1/resource/acr_test_service_resource?service=acr_test_service&expand=false')
1010
- .set('content-type', 'application/json')
1011
- .set('x-auth-token', alltokens.scopedtoken.tenant0) // tenant0
1012
- .end(function(err, res){
1013
- expect(res).to.have.status(200);
1014
- expect(res).to.be.json;
1015
- expect(res.body).to.be.an('object');
1016
- expect(res.body.result).to.be.a('boolean').to.be.true;
1017
- expect(res.body.message).to.be.a('null');
1018
- expect(res.body.resource).to.be.an('object');
1019
- expect(res.body.resource.string).to.be.a('string').to.equal('test service resource data for acr test in tenant0 owner');
1020
- expect(res.body.resource.object).to.be.a('null');
1021
- expect(res.body.resource.expire).to.be.a('null');
1022
- expect(res.body.resource.keys).to.be.an('object').to.deep.equal({foo: 'bar'});
1023
- expect(res.body.resource.aliases).to.be.an.instanceof(Array).to.have.lengthOf(0);
1024
-
1025
- done();
1026
- });
1027
- });
1028
- });
1029
-
1030
- it('PUT /v1/acr : create service(testservice) in tenant0 by scoped token with status 200(but error 401/403 in mocha)', function(done){ // eslint-disable-line no-undef
1031
- var uri = '/v1/acr';
1032
- uri += '/testservice'; // path: yrn:yahoo:testservice::tenant0
1033
-
1034
- chai.request(app)
1035
- .put(uri)
1036
- .set('content-type', 'application/json')
1037
- .set('x-auth-token', alltokens.scopedtoken.tenant0) // tenant0
1038
- .end(function(err, res){
1039
- //
1040
- // [NOTE]
1041
- // We could not check create service for tenant with mocha.
1042
- // Because we could not get listening port before start test at loading test data
1043
- // which had verify url.
1044
- // Then we got connect error here.
1045
- //
1046
- expect(res.status).to.satisfy(function(status){
1047
- return (status == 403 || status == 401);
1048
- });
1049
- expect(res).to.be.json;
1050
- expect(res.body).to.be.an('object');
1051
- expect(res.body.result).to.be.a('boolean').to.be.false;
1052
- expect(res.body.message).to.be.a('string');
1053
- expect(res.body.message).to.satisfy(function(message){
1054
- return (-1 != message.indexOf('connect ECONNREFUSED') || -1 != message.indexOf('got error response for verify request by status=401') || -1 != message.indexOf('parameter is wrong : verifyurl='));
1055
- });
1056
-
1057
- done();
1058
-
1059
- //
1060
- // We expect following when it works.
1061
- //
1062
- // expect(res).to.have.status(200);
1063
- // expect(res).to.be.json;
1064
- // expect(res.body).to.be.an('object');
1065
- // expect(res.body.result).to.be.a('boolean').to.be.true;
1066
- // expect(res.body.message).to.be.a('null');
1067
- //
1068
- // //
1069
- // // Check resource under service
1070
- // //
1071
- // chai.request(app)
1072
- // .get('/v1/resource/test_service_resource?service=testservice&expand=false')
1073
- // .set('content-type', 'application/json')
1074
- // .set('x-auth-token', alltokens.scopedtoken.tenant0) // tenant0
1075
- // .end(function(err, res){
1076
- // expect(res).to.have.status(200);
1077
- // expect(res).to.be.json;
1078
- // expect(res.body).to.be.an('object');
1079
- // expect(res.body.result).to.be.a('boolean').to.be.true;
1080
- // expect(res.body.message).to.be.a('null');
1081
- // expect(res.body.resource).to.be.an('object');
1082
- // expect(res.body.resource.string).to.be.a('string').to.equal('test service in tenant resource data for debug');
1083
- // expect(res.body.resource.object).to.be.a('null');
1084
- // expect(res.body.resource.expire).to.be.a('null');
1085
- // expect(res.body.resource.keys).to.be.an('object').to.deep.equal({test_service_key: 'test_service_value'});
1086
- // expect(res.body.resource.aliases).to.be.an.instanceof(Array).to.have.lengthOf(0);
1087
- //
1088
- // done();
1089
- // });
1090
- });
1091
- });
1092
- });
1093
-
1094
- /*
1095
- * Local variables:
1096
- * tab-width: 4
1097
- * c-basic-offset: 4
1098
- * End:
1099
- * vim600: noexpandtab sw=4 ts=4 fdm=marker
1100
- * vim<600: noexpandtab sw=4 ts=4
1101
- */