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.
- package/config/k2hr3-init.sh.templ +4 -4
- package/dist/.gitkeep +0 -0
- package/dist/src/app.js +262 -0
- package/{bin → dist/src/bin}/run.sh +1 -1
- package/dist/src/bin/watcher.js +113 -0
- package/dist/src/bin/www.js +217 -0
- package/dist/src/lib/basicipcheck.js +392 -0
- package/dist/src/lib/cacerts.js +106 -0
- package/dist/src/lib/dbglogging.js +190 -0
- package/dist/src/lib/dummyuserapi.js +719 -0
- package/dist/src/lib/ipwatch.js +354 -0
- package/dist/src/lib/k2hr3acrutil.js +532 -0
- package/dist/src/lib/k2hr3apiutil.js +1444 -0
- package/dist/src/lib/k2hr3cliutil.js +183 -0
- package/dist/src/lib/k2hr3config.js +832 -0
- package/dist/src/lib/k2hr3cryptutil.js +258 -0
- package/dist/src/lib/k2hr3dkc.js +12121 -0
- package/dist/src/lib/k2hr3extdata.js +198 -0
- package/dist/src/lib/k2hr3keys.js +207 -0
- package/dist/src/lib/k2hr3resutil.js +111 -0
- package/dist/src/lib/k2hr3template.js +6546 -0
- package/dist/src/lib/k2hr3tokens.js +2643 -0
- package/dist/src/lib/k2hr3userdata.js +296 -0
- package/dist/src/lib/k8soidc.js +1000 -0
- package/dist/src/lib/openstackapiv2.js +695 -0
- package/dist/src/lib/openstackapiv3.js +932 -0
- package/dist/src/lib/openstackep.js +667 -0
- package/{tests/auto_common.js → dist/src/lib/types.js} +4 -38
- package/dist/src/routes/acr.js +704 -0
- package/dist/src/routes/debugVerify.js +294 -0
- package/dist/src/routes/extdata.js +219 -0
- package/dist/src/routes/list.js +264 -0
- package/dist/src/routes/policy.js +840 -0
- package/dist/src/routes/resource.js +1489 -0
- package/dist/src/routes/role.js +2627 -0
- package/dist/src/routes/service.js +908 -0
- package/dist/src/routes/tenant.js +1141 -0
- package/dist/src/routes/userTokens.js +482 -0
- package/dist/src/routes/userdata.js +212 -0
- package/dist/src/routes/version.js +103 -0
- package/package.json +152 -121
- package/ChangeLog +0 -378
- package/app.js +0 -292
- package/bin/watcher +0 -122
- package/bin/www +0 -180
- package/eslint.config.mjs +0 -68
- package/lib/basicipcheck.js +0 -376
- package/lib/cacerts.js +0 -71
- package/lib/dbglogging.js +0 -151
- package/lib/dummyuserapi.js +0 -766
- package/lib/ipwatch.js +0 -379
- package/lib/k2hr3acrutil.js +0 -516
- package/lib/k2hr3apiutil.js +0 -1494
- package/lib/k2hr3cliutil.js +0 -191
- package/lib/k2hr3config.js +0 -826
- package/lib/k2hr3cryptutil.js +0 -254
- package/lib/k2hr3dkc.js +0 -12632
- package/lib/k2hr3extdata.js +0 -198
- package/lib/k2hr3keys.js +0 -234
- package/lib/k2hr3resutil.js +0 -100
- package/lib/k2hr3template.js +0 -6925
- package/lib/k2hr3tokens.js +0 -2799
- package/lib/k2hr3userdata.js +0 -312
- package/lib/k8soidc.js +0 -1012
- package/lib/openstackapiv2.js +0 -764
- package/lib/openstackapiv3.js +0 -1032
- package/lib/openstackep.js +0 -553
- package/routes/acr.js +0 -738
- package/routes/debugVerify.js +0 -263
- package/routes/extdata.js +0 -232
- package/routes/list.js +0 -270
- package/routes/policy.js +0 -869
- package/routes/resource.js +0 -1441
- package/routes/role.js +0 -2664
- package/routes/service.js +0 -894
- package/routes/tenant.js +0 -1095
- package/routes/userTokens.js +0 -511
- package/routes/userdata.js +0 -218
- package/routes/version.js +0 -108
- package/templ/Dockerfile.templ +0 -71
- package/tests/auto_acr.js +0 -1101
- package/tests/auto_acr_spec.js +0 -79
- package/tests/auto_all_spec.js +0 -142
- package/tests/auto_control_subprocess.sh +0 -243
- package/tests/auto_extdata.js +0 -220
- package/tests/auto_extdata_spec.js +0 -79
- package/tests/auto_init_config_json.sh +0 -275
- package/tests/auto_k2hdkc_server.ini +0 -109
- package/tests/auto_k2hdkc_slave.ini +0 -83
- package/tests/auto_list.js +0 -439
- package/tests/auto_list_spec.js +0 -79
- package/tests/auto_policy.js +0 -1579
- package/tests/auto_policy_spec.js +0 -79
- package/tests/auto_resource.js +0 -10956
- package/tests/auto_resource_spec.js +0 -79
- package/tests/auto_role.js +0 -6150
- package/tests/auto_role_spec.js +0 -79
- package/tests/auto_service.js +0 -770
- package/tests/auto_service_spec.js +0 -79
- package/tests/auto_subprocesses.js +0 -114
- package/tests/auto_template.sh +0 -126
- package/tests/auto_tenant.js +0 -1100
- package/tests/auto_tenant_spec.js +0 -79
- package/tests/auto_token_util.js +0 -219
- package/tests/auto_userdata.js +0 -292
- package/tests/auto_userdata_spec.js +0 -79
- package/tests/auto_usertokens.js +0 -565
- package/tests/auto_usertokens_spec.js +0 -79
- package/tests/auto_version.js +0 -127
- package/tests/auto_version_spec.js +0 -79
- package/tests/auto_watcher.js +0 -157
- package/tests/auto_watcher_spec.js +0 -79
- package/tests/k2hdkc_test.data +0 -986
- package/tests/k2hdkc_test_load.sh +0 -255
- package/tests/k2hr3template_test.js +0 -187
- package/tests/k2hr3template_test.sh +0 -339
- package/tests/k2hr3template_test_async.js +0 -216
- package/tests/k2hr3template_test_template.result +0 -7117
- package/tests/k2hr3template_test_template.txt +0 -3608
- package/tests/k2hr3template_test_vars.js +0 -194
- package/tests/manual_acr_delete.js +0 -143
- package/tests/manual_acr_get.js +0 -297
- package/tests/manual_acr_postput.js +0 -215
- package/tests/manual_allusertenant_get.js +0 -113
- package/tests/manual_extdata_get.js +0 -191
- package/tests/manual_k2hr3keys_get.js +0 -84
- package/tests/manual_list_gethead.js +0 -230
- package/tests/manual_policy_delete.js +0 -132
- package/tests/manual_policy_gethead.js +0 -275
- package/tests/manual_policy_postput.js +0 -297
- package/tests/manual_resource_delete.js +0 -433
- package/tests/manual_resource_gethead.js +0 -423
- package/tests/manual_resource_postput.js +0 -487
- package/tests/manual_role_delete.js +0 -404
- package/tests/manual_role_gethead.js +0 -547
- package/tests/manual_role_postput.js +0 -544
- package/tests/manual_service_delete.js +0 -153
- package/tests/manual_service_gethead.js +0 -178
- package/tests/manual_service_postput.js +0 -348
- package/tests/manual_tenant_delete.js +0 -186
- package/tests/manual_tenant_gethead.js +0 -268
- package/tests/manual_tenant_postput.js +0 -293
- package/tests/manual_test.sh +0 -352
- package/tests/manual_userdata_get.js +0 -173
- package/tests/manual_usertoken_gethead.js +0 -136
- package/tests/manual_usertoken_postput.js +0 -310
- package/tests/manual_version_get.js +0 -127
- package/tests/run_local_test_k2hdkc.sh +0 -174
- package/tests/test.sh +0 -333
package/tests/auto_usertokens.js
DELETED
|
@@ -1,565 +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: Mon Dec 25 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
|
-
|
|
30
|
-
//--------------------------------------------------------------
|
|
31
|
-
// Main describe section
|
|
32
|
-
//--------------------------------------------------------------
|
|
33
|
-
describe('API : USER TOKEN', function(){ // eslint-disable-line no-undef
|
|
34
|
-
//
|
|
35
|
-
// Common data
|
|
36
|
-
//
|
|
37
|
-
let unscopedToken = '';
|
|
38
|
-
let scopedToken = '';
|
|
39
|
-
|
|
40
|
-
//
|
|
41
|
-
// Before in describe section
|
|
42
|
-
//
|
|
43
|
-
before(function(){ // eslint-disable-line no-undef
|
|
44
|
-
// Nothing to do
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
//
|
|
48
|
-
// After in describe section
|
|
49
|
-
//
|
|
50
|
-
after(function(){ // eslint-disable-line no-undef
|
|
51
|
-
// Nothing to do
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
//
|
|
55
|
-
// Run Test(POST - SUCCESS)
|
|
56
|
-
//
|
|
57
|
-
it('POST /v1/user/tokens : unscoped token by user credential(no tenant) with status 201', function(done){ // eslint-disable-line no-undef
|
|
58
|
-
chai.request(app)
|
|
59
|
-
.post('/v1/user/tokens')
|
|
60
|
-
.set('content-type', 'application/json')
|
|
61
|
-
.send({
|
|
62
|
-
auth: {
|
|
63
|
-
tenantName: null,
|
|
64
|
-
passwordCredentials: {
|
|
65
|
-
username: 'dummyuser',
|
|
66
|
-
password: null
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
})
|
|
70
|
-
.end(function(err, res){
|
|
71
|
-
expect(res).to.have.status(201);
|
|
72
|
-
expect(res).to.be.json;
|
|
73
|
-
expect(res.body).to.be.an('object');
|
|
74
|
-
expect(res.body.result).to.be.a('boolean').to.be.true;
|
|
75
|
-
expect(res.body.message).to.be.a('string').to.equal('succeed');
|
|
76
|
-
expect(res.body.scoped).to.be.a('boolean').to.be.false;
|
|
77
|
-
expect(res.body.token).to.be.a('string').is.not.empty;
|
|
78
|
-
|
|
79
|
-
unscopedToken = 'U=' + res.body.token;
|
|
80
|
-
done();
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it('POST /v1/user/tokens : scoped token by user credential(and tenant) with status 201', function(done){ // eslint-disable-line no-undef
|
|
85
|
-
chai.request(app)
|
|
86
|
-
.post('/v1/user/tokens')
|
|
87
|
-
.set('content-type', 'application/json')
|
|
88
|
-
.send({
|
|
89
|
-
auth: {
|
|
90
|
-
tenantName: 'tenant0',
|
|
91
|
-
passwordCredentials: {
|
|
92
|
-
username: 'dummyuser',
|
|
93
|
-
password: null
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
})
|
|
97
|
-
.end(function(err, res){
|
|
98
|
-
expect(res).to.have.status(201);
|
|
99
|
-
expect(res).to.be.json;
|
|
100
|
-
expect(res.body).to.be.an('object');
|
|
101
|
-
expect(res.body.result).to.be.a('boolean').to.be.true;
|
|
102
|
-
expect(res.body.message).to.be.a('string').to.equal('succeed');
|
|
103
|
-
expect(res.body.scoped).to.be.a('boolean').to.be.true;
|
|
104
|
-
expect(res.body.token).to.be.a('string').is.not.empty;
|
|
105
|
-
|
|
106
|
-
scopedToken = 'U=' + res.body.token;
|
|
107
|
-
done();
|
|
108
|
-
});
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
it('POST /v1/user/tokens : scoped token by unscoped token with status 201', function(done){ // eslint-disable-line no-undef
|
|
112
|
-
chai.request(app)
|
|
113
|
-
.post('/v1/user/tokens')
|
|
114
|
-
.set('content-type', 'application/json')
|
|
115
|
-
.set('x-auth-token', unscopedToken)
|
|
116
|
-
.send({
|
|
117
|
-
auth: {
|
|
118
|
-
tenantName: 'tenant0'
|
|
119
|
-
}
|
|
120
|
-
})
|
|
121
|
-
.end(function(err, res){
|
|
122
|
-
expect(res).to.have.status(201);
|
|
123
|
-
expect(res).to.be.json;
|
|
124
|
-
expect(res.body).to.be.an('object');
|
|
125
|
-
expect(res.body.result).to.be.a('boolean').to.be.true;
|
|
126
|
-
expect(res.body.message).to.be.a('string').to.equal('succeed');
|
|
127
|
-
expect(res.body.scoped).to.be.a('boolean').to.be.true;
|
|
128
|
-
expect(res.body.token).to.be.a('string').is.not.empty;
|
|
129
|
-
|
|
130
|
-
scopedToken = 'U=' + res.body.token;
|
|
131
|
-
done();
|
|
132
|
-
});
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
//
|
|
137
|
-
// Run Test(POST - FAILURE)
|
|
138
|
-
//
|
|
139
|
-
it('POST /v1/user/tokens : failure unscoped token by invalid user credential(no tenant) with status 400', function(done){ // eslint-disable-line no-undef
|
|
140
|
-
chai.request(app)
|
|
141
|
-
.post('/v1/user/tokens')
|
|
142
|
-
.set('content-type', 'application/json')
|
|
143
|
-
.send({
|
|
144
|
-
auth: {
|
|
145
|
-
tenantName: null,
|
|
146
|
-
passwordCredentials: {
|
|
147
|
-
username: null, // any string for user name is allowed, then set null.
|
|
148
|
-
password: null
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
})
|
|
152
|
-
.end(function(err, res){
|
|
153
|
-
expect(res).to.have.status(400);
|
|
154
|
-
expect(res).to.be.json;
|
|
155
|
-
expect(res.body).to.be.an('object');
|
|
156
|
-
expect(res.body.result).to.be.a('boolean').to.be.false;
|
|
157
|
-
expect(res.body.message).to.be.a('string').to.equal('Some parameter(user name or unscoped token) is wrong.');
|
|
158
|
-
|
|
159
|
-
done();
|
|
160
|
-
});
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
it('POST /v1/user/tokens : failure scoped token by invalid user credential(and tenant) with status 400', function(done){ // eslint-disable-line no-undef
|
|
164
|
-
chai.request(app)
|
|
165
|
-
.post('/v1/user/tokens')
|
|
166
|
-
.set('content-type', 'application/json')
|
|
167
|
-
.send({
|
|
168
|
-
auth: {
|
|
169
|
-
tenantName: 'tenant0',
|
|
170
|
-
passwordCredentials: {
|
|
171
|
-
username: null, // any string for user name is allowed, then set null.
|
|
172
|
-
password: null
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
})
|
|
176
|
-
.end(function(err, res){
|
|
177
|
-
expect(res).to.have.status(400);
|
|
178
|
-
expect(res).to.be.json;
|
|
179
|
-
expect(res.body).to.be.an('object');
|
|
180
|
-
expect(res.body.result).to.be.a('boolean').to.be.false;
|
|
181
|
-
expect(res.body.message).to.be.a('string').to.equal('Some parameter(user name or unscoped token) is wrong.');
|
|
182
|
-
|
|
183
|
-
done();
|
|
184
|
-
});
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
it('POST /v1/user/tokens : failure scoped token by user credential(and invalid tenant) with status 404', function(done){ // eslint-disable-line no-undef
|
|
188
|
-
chai.request(app)
|
|
189
|
-
.post('/v1/user/tokens')
|
|
190
|
-
.set('content-type', 'application/json')
|
|
191
|
-
.send({
|
|
192
|
-
auth: {
|
|
193
|
-
tenantName: 'tenantERROR',
|
|
194
|
-
passwordCredentials: {
|
|
195
|
-
username: 'dummyuser',
|
|
196
|
-
password: null
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
})
|
|
200
|
-
.end(function(err, res){
|
|
201
|
-
expect(res).to.have.status(404);
|
|
202
|
-
expect(res).to.be.json;
|
|
203
|
-
expect(res.body).to.be.an('object');
|
|
204
|
-
expect(res.body.result).to.be.a('boolean').to.be.false;
|
|
205
|
-
expect(res.body.message).to.be.a('string').to.have.string('could not get scoped user token for user=dummyuser, tenant=tenantERROR by could not get scoped user token for user dummyuser by some parameters are wrong : token=');
|
|
206
|
-
|
|
207
|
-
done();
|
|
208
|
-
});
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
it('POST /v1/user/tokens : failure scoped token by invalid unscoped token with status 404', function(done){ // eslint-disable-line no-undef
|
|
212
|
-
chai.request(app)
|
|
213
|
-
.post('/v1/user/tokens')
|
|
214
|
-
.set('content-type', 'application/json')
|
|
215
|
-
.set('x-auth-token', 'error_dummy_token')
|
|
216
|
-
.send({
|
|
217
|
-
auth: {
|
|
218
|
-
tenantName: 'tenant0'
|
|
219
|
-
}
|
|
220
|
-
})
|
|
221
|
-
.end(function(err, res){
|
|
222
|
-
expect(res).to.have.status(404);
|
|
223
|
-
expect(res).to.be.json;
|
|
224
|
-
expect(res.body).to.be.an('object');
|
|
225
|
-
expect(res.body.result).to.be.a('boolean').to.be.false;
|
|
226
|
-
expect(res.body.message).to.be.a('string').to.equal('could not get scoped user token for other token, tenant=tenant0 by could not get user access token by could not get user access token by getUserUnscopedTokenByToken is not implemented');
|
|
227
|
-
|
|
228
|
-
done();
|
|
229
|
-
});
|
|
230
|
-
});
|
|
231
|
-
|
|
232
|
-
it('POST /v1/user/tokens : failure scoped token by invalid tenant name and unscoped token with status 404', function(done){ // eslint-disable-line no-undef
|
|
233
|
-
chai.request(app)
|
|
234
|
-
.post('/v1/user/tokens')
|
|
235
|
-
.set('content-type', 'application/json')
|
|
236
|
-
.set('x-auth-token', unscopedToken)
|
|
237
|
-
.send({
|
|
238
|
-
auth: {
|
|
239
|
-
tenantName: 'tenantERROR'
|
|
240
|
-
}
|
|
241
|
-
})
|
|
242
|
-
.end(function(err, res){
|
|
243
|
-
expect(res).to.have.status(404);
|
|
244
|
-
expect(res).to.be.json;
|
|
245
|
-
expect(res.body).to.be.an('object');
|
|
246
|
-
expect(res.body.result).to.be.a('boolean').to.be.false;
|
|
247
|
-
expect(res.body.message).to.be.a('string').to.have.string('could not get scoped user token for user=dummyuser, tenant=tenantERROR by could not get scoped user token for user dummyuser by some parameters are wrong : token=');
|
|
248
|
-
|
|
249
|
-
done();
|
|
250
|
-
});
|
|
251
|
-
});
|
|
252
|
-
|
|
253
|
-
//
|
|
254
|
-
// Run Test(PUT - SUCCESS)
|
|
255
|
-
//
|
|
256
|
-
it('PUT /v1/user/tokens : unscoped token by user credential(no tenant) with status 201', function(done){ // eslint-disable-line no-undef
|
|
257
|
-
let url = '/v1/user/tokens';
|
|
258
|
-
url += '?tenantname=';
|
|
259
|
-
url += '&username=dummyuser';
|
|
260
|
-
url += '&password=';
|
|
261
|
-
chai.request(app)
|
|
262
|
-
.put(url)
|
|
263
|
-
.set('content-type', 'application/json')
|
|
264
|
-
.end(function(err, res){
|
|
265
|
-
expect(res).to.have.status(201);
|
|
266
|
-
expect(res).to.be.json;
|
|
267
|
-
expect(res.body).to.be.an('object');
|
|
268
|
-
expect(res.body.result).to.be.a('boolean').to.be.true;
|
|
269
|
-
expect(res.body.message).to.be.a('string').to.equal('succeed');
|
|
270
|
-
expect(res.body.scoped).to.be.a('boolean').to.be.false;
|
|
271
|
-
expect(res.body.token).to.be.a('string').is.not.empty;
|
|
272
|
-
|
|
273
|
-
unscopedToken = 'U=' + res.body.token;
|
|
274
|
-
done();
|
|
275
|
-
});
|
|
276
|
-
});
|
|
277
|
-
|
|
278
|
-
it('PUT /v1/user/tokens : scoped token by user credential(and tenant) with status 201', function(done){ // eslint-disable-line no-undef
|
|
279
|
-
let url = '/v1/user/tokens';
|
|
280
|
-
url += '?tenantname=tenant0';
|
|
281
|
-
url += '&username=dummyuser';
|
|
282
|
-
url += '&password=';
|
|
283
|
-
chai.request(app)
|
|
284
|
-
.put(url)
|
|
285
|
-
.set('content-type', 'application/json')
|
|
286
|
-
.end(function(err, res){
|
|
287
|
-
expect(res).to.have.status(201);
|
|
288
|
-
expect(res).to.be.json;
|
|
289
|
-
expect(res.body).to.be.an('object');
|
|
290
|
-
expect(res.body.result).to.be.a('boolean').to.be.true;
|
|
291
|
-
expect(res.body.message).to.be.a('string').to.equal('succeed');
|
|
292
|
-
expect(res.body.scoped).to.be.a('boolean').to.be.true;
|
|
293
|
-
expect(res.body.token).to.be.a('string').is.not.empty;
|
|
294
|
-
|
|
295
|
-
scopedToken = 'U=' + res.body.token;
|
|
296
|
-
done();
|
|
297
|
-
});
|
|
298
|
-
});
|
|
299
|
-
|
|
300
|
-
it('PUT /v1/user/tokens : scoped token by unscoped token with status 201', function(done){ // eslint-disable-line no-undef
|
|
301
|
-
let url = '/v1/user/tokens';
|
|
302
|
-
url += '?tenantname=tenant0';
|
|
303
|
-
chai.request(app)
|
|
304
|
-
.put(url)
|
|
305
|
-
.set('content-type', 'application/json')
|
|
306
|
-
.set('x-auth-token', unscopedToken)
|
|
307
|
-
.end(function(err, res){
|
|
308
|
-
expect(res).to.have.status(201);
|
|
309
|
-
expect(res).to.be.json;
|
|
310
|
-
expect(res.body).to.be.an('object');
|
|
311
|
-
expect(res.body.result).to.be.a('boolean').to.be.true;
|
|
312
|
-
expect(res.body.message).to.be.a('string').to.equal('succeed');
|
|
313
|
-
expect(res.body.scoped).to.be.a('boolean').to.be.true;
|
|
314
|
-
expect(res.body.token).to.be.a('string').is.not.empty;
|
|
315
|
-
|
|
316
|
-
scopedToken = 'U=' + res.body.token;
|
|
317
|
-
done();
|
|
318
|
-
});
|
|
319
|
-
});
|
|
320
|
-
|
|
321
|
-
//
|
|
322
|
-
// Run Test(PUT - FAILURE)
|
|
323
|
-
//
|
|
324
|
-
it('PUT /v1/user/tokens : failure unscoped token by invalid user credential(no tenant) with status 400', function(done){ // eslint-disable-line no-undef
|
|
325
|
-
let url = '/v1/user/tokens';
|
|
326
|
-
url += '?tenantname=';
|
|
327
|
-
url += '&username='; // any string for user name is allowed, then set null.
|
|
328
|
-
url += '&password=';
|
|
329
|
-
chai.request(app)
|
|
330
|
-
.put(url)
|
|
331
|
-
.set('content-type', 'application/json')
|
|
332
|
-
.end(function(err, res){
|
|
333
|
-
expect(res).to.have.status(400);
|
|
334
|
-
expect(res).to.be.json;
|
|
335
|
-
expect(res.body).to.be.an('object');
|
|
336
|
-
expect(res.body.result).to.be.a('boolean').to.be.false;
|
|
337
|
-
expect(res.body.message).to.be.a('string').to.equal('There is no x-auth-token header');
|
|
338
|
-
|
|
339
|
-
done();
|
|
340
|
-
});
|
|
341
|
-
});
|
|
342
|
-
|
|
343
|
-
it('PUT /v1/user/tokens : failure scoped token by invalid user credential(and tenant) with status 400', function(done){ // eslint-disable-line no-undef
|
|
344
|
-
let url = '/v1/user/tokens';
|
|
345
|
-
url += '?tenantname=tenant0';
|
|
346
|
-
url += '&username='; // any string for user name is allowed, then set null.
|
|
347
|
-
url += '&password=';
|
|
348
|
-
chai.request(app)
|
|
349
|
-
.put(url)
|
|
350
|
-
.set('content-type', 'application/json')
|
|
351
|
-
.end(function(err, res){
|
|
352
|
-
expect(res).to.have.status(400);
|
|
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.false;
|
|
356
|
-
expect(res.body.message).to.be.a('string').to.equal('There is no x-auth-token header');
|
|
357
|
-
|
|
358
|
-
done();
|
|
359
|
-
});
|
|
360
|
-
});
|
|
361
|
-
|
|
362
|
-
it('PUT /v1/user/tokens : failure scoped token by user credential(and invalid tenant) with status 404', function(done){ // eslint-disable-line no-undef
|
|
363
|
-
let url = '/v1/user/tokens';
|
|
364
|
-
url += '?tenantname=tenantERROR';
|
|
365
|
-
url += '&username=dummyuser';
|
|
366
|
-
url += '&password=';
|
|
367
|
-
chai.request(app)
|
|
368
|
-
.put(url)
|
|
369
|
-
.set('content-type', 'application/json')
|
|
370
|
-
.end(function(err, res){
|
|
371
|
-
expect(res).to.have.status(404);
|
|
372
|
-
expect(res).to.be.json;
|
|
373
|
-
expect(res.body).to.be.an('object');
|
|
374
|
-
expect(res.body.result).to.be.a('boolean').to.be.false;
|
|
375
|
-
expect(res.body.message).to.be.a('string').to.have.string('could not get scoped user token for user=dummyuser, tenant=tenantERROR by could not get scoped user token for user dummyuser by some parameters are wrong : token=');
|
|
376
|
-
|
|
377
|
-
done();
|
|
378
|
-
});
|
|
379
|
-
});
|
|
380
|
-
|
|
381
|
-
it('PUT /v1/user/tokens : failure scoped token by invalid unscoped token with status 404', function(done){ // eslint-disable-line no-undef
|
|
382
|
-
let url = '/v1/user/tokens';
|
|
383
|
-
url += '?tenantname=tenant0';
|
|
384
|
-
chai.request(app)
|
|
385
|
-
.put(url)
|
|
386
|
-
.set('content-type', 'application/json')
|
|
387
|
-
.set('x-auth-token', 'error_dummy_token')
|
|
388
|
-
.end(function(err, res){
|
|
389
|
-
expect(res).to.have.status(404);
|
|
390
|
-
expect(res).to.be.json;
|
|
391
|
-
expect(res.body).to.be.an('object');
|
|
392
|
-
expect(res.body.result).to.be.a('boolean').to.be.false;
|
|
393
|
-
expect(res.body.message).to.be.a('string').to.equal('could not get scoped user token for other token, tenant=tenant0 by could not get user access token by could not get user access token by getUserUnscopedTokenByToken is not implemented');
|
|
394
|
-
|
|
395
|
-
done();
|
|
396
|
-
});
|
|
397
|
-
});
|
|
398
|
-
|
|
399
|
-
it('PUT /v1/user/tokens : failure scoped token by invalid tenant name and unscoped token with status 404', function(done){ // eslint-disable-line no-undef
|
|
400
|
-
let url = '/v1/user/tokens';
|
|
401
|
-
url += '?tenantname=tenantERROR';
|
|
402
|
-
chai.request(app)
|
|
403
|
-
.put(url)
|
|
404
|
-
.set('content-type', 'application/json')
|
|
405
|
-
.set('x-auth-token', unscopedToken)
|
|
406
|
-
.end(function(err, res){
|
|
407
|
-
expect(res).to.have.status(404);
|
|
408
|
-
expect(res).to.be.json;
|
|
409
|
-
expect(res.body).to.be.an('object');
|
|
410
|
-
expect(res.body.result).to.be.a('boolean').to.be.false;
|
|
411
|
-
expect(res.body.message).to.be.a('string').to.have.string('could not get scoped user token for user=dummyuser, tenant=tenantERROR by could not get scoped user token for user dummyuser by some parameters are wrong : token=');
|
|
412
|
-
|
|
413
|
-
done();
|
|
414
|
-
});
|
|
415
|
-
});
|
|
416
|
-
|
|
417
|
-
//
|
|
418
|
-
// Run Test(GET - SUCCESS)
|
|
419
|
-
//
|
|
420
|
-
it('GET /v1/user/tokens : tenant list by unscoped token with status 200', function(done){ // eslint-disable-line no-undef
|
|
421
|
-
chai.request(app)
|
|
422
|
-
.get('/v1/user/tokens')
|
|
423
|
-
.set('content-type', 'application/json')
|
|
424
|
-
.set('x-auth-token', unscopedToken)
|
|
425
|
-
.end(function(err, res){
|
|
426
|
-
expect(res).to.have.status(200);
|
|
427
|
-
expect(res).to.be.json;
|
|
428
|
-
expect(res.body).to.be.an('object');
|
|
429
|
-
expect(res.body.result).to.be.a('boolean').to.be.true;
|
|
430
|
-
expect(res.body.message).to.be.a('string').to.equal('succeed');
|
|
431
|
-
expect(res.body.scoped).to.be.a('boolean').to.be.false;
|
|
432
|
-
expect(res.body.user).to.be.a('string').to.equal('dummyuser');
|
|
433
|
-
expect(res.body.tenants).to.be.an.instanceof(Array).to.have.lengthOf(5);
|
|
434
|
-
expect(res.body.tenants[0]).to.deep.equal({name: 'tenant0', id: '1000', description: 'dummy tenant no.0', display: 'dummy_tenant_0'});
|
|
435
|
-
expect(res.body.tenants[1]).to.deep.equal({name: 'tenant1', id: '1001', description: 'dummy tenant no.1', display: 'dummy_tenant_1'});
|
|
436
|
-
expect(res.body.tenants[2]).to.deep.equal({name: 'tenant2', id: '1002', description: 'dummy tenant no.2', display: 'dummy_tenant_2'});
|
|
437
|
-
expect(res.body.tenants[3]).to.deep.equal({name: 'tenant3', id: '1003', description: 'dummy tenant no.3', display: 'dummy_tenant_3'});
|
|
438
|
-
expect(res.body.tenants[4]).to.deep.equal({name: 'tenant4', id: '1004', description: 'dummy tenant no.4', display: 'dummy_tenant_4'});
|
|
439
|
-
|
|
440
|
-
done();
|
|
441
|
-
});
|
|
442
|
-
});
|
|
443
|
-
|
|
444
|
-
it('GET /v1/user/tokens : tenant list by scoped token with status 200', function(done){ // eslint-disable-line no-undef
|
|
445
|
-
chai.request(app)
|
|
446
|
-
.get('/v1/user/tokens')
|
|
447
|
-
.set('content-type', 'application/json')
|
|
448
|
-
.set('x-auth-token', scopedToken)
|
|
449
|
-
.end(function(err, res){
|
|
450
|
-
expect(res).to.have.status(200);
|
|
451
|
-
expect(res).to.be.json;
|
|
452
|
-
expect(res.body).to.be.an('object');
|
|
453
|
-
expect(res.body.result).to.be.a('boolean').to.be.true;
|
|
454
|
-
expect(res.body.message).to.be.a('string').to.equal('succeed');
|
|
455
|
-
expect(res.body.scoped).to.be.a('boolean').to.be.true;
|
|
456
|
-
expect(res.body.user).to.be.a('string').to.equal('dummyuser');
|
|
457
|
-
expect(res.body.tenants).to.be.an.instanceof(Array).to.have.lengthOf(1);
|
|
458
|
-
expect(res.body.tenants[0]).to.deep.equal({name: 'tenant0', id: '1000', description: 'dummy tenant no.0', display: 'dummy_tenant_0'});
|
|
459
|
-
|
|
460
|
-
done();
|
|
461
|
-
});
|
|
462
|
-
});
|
|
463
|
-
|
|
464
|
-
//
|
|
465
|
-
// Run Test(GET - FAILURE)
|
|
466
|
-
//
|
|
467
|
-
it('GET /v1/user/tokens : failure tenant list by invalid unscoped token with status 401', function(done){ // eslint-disable-line no-undef
|
|
468
|
-
chai.request(app)
|
|
469
|
-
.get('/v1/user/tokens')
|
|
470
|
-
.set('content-type', 'application/json')
|
|
471
|
-
.set('x-auth-token', 'error_dummy_token')
|
|
472
|
-
.end(function(err, res){
|
|
473
|
-
expect(res).to.have.status(401);
|
|
474
|
-
expect(res).to.be.json;
|
|
475
|
-
expect(res.body).to.be.an('object');
|
|
476
|
-
expect(res.body.result).to.be.a('boolean').to.be.false;
|
|
477
|
-
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.');
|
|
478
|
-
|
|
479
|
-
done();
|
|
480
|
-
});
|
|
481
|
-
});
|
|
482
|
-
|
|
483
|
-
it('GET /v1/user/tokens : failure tenant list by invalid scoped token with status 401', function(done){ // eslint-disable-line no-undef
|
|
484
|
-
chai.request(app)
|
|
485
|
-
.get('/v1/user/tokens')
|
|
486
|
-
.set('content-type', 'application/json')
|
|
487
|
-
.set('x-auth-token', 'error_dummy_token')
|
|
488
|
-
.end(function(err, res){
|
|
489
|
-
expect(res).to.have.status(401);
|
|
490
|
-
expect(res).to.be.json;
|
|
491
|
-
expect(res.body).to.be.an('object');
|
|
492
|
-
expect(res.body.result).to.be.a('boolean').to.be.false;
|
|
493
|
-
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.');
|
|
494
|
-
|
|
495
|
-
done();
|
|
496
|
-
});
|
|
497
|
-
});
|
|
498
|
-
|
|
499
|
-
//
|
|
500
|
-
// Run Test(HEAD - SUCCESS)
|
|
501
|
-
//
|
|
502
|
-
it('HEAD /v1/user/tokens : tenant list by unscoped token with status 204', function(done){ // eslint-disable-line no-undef
|
|
503
|
-
chai.request(app)
|
|
504
|
-
.head('/v1/user/tokens')
|
|
505
|
-
.set('content-type', 'application/json')
|
|
506
|
-
.set('x-auth-token', unscopedToken)
|
|
507
|
-
.end(function(err, res){
|
|
508
|
-
expect(res).to.have.status(204);
|
|
509
|
-
expect(res.body).to.be.empty;
|
|
510
|
-
|
|
511
|
-
done();
|
|
512
|
-
});
|
|
513
|
-
});
|
|
514
|
-
|
|
515
|
-
it('HEAD /v1/user/tokens : tenant list by scoped token with status 204', function(done){ // eslint-disable-line no-undef
|
|
516
|
-
chai.request(app)
|
|
517
|
-
.head('/v1/user/tokens')
|
|
518
|
-
.set('content-type', 'application/json')
|
|
519
|
-
.set('x-auth-token', scopedToken)
|
|
520
|
-
.end(function(err, res){
|
|
521
|
-
expect(res).to.have.status(204);
|
|
522
|
-
expect(res.body).to.be.empty;
|
|
523
|
-
|
|
524
|
-
done();
|
|
525
|
-
});
|
|
526
|
-
});
|
|
527
|
-
|
|
528
|
-
//
|
|
529
|
-
// Run Test(HEAD - FAILURE)
|
|
530
|
-
//
|
|
531
|
-
it('HEAD /v1/user/tokens : failure tenant list by invalid unscoped token with status 401', function(done){ // eslint-disable-line no-undef
|
|
532
|
-
chai.request(app)
|
|
533
|
-
.head('/v1/user/tokens')
|
|
534
|
-
.set('content-type', 'application/json')
|
|
535
|
-
.set('x-auth-token', 'error_dummy_token')
|
|
536
|
-
.end(function(err, res){
|
|
537
|
-
expect(res).to.have.status(401);
|
|
538
|
-
expect(res.body).to.be.empty;
|
|
539
|
-
|
|
540
|
-
done();
|
|
541
|
-
});
|
|
542
|
-
});
|
|
543
|
-
|
|
544
|
-
it('HEAD /v1/user/tokens : failure tenant list by invalid scoped token with status 401', function(done){ // eslint-disable-line no-undef
|
|
545
|
-
chai.request(app)
|
|
546
|
-
.head('/v1/user/tokens')
|
|
547
|
-
.set('content-type', 'application/json')
|
|
548
|
-
.set('x-auth-token', 'error_dummy_token')
|
|
549
|
-
.end(function(err, res){
|
|
550
|
-
expect(res).to.have.status(401);
|
|
551
|
-
expect(res.body).to.be.empty;
|
|
552
|
-
|
|
553
|
-
done();
|
|
554
|
-
});
|
|
555
|
-
});
|
|
556
|
-
});
|
|
557
|
-
|
|
558
|
-
/*
|
|
559
|
-
* Local variables:
|
|
560
|
-
* tab-width: 4
|
|
561
|
-
* c-basic-offset: 4
|
|
562
|
-
* End:
|
|
563
|
-
* vim600: noexpandtab sw=4 ts=4 fdm=marker
|
|
564
|
-
* vim<600: noexpandtab sw=4 ts=4
|
|
565
|
-
*/
|
|
@@ -1,79 +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: Mon Dec 25 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; // eslint-disable-line no-unused-vars
|
|
25
|
-
var chaiHttp = common.chaiHttp; // eslint-disable-line no-unused-vars
|
|
26
|
-
var app = common.app; // eslint-disable-line no-unused-vars
|
|
27
|
-
var assert = common.assert; // eslint-disable-line no-unused-vars
|
|
28
|
-
var expect = common.expect; // eslint-disable-line no-unused-vars
|
|
29
|
-
var subproc = require('./auto_subprocesses');
|
|
30
|
-
|
|
31
|
-
//--------------------------------------------------------------
|
|
32
|
-
// Before in global section
|
|
33
|
-
//--------------------------------------------------------------
|
|
34
|
-
before(function(){ // eslint-disable-line no-undef
|
|
35
|
-
//
|
|
36
|
-
// Start all sub processes
|
|
37
|
-
//
|
|
38
|
-
subproc.start(this);
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
//--------------------------------------------------------------
|
|
42
|
-
// After in global section
|
|
43
|
-
//--------------------------------------------------------------
|
|
44
|
-
after(function(){ // eslint-disable-line no-undef
|
|
45
|
-
//
|
|
46
|
-
// Stop all sub processes
|
|
47
|
-
//
|
|
48
|
-
subproc.stop(this);
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
//--------------------------------------------------------------
|
|
52
|
-
// BeforeEach in global section
|
|
53
|
-
//--------------------------------------------------------------
|
|
54
|
-
beforeEach(function(){ // eslint-disable-line no-undef
|
|
55
|
-
// Nothing to do
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
//--------------------------------------------------------------
|
|
59
|
-
// AfterEach in global section
|
|
60
|
-
//--------------------------------------------------------------
|
|
61
|
-
afterEach(function(){ // eslint-disable-line no-undef
|
|
62
|
-
// Nothing to do
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
//--------------------------------------------------------------
|
|
66
|
-
// Sub describe section
|
|
67
|
-
//--------------------------------------------------------------
|
|
68
|
-
describe('SUB API TEST: USER TOKEN', function(){ // eslint-disable-line no-undef
|
|
69
|
-
require('./auto_usertokens');
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
/*
|
|
73
|
-
* Local variables:
|
|
74
|
-
* tab-width: 4
|
|
75
|
-
* c-basic-offset: 4
|
|
76
|
-
* End:
|
|
77
|
-
* vim600: noexpandtab sw=4 ts=4 fdm=marker
|
|
78
|
-
* vim<600: noexpandtab sw=4 ts=4
|
|
79
|
-
*/
|