UNPKG

k2hr3-api

Version:

K2HR3 REST API is K2hdkc based Resource and Roles and policy Rules

1,124 lines (1,054 loc) 581 kB
/* * K2HR3 REST API * * Copyright 2017 Yahoo Japan Corporation. * * K2HR3 is K2hdkc based Resource and Roles and policy Rules, gathers * common management information for the cloud. * K2HR3 can dynamically manage information as "who", "what", "operate". * These are stored as roles, resources, policies in K2hdkc, and the * client system can dynamically read and modify these information. * * For the full copyright and license information, please view * the license file that was distributed with this source code. * * AUTHOR: Takeshi Nakatani * CREATE: Tue Dec 19 2017 * REVISION: * */ 'use strict'; var common = require('./auto_common'); // Common objects for Chai var chai = common.chai; var chaiHttp = common.chaiHttp; // eslint-disable-line no-unused-vars var app = common.app; var assert = common.assert; // eslint-disable-line no-unused-vars var expect = common.expect; var tokenutil = require('./auto_token_util'); // Token utility //-------------------------------------------------------------- // Main describe section //-------------------------------------------------------------- describe('API : RESOURCE', function(){ // eslint-disable-line no-undef var alltokens = {}; // // Before in describe section // before(function(done){ // eslint-disable-line no-undef // Nothing to do tokenutil.before(this, alltokens, done); }); // // After in describe section // after(function(){ // eslint-disable-line no-undef // Nothing to do }); // // Run Test(POST - NEW SET - SUCCESS) // it('POST /v1/resource : set all new resource by scoped token with status 201', function(done){ // eslint-disable-line no-undef chai.request(app) .post('/v1/resource') .set('content-type', 'application/json') .set('x-auth-token', alltokens.scopedtoken.tenant0) // tenant0 .send({ resource: { name: 'autotest_post_dummy_resource1', // path: yrn:yahoo:::tenant0:resource:autotest_post_dummy_resource1 type: 'string', // type: string data: 'autotest_post:string:value', // data: dummy string keys: { // keys: 2 dummy objects foo: 'bar', hoge: 'fuga' }, alias: [ // alias: 2 dummy resource paths 'yrn:yahoo:::tenant0:resource:autotest_post_dummy_alias1', 'yrn:yahoo:::tenant0:resource:autotest_post_dummy_alias2' ] } }) .end(function(err, res){ expect(res).to.have.status(201); expect(res).to.be.json; expect(res.body).to.be.an('object'); expect(res.body.result).to.be.a('boolean').to.be.true; expect(res.body.message).to.be.a('null'); // // Check resource data(not expand) set by this case. // chai.request(app) .get('/v1/resource/autotest_post_dummy_resource1?expand=false') .set('content-type', 'application/json') .set('x-auth-token', alltokens.scopedtoken.tenant0) // tenant0 .end(function(err, res){ expect(res).to.have.status(200); expect(res).to.be.json; expect(res.body).to.be.an('object'); expect(res.body.result).to.be.a('boolean').to.be.true; expect(res.body.message).to.be.a('null'); expect(res.body.resource).to.be.an('object'); expect(res.body.resource.string).to.be.a('string').to.equal('autotest_post:string:value'); expect(res.body.resource.object).to.be.a('null'); expect(res.body.resource.expire).to.be.a('null'); expect(res.body.resource.keys).to.be.an('object').to.deep.equal({foo: 'bar', hoge: 'fuga'}); expect(res.body.resource.aliases).to.be.an.instanceof(Array).to.have.lengthOf(2); expect(res.body.resource.aliases[0]).to.be.a('string').to.equal('yrn:yahoo:::tenant0:resource:autotest_post_dummy_alias1'); expect(res.body.resource.aliases[1]).to.be.a('string').to.equal('yrn:yahoo:::tenant0:resource:autotest_post_dummy_alias2'); done(); }); }); }); it('POST /v1/resource : set all new resource by scoped token with status 201', function(done){ // eslint-disable-line no-undef chai.request(app) .post('/v1/resource') .set('content-type', 'application/json') .set('x-auth-token', alltokens.scopedtoken.tenant0) // tenant0 .send({ resource: { name: 'autotest_post_dummy_resource2', // path: yrn:yahoo:::tenant0:resource:autotest_post_dummy_resource2 type: 'object', // type: object data: { // data: dummy object value autotest_post_obj_key1: 'autotest_post_obj_val1', autotest_post_obj_key2: 'autotest_post_obj_val2' }, keys: { // keys: 2 dummy objects fruits: 'apple', fish: 'tuna' }, alias: [ // alias: 2 dummy resource paths 'yrn:yahoo:::tenant0:resource:autotest_post_dummy_alias1', 'yrn:yahoo:::tenant0:resource:autotest_post_dummy_alias2' ] } }) .end(function(err, res){ expect(res).to.have.status(201); expect(res).to.be.json; expect(res.body).to.be.an('object'); expect(res.body.result).to.be.a('boolean').to.be.true; expect(res.body.message).to.be.a('null'); // // Check resource data(not expand) set by this case. // chai.request(app) .get('/v1/resource/autotest_post_dummy_resource2?expand=false') .set('content-type', 'application/json') .set('x-auth-token', alltokens.scopedtoken.tenant0) // tenant0 .end(function(err, res){ expect(res).to.have.status(200); expect(res).to.be.json; expect(res.body).to.be.an('object'); expect(res.body.result).to.be.a('boolean').to.be.true; expect(res.body.message).to.be.a('null'); expect(res.body.resource).to.be.an('object'); expect(res.body.resource.string).to.be.a('null'); expect(res.body.resource.object).to.be.an('object').to.deep.equal({autotest_post_obj_key1: 'autotest_post_obj_val1', autotest_post_obj_key2: 'autotest_post_obj_val2'}); expect(res.body.resource.expire).to.be.a('null'); expect(res.body.resource.keys).to.be.an('object').to.deep.equal({fruits: 'apple', fish: 'tuna'}); expect(res.body.resource.aliases).to.be.an.instanceof(Array).to.have.lengthOf(2); expect(res.body.resource.aliases[0]).to.be.a('string').to.equal('yrn:yahoo:::tenant0:resource:autotest_post_dummy_alias1'); expect(res.body.resource.aliases[1]).to.be.a('string').to.equal('yrn:yahoo:::tenant0:resource:autotest_post_dummy_alias2'); done(); }); }); }); // // Run Test(POST - ALL SET - SUCCESS) // it('POST /v1/resource : set all resource by scoped token with status 201', function(done){ // eslint-disable-line no-undef chai.request(app) .post('/v1/resource') .set('content-type', 'application/json') .set('x-auth-token', alltokens.scopedtoken.tenant0) // tenant0 .send({ resource: { name: 'k2hr3_entest_obj_res_03', // path: yrn:yahoo:::tenant0:resource:k2hr3_entest_obj_res_03 type: 'string', // type: string data: 'autotest_post:string:value', // data: dummy string keys: { // keys: 2 dummy objects foo: 'bar', hoge: 'fuga' }, alias: [ // alias: 2 dummy resource paths 'yrn:yahoo:::tenant0:resource:autotest_post_dummy_alias1', 'yrn:yahoo:::tenant0:resource:autotest_post_dummy_alias2' ] } }) .end(function(err, res){ expect(res).to.have.status(201); expect(res).to.be.json; expect(res.body).to.be.an('object'); expect(res.body.result).to.be.a('boolean').to.be.true; expect(res.body.message).to.be.a('null'); // // Check resource data(not expand) set by this case. // chai.request(app) .get('/v1/resource/k2hr3_entest_obj_res_03?expand=false') .set('content-type', 'application/json') .set('x-auth-token', alltokens.scopedtoken.tenant0) // tenant0 .end(function(err, res){ expect(res).to.have.status(200); expect(res).to.be.json; expect(res.body).to.be.an('object'); expect(res.body.result).to.be.a('boolean').to.be.true; expect(res.body.message).to.be.a('null'); expect(res.body.resource).to.be.an('object'); expect(res.body.resource.string).to.be.a('string').to.equal('autotest_post:string:value'); expect(res.body.resource.object).to.be.a('null'); expect(res.body.resource.expire).to.be.a('null'); expect(res.body.resource.keys).to.be.an('object').to.deep.equal({foo: 'bar', hoge: 'fuga'}); expect(res.body.resource.aliases).to.be.an.instanceof(Array).to.have.lengthOf(2); expect(res.body.resource.aliases[0]).to.be.a('string').to.equal('yrn:yahoo:::tenant0:resource:autotest_post_dummy_alias1'); expect(res.body.resource.aliases[1]).to.be.a('string').to.equal('yrn:yahoo:::tenant0:resource:autotest_post_dummy_alias2'); done(); }); }); }); it('POST /v1/resource : set all resource by role token with status 201', function(done){ // eslint-disable-line no-undef chai.request(app) .post('/v1/resource/k2hr3_entest_obj_res_03') // path: yrn:yahoo:::tenant0:resource:k2hr3_entest_obj_res_03 .set('content-type', 'application/json') .set('x-auth-token', alltokens.roletoken.tenant0_k2hr3_entest_obj_role_03) // role: yrn:yahoo:::tenant0:role:k2hr3_entest_obj_role_03 (this role can access to k2hr3_entest_obj_res_03) .send({ resource: { type: 'object', // type: object data: { // data: dummy object value autotest_post_obj_key1: 'autotest_post_obj_val1', autotest_post_obj_key2: 'autotest_post_obj_val2' }, keys: { // keys: 2 dummy objects fruits: 'apple', fish: 'tuna' } // // alias: can not specify aliases by role token, then not update this. } }) .end(function(err, res){ expect(res).to.have.status(201); expect(res).to.be.json; expect(res.body).to.be.an('object'); expect(res.body.result).to.be.a('boolean').to.be.true; expect(res.body.message).to.be.a('null'); // // Check resource data(not expand) set by this case. // chai.request(app) .get('/v1/resource/k2hr3_entest_obj_res_03?expand=false') .set('content-type', 'application/json') .set('x-auth-token', alltokens.scopedtoken.tenant0) // tenant0 .end(function(err, res){ expect(res).to.have.status(200); expect(res).to.be.json; expect(res.body).to.be.an('object'); expect(res.body.result).to.be.a('boolean').to.be.true; expect(res.body.message).to.be.a('null'); expect(res.body.resource).to.be.an('object'); expect(res.body.resource.string).to.be.a('null'); expect(res.body.resource.object).to.be.an('object').to.deep.equal({autotest_post_obj_key1: 'autotest_post_obj_val1', autotest_post_obj_key2: 'autotest_post_obj_val2'}); expect(res.body.resource.expire).to.be.a('null'); expect(res.body.resource.keys).to.be.an('object').to.deep.equal({fruits: 'apple', fish: 'tuna'}); expect(res.body.resource.aliases).to.be.an.instanceof(Array).to.have.lengthOf(2); expect(res.body.resource.aliases[0]).to.be.a('string').to.equal('yrn:yahoo:::tenant0:resource:autotest_post_dummy_alias1'); expect(res.body.resource.aliases[1]).to.be.a('string').to.equal('yrn:yahoo:::tenant0:resource:autotest_post_dummy_alias2'); done(); }); }); }); it('POST /v1/resource : set all resource by no token with status 201', function(done){ // eslint-disable-line no-undef chai.request(app) .post('/v1/resource/yrn:yahoo:::tenant0:resource:k2hr3_entest_obj_res_03') // path: yrn:yahoo:::tenant0:resource:k2hr3_entest_obj_res_03 .set('content-type', 'application/json') .send({ resource: { port: null, // port: null = 0 = any cuk: null, // cuk: null role: 'yrn:yahoo:::tenant0:role:k2hr3_entest_obj_role_03', // role: yrn:yahoo:::tenant0:role:k2hr3_entest_obj_role_03 (this role can access to k2hr3_entest_obj_res_03) type: 'string', // type: string data: 'autotest_post:string:value', // data: dummy string keys: { // keys: 2 dummy objects fruits: 'orange', fish: 'barracuda' } // // alias: can not specify aliases by role token, then not update this. } }) .end(function(err, res){ expect(res).to.have.status(201); expect(res).to.be.json; expect(res.body).to.be.an('object'); expect(res.body.result).to.be.a('boolean').to.be.true; expect(res.body.message).to.be.a('null'); // // Check resource data(not expand) set by this case. // chai.request(app) .get('/v1/resource/k2hr3_entest_obj_res_03?expand=false') .set('content-type', 'application/json') .set('x-auth-token', alltokens.scopedtoken.tenant0) // tenant0 .end(function(err, res){ expect(res).to.have.status(200); expect(res).to.be.json; expect(res.body).to.be.an('object'); expect(res.body.result).to.be.a('boolean').to.be.true; expect(res.body.message).to.be.a('null'); expect(res.body.resource).to.be.an('object'); expect(res.body.resource.string).to.be.a('string').to.equal('autotest_post:string:value'); expect(res.body.resource.object).to.be.a('null'); expect(res.body.resource.expire).to.be.a('null'); expect(res.body.resource.keys).to.be.an('object').to.deep.equal({fruits: 'orange', fish: 'barracuda'}); expect(res.body.resource.aliases).to.be.an.instanceof(Array).to.have.lengthOf(2); expect(res.body.resource.aliases[0]).to.be.a('string').to.equal('yrn:yahoo:::tenant0:resource:autotest_post_dummy_alias1'); expect(res.body.resource.aliases[1]).to.be.a('string').to.equal('yrn:yahoo:::tenant0:resource:autotest_post_dummy_alias2'); done(); }); }); }); // // Run Test(POST - A PART SET - SUCCESS) // it('POST /v1/resource : set obj value resource by scoped token with status 201', function(done){ // eslint-disable-line no-undef chai.request(app) .post('/v1/resource') .set('content-type', 'application/json') .set('x-auth-token', alltokens.scopedtoken.tenant0) // tenant0 .send({ resource: { name: 'k2hr3_entest_obj_res_03', // path: yrn:yahoo:::tenant0:resource:k2hr3_entest_obj_res_03 type: 'object', // type: object data: { // data: dummy object value autotest_post_obj_key1: 'autotest_post_obj_val1', autotest_post_obj_key2: 'autotest_post_obj_val2' } // // keys: not set // // alias: not set } }) .end(function(err, res){ expect(res).to.have.status(201); expect(res).to.be.json; expect(res.body).to.be.an('object'); expect(res.body.result).to.be.a('boolean').to.be.true; expect(res.body.message).to.be.a('null'); // // Check resource data(not expand) set by this case. // chai.request(app) .get('/v1/resource/k2hr3_entest_obj_res_03?expand=false') .set('content-type', 'application/json') .set('x-auth-token', alltokens.scopedtoken.tenant0) // tenant0 .end(function(err, res){ expect(res).to.have.status(200); expect(res).to.be.json; expect(res.body).to.be.an('object'); expect(res.body.result).to.be.a('boolean').to.be.true; expect(res.body.message).to.be.a('null'); expect(res.body.resource).to.be.an('object'); expect(res.body.resource.string).to.be.a('null'); expect(res.body.resource.object).to.be.an('object').to.deep.equal({autotest_post_obj_key1: 'autotest_post_obj_val1', autotest_post_obj_key2: 'autotest_post_obj_val2'}); expect(res.body.resource.expire).to.be.a('null'); expect(res.body.resource.keys).to.be.an('object').to.deep.equal({fruits: 'orange', fish: 'barracuda'}); expect(res.body.resource.aliases).to.be.an.instanceof(Array).to.have.lengthOf(2); expect(res.body.resource.aliases[0]).to.be.a('string').to.equal('yrn:yahoo:::tenant0:resource:autotest_post_dummy_alias1'); expect(res.body.resource.aliases[1]).to.be.a('string').to.equal('yrn:yahoo:::tenant0:resource:autotest_post_dummy_alias2'); done(); }); }); }); it('POST /v1/resource : set str value resource by scoped token with status 201', function(done){ // eslint-disable-line no-undef chai.request(app) .post('/v1/resource') .set('content-type', 'application/json') .set('x-auth-token', alltokens.scopedtoken.tenant0) // tenant0 .send({ resource: { name: 'k2hr3_entest_obj_res_03', // path: yrn:yahoo:::tenant0:resource:k2hr3_entest_obj_res_03 type: 'string', // type: string data: 'autotest_post:string:value', // data: dummy string // // keys: not set // // alias: not set } }) .end(function(err, res){ expect(res).to.have.status(201); expect(res).to.be.json; expect(res.body).to.be.an('object'); expect(res.body.result).to.be.a('boolean').to.be.true; expect(res.body.message).to.be.a('null'); // // Check resource data(not expand) set by this case. // chai.request(app) .get('/v1/resource/k2hr3_entest_obj_res_03?expand=false') .set('content-type', 'application/json') .set('x-auth-token', alltokens.scopedtoken.tenant0) // tenant0 .end(function(err, res){ expect(res).to.have.status(200); expect(res).to.be.json; expect(res.body).to.be.an('object'); expect(res.body.result).to.be.a('boolean').to.be.true; expect(res.body.message).to.be.a('null'); expect(res.body.resource).to.be.an('object'); expect(res.body.resource.string).to.be.a('string').to.equal('autotest_post:string:value'); expect(res.body.resource.object).to.be.a('null'); expect(res.body.resource.expire).to.be.a('null'); expect(res.body.resource.keys).to.be.an('object').to.deep.equal({fruits: 'orange', fish: 'barracuda'}); expect(res.body.resource.aliases).to.be.an.instanceof(Array).to.have.lengthOf(2); expect(res.body.resource.aliases[0]).to.be.a('string').to.equal('yrn:yahoo:::tenant0:resource:autotest_post_dummy_alias1'); expect(res.body.resource.aliases[1]).to.be.a('string').to.equal('yrn:yahoo:::tenant0:resource:autotest_post_dummy_alias2'); done(); }); }); }); it('POST /v1/resource : set keys resource by scoped token with status 201', function(done){ // eslint-disable-line no-undef chai.request(app) .post('/v1/resource') .set('content-type', 'application/json') .set('x-auth-token', alltokens.scopedtoken.tenant0) // tenant0 .send({ resource: { name: 'k2hr3_entest_obj_res_03', // path: yrn:yahoo:::tenant0:resource:k2hr3_entest_obj_res_03 // // type: not set // // data: not set keys: { // keys: 2 dummy objects foo: 'bar', hoge: 'fuga' } // // alias: not set } }) .end(function(err, res){ expect(res).to.have.status(201); expect(res).to.be.json; expect(res.body).to.be.an('object'); expect(res.body.result).to.be.a('boolean').to.be.true; expect(res.body.message).to.be.a('null'); // // Check resource data(not expand) set by this case. // chai.request(app) .get('/v1/resource/k2hr3_entest_obj_res_03?expand=false') .set('content-type', 'application/json') .set('x-auth-token', alltokens.scopedtoken.tenant0) // tenant0 .end(function(err, res){ expect(res).to.have.status(200); expect(res).to.be.json; expect(res.body).to.be.an('object'); expect(res.body.result).to.be.a('boolean').to.be.true; expect(res.body.message).to.be.a('null'); expect(res.body.resource).to.be.an('object'); expect(res.body.resource.string).to.be.a('string').to.equal('autotest_post:string:value'); expect(res.body.resource.object).to.be.a('null'); expect(res.body.resource.expire).to.be.a('null'); expect(res.body.resource.keys).to.be.an('object').to.deep.equal({foo: 'bar', hoge: 'fuga'}); expect(res.body.resource.aliases).to.be.an.instanceof(Array).to.have.lengthOf(2); expect(res.body.resource.aliases[0]).to.be.a('string').to.equal('yrn:yahoo:::tenant0:resource:autotest_post_dummy_alias1'); expect(res.body.resource.aliases[1]).to.be.a('string').to.equal('yrn:yahoo:::tenant0:resource:autotest_post_dummy_alias2'); done(); }); }); }); it('POST /v1/resource : set aliases resource by scoped token with status 201', function(done){ // eslint-disable-line no-undef chai.request(app) .post('/v1/resource') .set('content-type', 'application/json') .set('x-auth-token', alltokens.scopedtoken.tenant0) // tenant0 .send({ resource: { name: 'k2hr3_entest_obj_res_03', // path: yrn:yahoo:::tenant0:resource:k2hr3_entest_obj_res_03 // // type: not set // // data: not set // // keys: not set alias: [ // alias: 2 dummy resource paths 'yrn:yahoo:::tenant0:resource:autotest_post_dummy_alias3', 'yrn:yahoo:::tenant0:resource:autotest_post_dummy_alias4' ] } }) .end(function(err, res){ expect(res).to.have.status(201); expect(res).to.be.json; expect(res.body).to.be.an('object'); expect(res.body.result).to.be.a('boolean').to.be.true; expect(res.body.message).to.be.a('null'); // // Check resource data(not expand) set by this case. // chai.request(app) .get('/v1/resource/k2hr3_entest_obj_res_03?expand=false') .set('content-type', 'application/json') .set('x-auth-token', alltokens.scopedtoken.tenant0) // tenant0 .end(function(err, res){ expect(res).to.have.status(200); expect(res).to.be.json; expect(res.body).to.be.an('object'); expect(res.body.result).to.be.a('boolean').to.be.true; expect(res.body.message).to.be.a('null'); expect(res.body.resource).to.be.an('object'); expect(res.body.resource.string).to.be.a('string').to.equal('autotest_post:string:value'); expect(res.body.resource.object).to.be.a('null'); expect(res.body.resource.expire).to.be.a('null'); expect(res.body.resource.keys).to.be.an('object').to.deep.equal({foo: 'bar', hoge: 'fuga'}); expect(res.body.resource.aliases).to.be.an.instanceof(Array).to.have.lengthOf(2); expect(res.body.resource.aliases[0]).to.be.a('string').to.equal('yrn:yahoo:::tenant0:resource:autotest_post_dummy_alias3'); expect(res.body.resource.aliases[1]).to.be.a('string').to.equal('yrn:yahoo:::tenant0:resource:autotest_post_dummy_alias4'); done(); }); }); }); it('POST /v1/resource : set obj value resource by role token with status 201', function(done){ // eslint-disable-line no-undef chai.request(app) .post('/v1/resource/k2hr3_entest_obj_res_03') // path: yrn:yahoo:::tenant0:resource:k2hr3_entest_obj_res_03 .set('content-type', 'application/json') .set('x-auth-token', alltokens.roletoken.tenant0_k2hr3_entest_obj_role_03) // role: yrn:yahoo:::tenant0:role:k2hr3_entest_obj_role_03 (this role can access to k2hr3_entest_obj_res_03) .send({ resource: { type: 'object', // type: object data: { // data: dummy object value autotest_post_obj_key1: 'autotest_post_obj_val1', autotest_post_obj_key2: 'autotest_post_obj_val2' } // // keys: not set // // alias: not set } }) .end(function(err, res){ expect(res).to.have.status(201); expect(res).to.be.json; expect(res.body).to.be.an('object'); expect(res.body.result).to.be.a('boolean').to.be.true; expect(res.body.message).to.be.a('null'); // // Check resource data(not expand) set by this case. // chai.request(app) .get('/v1/resource/k2hr3_entest_obj_res_03?expand=false') .set('content-type', 'application/json') .set('x-auth-token', alltokens.scopedtoken.tenant0) // tenant0 .end(function(err, res){ expect(res).to.have.status(200); expect(res).to.be.json; expect(res.body).to.be.an('object'); expect(res.body.result).to.be.a('boolean').to.be.true; expect(res.body.message).to.be.a('null'); expect(res.body.resource).to.be.an('object'); expect(res.body.resource.string).to.be.a('null'); expect(res.body.resource.object).to.be.an('object').to.deep.equal({autotest_post_obj_key1: 'autotest_post_obj_val1', autotest_post_obj_key2: 'autotest_post_obj_val2'}); expect(res.body.resource.expire).to.be.a('null'); expect(res.body.resource.keys).to.be.an('object').to.deep.equal({foo: 'bar', hoge: 'fuga'}); expect(res.body.resource.aliases).to.be.an.instanceof(Array).to.have.lengthOf(2); expect(res.body.resource.aliases[0]).to.be.a('string').to.equal('yrn:yahoo:::tenant0:resource:autotest_post_dummy_alias3'); expect(res.body.resource.aliases[1]).to.be.a('string').to.equal('yrn:yahoo:::tenant0:resource:autotest_post_dummy_alias4'); done(); }); }); }); it('POST /v1/resource : set str value resource by role token with status 201', function(done){ // eslint-disable-line no-undef chai.request(app) .post('/v1/resource/k2hr3_entest_obj_res_03') // path: yrn:yahoo:::tenant0:resource:k2hr3_entest_obj_res_03 .set('content-type', 'application/json') .set('x-auth-token', alltokens.roletoken.tenant0_k2hr3_entest_obj_role_03) // role: yrn:yahoo:::tenant0:role:k2hr3_entest_obj_role_03 (this role can access to k2hr3_entest_obj_res_03) .send({ resource: { type: 'string', // type: string data: 'autotest_post:string:value', // data: dummy string // // keys: not set // // alias: not set } }) .end(function(err, res){ expect(res).to.have.status(201); expect(res).to.be.json; expect(res.body).to.be.an('object'); expect(res.body.result).to.be.a('boolean').to.be.true; expect(res.body.message).to.be.a('null'); // // Check resource data(not expand) set by this case. // chai.request(app) .get('/v1/resource/k2hr3_entest_obj_res_03?expand=false') .set('content-type', 'application/json') .set('x-auth-token', alltokens.scopedtoken.tenant0) // tenant0 .end(function(err, res){ expect(res).to.have.status(200); expect(res).to.be.json; expect(res.body).to.be.an('object'); expect(res.body.result).to.be.a('boolean').to.be.true; expect(res.body.message).to.be.a('null'); expect(res.body.resource).to.be.an('object'); expect(res.body.resource.string).to.be.a('string').to.equal('autotest_post:string:value'); expect(res.body.resource.object).to.be.a('null'); expect(res.body.resource.expire).to.be.a('null'); expect(res.body.resource.keys).to.be.an('object').to.deep.equal({foo: 'bar', hoge: 'fuga'}); expect(res.body.resource.aliases).to.be.an.instanceof(Array).to.have.lengthOf(2); expect(res.body.resource.aliases[0]).to.be.a('string').to.equal('yrn:yahoo:::tenant0:resource:autotest_post_dummy_alias3'); expect(res.body.resource.aliases[1]).to.be.a('string').to.equal('yrn:yahoo:::tenant0:resource:autotest_post_dummy_alias4'); done(); }); }); }); it('POST /v1/resource : set keys resource by role token with status 201', function(done){ // eslint-disable-line no-undef chai.request(app) .post('/v1/resource/k2hr3_entest_obj_res_03') // path: yrn:yahoo:::tenant0:resource:k2hr3_entest_obj_res_03 .set('content-type', 'application/json') .set('x-auth-token', alltokens.roletoken.tenant0_k2hr3_entest_obj_role_03) // role: yrn:yahoo:::tenant0:role:k2hr3_entest_obj_role_03 (this role can access to k2hr3_entest_obj_res_03) .send({ resource: { // // type: not set // // data: not set keys: { // keys: 2 dummy objects fruits: 'apple', fish: 'tuna' } // // alias: not set } }) .end(function(err, res){ expect(res).to.have.status(201); expect(res).to.be.json; expect(res.body).to.be.an('object'); expect(res.body.result).to.be.a('boolean').to.be.true; expect(res.body.message).to.be.a('null'); // // Check resource data(not expand) set by this case. // chai.request(app) .get('/v1/resource/k2hr3_entest_obj_res_03?expand=false') .set('content-type', 'application/json') .set('x-auth-token', alltokens.scopedtoken.tenant0) // tenant0 .end(function(err, res){ expect(res).to.have.status(200); expect(res).to.be.json; expect(res.body).to.be.an('object'); expect(res.body.result).to.be.a('boolean').to.be.true; expect(res.body.message).to.be.a('null'); expect(res.body.resource).to.be.an('object'); expect(res.body.resource.string).to.be.a('string').to.equal('autotest_post:string:value'); expect(res.body.resource.object).to.be.a('null'); expect(res.body.resource.expire).to.be.a('null'); expect(res.body.resource.keys).to.be.an('object').to.deep.equal({fruits: 'apple', fish: 'tuna'}); expect(res.body.resource.aliases).to.be.an.instanceof(Array).to.have.lengthOf(2); expect(res.body.resource.aliases[0]).to.be.a('string').to.equal('yrn:yahoo:::tenant0:resource:autotest_post_dummy_alias3'); expect(res.body.resource.aliases[1]).to.be.a('string').to.equal('yrn:yahoo:::tenant0:resource:autotest_post_dummy_alias4'); done(); }); }); }); it('POST /v1/resource : set obj value resource by no token with status 201', function(done){ // eslint-disable-line no-undef chai.request(app) .post('/v1/resource/yrn:yahoo:::tenant0:resource:k2hr3_entest_obj_res_03') // path: yrn:yahoo:::tenant0:resource:k2hr3_entest_obj_res_03 .set('content-type', 'application/json') .send({ resource: { port: null, // port: null = 0 = any cuk: null, // cuk: null role: 'yrn:yahoo:::tenant0:role:k2hr3_entest_obj_role_03', // role: yrn:yahoo:::tenant0:role:k2hr3_entest_obj_role_03 (this role can access to k2hr3_entest_obj_res_03) type: 'object', // type: object data: { // data: dummy object value autotest_post_obj_key1: 'autotest_post_obj_val1', autotest_post_obj_key2: 'autotest_post_obj_val2' } // // keys: not set // // alias: not set } }) .end(function(err, res){ expect(res).to.have.status(201); expect(res).to.be.json; expect(res.body).to.be.an('object'); expect(res.body.result).to.be.a('boolean').to.be.true; expect(res.body.message).to.be.a('null'); // // Check resource data(not expand) set by this case. // chai.request(app) .get('/v1/resource/k2hr3_entest_obj_res_03?expand=false') .set('content-type', 'application/json') .set('x-auth-token', alltokens.scopedtoken.tenant0) // tenant0 .end(function(err, res){ expect(res).to.have.status(200); expect(res).to.be.json; expect(res.body).to.be.an('object'); expect(res.body.result).to.be.a('boolean').to.be.true; expect(res.body.message).to.be.a('null'); expect(res.body.resource).to.be.an('object'); expect(res.body.resource.string).to.be.a('null'); expect(res.body.resource.object).to.be.an('object').to.deep.equal({autotest_post_obj_key1: 'autotest_post_obj_val1', autotest_post_obj_key2: 'autotest_post_obj_val2'}); expect(res.body.resource.expire).to.be.a('null'); expect(res.body.resource.keys).to.be.an('object').to.deep.equal({fruits: 'apple', fish: 'tuna'}); expect(res.body.resource.aliases).to.be.an.instanceof(Array).to.have.lengthOf(2); expect(res.body.resource.aliases[0]).to.be.a('string').to.equal('yrn:yahoo:::tenant0:resource:autotest_post_dummy_alias3'); expect(res.body.resource.aliases[1]).to.be.a('string').to.equal('yrn:yahoo:::tenant0:resource:autotest_post_dummy_alias4'); done(); }); }); }); it('POST /v1/resource : set str value resource by no token with status 201', function(done){ // eslint-disable-line no-undef chai.request(app) .post('/v1/resource/yrn:yahoo:::tenant0:resource:k2hr3_entest_obj_res_03') // path: yrn:yahoo:::tenant0:resource:k2hr3_entest_obj_res_03 .set('content-type', 'application/json') .send({ resource: { port: null, // port: null = 0 = any cuk: null, // cuk: null role: 'yrn:yahoo:::tenant0:role:k2hr3_entest_obj_role_03', // role: yrn:yahoo:::tenant0:role:k2hr3_entest_obj_role_03 (this role can access to k2hr3_entest_obj_res_03) type: 'string', // type: string data: 'autotest_post:string:value', // data: dummy string // // keys: not set // // alias: not set } }) .end(function(err, res){ expect(res).to.have.status(201); expect(res).to.be.json; expect(res.body).to.be.an('object'); expect(res.body.result).to.be.a('boolean').to.be.true; expect(res.body.message).to.be.a('null'); // // Check resource data(not expand) set by this case. // chai.request(app) .get('/v1/resource/k2hr3_entest_obj_res_03?expand=false') .set('content-type', 'application/json') .set('x-auth-token', alltokens.scopedtoken.tenant0) // tenant0 .end(function(err, res){ expect(res).to.have.status(200); expect(res).to.be.json; expect(res.body).to.be.an('object'); expect(res.body.result).to.be.a('boolean').to.be.true; expect(res.body.message).to.be.a('null'); expect(res.body.resource).to.be.an('object'); expect(res.body.resource.string).to.be.a('string').to.equal('autotest_post:string:value'); expect(res.body.resource.object).to.be.a('null'); expect(res.body.resource.expire).to.be.a('null'); expect(res.body.resource.keys).to.be.an('object').to.deep.equal({fruits: 'apple', fish: 'tuna'}); expect(res.body.resource.aliases).to.be.an.instanceof(Array).to.have.lengthOf(2); expect(res.body.resource.aliases[0]).to.be.a('string').to.equal('yrn:yahoo:::tenant0:resource:autotest_post_dummy_alias3'); expect(res.body.resource.aliases[1]).to.be.a('string').to.equal('yrn:yahoo:::tenant0:resource:autotest_post_dummy_alias4'); done(); }); }); }); it('POST /v1/resource : set keys resource by no token with status 201', function(done){ // eslint-disable-line no-undef chai.request(app) .post('/v1/resource/yrn:yahoo:::tenant0:resource:k2hr3_entest_obj_res_03') // path: yrn:yahoo:::tenant0:resource:k2hr3_entest_obj_res_03 .set('content-type', 'application/json') .send({ resource: { port: null, // port: null = 0 = any cuk: null, // cuk: null role: 'yrn:yahoo:::tenant0:role:k2hr3_entest_obj_role_03', // role: yrn:yahoo:::tenant0:role:k2hr3_entest_obj_role_03 (this role can access to k2hr3_entest_obj_res_03) // // type: not set // // data: not set keys: { // keys: 2 dummy objects fruits: 'orange', fish: 'barracuda' } // // alias: not set } }) .end(function(err, res){ expect(res).to.have.status(201); expect(res).to.be.json; expect(res.body).to.be.an('object'); expect(res.body.result).to.be.a('boolean').to.be.true; expect(res.body.message).to.be.a('null'); // // Check resource data(not expand) set by this case. // chai.request(app) .get('/v1/resource/k2hr3_entest_obj_res_03?expand=false') .set('content-type', 'application/json') .set('x-auth-token', alltokens.scopedtoken.tenant0) // tenant0 .end(function(err, res){ expect(res).to.have.status(200); expect(res).to.be.json; expect(res.body).to.be.an('object'); expect(res.body.result).to.be.a('boolean').to.be.true; expect(res.body.message).to.be.a('null'); expect(res.body.resource).to.be.an('object'); expect(res.body.resource.string).to.be.a('string').to.equal('autotest_post:string:value'); expect(res.body.resource.object).to.be.a('null'); expect(res.body.resource.expire).to.be.a('null'); expect(res.body.resource.keys).to.be.an('object').to.deep.equal({fruits: 'orange', fish: 'barracuda'}); expect(res.body.resource.aliases).to.be.an.instanceof(Array).to.have.lengthOf(2); expect(res.body.resource.aliases[0]).to.be.a('string').to.equal('yrn:yahoo:::tenant0:resource:autotest_post_dummy_alias3'); expect(res.body.resource.aliases[1]).to.be.a('string').to.equal('yrn:yahoo:::tenant0:resource:autotest_post_dummy_alias4'); done(); }); }); }); // // Run Test(POST - FAILURE) // it('POST /v1/resource : failure set all resource by invalid scoped token with status 401', function(done){ // eslint-disable-line no-undef chai.request(app) .post('/v1/resource') .set('content-type', 'application/json') .set('x-auth-token', 'U=error_dummy_token') // invalid token .send({ resource: { name: 'k2hr3_entest_obj_res_03', // path: yrn:yahoo:::tenant0:resource:k2hr3_entest_obj_res_03 type: 'string', // type: string data: 'autotest_post:string:value', // data: dummy string keys: { // keys: 2 dummy objects foo: 'bar', hoge: 'fuga' }, alias: [ // alias: 2 dummy resource paths 'yrn:yahoo:::tenant0:resource:autotest_post_dummy_alias1', 'yrn:yahoo:::tenant0:resource:autotest_post_dummy_alias2' ] } }) .end(function(err, res){ expect(res).to.have.status(401); expect(res).to.be.json; expect(res.body).to.be.an('object'); expect(res.body.result).to.be.a('boolean').to.be.false; 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.'); done(); }); }); it('POST /v1/resource : failure set invalid resource by scoped token with status 400', function(done){ // eslint-disable-line no-undef chai.request(app) .post('/v1/resource') .set('content-type', 'application/json') .set('x-auth-token', alltokens.scopedtoken.tenant0) // tenant0 .send({ wrong_key: { // wrong main key name: 'k2hr3_entest_obj_res_03', // path: yrn:yahoo:::tenant0:resource:k2hr3_entest_obj_res_03 type: 'string', // type: string data: 'autotest_post:string:value', // data: dummy string keys: { // keys: 2 dummy objects foo: 'bar', hoge: 'fuga' }, alias: [ // alias: 2 dummy resource paths 'yrn:yahoo:::tenant0:resource:autotest_post_dummy_alias1', 'yrn:yahoo:::tenant0:resource:autotest_post_dummy_alias2' ] } }) .end(function(err, res){ expect(res).to.have.status(400); expect(res).to.be.json; expect(res.body).to.be.an('object'); expect(res.body.result).to.be.a('boolean').to.be.false; expect(res.body.message).to.be.a('string').to.equal('POST body does not have resource data'); done(); }); }); it('POST /v1/resource : failure set all resource by invalid role token with status 401', function(done){ // eslint-disable-line no-undef chai.request(app) .post('/v1/resource/k2hr3_entest_obj_res_03') // path: yrn:yahoo:::tenant0:resource:k2hr3_entest_obj_res_03 .set('content-type', 'application/json') .set('x-auth-token', 'R=error_dummy_token') // invalid token .send({ resource: { type: 'object', // type: object data: { // data: dummy object value autotest_post_obj_key1: 'autotest_post_obj_val1', autotest_post_obj_key2: 'autotest_post_obj_val2' }, keys: { // keys: 2 dummy objects fruits: 'apple', fish: 'tuna' } // // alias: can not specify aliases by role token, then not update this. } }) .end(function(err, res){ expect(res).to.have.status(401); expect(res).to.be.json; expect(res.body).to.be.an('object'); expect(res.body.result).to.be.a('boolean').to.be.false; 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.'); done(); }); }); it('POST /v1/resource : failure set all resource by not allowed role token with status 400', function(done){ // eslint-disable-line no-undef chai.request(app) .post('/v1/resource/k2hr3_entest_obj_res_03') // path: yrn:yahoo:::tenant0:resource:k2hr3_entest_obj_res_03 .set('content-type', 'application/json') .set('x-auth-token', alltokens.roletoken.tenant0_k2hr3_entest_str_role_01) // role: yrn:yahoo:::tenant0:role:k2hr3_entest_obj_role_03 (this role can access to k2hr3_entest_str_res_01) .send({ resource: { type: 'object', // type: object data: { // data: dummy object value autotest_post_obj_key1: 'autotest_post_obj_val1', autotest_post_obj_key2: 'autotest_post_obj_val2' }, keys: { // keys: 2 dummy objects fruits: 'apple', fish: 'tuna' } // // alias: can not specify aliases by role token, then not update this. } }) .end(function(err, res){ expect(res).to.have.status(400); expect(res).to.be.json; expect(res.body).to.be.an('object'); expect(res.body.result).to.be.a('boolean').to.be.false; expect(res.body.message).to.be.a('string').to.equal('could not create resource("k2hr3_entest_obj_res_03") for tenant(tenant0), role(k2hr3_entest_str_role_01)'); done(); }); }); it('POST /v1/resource : failure set invalid resource by not allowed role token with status 400', function(done){ // eslint-disable-line no-undef chai.request(app) .post('/v1/resource/k2hr3_entest_obj_res_03') // path: yrn:yahoo:::tenant0:resource:k2hr3_entest_obj_res_03 .set('content-type', 'application/json') .set('x-auth-token', alltokens.roletoken.tenant0_k2hr3_entest_obj_role_03) // role: yrn:yahoo:::tenant0:role:k2hr3_entest_obj_role_03 (this role can access to k2hr3_entest_obj_res_03) .send({ wrong_key: { // wrong main key type: 'object', // type: object data: { // data: dummy object value autotest_post_obj_key1: 'autotest_post_obj_val1', autotest_post_obj_key2: 'autotest_post_obj_val2' }, keys: { // keys: 2 dummy objects fruits: 'apple', fish: 'tuna' } // // alias: can not specify aliases by role token, then not update this. } }) .end(function(err, res){ expect(res).to.have.status(400); expect(res).to.be.json; expect(res.body).to.be.an('object'); expect(res.body.result).to.be.a('boolean').to.be.false; expect(res.body.message).to.be.a('string').to.equal('POST body does not have resource data'); done(); }); }); it('POST /v1/resource : failure set alias resource by role token with status 400', function(done){ // eslint-disable-line no-undef chai.request(app) .post('/v1/resource/k2hr3_entest_obj_res_03') // path: yrn:yahoo:::tenant0:resource:k2hr3_entest_obj_res_03 .set('content-type', 'application/json') .set('x-auth-token', alltokens.roletoken.tenant0_k2hr3_entest_obj_role_03) // role: yrn:yahoo:::tenant0:role:k2hr3_entest_obj_role_03 (this role can access to k2hr3_entest_obj_res_03) .send({ resource: { type: 'object', // type: object data: { // data: dummy object value autotest_post_obj_key1: 'autotest_post_obj_val1', autotest_post_obj_key2: 'autotest_post_obj_val2' }, keys: { // keys: 2 dummy objects fruits: 'apple', fish: 'tuna' }, alias: [ // alias: 2 dummy resource paths 'yrn:yahoo:::tenant0:resource:autotest_post_dummy_alias3', 'yrn:yahoo:::tenant0:resource:autotest_post_dummy_alias4' ] } }) .end(function(err, res){ expect(res).to.have.status(400); expect(res).to.be.json; expect(res.body).to.be.an('object'); expect(res.body.result).to.be.a('boolean').to.be.false; expect(res.body.message).to.be.a('string').to.equal('POST resource:alias field is specified, but it is not allowed by not user token : ["yrn:yahoo:::tenant0:resource:autotest_post_dummy_alias3","yrn:yahoo:::tenant0:resource:autotest_post_dummy_alias4"]'); done(); }); }); it('POST /v1/resource : failure set all resource by no token(not allowed 127.0.0.1) with status 400', function(done){ // eslint-disable-line no-undef chai.request(app) .post('/v1/resource/yrn:yahoo:::tenant0:resource:k2hr3_entest_obj_res_03') // path: yrn:yahoo:::tenant0:resource:k2hr3_entest_obj_res_03 .set('content-type', 'application/json') .send({ resource: { port: null, // port: null = 0 = any cuk: null, // cuk: null role: 'yrn:yahoo:::tenant0:role:k2hr3_entest_str_role_03', // role: yrn:yahoo:::tenant0:role:k2hr3_entest_str_role_03 (127.0.0.1 is not this role member) type: 'string', // type: string data: 'autotest_post:string:value', // data: dummy string keys: { // keys: 2 dummy objects fruits: 'orange', fish: 'barracuda' } // // alias: can not specify aliases by no token, then not update this. } }) .end(function(err, res){ expect(res).to.have.status(400); expect(res).to.be.json; expect(res.body).to.be.an('object'); expect(res.body.result).to.be.a('boolean').to.be.false; expect(res.body.message).to.be.a('string').to.equal('ip:port(127.0.0.1:0) is not role(yrn:yahoo:::tenant0:role:k2hr3_entest_str_role_03) member.'); done(); }); }); it('POST /v1/resource : failure set invalid resource by no token with status 400', function(done){ // eslint-disable-line no-undef chai.request(app) .post('/v1/resource/yrn:yahoo:::tenant0:resource:k2hr3_entest_obj_res_03') // path: yrn:yahoo:::tenant0:resource:k2hr3_entest_obj_res_03 .set('content-type', 'application/json') .send({ wrong_key: { // wrong main key port: null, // port: null = 0 = any cuk: null, // cuk: null role: 'yrn:yahoo:::tenant0:role:k2hr3_entest_obj_role_03', // role: yrn:yahoo:::tenant0:role:k2hr3_entest_obj_role_03 (this role can access to k2hr3_entest_obj_res_03) type: 'string', // type: string data: 'autotest_post:string:value', // data: dummy string keys: { // keys: 2 dummy objects fruits: 'orange', fish: 'barracuda' } // // alias: can not specify aliases by no token, then not update this. } }) .end(function(err, res){ expect(res).to.have.status(400); expect(res).to.be.json; expect(res.body).to.be.an('object'); expect(res.body.result).to.be.a('boolean').to.be.false; expect(res.body.message).to.be.a('string').to.equal('POST body does not have resource data'); done(); }); }); it('POST /v1/resource : failure set alias resource by no token with status 400', function(done){ // eslint-disable-line no-undef chai.request(app) .post('/v1/resource/yrn:yahoo:::tenant0:resource:k2hr3_entest_obj_res_03') // path: yrn:yahoo:::tenant0:resource:k2hr3_entest_obj_res_03 .set('content-type', 'application/json') .send({ resource: { port: null, // port: null = 0 = any cuk: null, // cuk: null role: 'yrn:yahoo:::tenant0:role:k2hr3_entest_obj_role_03', // role: yrn:yahoo:::tenant0:role:k2hr3_entest_obj_role_03 (this role can access to k2hr3_entest_obj_res_03) type: 'string', // type: string data: 'autotest_post:string:value', // data: dummy string keys: { // keys: 2 dummy objects fruits: 'orange', fish: 'barracuda' }, alias: [ // alias: 2 dummy resource paths 'yrn:yahoo:::tenant0:resource:autotest_post_dummy_alias3', 'yrn:yahoo:::tenant0:resource:autotest_post_dummy_alias4' ] } }) .end(function(err, res){ expect(res).to.have.status(400); expect(res).to.be.json; expect(res.body).to.be.an('object'); expect(res.body.result).to.be.a('boolean').to.be.false; expect(res.body.message).to.be.a('string').to.equal('POST resource:alias field is specified, but it is not allowed by not user token : ["yrn:yahoo:::tenant0:resource:autotest_post_dummy_alias3","yrn:yahoo:::tenant0:resource:autotest_post_dummy_alias4"]'); done(); }); }); // // Run Test(PUT - NEW SET - SUCCESS) // it('PUT /v1/resource : set all new resource by scoped token with status 201', function(done){ // eslint-disable-line no-undef var uri = '/v1/resource'; uri += '?name=autotest_post_dummy_resource3'; // path: yrn:yahoo:::tenant0:resource:autotest_post_dummy_resource3 uri += '&type=string'; // type: string uri += '&data=' + JSON.stringify('autotest_post:string:value'); // data: dummy string uri += '&keys=' + JSON.stringify({ // keys: 2 dummy objects foo: 'bar', hoge: 'fuga' }); uri += '&alias=' + JSON.stringify([ // alias: 2 dummy resource paths 'yrn:yahoo:::tenant0:resource:autotest_post_dummy_alias1',