k2hr3-api
Version:
K2HR3 REST API is K2hdkc based Resource and Roles and policy Rules
1,120 lines (1,047 loc) • 284 kB
JavaScript
/*
* 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 : ROLE', function(){ // eslint-disable-line no-undef
//
// Common data
//
var alltokens = {};
var user_roletoken_tenant0_k2hr3_entest_obj_role_01 = '';
var user_roletoken_tenant0_k2hr3_entest_obj_role_02 = '';
var user_roletoken_tenant0_k2hr3_entest_obj_role_03 = '';
var user_roletoken_tenant0_k2hr3_entest_obj_role_04 = '';
var user_roletoken_tenant0_k2hr3_entest_str_role_01 = '';
var user_roletoken_tenant0_k2hr3_entest_str_role_02 = '';
var user_roletoken_tenant0_k2hr3_entest_str_role_03 = '';
var user_roletoken_tenant0_test_service_tenant = '';
var user_roletoken_testservice_tenant0_acr_role = '';
var ip_roletoken_tenant0_k2hr3_entest_obj_role_01 = '';
var ip_roletoken_tenant0_k2hr3_entest_obj_role_02 = '';
var ip_roletoken_tenant0_k2hr3_entest_obj_role_03 = '';
var ip_roletoken_tenant0_k2hr3_entest_obj_role_04 = '';
var ip_roletoken_tenant0_k2hr3_entest_str_role_01 = '';
var ip_roletoken_tenant0_k2hr3_entest_str_role_02 = '';
var ip_roletoken_tenant0_k2hr3_entest_str_role_03 = '';
var ip_roletoken_tenant0_test_service_tenant = '';
var ip_roletoken_testservice_tenant0_acr_role = '';
var ip_roletoken_tenant0_auto_test_role = '';
var ip_roletoken_tenant0_k8s_test_role = '';
var user_roletoken_tenant0_autotest_post_dummy_role1= ''; // eslint-disable-line no-unused-vars
var user_roletoken_tenant0_autotest_post_dummy_role3= ''; // eslint-disable-line no-unused-vars
var user_roletoken_tenant0_autotest_put_dummy_role1 = ''; // eslint-disable-line no-unused-vars
var user_roletoken_tenant0_autotest_put_dummy_role4 = ''; // eslint-disable-line no-unused-vars
var ip_roletoken_tenant0_autotest_post_dummy_role1 = ''; // eslint-disable-line no-unused-vars
var ip_roletoken_tenant0_autotest_post_dummy_role3 = ''; // eslint-disable-line no-unused-vars
var ip_roletoken_tenant0_autotest_put_dummy_role1 = ''; // eslint-disable-line no-unused-vars
var ip_roletoken_tenant0_autotest_put_dummy_role4 = ''; // eslint-disable-line no-unused-vars
//
// 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/FAILURE)
//
it('POST /v1/role : set all new role(autotest_post_dummy_role1) by scoped token with status 201', function(done){ // eslint-disable-line no-undef
chai.request(app)
.post('/v1/role')
.set('content-type', 'application/json')
.set('x-auth-token', alltokens.scopedtoken.tenant0) // tenant0
.send({
role: {
name: 'autotest_post_dummy_role1', // path: yrn:yahoo:::tenant0:role:autotest_post_dummy_role1
policies: [ // policies: yrn:yahoo:::tenant0:policy:k2hr3_entest_obj_pol_03
'yrn:yahoo:::tenant0:policy:k2hr3_entest_obj_pol_03'
],
alias: [ // alias: yrn:yahoo:::tenant0:role:autotest_post_dummy_role2(not exist)
'yrn:yahoo:::tenant0:role:autotest_post_dummy_role2'
]
}
})
.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/role/autotest_post_dummy_role1?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.role).to.be.an('object');
expect(res.body.role.policies).to.be.an.instanceof(Array).to.have.lengthOf(1);
expect(res.body.role.policies[0]).to.be.a('string').to.equal('yrn:yahoo:::tenant0:policy:k2hr3_entest_obj_pol_03');
expect(res.body.role.aliases).to.be.an.instanceof(Array).to.have.lengthOf(1);
expect(res.body.role.aliases[0]).to.be.a('string').to.equal('yrn:yahoo:::tenant0:role:autotest_post_dummy_role2');
expect(res.body.role.hosts).to.be.an('object').to.deep.equal({hostnames: [], ips: []});
done();
});
});
});
it('POST /v1/role : failure(no token) set all new role(autotest_post_error_role1) by scoped token with status 400', function(done){ // eslint-disable-line no-undef
chai.request(app)
.post('/v1/role')
.set('content-type', 'application/json')
.send({
role: {
name: 'autotest_post_error_role1', // path: yrn:yahoo:::tenant0:role:autotest_post_error_role1
policies: [ // policies: yrn:yahoo:::tenant0:policy:k2hr3_entest_obj_pol_03
'yrn:yahoo:::tenant0:policy:k2hr3_entest_obj_pol_03'
],
alias: [ // alias: yrn:yahoo:::tenant0:role:autotest_post_error_role2(not exist)
'yrn:yahoo:::tenant0:role:autotest_post_error_role2'
]
}
})
.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.an('string').to.equal('There is no x-auth-token header');
done();
});
});
it('POST /v1/role : failure(invalid user token) set all new role(autotest_post_error_role1) by scoped token with status 401', function(done){ // eslint-disable-line no-undef
chai.request(app)
.post('/v1/role')
.set('content-type', 'application/json')
.set('x-auth-token', 'U=invalid_token') // invalid token
.send({
role: {
name: 'autotest_post_error_role1', // path: yrn:yahoo:::tenant0:role:autotest_post_error_role1
policies: [ // policies: yrn:yahoo:::tenant0:policy:k2hr3_entest_obj_pol_03
'yrn:yahoo:::tenant0:policy:k2hr3_entest_obj_pol_03'
],
alias: [ // alias: yrn:yahoo:::tenant0:role:autotest_post_error_role2(not exist)
'yrn:yahoo:::tenant0:role:autotest_post_error_role2'
]
}
})
.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.an('string').to.equal('token(invalid_token) is not existed, because it is expired or not set yet.');
done();
});
});
it('POST /v1/role : failure(invalid role token) set all new role(autotest_post_error_role1) by scoped token with status 400', function(done){ // eslint-disable-line no-undef
chai.request(app)
.post('/v1/role')
.set('content-type', 'application/json')
.set('x-auth-token', 'R=invalid_token') // invalid token
.send({
role: {
name: 'autotest_post_error_role1', // path: yrn:yahoo:::tenant0:role:autotest_post_error_role1
policies: [ // policies: yrn:yahoo:::tenant0:policy:k2hr3_entest_obj_pol_03
'yrn:yahoo:::tenant0:policy:k2hr3_entest_obj_pol_03'
],
alias: [ // alias: yrn:yahoo:::tenant0:role:autotest_post_error_role2(not exist)
'yrn:yahoo:::tenant0:role:autotest_post_error_role2'
]
}
})
.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.an('string').to.equal('x-auth-token header token is not role token');
done();
});
});
it('POST /v1/role : failure set all new role(no role name) by scoped token with status 400', function(done){ // eslint-disable-line no-undef
chai.request(app)
.post('/v1/role')
.set('content-type', 'application/json')
.set('x-auth-token', alltokens.scopedtoken.tenant0) // tenant0
.send({
role: {
policies: [ // policies: yrn:yahoo:::tenant0:policy:k2hr3_entest_obj_pol_03
'yrn:yahoo:::tenant0:policy:k2hr3_entest_obj_pol_03'
],
alias: [ // alias: yrn:yahoo:::tenant0:role:autotest_post_error_role2(not exist)
'yrn:yahoo:::tenant0:role:autotest_post_error_role2'
]
}
})
.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.an('string').to.equal('role:name field is wrong : undefined');
done();
});
});
it('POST /v1/role : failure(no data) set all new role(autotest_post_error_role1) by scoped token with status 400', function(done){ // eslint-disable-line no-undef
chai.request(app)
.post('/v1/role')
.set('content-type', 'application/json')
.set('x-auth-token', alltokens.scopedtoken.tenant0) // tenant0
.send({
wrong_role: {
name: 'autotest_post_error_role1', // path: yrn:yahoo:::tenant0:role:autotest_post_error_role1
policies: [ // policies: yrn:yahoo:::tenant0:policy:k2hr3_entest_obj_pol_03
'yrn:yahoo:::tenant0:policy:k2hr3_entest_obj_pol_03'
],
alias: [ // alias: yrn:yahoo:::tenant0:role:autotest_post_error_role2(not exist)
'yrn:yahoo:::tenant0:role:autotest_post_error_role2'
]
}
})
.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.an('string').to.equal('POST body does not have role data');
done();
});
});
//
// Run Test(POST - ADD HOST - SUCCESS/FAILURE)
//
it('POST /v1/role : add one host to role(autotest_post_dummy_role1) by scoped token with status 201', function(done){ // eslint-disable-line no-undef
chai.request(app)
.post('/v1/role/autotest_post_dummy_role1') // path: yrn:yahoo:::tenant0:role:autotest_post_dummy_role1
.set('content-type', 'application/json')
.set('x-auth-token', alltokens.scopedtoken.tenant0) // tenant0
.send({
host: {
host: 'role.auto.test.k2hr3.dummy.yahoo.co.jp', // host: role.auto.test.k2hr3.dummy.yahoo.co.jp
port: 0, // port: 0(any)
cuk: null, // cuk: null
extra: null // extra: null
},
clear_hostname: false,
clear_ips: false
})
.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/role/autotest_post_dummy_role1?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.role).to.be.an('object');
expect(res.body.role.policies).to.be.an.instanceof(Array).to.have.lengthOf(1);
expect(res.body.role.policies[0]).to.be.a('string').to.equal('yrn:yahoo:::tenant0:policy:k2hr3_entest_obj_pol_03');
expect(res.body.role.aliases).to.be.an.instanceof(Array).to.have.lengthOf(1);
expect(res.body.role.aliases[0]).to.be.a('string').to.equal('yrn:yahoo:::tenant0:role:autotest_post_dummy_role2');
expect(res.body.role.hosts).to.be.an('object').to.deep.equal({hostnames: ['role.auto.test.k2hr3.dummy.yahoo.co.jp * '], ips: []});
done();
});
});
});
it('POST /v1/role : failure(no token) add host to role(autotest_post_dummy_role1) by scoped token with status 400', function(done){ // eslint-disable-line no-undef
chai.request(app)
.post('/v1/role/autotest_post_dummy_role1') // path: yrn:yahoo:::tenant0:role:autotest_post_dummy_role1
.set('content-type', 'application/json')
.send({
host: {
host: 'role.auto.test.k2hr3.dummy.yahoo.co.jp', // host: role.auto.test.k2hr3.dummy.yahoo.co.jp
port: 0, // port: 0(any)
cuk: null, // cuk: null
extra: null // extra: null
},
clear_hostname: false,
clear_ips: false
})
.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.an('string').to.equal('There is no x-auth-token header');
done();
});
});
it('POST /v1/role : failure(invalid user token) add host to role(autotest_post_dummy_role1) by scoped token with status 401', function(done){ // eslint-disable-line no-undef
chai.request(app)
.post('/v1/role/autotest_post_dummy_role1') // path: yrn:yahoo:::tenant0:role:autotest_post_dummy_role1
.set('content-type', 'application/json')
.set('x-auth-token', 'U=invalid_token') // invalid token
.send({
host: {
host: 'role.auto.test.k2hr3.dummy.yahoo.co.jp', // host: role.auto.test.k2hr3.dummy.yahoo.co.jp
port: 0, // port: 0(any)
cuk: null, // cuk: null
extra: null // extra: null
},
clear_hostname: false,
clear_ips: false
})
.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.an('string').to.equal('token(invalid_token) is not existed, because it is expired or not set yet.');
done();
});
});
it('POST /v1/role : failure(invalid role token) add host to role(autotest_post_dummy_role1) by scoped token with status 401', function(done){ // eslint-disable-line no-undef
chai.request(app)
.post('/v1/role/autotest_post_dummy_role1') // path: yrn:yahoo:::tenant0:role:autotest_post_dummy_role1
.set('content-type', 'application/json')
.set('x-auth-token', 'R=invalid_token') // invalid token
.send({
host: {
host: 'role.auto.test.k2hr3.dummy.yahoo.co.jp', // host: role.auto.test.k2hr3.dummy.yahoo.co.jp
port: 0, // port: 0(any)
cuk: null, // cuk: null
extra: null // extra: null
},
clear_hostname: false,
clear_ips: false
})
.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.an('string').to.equal('token(invalid_token) is not existed, because it is expired or not set yet.');
done();
});
});
it('POST /v1/role : add one host to role(new autotest_post_dummy_role3) by scoped token with status 400', function(done){ // eslint-disable-line no-undef
chai.request(app)
.post('/v1/role/autotest_post_dummy_role3') // path: yrn:yahoo:::tenant0:role:autotest_post_dummy_role3
.set('content-type', 'application/json')
.set('x-auth-token', alltokens.scopedtoken.tenant0) // tenant0
.send({
host: {
host: 'role.auto.test.k2hr3.dummy.yahoo.co.jp', // host: role.auto.test.k2hr3.dummy.yahoo.co.jp
port: 0, // port: 0(any)
cuk: null, // cuk: null
extra: null // extra: null
},
clear_hostname: false,
clear_ips: false
})
.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/role/autotest_post_dummy_role3?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.role).to.be.an('object');
expect(res.body.role.policies).to.be.an.instanceof(Array).to.have.lengthOf(0);
expect(res.body.role.aliases).to.be.an.instanceof(Array).to.have.lengthOf(0);
expect(res.body.role.hosts).to.be.an('object').to.deep.equal({hostnames: ['role.auto.test.k2hr3.dummy.yahoo.co.jp * '], ips: []});
done();
});
});
});
it('POST /v1/role : failure(no data) add host to role(autotest_post_dummy_role1) by scoped token with status 400', function(done){ // eslint-disable-line no-undef
chai.request(app)
.post('/v1/role/autotest_post_dummy_role1') // path: yrn:yahoo:::tenant0:role:autotest_post_dummy_role1
.set('content-type', 'application/json')
.set('x-auth-token', alltokens.scopedtoken.tenant0) // tenant0
.send({
wrong_host: {
host: 'role.auto.test.k2hr3.dummy.yahoo.co.jp', // host: role.auto.test.k2hr3.dummy.yahoo.co.jp
port: 0, // port: 0(any)
cuk: null, // cuk: null
extra: null // extra: null
},
clear_hostname: false,
clear_ips: false
})
.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.an('string').to.equal('POST body does not have host data');
done();
});
});
it('POST /v1/role : add no host name to role(autotest_post_dummy_role3) by scoped token with status 201', function(done){ // eslint-disable-line no-undef
chai.request(app)
.post('/v1/role/autotest_post_dummy_role3') // path: yrn:yahoo:::tenant0:role:autotest_post_dummy_role3
.set('content-type', 'application/json')
.set('x-auth-token', alltokens.scopedtoken.tenant0) // tenant0
.send({
host: {
port: 0, // port: 0(any)
cuk: null, // cuk: null
extra: null // extra: null
},
clear_hostname: false,
clear_ips: false
})
.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/role/autotest_post_dummy_role3?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.role).to.be.an('object');
expect(res.body.role.policies).to.be.an.instanceof(Array).to.have.lengthOf(0);
expect(res.body.role.aliases).to.be.an.instanceof(Array).to.have.lengthOf(0);
expect(res.body.role.hosts).to.be.an('object').to.deep.equal({hostnames: ['role.auto.test.k2hr3.dummy.yahoo.co.jp * '], ips: ['127.0.0.1 * ']});
done();
});
});
});
it('POST /v1/role : add empty host data to role(autotest_post_dummy_role3) by scoped token with status 201', function(done){ // eslint-disable-line no-undef
chai.request(app)
.post('/v1/role/autotest_post_dummy_role3') // path: yrn:yahoo:::tenant0:role:autotest_post_dummy_role3
.set('content-type', 'application/json')
.set('x-auth-token', alltokens.scopedtoken.tenant0) // tenant0
.send({
host: {
},
clear_hostname: false,
clear_ips: false
})
.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/role/autotest_post_dummy_role3?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.role).to.be.an('object');
expect(res.body.role.policies).to.be.an.instanceof(Array).to.have.lengthOf(0);
expect(res.body.role.aliases).to.be.an.instanceof(Array).to.have.lengthOf(0);
expect(res.body.role.hosts).to.be.an('object').to.deep.equal({hostnames: ['role.auto.test.k2hr3.dummy.yahoo.co.jp * '], ips: ['127.0.0.1 * ']});
done();
});
});
});
it('POST /v1/role : add empty host array to role(autotest_post_dummy_role3) by scoped token with status 201', function(done){ // eslint-disable-line no-undef
chai.request(app)
.post('/v1/role/autotest_post_dummy_role3') // path: yrn:yahoo:::tenant0:role:autotest_post_dummy_role3
.set('content-type', 'application/json')
.set('x-auth-token', alltokens.scopedtoken.tenant0) // tenant0
.send({
host: [],
clear_hostname: false,
clear_ips: false
})
.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/role/autotest_post_dummy_role3?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.role).to.be.an('object');
expect(res.body.role.policies).to.be.an.instanceof(Array).to.have.lengthOf(0);
expect(res.body.role.aliases).to.be.an.instanceof(Array).to.have.lengthOf(0);
expect(res.body.role.hosts).to.be.an('object').to.deep.equal({hostnames: ['role.auto.test.k2hr3.dummy.yahoo.co.jp * '], ips: ['127.0.0.1 * ']});
done();
});
});
});
it('POST /v1/role : add some host to role(autotest_post_dummy_role1) by scoped token with status 201', function(done){ // eslint-disable-line no-undef
chai.request(app)
.post('/v1/role/autotest_post_dummy_role1') // path: yrn:yahoo:::tenant0:role:autotest_post_dummy_role1
.set('content-type', 'application/json')
.set('x-auth-token', alltokens.scopedtoken.tenant0) // tenant0
.send({
host: [
{
host: 'role1.auto.test.k2hr3.dummy.yahoo.co.jp', // host: role1.auto.test.k2hr3.dummy.yahoo.co.jp
port: 8000, // port: 8000
cuk: null, // cuk: null
extra: null // extra: null
},
{
host: 'role2.auto.test.k2hr3.dummy.yahoo.co.jp', // host: role2.auto.test.k2hr3.dummy.yahoo.co.jp
port: null, // port: null(any)
cuk: null, // cuk: null
extra: null // extra: null
},
{
host: 'role3.auto.test.k2hr3.dummy.yahoo.co.jp', // host: role3.auto.test.k2hr3.dummy.yahoo.co.jp
port: 8000, // port: 8000
cuk: 'cuk', // cuk: cuk
extra: 'openstack-auto-v1' // extra: openstack-auto-v1(if cuk is string type, must be openstack-auto-v1)
},
],
clear_hostname: false,
clear_ips: false
})
.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/role/autotest_post_dummy_role1?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.role).to.be.an('object');
expect(res.body.role.policies).to.be.an.instanceof(Array).to.have.lengthOf(1);
expect(res.body.role.policies[0]).to.be.a('string').to.equal('yrn:yahoo:::tenant0:policy:k2hr3_entest_obj_pol_03');
expect(res.body.role.aliases).to.be.an.instanceof(Array).to.have.lengthOf(1);
expect(res.body.role.aliases[0]).to.be.a('string').to.equal('yrn:yahoo:::tenant0:role:autotest_post_dummy_role2');
expect(res.body.role.hosts).to.be.an('object').to.deep.equal({hostnames: ['role.auto.test.k2hr3.dummy.yahoo.co.jp * ', 'role1.auto.test.k2hr3.dummy.yahoo.co.jp 8000 ', 'role2.auto.test.k2hr3.dummy.yahoo.co.jp * ', 'role3.auto.test.k2hr3.dummy.yahoo.co.jp 8000 cuk openstack-auto-v1'], ips: []});
done();
});
});
});
it('POST /v1/role : add some same host with aonther port to role(autotest_post_dummy_role1) by scoped token with status 201', function(done){ // eslint-disable-line no-undef
chai.request(app)
.post('/v1/role/autotest_post_dummy_role1') // path: yrn:yahoo:::tenant0:role:autotest_post_dummy_role1
.set('content-type', 'application/json')
.set('x-auth-token', alltokens.scopedtoken.tenant0) // tenant0
.send({
host: [
{
host: 'role1.auto.test.k2hr3.dummy.yahoo.co.jp', // host: role1.auto.test.k2hr3.dummy.yahoo.co.jp
port: 0, // port: 0(any) : 8000 -> 0
cuk: null, // cuk: null
extra: null // extra: null
},
{
host: 'role2.auto.test.k2hr3.dummy.yahoo.co.jp', // host: role2.auto.test.k2hr3.dummy.yahoo.co.jp
port: 8000, // port: 8000 : 0 <- 8000
cuk: null, // cuk: null
extra: null // extra: null
},
{
host: 'role3.auto.test.k2hr3.dummy.yahoo.co.jp', // host: role3.auto.test.k2hr3.dummy.yahoo.co.jp
port: 9000, // port: 9000 : 8000 + 9000
cuk: 'cuk', // cuk: cuk
extra: 'openstack-auto-v1' // extra: openstack-auto-v1(if cuk is string type, must be openstack-auto-v1)
},
],
clear_hostname: false,
clear_ips: false
})
.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/role/autotest_post_dummy_role1?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.role).to.be.an('object');
expect(res.body.role.policies).to.be.an.instanceof(Array).to.have.lengthOf(1);
expect(res.body.role.policies[0]).to.be.a('string').to.equal('yrn:yahoo:::tenant0:policy:k2hr3_entest_obj_pol_03');
expect(res.body.role.aliases).to.be.an.instanceof(Array).to.have.lengthOf(1);
expect(res.body.role.aliases[0]).to.be.a('string').to.equal('yrn:yahoo:::tenant0:role:autotest_post_dummy_role2');
expect(res.body.role.hosts).to.be.an('object').to.deep.equal({hostnames: ['role.auto.test.k2hr3.dummy.yahoo.co.jp * ', 'role1.auto.test.k2hr3.dummy.yahoo.co.jp * ', 'role2.auto.test.k2hr3.dummy.yahoo.co.jp 8000 ', 'role3.auto.test.k2hr3.dummy.yahoo.co.jp 8000 cuk openstack-auto-v1', 'role3.auto.test.k2hr3.dummy.yahoo.co.jp 9000 cuk openstack-auto-v1'], ips: []});
done();
});
});
});
it('POST /v1/role : add one host with clear to role(autotest_post_dummy_role1) by scoped token with status 201', function(done){ // eslint-disable-line no-undef
chai.request(app)
.post('/v1/role/autotest_post_dummy_role1') // path: yrn:yahoo:::tenant0:role:autotest_post_dummy_role1
.set('content-type', 'application/json')
.set('x-auth-token', alltokens.scopedtoken.tenant0) // tenant0
.send({
host: {
host: 'role0.auto.test.k2hr3.dummy.yahoo.co.jp', // host: role0.auto.test.k2hr3.dummy.yahoo.co.jp
port: 0, // port: 0(any)
cuk: null, // cuk: null
extra: null // extra: null
},
clear_hostname: true, // clear all hostname
clear_ips: false
})
.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/role/autotest_post_dummy_role1?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.role).to.be.an('object');
expect(res.body.role.policies).to.be.an.instanceof(Array).to.have.lengthOf(1);
expect(res.body.role.policies[0]).to.be.a('string').to.equal('yrn:yahoo:::tenant0:policy:k2hr3_entest_obj_pol_03');
expect(res.body.role.aliases).to.be.an.instanceof(Array).to.have.lengthOf(1);
expect(res.body.role.aliases[0]).to.be.a('string').to.equal('yrn:yahoo:::tenant0:role:autotest_post_dummy_role2');
expect(res.body.role.hosts).to.be.an('object').to.deep.equal({hostnames: ['role0.auto.test.k2hr3.dummy.yahoo.co.jp * '], ips: []});
done();
});
});
});
it('POST /v1/role : add one ip to role(autotest_post_dummy_role1) by scoped token with status 201', function(done){ // eslint-disable-line no-undef
chai.request(app)
.post('/v1/role/autotest_post_dummy_role1') // path: yrn:yahoo:::tenant0:role:autotest_post_dummy_role1
.set('content-type', 'application/json')
.set('x-auth-token', alltokens.scopedtoken.tenant0) // tenant0
.send({
host: {
host: '127.0.0.1', // ip: 127.0.0.1
port: 0, // port: 0(any)
cuk: null, // cuk: null
extra: null // extra: null
},
clear_hostname: false,
clear_ips: false
})
.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/role/autotest_post_dummy_role1?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.role).to.be.an('object');
expect(res.body.role.policies).to.be.an.instanceof(Array).to.have.lengthOf(1);
expect(res.body.role.policies[0]).to.be.a('string').to.equal('yrn:yahoo:::tenant0:policy:k2hr3_entest_obj_pol_03');
expect(res.body.role.aliases).to.be.an.instanceof(Array).to.have.lengthOf(1);
expect(res.body.role.aliases[0]).to.be.a('string').to.equal('yrn:yahoo:::tenant0:role:autotest_post_dummy_role2');
expect(res.body.role.hosts).to.be.an('object').to.deep.equal({hostnames: ['role0.auto.test.k2hr3.dummy.yahoo.co.jp * '], ips: ['127.0.0.1 * ']});
done();
});
});
});
it('POST /v1/role : add some ip to role(autotest_post_dummy_role1) by scoped token with status 201', function(done){ // eslint-disable-line no-undef
chai.request(app)
.post('/v1/role/autotest_post_dummy_role1') // path: yrn:yahoo:::tenant0:role:autotest_post_dummy_role1
.set('content-type', 'application/json')
.set('x-auth-token', alltokens.scopedtoken.tenant0) // tenant0
.send({
host: [
{
host: '127.0.0.2', // host: 127.0.0.2
port: 8000, // port: 8000
cuk: null, // cuk: null
extra: null // extra: null
},
{
host: '127.0.0.3', // host: 127.0.0.3
port: null, // port: null(any)
cuk: null, // cuk: null
extra: null // extra: null
},
{
host: '127.0.0.4', // host: 127.0.0.4
port: 8000, // port: 8000
cuk: 'cuk', // cuk: cuk
extra: 'openstack-auto-v1' // extra: openstack-auto-v1(if cuk is string type, must be openstack-auto-v1)
},
],
clear_hostname: false,
clear_ips: false
})
.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/role/autotest_post_dummy_role1?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.role).to.be.an('object');
expect(res.body.role.policies).to.be.an.instanceof(Array).to.have.lengthOf(1);
expect(res.body.role.policies[0]).to.be.a('string').to.equal('yrn:yahoo:::tenant0:policy:k2hr3_entest_obj_pol_03');
expect(res.body.role.aliases).to.be.an.instanceof(Array).to.have.lengthOf(1);
expect(res.body.role.aliases[0]).to.be.a('string').to.equal('yrn:yahoo:::tenant0:role:autotest_post_dummy_role2');
expect(res.body.role.hosts).to.be.an('object').to.deep.equal({hostnames: ['role0.auto.test.k2hr3.dummy.yahoo.co.jp * '], ips: ['127.0.0.1 * ', '127.0.0.2 8000 ', '127.0.0.3 * ', '127.0.0.4 8000 cuk openstack-auto-v1']});
done();
});
});
});
it('POST /v1/role : add some same ip with another port to role(autotest_post_dummy_role1) by scoped token with status 201', function(done){ // eslint-disable-line no-undef
chai.request(app)
.post('/v1/role/autotest_post_dummy_role1') // path: yrn:yahoo:::tenant0:role:autotest_post_dummy_role1
.set('content-type', 'application/json')
.set('x-auth-token', alltokens.scopedtoken.tenant0) // tenant0
.send({
host: [
{
host: '127.0.0.2', // host: 127.0.0.2
port: 0, // port: 0(any) : 8000 -> 0
cuk: 'cuk', // cuk: cuk
extra: 'openstack-auto-v1' // extra: openstack-auto-v1(if cuk is string type, must be openstack-auto-v1)
},
{
host: '127.0.0.3', // host: 127.0.0.3
port: 8000, // port: 8000 : 0 <- 8000
cuk: 'cuk', // cuk: cuk
extra: 'openstack-auto-v1' // extra: openstack-auto-v1(if cuk is string type, must be openstack-auto-v1)
},
{
host: '127.0.0.4', // host: 127.0.0.4
port: 9000, // port: 9000 : 8000 + 9000
cuk: 'cuk', // cuk: cuk
extra: 'openstack-auto-v1' // extra: openstack-auto-v1(if cuk is string type, must be openstack-auto-v1)
},
],
clear_hostname: false,
clear_ips: false
})
.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/role/autotest_post_dummy_role1?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.role).to.be.an('object');
expect(res.body.role.policies).to.be.an.instanceof(Array).to.have.lengthOf(1);
expect(res.body.role.policies[0]).to.be.a('string').to.equal('yrn:yahoo:::tenant0:policy:k2hr3_entest_obj_pol_03');
expect(res.body.role.aliases).to.be.an.instanceof(Array).to.have.lengthOf(1);
expect(res.body.role.aliases[0]).to.be.a('string').to.equal('yrn:yahoo:::tenant0:role:autotest_post_dummy_role2');
expect(res.body.role.hosts).to.be.an('object').to.deep.equal({hostnames: ['role0.auto.test.k2hr3.dummy.yahoo.co.jp * '], ips: ['127.0.0.1 * ', '127.0.0.2 * cuk openstack-auto-v1', '127.0.0.3 8000 cuk openstack-auto-v1', '127.0.0.4 8000 cuk openstack-auto-v1', '127.0.0.4 9000 cuk openstack-auto-v1']});
done();
});
});
});
it('POST /v1/role : add one ip with clear to role(autotest_post_dummy_role1) by scoped token with status 201', function(done){ // eslint-disable-line no-undef
chai.request(app)
.post('/v1/role/autotest_post_dummy_role1') // path: yrn:yahoo:::tenant0:role:autotest_post_dummy_role1
.set('content-type', 'application/json')
.set('x-auth-token', alltokens.scopedtoken.tenant0) // tenant0
.send({
host: {
host: '127.0.0.1', // host: 127.0.0.1
port: 0, // port: 0(any)
cuk: null, // cuk: null
extra: null // extra: null
},
clear_hostname: false,
clear_ips: true // clear all hostname
})
.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/role/autotest_post_dummy_role1?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.role).to.be.an('object');
expect(res.body.role.policies).to.be.an.instanceof(Array).to.have.lengthOf(1);
expect(res.body.role.policies[0]).to.be.a('string').to.equal('yrn:yahoo:::tenant0:policy:k2hr3_entest_obj_pol_03');
expect(res.body.role.aliases).to.be.an.instanceof(Array).to.have.lengthOf(1);
expect(res.body.role.aliases[0]).to.be.a('string').to.equal('yrn:yahoo:::tenant0:role:autotest_post_dummy_role2');
expect(res.body.role.hosts).to.be.an('object').to.deep.equal({hostnames: ['role0.auto.test.k2hr3.dummy.yahoo.co.jp * '], ips: ['127.0.0.1 * ']});
done();
});
});
});
it('POST /v1/role : add ip to role(k2hr3_entest_obj_role_01/k2hr3_entest_obj_role_02) by role token with status 201', function(done){ // eslint-disable-line no-undef
chai.request(app)
.post('/v1/role/yrn:yahoo:::tenant0:role:k2hr3_entest_obj_role_01/k2hr3_entest_obj_role_02')// path: yrn:yahoo:::tenant0:role:k2hr3_entest_obj_role_01/k2hr3_entest_obj_role_02
.set('content-type', 'application/json')
.set('x-auth-token', alltokens.roletoken.tenant0_k2hr3_entest_obj_role_02) // token: yrn:yahoo:::tenant0:role:k2hr3_entest_obj_role_01/k2hr3_entest_obj_role_02
.send({
host: {
port: 0, // port: 0(any)
cuk: null, // cuk: null
extra: null // extra: null
}
})
.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/role/k2hr3_entest_obj_role_01/k2hr3_entest_obj_role_02?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.role).to.be.an('object');
expect(res.body.role.policies).to.be.an.instanceof(Array).to.have.lengthOf(1);
expect(res.body.role.policies[0]).to.be.a('string').to.equal('yrn:yahoo:::tenant0:policy:k2hr3_entest_obj_pol_02');
expect(res.body.role.aliases).to.be.an.instanceof(Array).to.have.lengthOf(1);
expect(res.body.role.aliases[0]).to.be.a('string').to.equal('yrn:yahoo:::tenant0:role:k2hr3_entest_obj_role_03');
expect(res.body.role.hosts).to.be.an('object');
expect(res.body.role.hosts.hostnames).to.be.an.instanceof(Array).to.have.lengthOf(2);
expect(res.body.role.hosts.hostnames[0]).to.be.a('string').to.equal('host01.k2hr3_entest_obj_02.k2hr3.yahoo.co.jp * ');
expect(res.body.role.hosts.hostnames[1]).to.be.a('string').to.equal('host02.k2hr3_entest_obj_02.k2hr3.yahoo.co.jp * ');
expect(res.body.role.hosts.ips).to.be.an.instanceof(Array).to.have.lengthOf(4);
expect(res.body.role.hosts.ips[0]).to.be.a('string').to.equal('127.0.0.1 * ');
expect(res.body.role.hosts.ips[1]).to.be.a('string').to.equal('127.1.2.0 * ');
expect(res.body.role.hosts.ips[2]).to.be.a('string').to.equal('127.1.2.1 * ');
expect(res.body.role.hosts.ips[3]).to.be.a('string').to.equal('127.10.10.10 * ');
done();
});
});
});
it('POST /v1/role : overwrite ip to role(k2hr3_entest_obj_role_01/k2hr3_entest_obj_role_02) by role token with status 201', function(done){ // eslint-disable-line no-undef
chai.request(app)
.post('/v1/role/yrn:yahoo:::tenant0:role:k2hr3_entest_obj_role_01/k2hr3_entest_obj_role_02')// path: yrn:yahoo:::tenant0:role:k2hr3_entest_obj_role_01/k2hr3_entest_obj_role_02
.set('content-type', 'application/json')
.set('x-auth-token', alltokens.roletoken.tenant0_k2hr3_entest_obj_role_02) // token: yrn:yahoo:::tenant0:role:k2hr3_entest_obj_role_01/k2hr3_entest_obj_role_02
.send({
host: {
port: 8000, // port: 8000 : 0 -> 8000
cuk: 'cuk', // cuk: cuk
extra: 'openstack-auto-v1' // extra: openstack-auto-v1(if cuk is string type, must be openstack-auto-v1)
}
})
.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/role/k2hr3_entest_obj_role_01/k2hr3_entest_obj_role_02?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.role).to.be.an('object');
expect(res.body.role.policies).to.be.an.instanceof(Array).to.have.lengthOf(1);
expect(res.body.role.policies[0]).to.be.a('string').to.equal('yrn:yahoo:::tenant0:policy:k2hr3_entest_obj_pol_02');
expect(res.body.role.aliases).to.be.an.instanceof(Array).to.have.lengthOf(1);
expect(res.body.role.aliases[0]).to.be.a('string').to.equal('yrn:yahoo:::tenant0:role:k2hr3_entest_obj_role_03');
expect(res.body.role.hosts).to.be.an('object');
expect(res.body.role.hosts.hostnames).to.be.an.instanceof(Array).to.have.lengthOf(2);
expect(res.body.role.hosts.hostnames[0]).to.be.a('string').to.equal('host01.k2hr3_entest_obj_02.k2hr3.yahoo.co.jp * ');
expect(res.body.role.hosts.hostnames[1]).to.be.a('string').to.equal('host02.k2hr3_entest_obj_02.k2hr3.yahoo.co.jp * ');
expect(res.body.role.hosts.ips).to.be.an.instanceof(Array).to.have.lengthOf(4);
expect(res.body.role.hosts.ips[0]).to.be.a('string').to.equal('127.0.0.1 8000 cuk openstack-auto-v1');
expect(res.body.role.hosts.ips[1]).to.be.a('string').to.equal('127.1.2.0 * ');
expect(res.body.role.hosts.ips[2]).to.be.a('string').to.equal('127.1.2.1 * ');
expect(res.body.role.hosts.ips[3]).to.be.a('string').to.equal('127.10.10.10 * ');
done();
});
});
});
//
// Run Test(PUT - NEW SET - SUCCESS/FAILURE)
//
it('PUT /v1/role : set all new role(autotest_put_dummy_role1) by scoped token with status 201', function(done){ // eslint-disable-line no-undef
var uri = '/v1/role';
uri += '?name=autotest_put_dummy_role1'; // path: yrn:yahoo:::tenant0:role:autotest_put_dummy_role1
uri += '&policies=' + JSON.stringify([
'yrn:yahoo:::tenant0:policy:k2hr3_entest_obj_pol_03' // policies: yrn:yahoo:::tenant0:policy:k2hr3_entest_obj_pol_03
]);
uri += '&alias=' + JSON.stringify([
'yrn:yahoo:::tenant0:role:autotest_put_dummy_role2' // alias: yrn:yahoo:::tenant0:role:autotest_put_dummy_role2(not exist)
]);
chai.request(app)
.put(uri)
.set('content-type', 'application/json')
.set('x-auth-token', alltokens.scopedtoken.tenant0) // tenant0
.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/role/autotest_put_dummy_role1?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.role).to.be.an('object');
expect(res.body.role.policies).to.be.an.instanceof(Array).to.have.lengthOf(1);
expect(res.body.role.policies[0]).to.be.a('string').to.equal('yrn:yahoo:::tenant0