Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TEAMFOUR-499 - Service models unit tests #400

Merged
merged 2 commits into from
Jun 24, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
var items = [{
id: 1,
name: 'c1',
url: 'c1_url'
url: 'c1_url',
api_endpoint: {
Scheme: 'http',
Host: 'api.foo.com'
}
}];

$httpBackend.when('GET', '/pp/v1/proxy/v2/info').respond(200, {});
Expand Down Expand Up @@ -152,9 +156,9 @@
$scope.$apply();

serviceRegistrationCtrl.serviceInstances = [
{ name: 'c1', url: 'c1_url', username: 'dev', expires_at: 3600, valid: true },
{ name: 'c2', url: 'c2_url', username: 'dev', expires_at: 3600, valid: true },
{ name: 'c3', url: 'c3_url' }
{ name: 'c1', url: 'c1_url', api_endpoint: { Scheme: 'http', Host: 'c1_url' }, username: 'dev', expires_at: 3600, valid: true },
{ name: 'c2', url: 'c2_url', api_endpoint: { Scheme: 'http', Host: 'c2_url' },username: 'dev', expires_at: 3600, valid: true },
{ name: 'c3', url: 'c3_url', api_endpoint: { Scheme: 'http', Host: 'c3_url' } }
];
serviceRegistrationCtrl.userCnsiModel.numValid = 2;

Expand Down
63 changes: 39 additions & 24 deletions src/plugins/cloud-foundry/api/hcf/ServiceInstances.mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,44 +55,59 @@
};
},

ListAllServicePlansForService: function (guid) {
ListAllServiceInstances: function () {
return {
url: '/pp/v1/proxy/v2/services/' + guid + '/service_plans',
url: '/pp/v1/proxy/v2/service_instances',
response: {
200: {
body: {
guid: {
total_results: 1,
total_pages: 1,
prev_url: null,
next_url: null,
resources: [
"total_results": 1,
"total_pages": 1,
"prev_url": null,
"next_url": null,
"resources": [
{
metadata: {
guid: "d22b3754-d093-42a2-a294-5fda6c6db44c",
url: "/v2/service_plans/d22b3754-d093-42a2-a294-5fda6c6db44c",
created_at: "2016-05-12T00:45:19Z",
updated_at: null
"metadata": {
"guid": "b6e8fcbf-5b91-4850-ad4b-00b96e38c6d0",
"url": "/v2/service_instances/b6e8fcbf-5b91-4850-ad4b-00b96e38c6d0",
"created_at": "2016-05-12T00:45:07Z",
"updated_at": null
},
entity: {
name: "name-1686",
free: false,
description: "desc-109",
service_guid: "67229bc6-8fc9-4fe1-b8bc-8790cdae5334",
extra: null,
unique_id: "e010ae61-ec46-433d-bdf6-136ead10828b",
public: true,
active: true,
service_url: "/v2/services/67229bc6-8fc9-4fe1-b8bc-8790cdae5334",
service_instances_url: "/v2/service_plans/d22b3754-d093-42a2-a294-5fda6c6db44c/service_instances"
"entity": {
"name": "name-178",
"credentials": {
"creds-key-2": "creds-val-2"
},
"service_plan_guid": "9346c902-124e-4c35-9f6c-bfa4848887e5",
"space_guid": "de83d7e1-1894-49ce-940f-dea4bc484eac",
"gateway_data": null,
"dashboard_url": null,
"type": "managed_service_instance",
"last_operation": {
"type": "create",
"state": "succeeded",
"description": "service broker-provided description",
"updated_at": "2016-05-12T00:45:07Z",
"created_at": "2016-05-12T00:45:07Z"
},
"tags": [
"accounting",
"mongodb"
],
"space_url": "/v2/spaces/de83d7e1-1894-49ce-940f-dea4bc484eac",
"service_plan_url": "/v2/service_plans/9346c902-124e-4c35-9f6c-bfa4848887e5",
"service_bindings_url": "/v2/service_instances/b6e8fcbf-5b91-4850-ad4b-00b96e38c6d0/service_bindings",
"service_keys_url": "/v2/service_instances/b6e8fcbf-5b91-4850-ad4b-00b96e38c6d0/service_keys",
"routes_url": "/v2/service_instances/b6e8fcbf-5b91-4850-ad4b-00b96e38c6d0/routes"
}
}
]
}
}
}
}
}
};
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@
var applicationApi = this.apiManager.retrieve('cloud-foundry.api.Apps');
return applicationApi.UpdateApp(guid, newAppSpec)
.then(function (response) {
if(response.data[cnsiGuid].metadata) {
if (response.data[cnsiGuid].metadata) {
that.getAppSummary(cnsiGuid, response.data[cnsiGuid].metadata.guid);
}
return response.data[cnsiGuid];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
* @returns {ApplicationAccess}
*/
function ApplicationAccessFactory(modelManager) {


/**
* @name: ApplicationAccess
* @description: Constructor for ApplicationAccess
Expand All @@ -40,19 +38,16 @@
this.principal = principal;
this.flags = flags;
this.baseAccess = modelManager.retrieve('cloud-foundry.model.auth.checkers.baseAccess')(principal);

}

angular.extend(ApplicationAccess.prototype, {

/**
* @name: create
* @description: Does user have create application permission in the space
* @param {Object} space Domain space
* @returns {boolean}
*/
create: function(space) {

// Admin
if (this.baseAccess.create(space)) {
return true;
Expand All @@ -69,15 +64,13 @@
* @returns {boolean}
*/
update: function(app) {

// Admin
if (this.baseAccess.update(app)) {
return true;
}

// If user is developer in space app belongs to
return this.baseAccess._doesContainGuid(this.principal.userInfo.entity.spaces, app.entity.space_guid);

},

/**
Expand All @@ -104,5 +97,4 @@
return ApplicationAccess;
}


})();
7 changes: 3 additions & 4 deletions src/plugins/cloud-foundry/model/auth/checkers/base-access.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
modelManager.register('cloud-foundry.model.auth.checkers.baseAccess', BaseAccess);
}


function BaseAccess(principal) {
return {
create: function() {
Expand All @@ -33,12 +32,12 @@
delete: function() {
return principal.isAdmin();
},

_doesContainGuid: function(array, guid) {
return array.map(function(element) {
return element.metadata.guid;
}).indexOf(guid) > -1;
return element.metadata.guid;
}).indexOf(guid) > -1;
}

};
}
})();
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
* @param {app.api.modelManager} modelManager - the Model management service
* @returns {OrganizationAccess}
*/
function OrganizationAccessFactory(modelManager) {

function OrganizationAccessFactory(modelManager) {
/**
* @name: OrganizationAccess
* @description: Constructor for OrganizationAccess
Expand All @@ -39,7 +38,6 @@
this.principal = principal;
this.flags = flags;
this.baseAccess = modelManager.retrieve('cloud-foundry.model.auth.checkers.baseAccess')(principal);

}

angular.extend(OrganizationAccess.prototype, {
Expand Down Expand Up @@ -95,5 +93,4 @@
return OrganizationAccess;
}


})();
7 changes: 0 additions & 7 deletions src/plugins/cloud-foundry/model/auth/checkers/route-access.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
* @returns {RouteAccess}
*/
function RouteAccessFactory(modelManager) {

/**
* @name: RouteAccess
* @description: Constructor for RouteAccess
Expand All @@ -39,19 +38,16 @@
this.principal = principal;
this.flags = flags;
this.baseAccess = modelManager.retrieve('cloud-foundry.model.auth.checkers.baseAccess')(principal);

}

angular.extend(RouteAccess.prototype, {

/**
* @name: create
* @description: Does user have create route permission in the space
* @param {Object} space Domain space
* @returns {boolean}
*/
create: function(space) {

// Admin
if (this.baseAccess.create(space)) {
return true;
Expand Down Expand Up @@ -122,8 +118,6 @@
route.entity.space_guid);
},



/**
* @name: canHandle
* @description: Specifies that this ACL checker can handle `route` permission
Expand All @@ -138,5 +132,4 @@
return RouteAccess;
}


})();
Original file line number Diff line number Diff line change
Expand Up @@ -26,33 +26,29 @@
* @param {app.api.modelManager} modelManager - the Model management service
* @returns {ServiceInstanceAccess}
* @constructor
*/
*/
function ServiceInstanceAccessFactory(modelManager) {

/**
* @name: ServiceInstanceAccess
* @description: Constructor for ServiceInstanceAccess
* @param {Principal} principal Principal instance
* @param {Array} flags feature flags
* @constructor
*/
*/
function ServiceInstanceAccess(principal, flags) {
this.principal = principal;
this.flags = flags;

this.baseAccess = modelManager.retrieve('cloud-foundry.model.auth.checkers.baseAccess')(principal);
}

angular.extend(ServiceInstanceAccess.prototype, {

/**
* @name: create
* @description: Does user have create service instance permission in the space
* @param {Object} space Domain space
* @returns {boolean}
*/
create: function(space) {

// Admin
if (this.baseAccess.create(space)) {
return true;
Expand All @@ -67,28 +63,28 @@
/**
* @name: update
* @description: Does user have update service instance permission
* @param {Object} service_instance service instance detail
* @param {Object} serviceInstance service instance detail
* @returns {boolean}
*/
update: function(service_instance) {
update: function(serviceInstance) {
// Admin
if (this.baseAccess.update(service_instance)) {
if (this.baseAccess.update(serviceInstance)) {
return true;
}

// If user is developer in space the service instances belongs to
return this.baseAccess
._doesContainGuid(this.principal.userInfo.entity.spaces, service_instance.entity.space_guid);
._doesContainGuid(this.principal.userInfo.entity.spaces, serviceInstance.entity.space_guid);
},

/**
* @name: delete
* @description: Does user have delete application permission
* @param {Object} service_instance service instance detail
* @param {Object} serviceInstance service instance detail
* @returns {boolean}
*/
delete: function(service_instance) {
return this.baseAccess.update(service_instance);
delete: function(serviceInstance) {
return this.baseAccess.update(serviceInstance);
},

/**
Expand All @@ -105,5 +101,4 @@
return ServiceInstanceAccess;
}


})();
6 changes: 2 additions & 4 deletions src/plugins/cloud-foundry/model/auth/principal.factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@
];

function register(modelManager) {

modelManager.register('cloud-foundry.model.auth.principalFactory',
PrincipalFactory(modelManager));
}


/**
* @name: PrincipalFactory
* @description: Function to return a Principal instance
* @name PrincipalFactory
* @description Function to return a Principal instance
* @param {app.api.modelManager} modelManager - the Model management service
* @returns {Principal}
*/
Expand Down
11 changes: 5 additions & 6 deletions src/plugins/cloud-foundry/model/auth/principal.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@
* @name: isAllowed
* @description: Is user permitted to do the action
* @param {Object} context
* @param {String} resource_type ACL type
* @param {String} resourceType ACL type
* @param {String} action action name
* @param {Array} flags feature flags
* @returns {*}
*/
isAllowed: function(context, resource_type, action, flags) {
var accessChecker = this._getAccessChecker(resource_type, flags);
isAllowed: function(context, resourceType, action, flags) {
var accessChecker = this._getAccessChecker(resourceType, flags);
return accessChecker[action](context);
},

Expand Down Expand Up @@ -136,8 +136,8 @@
delete: 'delete'
}
};
}
,
},

/**
* @name: _getAccessChecker
* @description: Get Access checker for a given resource type
Expand All @@ -157,5 +157,4 @@
return Principal;
}


})();
Loading