k2hr3-api 1.0.25 → 1.0.27
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/ChangeLog +12 -0
- package/lib/k2hr3dkc.js +230 -59
- package/lib/k2hr3tokens.js +94 -60
- package/package.json +5 -5
- package/routes/tenant.js +120 -39
- package/routes/userTokens.js +77 -126
- package/tests/auto_tenant.js +119 -8
- package/tests/auto_usertokens.js +6 -6
- package/tests/manual_tenant_delete.js +46 -12
package/tests/auto_tenant.js
CHANGED
|
@@ -604,8 +604,7 @@ describe('API : TENANT', function(){ // eslint-disable-line no-undef
|
|
|
604
604
|
expect(res).to.be.json;
|
|
605
605
|
expect(res.body).to.be.an('object');
|
|
606
606
|
expect(res.body.result).to.be.a('boolean').to.be.false;
|
|
607
|
-
expect(res.body.message).to.be.a('string').to.have.string('PUT request
|
|
608
|
-
|
|
607
|
+
expect(res.body.message).to.be.a('string').to.have.string('PUT request tenant(local@autotest_put_tenant_3) does not allow user(dummyuser).');
|
|
609
608
|
done();
|
|
610
609
|
});
|
|
611
610
|
});
|
|
@@ -904,9 +903,9 @@ describe('API : TENANT', function(){ // eslint-disable-line no-undef
|
|
|
904
903
|
});
|
|
905
904
|
|
|
906
905
|
//
|
|
907
|
-
// Run Test(DELETE - TENANT - SUCCESS/FAILURE)
|
|
906
|
+
// Run Test(DELETE - TENANT USER - SUCCESS/FAILURE)
|
|
908
907
|
//
|
|
909
|
-
it('DELETE /v1/tenant/<tenant> : delete tenant(autotest_put_tenant_0) : success
|
|
908
|
+
it('DELETE /v1/tenant/<tenant> : delete tenant user(autotest_put_tenant_0) : success 204', function(done){ // eslint-disable-line no-undef
|
|
910
909
|
var uri = '/v1/tenant/autotest_put_tenant_0'; // tenant name
|
|
911
910
|
uri += '?id=' + autotest_put_tenant_0_id; // correct id
|
|
912
911
|
|
|
@@ -921,7 +920,7 @@ describe('API : TENANT', function(){ // eslint-disable-line no-undef
|
|
|
921
920
|
});
|
|
922
921
|
});
|
|
923
922
|
|
|
924
|
-
it('DELETE /v1/tenant/<tenant> : delete tenant(local@autotest_put_tenant_1) : success
|
|
923
|
+
it('DELETE /v1/tenant/<tenant> : delete tenant user(local@autotest_put_tenant_1) : success 204', function(done){ // eslint-disable-line no-undef
|
|
925
924
|
var uri = '/v1/tenant/local@autotest_put_tenant_1'; // tenant name
|
|
926
925
|
uri += '?id=' + autotest_put_tenant_1_id; // correct id
|
|
927
926
|
|
|
@@ -936,7 +935,7 @@ describe('API : TENANT', function(){ // eslint-disable-line no-undef
|
|
|
936
935
|
});
|
|
937
936
|
});
|
|
938
937
|
|
|
939
|
-
it('DELETE /v1/tenant/<tenant> : delete tenant(autotest_post_tenant_0) : failure(no token) 400', function(done){
|
|
938
|
+
it('DELETE /v1/tenant/<tenant> : delete tenant user(autotest_post_tenant_0) : failure(no token) 400', function(done){ // eslint-disable-line no-undef
|
|
940
939
|
var uri = '/v1/tenant/autotest_post_tenant_0'; // tenant name
|
|
941
940
|
uri += '?id=' + autotest_post_tenant_0_id; // correct id
|
|
942
941
|
|
|
@@ -950,7 +949,7 @@ describe('API : TENANT', function(){ // eslint-disable-line no-undef
|
|
|
950
949
|
});
|
|
951
950
|
});
|
|
952
951
|
|
|
953
|
-
it('DELETE /v1/tenant/<tenant> : delete tenant(local@autotest_post_tenant_0) : failure(no token) 400', function(done){
|
|
952
|
+
it('DELETE /v1/tenant/<tenant> : delete tenant user(local@autotest_post_tenant_0) : failure(no token) 400', function(done){ // eslint-disable-line no-undef
|
|
954
953
|
var uri = '/v1/tenant/local@autotest_post_tenant_0'; // tenant name
|
|
955
954
|
uri += '?id=' + autotest_post_tenant_0_id; // correct id
|
|
956
955
|
|
|
@@ -964,7 +963,7 @@ describe('API : TENANT', function(){ // eslint-disable-line no-undef
|
|
|
964
963
|
});
|
|
965
964
|
});
|
|
966
965
|
|
|
967
|
-
it('DELETE /v1/tenant/<tenant> : delete tenant(autotest_post_tenant_X) : failure(no exist tenant) 400', function(done){ // eslint-disable-line no-undef
|
|
966
|
+
it('DELETE /v1/tenant/<tenant> : delete tenant user(autotest_post_tenant_X) : failure(no exist tenant) 400', function(done){ // eslint-disable-line no-undef
|
|
968
967
|
var uri = '/v1/tenant/autotest_post_tenant_X'; // not exist tenant name
|
|
969
968
|
uri += '?id=' + autotest_post_tenant_0_id; // wrong id
|
|
970
969
|
|
|
@@ -977,6 +976,118 @@ describe('API : TENANT', function(){ // eslint-disable-line no-undef
|
|
|
977
976
|
done();
|
|
978
977
|
});
|
|
979
978
|
});
|
|
979
|
+
|
|
980
|
+
//
|
|
981
|
+
// Run Test(DELETE - TENANT - SUCCESS/FAILURE)
|
|
982
|
+
//
|
|
983
|
+
it('DELETE /v1/tenant : delete tenant(autotest_post_tenant_0) : failure(no token) 400', function(done){ // eslint-disable-line no-undef
|
|
984
|
+
var uri = '/v1/tenant';
|
|
985
|
+
uri += '?tenant=autotest_post_tenant_0'; // tenant name
|
|
986
|
+
uri += '&id=' + autotest_post_tenant_0_id; // correct id
|
|
987
|
+
|
|
988
|
+
chai.request(app)
|
|
989
|
+
.delete(uri)
|
|
990
|
+
.set('content-type', 'application/json')
|
|
991
|
+
.end(function(err, res){
|
|
992
|
+
expect(res).to.have.status(400);
|
|
993
|
+
|
|
994
|
+
done();
|
|
995
|
+
});
|
|
996
|
+
});
|
|
997
|
+
|
|
998
|
+
it('DELETE /v1/tenant : delete tenant(local@autotest_post_tenant_0) : failure(no tenant) 400', function(done){ // eslint-disable-line no-undef
|
|
999
|
+
var uri = '/v1/tenant';
|
|
1000
|
+
uri += '?id=' + autotest_post_tenant_0_id; // correct id
|
|
1001
|
+
|
|
1002
|
+
chai.request(app)
|
|
1003
|
+
.delete(uri)
|
|
1004
|
+
.set('content-type', 'application/json')
|
|
1005
|
+
.set('x-auth-token', alltokens.unscopedtoken) // unscoped token
|
|
1006
|
+
.end(function(err, res){
|
|
1007
|
+
expect(res).to.have.status(400);
|
|
1008
|
+
|
|
1009
|
+
done();
|
|
1010
|
+
});
|
|
1011
|
+
});
|
|
1012
|
+
|
|
1013
|
+
it('DELETE /v1/tenant : delete tenant(local@autotest_post_tenant_0) : failure(no id) 400', function(done){ // eslint-disable-line no-undef
|
|
1014
|
+
var uri = '/v1/tenant';
|
|
1015
|
+
uri += '?tenant=autotest_post_tenant_0'; // tenant name
|
|
1016
|
+
|
|
1017
|
+
chai.request(app)
|
|
1018
|
+
.delete(uri)
|
|
1019
|
+
.set('content-type', 'application/json')
|
|
1020
|
+
.set('x-auth-token', alltokens.unscopedtoken) // unscoped token
|
|
1021
|
+
.end(function(err, res){
|
|
1022
|
+
expect(res).to.have.status(400);
|
|
1023
|
+
|
|
1024
|
+
done();
|
|
1025
|
+
});
|
|
1026
|
+
});
|
|
1027
|
+
|
|
1028
|
+
it('DELETE /v1/tenant : delete tenant(autotest_post_tenant_X) : failure(no exist tenant) 400', function(done){ // eslint-disable-line no-undef
|
|
1029
|
+
var uri = '/v1/tenant';
|
|
1030
|
+
uri += '?tenant=autotest_post_tenant_X'; // not exist tenant name
|
|
1031
|
+
uri += '&id=' + autotest_post_tenant_0_id; // id
|
|
1032
|
+
|
|
1033
|
+
chai.request(app)
|
|
1034
|
+
.delete(uri)
|
|
1035
|
+
.set('content-type', 'application/json')
|
|
1036
|
+
.set('x-auth-token', alltokens.unscopedtoken) // unscoped token
|
|
1037
|
+
.end(function(err, res){
|
|
1038
|
+
expect(res).to.have.status(400);
|
|
1039
|
+
|
|
1040
|
+
done();
|
|
1041
|
+
});
|
|
1042
|
+
});
|
|
1043
|
+
|
|
1044
|
+
it('DELETE /v1/tenant : delete tenant(autotest_post_tenant_X) : failure(wrong id) 400', function(done){ // eslint-disable-line no-undef
|
|
1045
|
+
var uri = '/v1/tenant';
|
|
1046
|
+
uri += '?tenant=autotest_post_tenant_0'; // tenant name
|
|
1047
|
+
uri += '&id=' + autotest_post_tenant_1_id; // wrong id
|
|
1048
|
+
|
|
1049
|
+
chai.request(app)
|
|
1050
|
+
.delete(uri)
|
|
1051
|
+
.set('content-type', 'application/json')
|
|
1052
|
+
.set('x-auth-token', alltokens.unscopedtoken) // unscoped token
|
|
1053
|
+
.end(function(err, res){
|
|
1054
|
+
expect(res).to.have.status(400);
|
|
1055
|
+
|
|
1056
|
+
done();
|
|
1057
|
+
});
|
|
1058
|
+
});
|
|
1059
|
+
|
|
1060
|
+
it('DELETE /v1/tenant : delete tenant(autotest_post_tenant_0) : failure(not local@) 400', function(done){ // eslint-disable-line no-undef
|
|
1061
|
+
var uri = '/v1/tenant';
|
|
1062
|
+
uri += '?tenant=autotest_post_tenant_0'; // tenant name
|
|
1063
|
+
uri += '&id=' + autotest_post_tenant_0_id; // correct id
|
|
1064
|
+
|
|
1065
|
+
chai.request(app)
|
|
1066
|
+
.delete(uri)
|
|
1067
|
+
.set('content-type', 'application/json')
|
|
1068
|
+
.set('x-auth-token', alltokens.unscopedtoken) // unscoped token
|
|
1069
|
+
.end(function(err, res){
|
|
1070
|
+
expect(res).to.have.status(400);
|
|
1071
|
+
|
|
1072
|
+
done();
|
|
1073
|
+
});
|
|
1074
|
+
});
|
|
1075
|
+
|
|
1076
|
+
it('DELETE /v1/tenant/<tenant> : delete tenant(local@autotest_post_tenant_1) : success 204', function(done){ // eslint-disable-line no-undef
|
|
1077
|
+
var uri = '/v1/tenant';
|
|
1078
|
+
uri += '?tenant=local@autotest_post_tenant_1'; // tenant name
|
|
1079
|
+
uri += '&id=' + autotest_post_tenant_1_id; // correct id
|
|
1080
|
+
|
|
1081
|
+
chai.request(app)
|
|
1082
|
+
.delete(uri)
|
|
1083
|
+
.set('content-type', 'application/json')
|
|
1084
|
+
.set('x-auth-token', alltokens.unscopedtoken) // unscoped token
|
|
1085
|
+
.end(function(err, res){
|
|
1086
|
+
expect(res).to.have.status(204);
|
|
1087
|
+
|
|
1088
|
+
done();
|
|
1089
|
+
});
|
|
1090
|
+
});
|
|
980
1091
|
});
|
|
981
1092
|
|
|
982
1093
|
/*
|
package/tests/auto_usertokens.js
CHANGED
|
@@ -431,11 +431,11 @@ describe('API : USER TOKEN', function(){ // eslint-disable-line no-undef
|
|
|
431
431
|
expect(res.body.scoped).to.be.a('boolean').to.be.false;
|
|
432
432
|
expect(res.body.user).to.be.a('string').to.equal('dummyuser');
|
|
433
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', display: 'dummy_tenant_0'});
|
|
435
|
-
expect(res.body.tenants[1]).to.deep.equal({name: 'tenant1', display: 'dummy_tenant_1'});
|
|
436
|
-
expect(res.body.tenants[2]).to.deep.equal({name: 'tenant2', display: 'dummy_tenant_2'});
|
|
437
|
-
expect(res.body.tenants[3]).to.deep.equal({name: 'tenant3', display: 'dummy_tenant_3'});
|
|
438
|
-
expect(res.body.tenants[4]).to.deep.equal({name: 'tenant4', display: 'dummy_tenant_4'});
|
|
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
439
|
|
|
440
440
|
done();
|
|
441
441
|
});
|
|
@@ -455,7 +455,7 @@ describe('API : USER TOKEN', function(){ // eslint-disable-line no-undef
|
|
|
455
455
|
expect(res.body.scoped).to.be.a('boolean').to.be.true;
|
|
456
456
|
expect(res.body.user).to.be.a('string').to.equal('dummyuser');
|
|
457
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', display: '
|
|
458
|
+
expect(res.body.tenants[0]).to.deep.equal({name: 'tenant0', id: '1000', description: 'dummy tenant no.0', display: 'dummy_tenant_0'});
|
|
459
459
|
|
|
460
460
|
done();
|
|
461
461
|
});
|
|
@@ -40,20 +40,32 @@ var is_https = apiutil.compareCaseString('yes', process.env.HTTPS_ENV);
|
|
|
40
40
|
//
|
|
41
41
|
// Request API for test
|
|
42
42
|
//
|
|
43
|
-
function deleteV1Tenant(token, name, id)
|
|
43
|
+
function deleteV1Tenant(token, name, id, remove_all)
|
|
44
44
|
{
|
|
45
45
|
var headers = {
|
|
46
46
|
'Content-Type': 'application/json',
|
|
47
47
|
'Content-Length': 0,
|
|
48
48
|
'X-Auth-Token': token
|
|
49
49
|
};
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
50
|
+
|
|
51
|
+
var options;
|
|
52
|
+
if(remove_all){
|
|
53
|
+
options = {
|
|
54
|
+
'host': hostname,
|
|
55
|
+
'port': hostport,
|
|
56
|
+
'path': '/v1/tenant' + encodeURI('?tenant=' + name) + '&' + encodeURI('id=' + id),
|
|
57
|
+
'method': 'DELETE',
|
|
58
|
+
'headers': headers
|
|
59
|
+
};
|
|
60
|
+
}else{
|
|
61
|
+
options = {
|
|
62
|
+
'host': hostname,
|
|
63
|
+
'port': hostport,
|
|
64
|
+
'path': '/v1/tenant/' + name + encodeURI('?id=' + id),
|
|
65
|
+
'method': 'DELETE',
|
|
66
|
+
'headers': headers
|
|
67
|
+
};
|
|
68
|
+
}
|
|
57
69
|
|
|
58
70
|
r3logger.dlog('request options = ' + JSON.stringify(options));
|
|
59
71
|
r3logger.dlog('request headers = ' + JSON.stringify(headers));
|
|
@@ -134,10 +146,32 @@ cliutil.getConsoleInput('Unscoped(or Scoped) user token : ', true, false,
|
|
|
134
146
|
}
|
|
135
147
|
var _id = apiutil.getSafeString(id);
|
|
136
148
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
149
|
+
cliutil.getConsoleInput('Remove tenant(yes/no(default)) : ', true, false, function(isbreak, remove_all)
|
|
150
|
+
{
|
|
151
|
+
if(isbreak){
|
|
152
|
+
process.exit(0);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
var _remove_all;
|
|
156
|
+
if(!apiutil.isSafeString(remove_all) || 'no' == remove_all || 'n' == remove_all){
|
|
157
|
+
_remove_all = false;
|
|
158
|
+
}else if('yes' == remove_all || 'y' == remove_all){
|
|
159
|
+
_remove_all = true;
|
|
160
|
+
|
|
161
|
+
if(0 !== _tenant.indexOf('local@')){
|
|
162
|
+
console.log('Need tenant name started with local@ for remove it.');
|
|
163
|
+
process.exit(0);
|
|
164
|
+
}
|
|
165
|
+
}else{
|
|
166
|
+
console.log('input must be yes or no(null)');
|
|
167
|
+
process.exit(0);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
//
|
|
171
|
+
// Run
|
|
172
|
+
//
|
|
173
|
+
deleteV1Tenant(_token, _tenant, _id, _remove_all);
|
|
174
|
+
});
|
|
141
175
|
});
|
|
142
176
|
});
|
|
143
177
|
});
|