Skip to content

Commit

Permalink
Empty owner instead of explicit address for ShareAttributeRequestItem (
Browse files Browse the repository at this point in the history
…#250)

* fix: remove code that causes wrong error message to be shown

* test: throw correct error message if empty owner is specified for IdentityAttribute in ShareAttributeRequestItem

* fix: remove misleading examples

* fix: remove processing of empty string

* fix: remove misleading tests

* chore: exclude 1098618

* chore: do not exclude 1098618 anymore
  • Loading branch information
britsta authored Aug 26, 2024
1 parent 119fd8b commit c1ec658
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 44 deletions.
1 change: 0 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ export class ShareAttributeRequestItemProcessor extends GenericRequestItemProces
}

const requestItemAttributeJSON = requestItem.attribute.toJSON();
if (requestItemAttributeJSON.owner === "") {
requestItemAttributeJSON.owner = this.currentIdentityAddress.toString();
}

if (!_.isEqual(foundAttribute.content.toJSON(), requestItemAttributeJSON)) {
return ValidationResult.error(
Expand Down Expand Up @@ -165,10 +162,6 @@ export class ShareAttributeRequestItemProcessor extends GenericRequestItemProces
_params: AcceptRequestItemParametersJSON,
requestInfo: LocalRequestInfo
): Promise<ShareAttributeAcceptResponseItem> {
if (requestItem.attribute.owner.toString() === "") {
requestItem.attribute.owner = requestInfo.peer;
}

const localAttribute = await this.consumptionController.attributes.createSharedLocalAttribute({
content: requestItem.attribute,
peer: requestInfo.peer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,6 @@ describe("ShareAttributeRequestItemProcessor", function () {
owner: CoreAddress.from("Sender")
})
},
{
scenario: "an Identity Attribute with owner=<empty string>",
result: "success",
attribute: IdentityAttribute.from({
value: GivenName.fromAny({ value: "AGivenName" }),
owner: CoreAddress.from("")
})
},
{
scenario: "an Identity Attribute with owner=someOtherOwner",
result: "error",
Expand All @@ -95,16 +87,6 @@ describe("ShareAttributeRequestItemProcessor", function () {
key: "AKey"
})
},
{
scenario: "a Relationship Attribute with owner=<empty string>",
result: "success",
attribute: RelationshipAttribute.from({
value: ProprietaryString.fromAny({ value: "AGivenName", title: "ATitle" }),
owner: CoreAddress.from("Sender"),
confidentiality: RelationshipAttributeConfidentiality.Public,
key: "AKey"
})
},
{
scenario: "a Relationship Attribute with owner=someOtherOwner",
result: "success",
Expand Down Expand Up @@ -245,6 +227,39 @@ describe("ShareAttributeRequestItemProcessor", function () {
});
});

test("returns error when an empty string is specified for the owner of the IdentityAttribute instead of the explicit address", async function () {
const sender = testAccount.identity.address;
const recipient = CoreAddress.from("Recipient");

const sourceAttribute = await consumptionController.attributes.createRepositoryAttribute({
content: IdentityAttribute.from({
owner: sender,
value: GivenName.from({
value: "AGivenName"
})
})
});

const requestItem = ShareAttributeRequestItem.from({
mustBeAccepted: false,
attribute: IdentityAttribute.from({
owner: CoreAddress.from(""),
value: GivenName.from({
value: "AGivenName"
})
}),
sourceAttributeId: sourceAttribute.id
});
const request = Request.from({ items: [requestItem] });

const result = await processor.canCreateOutgoingRequestItem(requestItem, request, recipient);

expect(result).errorValidationResult({
code: "error.consumption.requests.invalidRequestItem",
message: `The Attribute with the given sourceAttributeId '${sourceAttribute.id.toString()}' does not match the given Attribute.`
});
});

test("returns error when the IdentityAttribute is a shared copy of a RepositoryAttribute", async function () {
const sender = testAccount.identity.address;
const recipient = CoreAddress.from("Recipient");
Expand Down Expand Up @@ -929,14 +944,14 @@ describe("ShareAttributeRequestItemProcessor", function () {
});

describe("accept", function () {
test("in case of an IdentityAttribute with 'owner=<empty>', creates a Local Attribute for the Sender of the Request", async function () {
test("returns success when accepting a shared IdentityAttribute", async function () {
const sender = CoreAddress.from("Sender");

const requestItem = ShareAttributeRequestItem.from({
mustBeAccepted: true,
sourceAttributeId: CoreId.from("aSourceAttributeId"),
attribute: TestObjectFactory.createIdentityAttribute({
owner: CoreAddress.from("")
owner: sender
})
});
const incomingRequest = LocalRequest.from({
Expand Down Expand Up @@ -965,14 +980,14 @@ describe("ShareAttributeRequestItemProcessor", function () {
expect(createdAttribute!.content.owner.toString()).toStrictEqual(sender.toString());
});

test("in case of a RelationshipAttribute with 'owner=<empty>', creates a Local Attribute for the Sender of the Request", async function () {
test("returns success when accepting a shared RelationshipAttribute", async function () {
const sender = CoreAddress.from("Sender");

const requestItem = ShareAttributeRequestItem.from({
mustBeAccepted: true,
sourceAttributeId: CoreId.from("aSourceAttributeId"),
attribute: TestObjectFactory.createRelationshipAttribute({
owner: CoreAddress.from("")
owner: sender
})
});
const incomingRequest = LocalRequest.from({
Expand Down Expand Up @@ -1004,18 +1019,10 @@ describe("ShareAttributeRequestItemProcessor", function () {

describe("applyIncomingResponseItem", function () {
test.each([
{
attributeType: "IdentityAttribute",
attributeOwner: ""
},
{
attributeType: "IdentityAttribute",
attributeOwner: "Sender"
},
{
attributeType: "RelationshipAttribute",
attributeOwner: ""
},
{
attributeType: "RelationshipAttribute",
attributeOwner: "Sender"
Expand All @@ -1024,19 +1031,17 @@ describe("ShareAttributeRequestItemProcessor", function () {
"in case of a ${value.attributeType}, creates a LocalAttribute with the Attribute from the RequestItem and the attributeId from the ResponseItem for the peer of the Request",

async function (testParams) {
testParams.attributeOwner = testParams.attributeOwner.replace("Sender", testAccount.identity.address.toString());

const sourceAttributeContent =
testParams.attributeType === "IdentityAttribute"
? TestObjectFactory.createIdentityAttribute({ owner: testAccount.identity.address })
: TestObjectFactory.createRelationshipAttribute({ owner: testAccount.identity.address });
? TestObjectFactory.createIdentityAttribute({ owner: CoreAddress.from(testParams.attributeOwner) })
: TestObjectFactory.createRelationshipAttribute({ owner: CoreAddress.from(testParams.attributeOwner) });

const sourceAttribute = await consumptionController.attributes.createAttributeUnsafe({
content: sourceAttributeContent
});

testParams.attributeOwner = testParams.attributeOwner.replace("Sender", testAccount.identity.address.toString());

sourceAttribute.content.owner = CoreAddress.from(testParams.attributeOwner);

const { localRequest, requestItem } = await createLocalRequest({ sourceAttribute });

const responseItem = ShareAttributeAcceptResponseItem.from({
Expand Down

0 comments on commit c1ec658

Please sign in to comment.