[Entanglement] Correctly Call Policy Service
Move, Copy, and Link services correctly call the policy service to check whether composition is allowed. Fixes open-1254.
This commit is contained in:
@@ -83,8 +83,8 @@ define(
|
|||||||
}
|
}
|
||||||
return policyService.allow(
|
return policyService.allow(
|
||||||
"composition",
|
"composition",
|
||||||
object.getCapability('type'),
|
parentCandidate.getCapability('type'),
|
||||||
parentCandidate.getCapability('type')
|
object.getCapability('type')
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -44,8 +44,8 @@ define(
|
|||||||
}
|
}
|
||||||
return policyService.allow(
|
return policyService.allow(
|
||||||
"composition",
|
"composition",
|
||||||
object.getCapability('type'),
|
parentCandidate.getCapability('type'),
|
||||||
parentCandidate.getCapability('type')
|
object.getCapability('type')
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -51,8 +51,8 @@ define(
|
|||||||
}
|
}
|
||||||
return policyService.allow(
|
return policyService.allow(
|
||||||
"composition",
|
"composition",
|
||||||
object.getCapability('type'),
|
parentCandidate.getCapability('type'),
|
||||||
parentCandidate.getCapability('type')
|
object.getCapability('type')
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -60,10 +60,16 @@ define(
|
|||||||
policyService
|
policyService
|
||||||
);
|
);
|
||||||
object = domainObjectFactory({
|
object = domainObjectFactory({
|
||||||
name: 'object'
|
name: 'object',
|
||||||
|
capabilities: {
|
||||||
|
type: { type: 'object' }
|
||||||
|
}
|
||||||
});
|
});
|
||||||
parentCandidate = domainObjectFactory({
|
parentCandidate = domainObjectFactory({
|
||||||
name: 'parentCandidate'
|
name: 'parentCandidate',
|
||||||
|
capabilities: {
|
||||||
|
type: { type: 'parentCandidate' }
|
||||||
|
}
|
||||||
});
|
});
|
||||||
validate = function () {
|
validate = function () {
|
||||||
return copyService.validate(object, parentCandidate);
|
return copyService.validate(object, parentCandidate);
|
||||||
@@ -88,6 +94,15 @@ define(
|
|||||||
parentCandidate.id = 'b';
|
parentCandidate.id = 'b';
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("calls policy service with correct args", function () {
|
||||||
|
validate();
|
||||||
|
expect(policyService.allow).toHaveBeenCalledWith(
|
||||||
|
"composition",
|
||||||
|
parentCandidate.capabilities.type,
|
||||||
|
object.capabilities.type
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
it("and returns false", function () {
|
it("and returns false", function () {
|
||||||
policyService.allow.andReturn(false);
|
policyService.allow.andReturn(false);
|
||||||
expect(validate()).toBe(false);
|
expect(validate()).toBe(false);
|
||||||
|
|||||||
@@ -84,10 +84,23 @@ define(
|
|||||||
describe("defers to policyService", function () {
|
describe("defers to policyService", function () {
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
object.id = 'abc';
|
object.id = 'abc';
|
||||||
|
object.capabilities.type = { type: 'object' };
|
||||||
parentCandidate.id = 'xyz';
|
parentCandidate.id = 'xyz';
|
||||||
|
parentCandidate.capabilities.type = {
|
||||||
|
type: 'parentCandidate'
|
||||||
|
};
|
||||||
parentCandidate.model.composition = [];
|
parentCandidate.model.composition = [];
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("calls policy service with correct args", function () {
|
||||||
|
validate();
|
||||||
|
expect(mockPolicyService.allow).toHaveBeenCalledWith(
|
||||||
|
"composition",
|
||||||
|
parentCandidate.capabilities.type,
|
||||||
|
object.capabilities.type
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
it("and returns false", function () {
|
it("and returns false", function () {
|
||||||
mockPolicyService.allow.andReturn(true);
|
mockPolicyService.allow.andReturn(true);
|
||||||
expect(validate()).toBe(true);
|
expect(validate()).toBe(true);
|
||||||
|
|||||||
@@ -65,7 +65,8 @@ define(
|
|||||||
name: 'object',
|
name: 'object',
|
||||||
id: 'a',
|
id: 'a',
|
||||||
capabilities: {
|
capabilities: {
|
||||||
context: objectContextCapability
|
context: objectContextCapability,
|
||||||
|
type: { type: 'object' }
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -79,7 +80,10 @@ define(
|
|||||||
parentCandidate = domainObjectFactory({
|
parentCandidate = domainObjectFactory({
|
||||||
name: 'parentCandidate',
|
name: 'parentCandidate',
|
||||||
model: { composition: [] },
|
model: { composition: [] },
|
||||||
id: 'c'
|
id: 'c',
|
||||||
|
capabilities: {
|
||||||
|
type: { type: 'parentCandidate' }
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
validate = function () {
|
validate = function () {
|
||||||
@@ -112,6 +116,15 @@ define(
|
|||||||
|
|
||||||
describe("defers to policyService", function () {
|
describe("defers to policyService", function () {
|
||||||
|
|
||||||
|
it("calls policy service with correct args", function () {
|
||||||
|
validate();
|
||||||
|
expect(policyService.allow).toHaveBeenCalledWith(
|
||||||
|
"composition",
|
||||||
|
parentCandidate.capabilities.type,
|
||||||
|
object.capabilities.type
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
it("and returns false", function () {
|
it("and returns false", function () {
|
||||||
policyService.allow.andReturn(false);
|
policyService.allow.andReturn(false);
|
||||||
expect(validate()).toBe(false);
|
expect(validate()).toBe(false);
|
||||||
|
|||||||
Reference in New Issue
Block a user