k2hr3-api 1.0.42 → 2.0.0

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 +2 -2
  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
@@ -1,1579 +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 : POLICY', function(){ // eslint-disable-line no-undef
35
- var alltokens = {};
36
-
37
- //
38
- // Before in describe section
39
- //
40
- before(function(done){ // eslint-disable-line no-undef
41
- // Nothing to do
42
- tokenutil.before(this, alltokens, done);
43
- });
44
-
45
- //
46
- // After in describe section
47
- //
48
- after(function(){ // eslint-disable-line no-undef
49
- // Nothing to do
50
- });
51
-
52
- // 1.1 POST /v1/policy, allowing a full access policy.
53
- it('POST /v1/policy with status 201, allowing a full access policy.', function(done){ // eslint-disable-line no-undef
54
- chai.request(app)
55
- .post('/v1/policy')
56
- .set('x-auth-token', alltokens.scopedtoken.tenant0)
57
- .set('content-type', 'application/json')
58
- .send({
59
- policy: {
60
- name:'post_case1',
61
- effect: 'allow',
62
- action:[
63
- 'yrn:yahoo::::action:read',
64
- 'yrn:yahoo::::action:write'
65
- ],
66
- resource:['yrn:yahoo:::tenant0:resource:k2hr3_entest_str_res_01'],
67
- alias:[],
68
- reference:'0',
69
- }
70
- })
71
- .end(function(err, res){
72
- expect(res).to.have.status(201);
73
- done();
74
- });
75
- });
76
- // 1.2 POST /v1/policy, allowing a read only access policy.
77
- it('POST /v1/policy with status 201, allowing a read only access policy.', function(done){ // eslint-disable-line no-undef
78
- chai.request(app)
79
- .post('/v1/policy')
80
- .set('x-auth-token', alltokens.scopedtoken.tenant0)
81
- .set('content-type', 'application/json')
82
- .send({
83
- policy: {
84
- name:'post_case2',
85
- effect: 'allow',
86
- action:[
87
- 'yrn:yahoo::::action:read'
88
- ],
89
- resource:['yrn:yahoo:::tenant0:resource:k2hr3_entest_str_res_01'],
90
- alias:[],
91
- reference:'0',
92
- }
93
- })
94
- .end(function(err, res){
95
- expect(res).to.have.status(201);
96
- expect(res).to.be.json;
97
- expect(res.body.result).to.be.a('boolean').to.be.true;
98
- expect(res.body.message).to.be.a('null');
99
- done();
100
- });
101
- });
102
-
103
- // 1.3 POST /v1/policy, allowing a write only access policy.
104
- it('POST /v1/policy with status 201, allowing a write only access policy.', function(done){ // eslint-disable-line no-undef
105
- chai.request(app)
106
- .post('/v1/policy')
107
- .set('x-auth-token', alltokens.scopedtoken.tenant0)
108
- .set('content-type', 'application/json')
109
- .send({
110
- policy: {
111
- name:'post_case3',
112
- effect: 'allow',
113
- action:[
114
- 'yrn:yahoo::::action:write'
115
- ],
116
- resource:['yrn:yahoo:::tenant0:resource:k2hr3_entest_str_res_01'],
117
- alias:[],
118
- reference:'0',
119
- }
120
- })
121
- .end(function(err, res){
122
- expect(res).to.have.status(201);
123
- expect(res).to.be.json;
124
- expect(res.body.result).to.be.a('boolean').to.be.true;
125
- expect(res.body.message).to.be.a('null');
126
- done();
127
- });
128
- });
129
-
130
- // 1.4 POST /v1/policy, allowing a no access policy.
131
- it('POST /v1/policy with status 201, allowing a no access policy.', function(done){ // eslint-disable-line no-undef
132
- chai.request(app)
133
- .post('/v1/policy')
134
- .set('x-auth-token', alltokens.scopedtoken.tenant0)
135
- .set('content-type', 'application/json')
136
- .send({
137
- policy: {
138
- name:'post_case4',
139
- effect: 'allow',
140
- action:[],
141
- resource:['yrn:yahoo:::tenant0:resource:k2hr3_entest_str_res_01'],
142
- alias:[],
143
- reference:'0',
144
- }
145
- })
146
- .end(function(err, res){
147
- expect(res).to.have.status(201);
148
- expect(res).to.be.json;
149
- expect(res.body.result).to.be.a('boolean').to.be.true;
150
- expect(res.body.message).to.be.a('null');
151
- done();
152
- });
153
- });
154
-
155
- // 1.5 POST /v1/policy, denying a full access policy.
156
- it('POST /v1/policy with status 201, denying a full access policy.', function(done){ // eslint-disable-line no-undef
157
- chai.request(app)
158
- .post('/v1/policy')
159
- .set('x-auth-token', alltokens.scopedtoken.tenant0)
160
- .set('content-type', 'application/json')
161
- .send({
162
- policy: {
163
- name:'post_case5',
164
- effect: 'deny',
165
- action:[
166
- 'yrn:yahoo::::action:read',
167
- 'yrn:yahoo::::action:write'
168
- ],
169
- resource:['yrn:yahoo:::tenant0:resource:k2hr3_entest_str_res_01'],
170
- alias:[],
171
- reference:'0',
172
- }
173
- })
174
- .end(function(err, res){
175
- expect(res).to.have.status(201);
176
- expect(res).to.be.json;
177
- expect(res.body.result).to.be.a('boolean').to.be.true;
178
- expect(res.body.message).to.be.a('null');
179
- done();
180
- });
181
- });
182
- // 1.6 POST /v1/policy, denying a read only access policy.
183
- it('POST /v1/policy with status 201, denying a read only access policy.', function(done){ // eslint-disable-line no-undef
184
- chai.request(app)
185
- .post('/v1/policy')
186
- .set('x-auth-token', alltokens.scopedtoken.tenant0)
187
- .set('content-type', 'application/json')
188
- .send({
189
- policy: {
190
- name:'post_case6',
191
- effect: 'deny',
192
- action:[
193
- 'yrn:yahoo::::action:read'
194
- ],
195
- resource:['yrn:yahoo:::tenant0:resource:k2hr3_entest_str_res_01'],
196
- alias:[],
197
- reference:'0',
198
- }
199
- })
200
- .end(function(err, res){
201
- expect(res).to.have.status(201);
202
- expect(res).to.be.json;
203
- expect(res.body.result).to.be.a('boolean').to.be.true;
204
- expect(res.body.message).to.be.a('null');
205
- done();
206
- });
207
- });
208
-
209
- // 1.7 POST /v1/policy, denying a write only access policy.
210
- it('POST /v1/policy with status 201, denying a write only access policy.', function(done){ // eslint-disable-line no-undef
211
- chai.request(app)
212
- .post('/v1/policy')
213
- .set('x-auth-token', alltokens.scopedtoken.tenant0)
214
- .set('content-type', 'application/json')
215
- .send({
216
- policy: {
217
- name:'post_case7',
218
- effect: 'deny',
219
- action:[
220
- 'yrn:yahoo::::action:write'
221
- ],
222
- resource:['yrn:yahoo:::tenant0:resource:k2hr3_entest_str_res_01'],
223
- alias:[],
224
- reference:'0',
225
- }
226
- })
227
- .end(function(err, res){
228
- expect(res).to.have.status(201);
229
- expect(res).to.be.json;
230
- expect(res.body.result).to.be.a('boolean').to.be.true;
231
- expect(res.body.message).to.be.a('null');
232
- done();
233
- });
234
- });
235
-
236
- // 1.8 POST /v1/policy, denying a no access policy.
237
- it('POST /v1/policy with status 201, denying a no access policy.', function(done){ // eslint-disable-line no-undef
238
- chai.request(app)
239
- .post('/v1/policy')
240
- .set('x-auth-token', alltokens.scopedtoken.tenant0)
241
- .set('content-type', 'application/json')
242
- .send({
243
- policy: {
244
- name:'post_case8',
245
- effect: 'deny',
246
- action:[],
247
- resource:['yrn:yahoo:::tenant0:resource:k2hr3_entest_str_res_01'],
248
- alias:[],
249
- reference:'0',
250
- }
251
- })
252
- .end(function(err, res){
253
- expect(res).to.have.status(201);
254
- expect(res).to.be.json;
255
- expect(res.body.result).to.be.a('boolean').to.be.true;
256
- expect(res.body.message).to.be.a('null');
257
- done();
258
- });
259
- });
260
-
261
- // Memo: Error Test Cases
262
- // POST /v1/policy
263
- // ----CASE----|----INPUT-------|----VALUE-----
264
- // 1.9 |x-auth-token | (empty|broken value|invalid value data type)
265
- // 1.10 |policy/name | (empty|broken value|invalid value data type)
266
- // 1.11 |policy/effect | (empty|broken value|invalid value data type)
267
- // 1.12 |policy/action | (empty|broken value|invalid value data type)
268
- // 1.13 |policy/resource | (empty|broken value|invalid value data type)
269
- // 1.14 |policy/alias | (empty|broken value|invalid value data type)
270
-
271
- // 1.9.1 POST /v1/policy
272
- it('POST /v1/policy with invalid request header(no x-auth-token).', function(done){ // eslint-disable-line no-undef
273
- chai.request(app)
274
- .post('/v1/policy')
275
- .set('content-type', 'application/json')
276
- .send({
277
- policy: {
278
- name:'post_case1',
279
- effect: 'allow',
280
- action:[
281
- 'yrn:yahoo::::action:read',
282
- 'yrn:yahoo::::action:write'
283
- ],
284
- resource:['yrn:yahoo:::tenant0:resource:k2hr3_entest_str_res_01'],
285
- alias:[],
286
- reference:'0',
287
- }
288
- })
289
- .end(function(err, res){
290
- expect(res).to.have.status(400);
291
- expect(res).to.be.json;
292
- expect(res.body).to.be.an('object');
293
- expect(res.body.result).to.be.a('boolean').to.be.false;
294
- expect(res.body.message).to.be.a('string').to.equal('There is no x-auth-token header');
295
- done();
296
- });
297
- });
298
- // 1.9.2 POST /v1/policy
299
- it('POST /v1/policy with invalid request header(broken x-auth-token).', function(done){ // eslint-disable-line no-undef
300
- chai.request(app)
301
- .post('/v1/policy')
302
- .set('x-auth-token', 'U=error_dummy_token')
303
- .set('content-type', 'application/json')
304
- .send({
305
- policy: {
306
- name:'post_case1',
307
- effect: 'allow',
308
- action:[
309
- 'yrn:yahoo::::action:read',
310
- 'yrn:yahoo::::action:write'
311
- ],
312
- resource:['yrn:yahoo:::tenant0:resource:k2hr3_entest_str_res_01'],
313
- alias:[],
314
- reference:'0',
315
- }
316
- })
317
- .end(function(err, res){
318
- expect(res).to.have.status(401);
319
- expect(res).to.be.json;
320
- expect(res.body).to.be.an('object');
321
- expect(res.body.result).to.be.a('boolean').to.be.false;
322
- expect(res.body.message).to.be.a('string').to.equal('token(error_dummy_token) is not existed, because it is expired or not set yet.');
323
- done();
324
- });
325
- });
326
- // 1.10.1 POST /v1/policy
327
- it('POST /v1/policy with invalid request body(no policy/name).', function(done){ // eslint-disable-line no-undef
328
- chai.request(app)
329
- .post('/v1/policy')
330
- .set('x-auth-token', alltokens.scopedtoken.tenant0)
331
- .set('content-type', 'application/json')
332
- .send({
333
- policy: {
334
- effect: 'allow',
335
- action:[
336
- 'yrn:yahoo::::action:read',
337
- 'yrn:yahoo::::action:write'
338
- ],
339
- resource:['yrn:yahoo:::tenant0:resource:k2hr3_entest_str_res_01'],
340
- alias:[],
341
- reference:'0',
342
- }
343
- })
344
- .end(function(err, res){
345
- expect(res).to.have.status(400);
346
- expect(res).to.be.json;
347
- expect(res.body).to.be.an('object');
348
- expect(res.body.result).to.be.a('boolean').to.be.false;
349
- expect(res.body.message).to.be.a('string').to.equal('policy:name field is wrong : undefined');
350
- done();
351
- });
352
- });
353
- // 1.10.2 POST /v1/policy
354
- it('POST /v1/policy with invalid request body(broken policy/name).', function(done){ // eslint-disable-line no-undef
355
- chai.request(app)
356
- .post('/v1/policy')
357
- .set('x-auth-token', alltokens.scopedtoken.tenant0)
358
- .set('content-type', 'application/json')
359
- .send({
360
- policy: {
361
- name: '',
362
- effect: 'allow',
363
- action:[
364
- 'yrn:yahoo::::action:read',
365
- 'yrn:yahoo::::action:write'
366
- ],
367
- resource:['yrn:yahoo:::tenant0:resource:k2hr3_entest_str_res_01'],
368
- alias:[],
369
- reference:'0',
370
- }
371
- })
372
- .end(function(err, res){
373
- expect(res).to.have.status(400);
374
- expect(res).to.be.json;
375
- expect(res.body).to.be.an('object');
376
- expect(res.body.result).to.be.a('boolean').to.be.false;
377
- expect(res.body.message).to.be.a('string').to.equal('policy:name field is wrong : ""');
378
- done();
379
- });
380
- });
381
- // 1.10.3 POST /v1/policy
382
- it('POST /v1/policy with invalid request body(policy/name is not a String).', function(done){ // eslint-disable-line no-undef
383
- chai.request(app)
384
- .post('/v1/policy')
385
- .set('x-auth-token', alltokens.scopedtoken.tenant0)
386
- .set('content-type', 'application/json')
387
- .send({
388
- policy: {
389
- name: 1,
390
- effect: 'allow',
391
- action:[
392
- 'yrn:yahoo::::action:read',
393
- 'yrn:yahoo::::action:write'
394
- ],
395
- resource:['yrn:yahoo:::tenant0:resource:k2hr3_entest_str_res_01'],
396
- alias:[],
397
- reference:'0',
398
- }
399
- })
400
- .end(function(err, res){
401
- expect(res).to.have.status(400);
402
- expect(res).to.be.json;
403
- expect(res.body).to.be.an('object');
404
- expect(res.body.result).to.be.a('boolean').to.be.false;
405
- expect(res.body.message).to.be.a('string').to.equal('policy:name field is wrong : 1');
406
- done();
407
- });
408
- });
409
- // 1.11.1 POST /v1/policy
410
- it('POST /v1/policy without policy/effect.', function(done){ // eslint-disable-line no-undef
411
- chai.request(app)
412
- .post('/v1/policy')
413
- .set('x-auth-token', alltokens.scopedtoken.tenant0)
414
- .set('content-type', 'application/json')
415
- .send({
416
- policy: {
417
- name: '1.11.1',
418
- action:[
419
- 'yrn:yahoo::::action:read',
420
- 'yrn:yahoo::::action:write'
421
- ],
422
- resource:['yrn:yahoo:::tenant0:resource:k2hr3_entest_str_res_01'],
423
- alias:[],
424
- reference:'0',
425
- }
426
- })
427
- .end(function(err, res){
428
- expect(res).to.have.status(201);
429
- expect(res).to.be.json;
430
- expect(res.body).to.be.an('object');
431
- expect(res.body.result).to.be.a('boolean').to.be.true;
432
- done();
433
- });
434
- });
435
- // 1.11.2 POST /v1/policy
436
- it('POST /v1/policy with invalid request body(broken policy/effect).', function(done){ // eslint-disable-line no-undef
437
- chai.request(app)
438
- .post('/v1/policy')
439
- .set('x-auth-token', alltokens.scopedtoken.tenant0)
440
- .set('content-type', 'application/json')
441
- .send({
442
- policy: {
443
- name: '1.11.2',
444
- effect: 'ok',
445
- action:[
446
- 'yrn:yahoo::::action:read',
447
- 'yrn:yahoo::::action:write'
448
- ],
449
- resource:['yrn:yahoo:::tenant0:resource:k2hr3_entest_str_res_01'],
450
- alias:[],
451
- reference:'0',
452
- }
453
- })
454
- .end(function(err, res){
455
- expect(res).to.have.status(400);
456
- expect(res).to.be.json;
457
- expect(res.body).to.be.an('object');
458
- expect(res.body.result).to.be.a('boolean').to.be.false;
459
- done();
460
- });
461
- });
462
- // 1.11.3 POST /v1/policy
463
- it('POST /v1/policy with invalid request body(policy/effect is not a String).', function(done){ // eslint-disable-line no-undef
464
- chai.request(app)
465
- .post('/v1/policy')
466
- .set('x-auth-token', alltokens.scopedtoken.tenant0)
467
- .set('content-type', 'application/json')
468
- .send({
469
- policy: {
470
- name: '1.11.3',
471
- effect: 1,
472
- action:[
473
- 'yrn:yahoo::::action:read',
474
- 'yrn:yahoo::::action:write'
475
- ],
476
- resource:['yrn:yahoo:::tenant0:resource:k2hr3_entest_str_res_01'],
477
- alias:[],
478
- reference:'0',
479
- }
480
- })
481
- .end(function(err, res){
482
- expect(res).to.have.status(400);
483
- expect(res).to.be.json;
484
- expect(res.body).to.be.an('object');
485
- expect(res.body.result).to.be.a('boolean').to.be.false;
486
- expect(res.body.message).to.be.a('string').to.equal('policy:effect field is wrong : 1');
487
- done();
488
- });
489
- });
490
- // 1.12.1 POST /v1/policy
491
- it('POST /v1/policy without policy/action.', function(done){ // eslint-disable-line no-undef
492
- chai.request(app)
493
- .post('/v1/policy')
494
- .set('x-auth-token', alltokens.scopedtoken.tenant0)
495
- .set('content-type', 'application/json')
496
- .send({
497
- policy: {
498
- name: '1.12.1',
499
- effect: 'allow',
500
- resource:['yrn:yahoo:::tenant0:resource:k2hr3_entest_str_res_01'],
501
- alias:[],
502
- reference:'0',
503
- }
504
- })
505
- .end(function(err, res){
506
- expect(res).to.have.status(201);
507
- expect(res).to.be.json;
508
- expect(res.body).to.be.an('object');
509
- expect(res.body.result).to.be.a('boolean').to.be.true;
510
- done();
511
- });
512
- });
513
- // 1.12.2 POST /v1/policy
514
- it('POST /v1/policy with invalid request body(broken policy/action).', function(done){ // eslint-disable-line no-undef
515
- chai.request(app)
516
- .post('/v1/policy')
517
- .set('x-auth-token', alltokens.scopedtoken.tenant0)
518
- .set('content-type', 'application/json')
519
- .send({
520
- policy: {
521
- name: '1.12.2',
522
- effect: 'allow',
523
- action:[
524
- 'ok'
525
- ],
526
- resource:['yrn:yahoo:::tenant0:resource:k2hr3_entest_str_res_01'],
527
- alias:[],
528
- reference:'0',
529
- }
530
- })
531
- .end(function(err, res){
532
- expect(res).to.have.status(400);
533
- expect(res).to.be.json;
534
- expect(res.body).to.be.an('object');
535
- expect(res.body.result).to.be.a('boolean').to.be.false;
536
- done();
537
- });
538
- });
539
- // 1.12.3 POST /v1/policy
540
- it('POST /v1/policy with invalid request body(policy/action is not an Array).', function(done){ // eslint-disable-line no-undef
541
- chai.request(app)
542
- .post('/v1/policy')
543
- .set('x-auth-token', alltokens.scopedtoken.tenant0)
544
- .set('content-type', 'application/json')
545
- .send({
546
- policy: {
547
- name: '1.12.3',
548
- effect: 'allow',
549
- action: 1,
550
- resource:['yrn:yahoo:::tenant0:resource:k2hr3_entest_str_res_01'],
551
- alias:[],
552
- reference:'0',
553
- }
554
- })
555
- .end(function(err, res){
556
- expect(res).to.have.status(400);
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.false;
560
- expect(res.body.message).to.be.a('string').to.equal('policy:action field is wrong : 1');
561
- done();
562
- });
563
- });
564
- // 1.13.1 POST /v1/policy
565
- it('POST /v1/policy without policy/resource.', function(done){ // eslint-disable-line no-undef
566
- chai.request(app)
567
- .post('/v1/policy')
568
- .set('x-auth-token', alltokens.scopedtoken.tenant0)
569
- .set('content-type', 'application/json')
570
- .send({
571
- policy: {
572
- name: '1.12.1',
573
- effect: 'allow',
574
- action:[
575
- 'yrn:yahoo::::action:read',
576
- 'yrn:yahoo::::action:write'
577
- ],
578
- alias:[],
579
- reference:'0',
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
- done();
588
- });
589
- });
590
- // 1.13.2 POST /v1/policy
591
- it('POST /v1/policy with invalid request body(broken policy/resource).', function(done){ // eslint-disable-line no-undef
592
- chai.request(app)
593
- .post('/v1/policy')
594
- .set('x-auth-token', alltokens.scopedtoken.tenant0)
595
- .set('content-type', 'application/json')
596
- .send({
597
- policy: {
598
- name: '1.12.2',
599
- effect: 'allow',
600
- action:[
601
- 'yrn:yahoo::::action:read',
602
- 'yrn:yahoo::::action:write'
603
- ],
604
- resource:['not_found_resource'],
605
- alias:[],
606
- reference:'0',
607
- }
608
- })
609
- .end(function(err, res){
610
- expect(res).to.have.status(400);
611
- expect(res).to.be.json;
612
- expect(res.body).to.be.an('object');
613
- expect(res.body.result).to.be.a('boolean').to.be.false;
614
- done();
615
- });
616
- });
617
- // 1.13.3 POST /v1/policy
618
- it('POST /v1/policy with invalid request body(policy/resource is not an Array).', function(done){ // eslint-disable-line no-undef
619
- chai.request(app)
620
- .post('/v1/policy')
621
- .set('x-auth-token', alltokens.scopedtoken.tenant0)
622
- .set('content-type', 'application/json')
623
- .send({
624
- policy: {
625
- name: '1.12.3',
626
- effect: 'allow',
627
- action:[
628
- 'yrn:yahoo::::action:read',
629
- 'yrn:yahoo::::action:write'
630
- ],
631
- resource:1,
632
- alias:[],
633
- reference:'0',
634
- }
635
- })
636
- .end(function(err, res){
637
- expect(res).to.have.status(400);
638
- expect(res).to.be.json;
639
- expect(res.body).to.be.an('object');
640
- expect(res.body.result).to.be.a('boolean').to.be.false;
641
- expect(res.body.message).to.be.a('string').to.equal('policy:resource field is wrong : 1');
642
- done();
643
- });
644
- });
645
- // 1.14.1 POST /v1/policy
646
- it('POST /v1/policy without policy/alias.', function(done){ // eslint-disable-line no-undef
647
- chai.request(app)
648
- .post('/v1/policy')
649
- .set('x-auth-token', alltokens.scopedtoken.tenant0)
650
- .set('content-type', 'application/json')
651
- .send({
652
- policy: {
653
- name: '1.12.1',
654
- effect: 'allow',
655
- action:[
656
- 'yrn:yahoo::::action:read',
657
- 'yrn:yahoo::::action:write'
658
- ],
659
- resource:['yrn:yahoo:::tenant0:resource:k2hr3_entest_str_res_01'],
660
- reference:'0',
661
- }
662
- })
663
- .end(function(err, res){
664
- expect(res).to.have.status(201);
665
- expect(res).to.be.json;
666
- expect(res.body).to.be.an('object');
667
- expect(res.body.result).to.be.a('boolean').to.be.true;
668
- done();
669
- });
670
- });
671
- // 1.14.2 POST /v1/policy
672
- it('POST /v1/policy with invalid request body(broken policy/alias).', function(done){ // eslint-disable-line no-undef
673
- chai.request(app)
674
- .post('/v1/policy')
675
- .set('x-auth-token', alltokens.scopedtoken.tenant0)
676
- .set('content-type', 'application/json')
677
- .send({
678
- policy: {
679
- name: '1.12.2',
680
- effect: 'allow',
681
- action:[
682
- 'yrn:yahoo::::action:read',
683
- 'yrn:yahoo::::action:write'
684
- ],
685
- resource:['yrn:yahoo:::tenant0:resource:k2hr3_entest_str_res_01'],
686
- alias:['はろー、せかい'],
687
- reference:'0',
688
- }
689
- })
690
- .end(function(err, res){
691
- expect(res).to.have.status(400);
692
- expect(res).to.be.json;
693
- expect(res.body).to.be.an('object');
694
- expect(res.body.result).to.be.a('boolean').to.be.false;
695
- done();
696
- });
697
- });
698
- // 1.14.3 POST /v1/policy
699
- it('POST /v1/policy with invalid request body(policy/alias is not an Array).', function(done){ // eslint-disable-line no-undef
700
- chai.request(app)
701
- .post('/v1/policy')
702
- .set('x-auth-token', alltokens.scopedtoken.tenant0)
703
- .set('content-type', 'application/json')
704
- .send({
705
- policy: {
706
- name: '1.12.3',
707
- effect: 'allow',
708
- action:[
709
- 'yrn:yahoo::::action:read',
710
- 'yrn:yahoo::::action:write'
711
- ],
712
- resource:['yrn:yahoo:::tenant0:resource:k2hr3_entest_str_res_01'],
713
- alias:1,
714
- reference:'0',
715
- }
716
- })
717
- .end(function(err, res){
718
- expect(res).to.have.status(400);
719
- expect(res).to.be.json;
720
- expect(res.body).to.be.an('object');
721
- expect(res.body.result).to.be.a('boolean').to.be.false;
722
- expect(res.body.message).to.be.a('string').to.equal('policy:alias field is wrong : 1');
723
- done();
724
- });
725
- });
726
-
727
- // 2.1 PUT /v1/policy, allowing a full access policy.
728
- it('PUT /v1/policy with status 201, allowing a full access policy.', function(done){ // eslint-disable-line no-undef
729
- var json = {
730
- policy: {
731
- name: 'put_case1',
732
- effect: 'allow',
733
- action:[
734
- 'yrn:yahoo::::action:read',
735
- 'yrn:yahoo::::action:write'
736
- ],
737
- resource:['yrn:yahoo:::tenant0:resource:k2hr3_entest_str_res_01'],
738
- alias:[],
739
- reference:'0',
740
- }
741
- };
742
- var url = '/v1/policy?' + common.json2url(json.policy);
743
- chai.request(app)
744
- .put(url)
745
- .set('x-auth-token', alltokens.scopedtoken.tenant0)
746
- .set('content-type', 'application/json')
747
- .end(function(err, res){
748
- expect(res).to.have.status(201);
749
- done();
750
- });
751
- });
752
-
753
- // 2.2 PUT /v1/policy, allowing a read only access policy.
754
- it('PUT /v1/policy with status 201, allowing a read only access policy.', function(done){ // eslint-disable-line no-undef
755
- var json = {
756
- policy: {
757
- name:'put_case2',
758
- effect: 'allow',
759
- action:[
760
- 'yrn:yahoo::::action:read'
761
- ],
762
- resource:['yrn:yahoo:::tenant0:resource:k2hr3_entest_str_res_01'],
763
- alias:[],
764
- reference:'0',
765
- }
766
- };
767
- var url = '/v1/policy?' + common.json2url(json.policy);
768
- chai.request(app)
769
- .put(url)
770
- .set('x-auth-token', alltokens.scopedtoken.tenant0)
771
- .set('content-type', 'application/json')
772
- .end(function(err, res){
773
- expect(res).to.have.status(201);
774
- expect(res).to.be.json;
775
- expect(res.body.result).to.be.a('boolean').to.be.true;
776
- expect(res.body.message).to.be.a('null');
777
- done();
778
- });
779
- });
780
-
781
- // 2.3 PUT /v1/policy, allowing a write only access policy.
782
- it('PUT /v1/policy with status 201, allowing a write only access policy.', function(done){ // eslint-disable-line no-undef
783
- var json = {
784
- policy: {
785
- name:'put_case3',
786
- effect: 'allow',
787
- action:[
788
- 'yrn:yahoo::::action:write'
789
- ],
790
- resource:['yrn:yahoo:::tenant0:resource:k2hr3_entest_str_res_01'],
791
- alias:[],
792
- reference:'0',
793
- }
794
- };
795
- var url = '/v1/policy?' + common.json2url(json.policy);
796
- chai.request(app)
797
- .put(url)
798
- .set('x-auth-token', alltokens.scopedtoken.tenant0)
799
- .set('content-type', 'application/json')
800
- .end(function(err, res){
801
- expect(res).to.have.status(201);
802
- expect(res).to.be.json;
803
- expect(res.body.result).to.be.a('boolean').to.be.true;
804
- expect(res.body.message).to.be.a('null');
805
- done();
806
- });
807
- });
808
-
809
- // 2.4 PUT /v1/policy, allowing a no access policy.
810
- it('PUT /v1/policy with status 201, allowing a no access policy.', function(done){ // eslint-disable-line no-undef
811
- var json = {
812
- policy: {
813
- name:'put_case4',
814
- effect: 'allow',
815
- action:[],
816
- resource:['yrn:yahoo:::tenant0:resource:k2hr3_entest_str_res_01'],
817
- alias:[],
818
- reference:'0',
819
- }
820
- };
821
- var url = '/v1/policy?' + common.json2url(json.policy);
822
- chai.request(app)
823
- .put(url)
824
- .set('x-auth-token', alltokens.scopedtoken.tenant0)
825
- .set('content-type', 'application/json')
826
- .end(function(err, res){
827
- expect(res).to.have.status(201);
828
- expect(res).to.be.json;
829
- expect(res.body.result).to.be.a('boolean').to.be.true;
830
- expect(res.body.message).to.be.a('null');
831
- done();
832
- });
833
- });
834
-
835
- // 2.5 PUT /v1/policy, denying a full access policy.
836
- it('PUT /v1/policy with status 201, denying a full access policy.', function(done){ // eslint-disable-line no-undef
837
- var json = {
838
- policy: {
839
- name:'put_case5',
840
- effect: 'deny',
841
- action:[
842
- 'yrn:yahoo::::action:read',
843
- 'yrn:yahoo::::action:write'
844
- ],
845
- resource:['yrn:yahoo:::tenant0:resource:k2hr3_entest_str_res_01'],
846
- alias:[],
847
- reference:'0',
848
- }
849
- };
850
- var url = '/v1/policy?' + common.json2url(json.policy);
851
- chai.request(app)
852
- .put(url)
853
- .set('x-auth-token', alltokens.scopedtoken.tenant0)
854
- .set('content-type', 'application/json')
855
- .end(function(err, res){
856
- expect(res).to.have.status(201);
857
- expect(res).to.be.json;
858
- expect(res.body.result).to.be.a('boolean').to.be.true;
859
- expect(res.body.message).to.be.a('null');
860
- done();
861
- });
862
- });
863
-
864
- // 2.6 PUT /v1/policy, denying a read only access policy.
865
- it('PUT /v1/policy with status 201, denying a read access policy.', function(done){ // eslint-disable-line no-undef
866
- var json = {
867
- policy: {
868
- name:'put_case6',
869
- effect: 'deny',
870
- action:[
871
- 'yrn:yahoo::::action:read'
872
- ],
873
- resource:['yrn:yahoo:::tenant0:resource:k2hr3_entest_str_res_01'],
874
- alias:[],
875
- reference:'0',
876
- }
877
- };
878
- var url = '/v1/policy?' + common.json2url(json.policy);
879
- chai.request(app)
880
- .put(url)
881
- .set('x-auth-token', alltokens.scopedtoken.tenant0)
882
- .set('content-type', 'application/json')
883
- .end(function(err, res){
884
- expect(res).to.have.status(201);
885
- expect(res).to.be.json;
886
- expect(res.body.result).to.be.a('boolean').to.be.true;
887
- expect(res.body.message).to.be.a('null');
888
- done();
889
- });
890
- });
891
-
892
- // 2.7 PUT /v1/policy, denying a write only access policy.
893
- it('PUT /v1/policy with status 201, denying a write access policy.', function(done){ // eslint-disable-line no-undef
894
- var json = {
895
- policy: {
896
- name:'put_case7',
897
- effect: 'deny',
898
- action:[
899
- 'yrn:yahoo::::action:write'
900
- ],
901
- resource:['yrn:yahoo:::tenant0:resource:k2hr3_entest_str_res_01'],
902
- alias:[],
903
- reference:'0',
904
- }
905
- };
906
- var url = '/v1/policy?' + common.json2url(json.policy);
907
- chai.request(app)
908
- .put(url)
909
- .set('x-auth-token', alltokens.scopedtoken.tenant0)
910
- .set('content-type', 'application/json')
911
- .end(function(err, res){
912
- expect(res).to.have.status(201);
913
- expect(res).to.be.json;
914
- expect(res.body.result).to.be.a('boolean').to.be.true;
915
- expect(res.body.message).to.be.a('null');
916
- done();
917
- });
918
- });
919
-
920
- // 2.8 PUT /v1/policy, denying a no access policy.
921
- it('PUT /v1/policy with status 201, denying a no access policy.', function(done){ // eslint-disable-line no-undef
922
- var json = {
923
- policy: {
924
- name:'2.8',
925
- effect: 'deny',
926
- action:[],
927
- resource:['yrn:yahoo:::tenant0:resource:k2hr3_entest_str_res_01'],
928
- alias:[],
929
- reference:'0',
930
- }
931
- };
932
- var url = '/v1/policy?' + common.json2url(json.policy);
933
- chai.request(app)
934
- .put(url)
935
- .set('x-auth-token', alltokens.scopedtoken.tenant0)
936
- .set('content-type', 'application/json')
937
- .end(function(err, res){
938
- expect(res).to.have.status(201);
939
- expect(res).to.be.json;
940
- expect(res.body.result).to.be.a('boolean').to.be.true;
941
- expect(res.body.message).to.be.a('null');
942
- done();
943
- });
944
- });
945
-
946
- // Memo: Error Test Cases
947
- // PUT /v1/policy
948
- // ----CASE----|----INPUT-------|----VALUE-----
949
- // 2.9 |x-auth-token | (empty|broken value|invalid value data type)
950
- // 2.10 |policy/name | (empty|broken value|invalid value data type)
951
- // 2.11 |policy/effect | (empty|broken value|invalid value data type)
952
- // 2.12 |policy/action | (empty|broken value|invalid value data type)
953
- // 2.13 |policy/resource | (empty|broken value|invalid value data type)
954
- // 2.14 |policy/alias | (empty|broken value|invalid value data type)
955
-
956
- // 2.9.1 PUT /v1/policy
957
- it('PUT /v1/policy with invalid request header(no x-auth-token).', function(done){ // eslint-disable-line no-undef
958
- var json = {
959
- policy: {
960
- name:'2.9.1',
961
- effect: 'allow',
962
- action:[
963
- 'yrn:yahoo::::action:read',
964
- 'yrn:yahoo::::action:write'
965
- ],
966
- resource:['yrn:yahoo:::tenant0:resource:k2hr3_entest_str_res_01'],
967
- alias:[],
968
- reference:'0',
969
- }
970
- };
971
- var url = '/v1/policy?' + common.json2url(json.policy);
972
- chai.request(app)
973
- .put(url)
974
- .set('content-type', 'application/json')
975
- .end(function(err, res){
976
- expect(res).to.have.status(400);
977
- expect(res).to.be.json;
978
- expect(res.body).to.be.an('object');
979
- expect(res.body.result).to.be.a('boolean').to.be.false;
980
- expect(res.body.message).to.be.a('string').to.equal('There is no x-auth-token header');
981
- done();
982
- });
983
- });
984
- // 2.9.2 PUT /v1/policy
985
- it('PUT /v1/policy with invalid request header(broken x-auth-token).', function(done){ // eslint-disable-line no-undef
986
- var json = {
987
- policy: {
988
- name:'2.9.2',
989
- effect: 'allow',
990
- action:[
991
- 'yrn:yahoo::::action:read',
992
- 'yrn:yahoo::::action:write'
993
- ],
994
- resource:['yrn:yahoo:::tenant0:resource:k2hr3_entest_str_res_01'],
995
- alias:[],
996
- reference:'0',
997
- }
998
- };
999
- var url = '/v1/policy?' + common.json2url(json.policy);
1000
- chai.request(app)
1001
- .put(url)
1002
- .set('x-auth-token', 'U=error_dummy_token')
1003
- .set('content-type', 'application/json')
1004
- .end(function(err, res){
1005
- expect(res).to.have.status(401);
1006
- expect(res).to.be.json;
1007
- expect(res.body).to.be.an('object');
1008
- expect(res.body.result).to.be.a('boolean').to.be.false;
1009
- expect(res.body.message).to.be.a('string').to.equal('token(error_dummy_token) is not existed, because it is expired or not set yet.');
1010
- done();
1011
- });
1012
- });
1013
- // 2.10.1 PUT /v1/policy
1014
- it('PUT /v1/policy with invalid request body(no policy/name).', function(done){ // eslint-disable-line no-undef
1015
- var json = {
1016
- policy: {
1017
- effect: 'allow',
1018
- action:[
1019
- 'yrn:yahoo::::action:read',
1020
- 'yrn:yahoo::::action:write'
1021
- ],
1022
- resource:['yrn:yahoo:::tenant0:resource:k2hr3_entest_str_res_01'],
1023
- alias:[],
1024
- reference:'0',
1025
- }
1026
- };
1027
- var url = '/v1/policy?' + common.json2url(json.policy);
1028
- chai.request(app)
1029
- .put(url)
1030
- .set('x-auth-token', alltokens.scopedtoken.tenant0)
1031
- .set('content-type', 'application/json')
1032
- .end(function(err, res){
1033
- expect(res).to.have.status(400);
1034
- expect(res).to.be.json;
1035
- expect(res.body).to.be.an('object');
1036
- expect(res.body.result).to.be.a('boolean').to.be.false;
1037
- expect(res.body.message).to.be.a('string').to.equal('policy:name field is wrong : undefined');
1038
- done();
1039
- });
1040
- });
1041
- // 2.10.2 PUT /v1/policy
1042
- it('PUT /v1/policy with invalid request body(broken policy/name).', function(done){ // eslint-disable-line no-undef
1043
- var json = {
1044
- policy: {
1045
- name:'',
1046
- effect: 'allow',
1047
- action:[
1048
- 'yrn:yahoo::::action:read',
1049
- 'yrn:yahoo::::action:write'
1050
- ],
1051
- resource:['yrn:yahoo:::tenant0:resource:k2hr3_entest_str_res_01'],
1052
- alias:[],
1053
- reference:'0',
1054
- }
1055
- };
1056
- var url = '/v1/policy?' + common.json2url(json.policy);
1057
- chai.request(app)
1058
- .put(url)
1059
- .set('x-auth-token', alltokens.scopedtoken.tenant0)
1060
- .set('content-type', 'application/json')
1061
- .end(function(err, res){
1062
- expect(res).to.have.status(400);
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.false;
1066
- expect(res.body.message).to.be.a('string').to.equal('policy:name field is wrong : ""');
1067
- done();
1068
- });
1069
- });
1070
- // 2.10.3 PUT /v1/policy
1071
- it('PUT /v1/policy with invalid request body(policy/name is not a String).', function(done){ // eslint-disable-line no-undef
1072
- var json = {
1073
- policy: {
1074
- name:1,
1075
- effect: 'allow',
1076
- action:[
1077
- 'yrn:yahoo::::action:read',
1078
- 'yrn:yahoo::::action:write'
1079
- ],
1080
- resource:['yrn:yahoo:::tenant0:resource:k2hr3_entest_str_res_01'],
1081
- alias:[],
1082
- reference:'0',
1083
- }
1084
- };
1085
- var url = '/v1/policy?' + common.json2url(json.policy);
1086
- chai.request(app)
1087
- .put(url)
1088
- .set('x-auth-token', alltokens.scopedtoken.tenant0)
1089
- .set('content-type', 'application/json')
1090
- .end(function(err, res){
1091
- expect(res).to.have.status(201);
1092
- expect(res).to.be.json;
1093
- expect(res.body).to.be.an('object');
1094
- expect(res.body.result).to.be.a('boolean').to.be.true;
1095
- done();
1096
- });
1097
- });
1098
- // 2.11.1 PUT /v1/policy
1099
- it('PUT /v1/policy without policy/effect.', function(done){ // eslint-disable-line no-undef
1100
- var json = {
1101
- policy: {
1102
- name:'2.11.1',
1103
- action:[
1104
- 'yrn:yahoo::::action:read',
1105
- 'yrn:yahoo::::action:write'
1106
- ],
1107
- resource:['yrn:yahoo:::tenant0:resource:k2hr3_entest_str_res_01'],
1108
- alias:[],
1109
- reference:'0',
1110
- }
1111
- };
1112
- var url = '/v1/policy?' + common.json2url(json.policy);
1113
- chai.request(app)
1114
- .put(url)
1115
- .set('x-auth-token', alltokens.scopedtoken.tenant0)
1116
- .set('content-type', 'application/json')
1117
- .end(function(err, res){
1118
- expect(res).to.have.status(201);
1119
- expect(res).to.be.json;
1120
- expect(res.body).to.be.an('object');
1121
- expect(res.body.result).to.be.a('boolean').to.be.true;
1122
- done();
1123
- });
1124
- });
1125
- // 2.11.2 PUT /v1/policy
1126
- it('PUT /v1/policy with invalid request body(broken policy/effect).', function(done){ // eslint-disable-line no-undef
1127
- var json = {
1128
- policy: {
1129
- name:'2.11.2',
1130
- effect: 'ok',
1131
- action:[
1132
- 'yrn:yahoo::::action:read',
1133
- 'yrn:yahoo::::action:write'
1134
- ],
1135
- resource:['yrn:yahoo:::tenant0:resource:k2hr3_entest_str_res_01'],
1136
- alias:[],
1137
- reference:'0',
1138
- }
1139
- };
1140
- var url = '/v1/policy?' + common.json2url(json.policy);
1141
- chai.request(app)
1142
- .put(url)
1143
- .set('x-auth-token', alltokens.scopedtoken.tenant0)
1144
- .set('content-type', 'application/json')
1145
- .end(function(err, res){
1146
- expect(res).to.have.status(400);
1147
- expect(res).to.be.json;
1148
- expect(res.body).to.be.an('object');
1149
- expect(res.body.result).to.be.a('boolean').to.be.false;
1150
- done();
1151
- });
1152
- });
1153
- // 2.11.3 PUT /v1/policy
1154
- it('PUT /v1/policy with invalid request body(policy/effect is not a String).', function(done){ // eslint-disable-line no-undef
1155
- var json = {
1156
- policy: {
1157
- name:'2.11.3',
1158
- effect: 1,
1159
- action:[
1160
- 'yrn:yahoo::::action:read',
1161
- 'yrn:yahoo::::action:write'
1162
- ],
1163
- resource:['yrn:yahoo:::tenant0:resource:k2hr3_entest_str_res_01'],
1164
- alias:[],
1165
- reference:'0',
1166
- }
1167
- };
1168
- var url = '/v1/policy?' + common.json2url(json.policy);
1169
- chai.request(app)
1170
- .put(url)
1171
- .set('x-auth-token', alltokens.scopedtoken.tenant0)
1172
- .set('content-type', 'application/json')
1173
- .end(function(err, res){
1174
- expect(res).to.have.status(400);
1175
- expect(res).to.be.json;
1176
- expect(res.body).to.be.an('object');
1177
- expect(res.body.result).to.be.a('boolean').to.be.false;
1178
- expect(res.body.message).to.be.a('string').to.equal('policy:effect field is wrong : "1"');
1179
- done();
1180
- });
1181
- });
1182
- // 2.12.1 PUT /v1/policy
1183
- it('PUT /v1/policy without policy/action.', function(done){ // eslint-disable-line no-undef
1184
- var json = {
1185
- policy: {
1186
- name:'2.12.1',
1187
- effect: 'allow',
1188
- resource:['yrn:yahoo:::tenant0:resource:k2hr3_entest_str_res_01'],
1189
- alias:[],
1190
- reference:'0',
1191
- }
1192
- };
1193
- var url = '/v1/policy?' + common.json2url(json.policy);
1194
- chai.request(app)
1195
- .put(url)
1196
- .set('x-auth-token', alltokens.scopedtoken.tenant0)
1197
- .set('content-type', 'application/json')
1198
- .end(function(err, res){
1199
- expect(res).to.have.status(201);
1200
- expect(res).to.be.json;
1201
- expect(res.body).to.be.an('object');
1202
- expect(res.body.result).to.be.a('boolean').to.be.true;
1203
- done();
1204
- });
1205
- });
1206
- // 2.12.2 PUT /v1/policy
1207
- it('PUT /v1/policy with invalid request body(broken policy/action).', function(done){ // eslint-disable-line no-undef
1208
- var json = {
1209
- policy: {
1210
- name:'2.12.2',
1211
- effect: 'allow',
1212
- action:[
1213
- 'ok'
1214
- ],
1215
- resource:['yrn:yahoo:::tenant0:resource:k2hr3_entest_str_res_01'],
1216
- alias:[],
1217
- reference:'0',
1218
- }
1219
- };
1220
- var url = '/v1/policy?' + common.json2url(json.policy);
1221
- chai.request(app)
1222
- .put(url)
1223
- .set('x-auth-token', alltokens.scopedtoken.tenant0)
1224
- .set('content-type', 'application/json')
1225
- .end(function(err, res){
1226
- expect(res).to.have.status(400);
1227
- expect(res).to.be.json;
1228
- expect(res.body).to.be.an('object');
1229
- expect(res.body.result).to.be.a('boolean').to.be.false;
1230
- done();
1231
- });
1232
- });
1233
- // 2.12.3 PUT /v1/policy
1234
- it('PUT /v1/policy with invalid request body(policy/action is not an Array).', function(done){ // eslint-disable-line no-undef
1235
- var json = {
1236
- policy: {
1237
- name:'2.12.3',
1238
- effect: 'deny',
1239
- action: 1,
1240
- resource:['yrn:yahoo:::tenant0:resource:k2hr3_entest_str_res_01'],
1241
- alias:[],
1242
- reference:'0',
1243
- }
1244
- };
1245
- var url = '/v1/policy?' + common.json2url(json.policy);
1246
- chai.request(app)
1247
- .put(url)
1248
- .set('x-auth-token', alltokens.scopedtoken.tenant0)
1249
- .set('content-type', 'application/json')
1250
- .end(function(err, res){
1251
- expect(res).to.have.status(400);
1252
- expect(res).to.be.json;
1253
- expect(res.body).to.be.an('object');
1254
- expect(res.body.result).to.be.a('boolean').to.be.false;
1255
- expect(res.body.message).to.be.a('string').to.equal('policy:action field is wrong : "1"');
1256
- done();
1257
- });
1258
- });
1259
- // 2.13.1 PUT /v1/policy
1260
- it('PUT /v1/policy without policy/resource.', function(done){ // eslint-disable-line no-undef
1261
- var json = {
1262
- policy: {
1263
- name:'2.13.1',
1264
- effect: 'allow',
1265
- action:[],
1266
- alias:[],
1267
- reference:'0',
1268
- }
1269
- };
1270
- var url = '/v1/policy?' + common.json2url(json.policy);
1271
- chai.request(app)
1272
- .put(url)
1273
- .set('x-auth-token', alltokens.scopedtoken.tenant0)
1274
- .set('content-type', 'application/json')
1275
- .end(function(err, res){
1276
- expect(res).to.have.status(201);
1277
- expect(res).to.be.json;
1278
- expect(res.body).to.be.an('object');
1279
- expect(res.body.result).to.be.a('boolean').to.be.true;
1280
- done();
1281
- });
1282
- });
1283
- // 2.13.2 PUT /v1/policy
1284
- it('PUT /v1/policy with invalid request body(broken policy/resource).', function(done){ // eslint-disable-line no-undef
1285
- var json = {
1286
- policy: {
1287
- name:'2.13.2',
1288
- effect: 'allow',
1289
- action:[
1290
- 'yrn:yahoo::::action:read',
1291
- 'yrn:yahoo::::action:write'
1292
- ],
1293
- resource:['not_found_resource'],
1294
- alias:[],
1295
- reference:'0',
1296
- }
1297
- };
1298
- var url = '/v1/policy?' + common.json2url(json.policy);
1299
- chai.request(app)
1300
- .put(url)
1301
- .set('x-auth-token', alltokens.scopedtoken.tenant0)
1302
- .set('content-type', 'application/json')
1303
- .end(function(err, res){
1304
- expect(res).to.have.status(400);
1305
- expect(res).to.be.json;
1306
- expect(res.body).to.be.an('object');
1307
- expect(res.body.result).to.be.a('boolean').to.be.false;
1308
- done();
1309
- });
1310
- });
1311
- // 2.13.3 PUT /v1/policy
1312
- it('PUT /v1/policy with invalid request body(policy/resource is not an Array).', function(done){ // eslint-disable-line no-undef
1313
- var json = {
1314
- policy: {
1315
- name:'2.13.3',
1316
- effect: 'allow',
1317
- action:[
1318
- 'yrn:yahoo::::action:read',
1319
- 'yrn:yahoo::::action:write'
1320
- ],
1321
- resource:1,
1322
- alias:[],
1323
- reference:'0',
1324
- }
1325
- };
1326
- var url = '/v1/policy?' + common.json2url(json.policy);
1327
- chai.request(app)
1328
- .put(url)
1329
- .set('x-auth-token', alltokens.scopedtoken.tenant0)
1330
- .set('content-type', 'application/json')
1331
- .end(function(err, res){
1332
- expect(res).to.have.status(400);
1333
- expect(res).to.be.json;
1334
- expect(res.body).to.be.an('object');
1335
- expect(res.body.result).to.be.a('boolean').to.be.false;
1336
- expect(res.body.message).to.be.a('string').to.equal('policy:resource field is wrong : "1"');
1337
- done();
1338
- });
1339
- });
1340
- // 2.14.1 PUT /v1/policy
1341
- it('PUT /v1/policy without policy/alias.', function(done){ // eslint-disable-line no-undef
1342
- var json = {
1343
- policy: {
1344
- name:'2.14.1',
1345
- effect: 'allow',
1346
- action:[
1347
- 'yrn:yahoo::::action:read',
1348
- 'yrn:yahoo::::action:write'
1349
- ],
1350
- resource:['yrn:yahoo:::tenant0:resource:k2hr3_entest_str_res_01'],
1351
- reference:'0',
1352
- }
1353
- };
1354
- var url = '/v1/policy?' + common.json2url(json.policy);
1355
- chai.request(app)
1356
- .put(url)
1357
- .set('x-auth-token', alltokens.scopedtoken.tenant0)
1358
- .set('content-type', 'application/json')
1359
- .end(function(err, res){
1360
- expect(res).to.have.status(201);
1361
- expect(res).to.be.json;
1362
- expect(res.body).to.be.an('object');
1363
- expect(res.body.result).to.be.a('boolean').to.be.true;
1364
- done();
1365
- });
1366
- });
1367
- // 2.14.2 PUT /v1/policy
1368
- it('PUT /v1/policy with invalid request body(broken policy/alias).', function(done){ // eslint-disable-line no-undef
1369
- var json = {
1370
- policy: {
1371
- name:'2.14.2',
1372
- effect: 'allow',
1373
- action:[],
1374
- resource:['yrn:yahoo:::tenant0:resource:k2hr3_entest_str_res_01'],
1375
- alias:['はろー、せかい'],
1376
- reference:'0',
1377
- }
1378
- };
1379
- var url = '/v1/policy?' + common.json2url(json.policy);
1380
- chai.request(app)
1381
- .put(url)
1382
- .set('x-auth-token', alltokens.scopedtoken.tenant0)
1383
- .set('content-type', 'application/json')
1384
- .end(function(err, res){
1385
- expect(res).to.have.status(400);
1386
- expect(res).to.be.json;
1387
- expect(res.body).to.be.an('object');
1388
- expect(res.body.result).to.be.a('boolean').to.be.false;
1389
- done();
1390
- });
1391
- });
1392
- // 2.14.3 PUT /v1/policy
1393
- it('PUT /v1/policy with invalid request body(policy/alias is not an Array).', function(done){ // eslint-disable-line no-undef
1394
- var json = {
1395
- policy: {
1396
- name:'2.14.3',
1397
- effect: 'allow',
1398
- action:[],
1399
- resource:['yrn:yahoo:::tenant0:resource:k2hr3_entest_str_res_01'],
1400
- alias:1,
1401
- reference:'0',
1402
- }
1403
- };
1404
- var url = '/v1/policy?' + common.json2url(json.policy);
1405
- chai.request(app)
1406
- .put(url)
1407
- .set('x-auth-token', alltokens.scopedtoken.tenant0)
1408
- .set('content-type', 'application/json')
1409
- .end(function(err, res){
1410
- expect(res).to.have.status(400);
1411
- expect(res).to.be.json;
1412
- expect(res.body).to.be.an('object');
1413
- expect(res.body.result).to.be.a('boolean').to.be.false;
1414
- expect(res.body.message).to.be.a('string').to.equal('policy:alias field is wrong : "1"');
1415
- done();
1416
- });
1417
- });
1418
-
1419
- // 3.1 GET /v1/policy without service.
1420
- it('GET /v1/policy with status 200.', function(done){ // eslint-disable-line no-undef
1421
- var url = '/v1/policy/k2hr3_entest_str_pol_01';
1422
- chai.request(app)
1423
- .get(url)
1424
- .set('x-auth-token', alltokens.scopedtoken.tenant0)
1425
- .set('content-type', 'application/json')
1426
- .end(function(err, res){
1427
- expect(res).to.have.status(200);
1428
- expect(res).to.be.json;
1429
- expect(res.body.result).to.be.a('boolean').to.be.true;
1430
- expect(res.body.message).to.be.a('null');
1431
- done();
1432
- });
1433
- });
1434
-
1435
- // 3.2 GET /v1/policy with service.
1436
- it('GET /v1/policy with a service with status 200.', function(done){ // eslint-disable-line no-undef
1437
- var url = '/v1/policy/yrn:yahoo:testservice::tenant0:policy:acr-policy';
1438
- chai.request(app)
1439
- .get(url)
1440
- .set('x-auth-token', alltokens.scopedtoken.tenant0)
1441
- .set('content-type', 'application/json')
1442
- .end(function(err, res){
1443
- expect(res).to.have.status(200);
1444
- expect(res).to.be.json;
1445
- expect(res.body.result).to.be.a('boolean').to.be.true;
1446
- expect(res.body.message).to.be.a('null');
1447
- expect(res.body.policy.effect).to.have.string('allow');
1448
- expect(res.body.policy.action).to.have.lengthOf(1);
1449
- expect(res.body.policy.action[0]).to.have.string('yrn:yahoo::::action:read');
1450
- expect(res.body.policy.resource).to.have.lengthOf(1);
1451
- expect(res.body.policy.resource[0]).to.have.string('yrn:yahoo:testservice::tenant0:resource:test_service_resource');
1452
- expect(res.body.policy.condition).to.have.lengthOf(0);
1453
- expect(res.body.policy.alias).to.have.lengthOf(0);
1454
- expect(res.body.policy.reference).to.equal(0);
1455
- done();
1456
- });
1457
- });
1458
-
1459
- // 3.3.1 GET /v1/policy
1460
- it('GET /v1/policy with invalid request header(no x-auth-token).', function(done){ // eslint-disable-line no-undef
1461
- var url = '/v1/policy/yrn:yahoo:testservice::tenant0:policy:acr-policy';
1462
- chai.request(app)
1463
- .get(url)
1464
- .set('content-type', 'application/json')
1465
- .end(function(err, res){
1466
- expect(res).to.have.status(400);
1467
- expect(res).to.be.json;
1468
- expect(res.body).to.be.an('object');
1469
- expect(res.body.result).to.be.a('boolean').to.be.false;
1470
- expect(res.body.message).to.be.a('string').to.equal('There is no x-auth-token header');
1471
- done();
1472
- });
1473
- });
1474
- // 3.3.2 GET /v1/policy
1475
- it('GET /v1/policy with invalid request header(broken x-auth-token).', function(done){ // eslint-disable-line no-undef
1476
- var url = '/v1/policy/yrn:yahoo:testservice::tenant0:policy:acr-policy';
1477
- chai.request(app)
1478
- .get(url)
1479
- .set('x-auth-token', 'U=error_dummy_token')
1480
- .set('content-type', 'application/json')
1481
- .end(function(err, res){
1482
- expect(res).to.have.status(401);
1483
- expect(res).to.be.json;
1484
- expect(res.body).to.be.an('object');
1485
- expect(res.body.result).to.be.a('boolean').to.be.false;
1486
- expect(res.body.message).to.be.a('string').to.equal('token(error_dummy_token) is not existed, because it is expired or not set yet.');
1487
- done();
1488
- });
1489
- });
1490
-
1491
- // 4.1 HEAD /v1/policy with service.
1492
- it('HEAD /v1/policy with a service with status 204.', function(done){ // eslint-disable-line no-undef
1493
- var url = '/v1/policy/yrn:yahoo:testservice::tenant0:policy:acr-policy?tenant=tenant0&service=testservice&action=yrn:yahoo::::action:read&resource=yrn:yahoo:testservice::tenant0:resource:test_service_resource';
1494
- chai.request(app)
1495
- .head(url)
1496
- .set('content-type', 'application/json')
1497
- .end(function(err, res){
1498
- expect(res).to.have.status(204);
1499
- done();
1500
- });
1501
- });
1502
-
1503
- // 4.2 HEAD /v1/policy with service.
1504
- it('HEAD /v1/policy with a service with status 403 as unauthorized action.', function(done){ // eslint-disable-line no-undef
1505
- var url = '/v1/policy/yrn:yahoo:testservice::tenant0:policy:acr-policy?tenant=tenant0&service=testservice&action=yrn:yahoo::::action:write&resource=yrn:yahoo:testservice::tenant0:resource:test_service_resource';
1506
- chai.request(app)
1507
- .head(url)
1508
- .set('content-type', 'application/json')
1509
- .end(function(err, res){
1510
- expect(res).to.have.status(403);
1511
- done();
1512
- });
1513
- });
1514
-
1515
- // 5. DELETE /v1/policy
1516
- it('DELETE /v1/policy without token header.', function(done){ // eslint-disable-line no-undef
1517
- var url = '/v1/policy/yrn:yahoo:testservice::tenant0:policy:acr-policy';
1518
- chai.request(app)
1519
- .delete(url)
1520
- .set('content-type', 'application/json')
1521
- .end(function(err, res){
1522
- expect(res).to.have.status(400);
1523
- done();
1524
- });
1525
- });
1526
- it('DELETE /v1/policy with invalid token.', function(done){ // eslint-disable-line no-undef
1527
- var url = '/v1/policy/yrn:yahoo:testservice::tenant0:policy:acr-policy';
1528
- chai.request(app)
1529
- .delete(url)
1530
- .set('content-type', 'application/json')
1531
- .set('x-auth-token', 'U=error_dummy_token')
1532
- .end(function(err, res){
1533
- expect(res).to.have.status(401);
1534
- done();
1535
- });
1536
- });
1537
- it('DELETE /v1/policy against no existent policy.', function(done){ // eslint-disable-line no-undef
1538
- var url = '/v1/policy/yrn:oohay:hogeservice::tenant0:policy:acr-policy';
1539
- chai.request(app)
1540
- .delete(url)
1541
- .set('content-type', 'application/json')
1542
- .set('x-auth-token', alltokens.scopedtoken.tenant0)
1543
- .end(function(err, res){
1544
- expect(res).to.have.status(204);
1545
- done();
1546
- });
1547
- });
1548
- it('DELETE /v1/policy tenant0\'s policy by tenant1', function(done){ // eslint-disable-line no-undef
1549
- var url = '/v1/policy/yrn:yahoo:::tenant0:policy:k2hr3_entest_str_pol_01';
1550
- chai.request(app)
1551
- .delete(url)
1552
- .set('content-type', 'application/json')
1553
- .set('x-auth-token', alltokens.scopedtoken.tenant1)
1554
- .end(function(err, res){
1555
- expect(res).to.have.status(204);
1556
- done();
1557
- });
1558
- });
1559
- it('DELETE /v1/policy with valid token.', function(done){ // eslint-disable-line no-undef
1560
- var url = '/v1/policy/yrn:yahoo:testservice::tenant0:policy:acr-policy';
1561
- chai.request(app)
1562
- .delete(url)
1563
- .set('content-type', 'application/json')
1564
- .set('x-auth-token', alltokens.scopedtoken.tenant0)
1565
- .end(function(err, res){
1566
- expect(res).to.have.status(204);
1567
- done();
1568
- });
1569
- });
1570
- });
1571
-
1572
- /*
1573
- * Local variables:
1574
- * tab-width: 4
1575
- * c-basic-offset: 4
1576
- * End:
1577
- * vim600: noexpandtab sw=4 ts=4 fdm=marker
1578
- * vim<600: noexpandtab sw=4 ts=4
1579
- */