Skip to content

Commit

Permalink
Merge branch 'fix/redundant-operator' into 'release/2023.1'
Browse files Browse the repository at this point in the history
OEQ-1586 - fix(ACLExpressionModule): redundant operator text for human-readable text and wrong "generate" function

See merge request edalex-group/development/oeq/openequella!240
  • Loading branch information
edalex-yinzi committed Aug 10, 2023
2 parents ed664ea + e87e529 commit 2287f63
Show file tree
Hide file tree
Showing 3 changed files with 216 additions and 183 deletions.
49 changes: 49 additions & 0 deletions react-front-end/__mocks__/ACLExpressionModule.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,15 @@ export const aclWithComplexSubExpression =
export const aclWithComplexSubExpressionInfix =
"Yasmin Day [user300] AND From 127.0.0.1%2F24 AND From *google* AND ( Owner OR Guest User Role OR Ronny Southgate [user400] OR ( NOT ( Fabienne Hobson [user100] OR Racheal Carlyle [user200] ) ) OR ( From aa AND ( NOT ( From bb OR From cc ) ) ) ) AND ( NOT ( Engineering & Computer Science Students OR Engineering & Computer Science Staff ) )";

export const aclWithEmptyRecipientExpression = "I:1 I:2 OR I:3 NOT AND";
export const aclWithEmptyRecipientExpressionInfix =
"( From 1 OR From 2 ) AND ( NOT From 3 )";

export const aclChildWithEmptyRecipientExpression =
"I:1 I:2 OR I:3 I:4 OR I:5 NOT AND OR";
export const aclChildWithEmptyRecipientExpressionInfix =
"From 1 OR From 2 OR ( ( From 3 OR From 4 ) AND ( NOT From 5 ) )";

export const everyoneACLExpression: ACLExpression = createACLExpression(
"OR",
[everyoneRecipient],
Expand Down Expand Up @@ -256,6 +265,46 @@ export const complexExpressionACLExpression: ACLExpression =
]
);

/**
* ```
* AND
* OR 1 2
* NOT 3
* ```
*/
export const withEmptyRecipientExpression: ACLExpression = createACLExpression(
"AND",
[],
[
createACLExpression("OR", [ipRecipient("1"), ipRecipient("2")], []),
createACLExpression("NOT", [ipRecipient("3")], []),
]
);

/**
* ```
* OR 1 2
* AND
* OR 3 4
* NOT 4
* ```
*/
export const childWithEmptyRecipientExpression: ACLExpression =
createACLExpression(
"OR",
[ipRecipient("1"), ipRecipient("2")],
[
createACLExpression(
"AND",
[],
[
createACLExpression("OR", [ipRecipient("3"), ipRecipient("4")], []),
createACLExpression("NOT", [ipRecipient("5")], []),
]
),
]
);

export const childSameOperatorExpression: ACLExpression = createACLExpression(
"AND",
[userContentAdminRecipient],
Expand Down
238 changes: 84 additions & 154 deletions react-front-end/__tests__/tsrc/modules/ACLExpressionModule.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ import {
aclUserInfix,
aclWithComplexSubExpression,
aclWithComplexSubExpressionInfix,
aclChildWithEmptyRecipientExpression,
aclChildWithEmptyRecipientExpressionInfix,
aclWithMultipleSubExpression,
aclWithMultipleSubExpressionInfix,
aclWithNestedSubExpression,
Expand All @@ -65,6 +67,7 @@ import {
childSameOperatorExpression,
complexExpressionACLExpression,
complexRedundantExpression,
childWithEmptyRecipientExpression,
emptyRecipientWithOneChildExpression,
everyoneACLExpression,
fourItemsACLExpression,
Expand Down Expand Up @@ -93,6 +96,9 @@ import {
withMultipleSubExpression,
withNestedSubExpressionACLExpression,
withSubExpressionACLExpression,
aclWithEmptyRecipientExpressionInfix,
aclWithEmptyRecipientExpression,
withEmptyRecipientExpression,
} from "../../../__mocks__/ACLExpressionModule.mock";
import { ignoreId } from "./ACLExpressionModuleTestHelper";

Expand All @@ -114,38 +120,71 @@ describe("ACLExpressionModule", () => {
aclExpression: ACLExpression
): E.Either<never, ACLExpression> => pipe(aclExpression, ignoreId, E.right);

const commonACLExpressionForParametricTests: [
string,
string,
string,
ACLExpression
][] = [
["everyone", aclEveryone, aclEveryoneInfix, everyoneACLExpression],
["aclOwner", aclOwner, aclOwnerInfix, ownerACLExpression],
["aclUser", aclUser, aclUserInfix, userACLExpression],
["aclNotUser", aclNotUser, aclNotUserInfix, notUserACLExpression],
["aclTwoItems", aclTwoItems, aclTwoItemsInfix, twoItemsACLExpression],
[
"aclThreeItems",
aclThreeItems,
aclThreeItemsInfix,
threeItemsACLExpression,
],
[
"fourItemsACLExpression",
aclFourItems,
aclFourItemsInfix,
fourItemsACLExpression,
],
[
"aclWithSubExpression",
aclWithSubExpression,
aclWithSubExpressionInfix,
withSubExpressionACLExpression,
],
[
"aclWithMultipleSubExpression",
aclWithMultipleSubExpression,
aclWithMultipleSubExpressionInfix,
withMultipleSubExpression,
],
[
"aclWithNestedSubExpression",
aclWithNestedSubExpression,
aclWithNestedSubExpressionInfix,
withNestedSubExpressionACLExpression,
],
[
"aclWithComplexSubExpression",
aclWithComplexSubExpression,
aclWithComplexSubExpressionInfix,
complexExpressionACLExpression,
],
[
"aclWithEmptyRecipientExpression",
aclWithEmptyRecipientExpression,
aclWithEmptyRecipientExpressionInfix,
withEmptyRecipientExpression,
],
[
"aclChildWithEmptyRecipientExpression",
aclChildWithEmptyRecipientExpression,
aclChildWithEmptyRecipientExpressionInfix,
childWithEmptyRecipientExpression,
],
];

describe("parse", () => {
it.each([
["everyone", aclEveryone, everyoneACLExpression],
["aclOwner", aclOwner, ownerACLExpression],
["aclUser", aclUser, userACLExpression],
["aclNotUser", aclNotUser, notUserACLExpression],
["aclTwoItems", aclTwoItems, twoItemsACLExpression],
["aclThreeItems", aclThreeItems, threeItemsACLExpression],
["fourItemsACLExpression", aclFourItems, fourItemsACLExpression],
[
"aclWithSubExpression",
aclWithSubExpression,
withSubExpressionACLExpression,
],
[
"aclWithMultipleSubExpression",
aclWithMultipleSubExpression,
withMultipleSubExpression,
],
[
"aclWithNestedSubExpression",
aclWithNestedSubExpression,
withNestedSubExpressionACLExpression,
],
[
"aclWithComplexSubExpression",
aclWithComplexSubExpression,
complexExpressionACLExpression,
],
])(
it.each(commonACLExpressionForParametricTests)(
"parse %s as ACL Expressions",
(_, aclExpression, expectedExpression) => {
(_, aclExpression, _infix, expectedExpression) => {
expect(parse(aclExpression)).toEqual(
expectedRightResult(expectedExpression)
);
Expand Down Expand Up @@ -225,37 +264,9 @@ describe("ACLExpressionModule", () => {
});

describe("generate", () => {
it.each([
["everyoneACLExpression", everyoneACLExpression, aclEveryone],
["ownerACLExpression", ownerACLExpression, aclOwner],
["userACLExpression", userACLExpression, aclUser],
["notUserACLExpression", notUserACLExpression, aclNotUser],
["twoItemsACLExpression", twoItemsACLExpression, aclTwoItems],
["threeItemsACLExpression", threeItemsACLExpression, aclThreeItems],
["fourItemsACLExpression", fourItemsACLExpression, aclFourItems],
[
"withSubExpressionACLExpression",
withSubExpressionACLExpression,
aclWithSubExpression,
],
[
"withMultipleSubExpression",
withMultipleSubExpression,
aclWithMultipleSubExpression,
],
[
"withNestedSubExpressionACLExpression",
withNestedSubExpressionACLExpression,
aclWithNestedSubExpression,
],
[
"complexExpressionACLExpression",
complexExpressionACLExpression,
aclWithComplexSubExpression,
],
])(
it.each(commonACLExpressionForParametricTests)(
"generate postfix ACL Expression text from %s",
(_, aclExpression, expectedExpression) => {
(_, expectedExpression, _infix, aclExpression) => {
expect(generate(aclExpression)).toEqual(expectedExpression);
}
);
Expand All @@ -271,40 +282,12 @@ describe("ACLExpressionModule", () => {
resolveRoleProvider: findRoleById,
});

it.each([
["everyoneACLExpression", everyoneACLExpression, aclEveryoneInfix],
["ownerACLExpression", ownerACLExpression, aclOwnerInfix],
["userACLExpression", userACLExpression, aclUserInfix],
["notUserACLExpression", notUserACLExpression, aclNotUserInfix],
["twoItemsACLExpression", twoItemsACLExpression, aclTwoItemsInfix],
["threeItemsACLExpression", threeItemsACLExpression, aclThreeItemsInfix],
["fourItemsACLExpression", fourItemsACLExpression, aclFourItemsInfix],
[
"withSubExpressionACLExpression",
withSubExpressionACLExpression,
aclWithSubExpressionInfix,
],
[
"withMultipleSubExpression",
withMultipleSubExpression,
aclWithMultipleSubExpressionInfix,
],
[
"withNestedSubExpressionACLExpression",
withNestedSubExpressionACLExpression,
aclWithNestedSubExpressionInfix,
],
[
"complexExpressionACLExpression",
complexExpressionACLExpression,
aclWithComplexSubExpressionInfix,
],
])(
it.each(commonACLExpressionForParametricTests)(
"generate infix ACL Expression text (human readable text) from %s",
async (_, aclExpression, expectedExpression) => {
async (_, _acl, expectedInfixText, aclExpression) => {
await expect(
generateHumanReadableWithMocks(aclExpression)()
).resolves.toEqual(expectedExpression);
).resolves.toEqual(expectedInfixText);
}
);
});
Expand Down Expand Up @@ -426,71 +409,18 @@ describe("ACLExpressionModule", () => {
});

describe("values produced by the module, should also work with the module", () => {
it.each([
["everyone", aclEveryone, everyoneACLExpression],
["aclOwner", aclOwner, ownerACLExpression],
["aclUser", aclUser, userACLExpression],
["aclNotUser", aclNotUser, notUserACLExpression],
["aclTwoItems", aclTwoItems, twoItemsACLExpression],
["aclThreeItems", aclThreeItems, threeItemsACLExpression],
["fourItemsACLExpression", aclFourItems, fourItemsACLExpression],
[
"aclWithSubExpression",
aclWithSubExpression,
withSubExpressionACLExpression,
],
[
"aclWithMultipleSubExpression",
aclWithMultipleSubExpression,
withMultipleSubExpression,
],
[
"aclWithNestedSubExpression",
aclWithNestedSubExpression,
withNestedSubExpressionACLExpression,
],
[
"aclWithComplexSubExpression",
aclWithComplexSubExpression,
complexExpressionACLExpression,
],
])("parse -> generate -> parse: %s", (_, acl, expectedACLExpression) => {
expect(pipe(acl, parse, handleParse, generate, parse)).toEqual(
expectedRightResult(expectedACLExpression)
);
});
it.each(commonACLExpressionForParametricTests)(
"parse -> generate -> parse: %s",
(_, acl, _infix, expectedACLExpression) => {
expect(pipe(acl, parse, handleParse, generate, parse)).toEqual(
expectedRightResult(expectedACLExpression)
);
}
);

it.each([
["everyone", everyoneACLExpression, aclEveryone],
["aclOwner", ownerACLExpression, aclOwner],
["aclUser", userACLExpression, aclUser],
["aclNotUser", notUserACLExpression, aclNotUser],
["aclTwoItems", twoItemsACLExpression, aclTwoItems],
["aclThreeItems", threeItemsACLExpression, aclThreeItems],
["fourItemsACLExpression", fourItemsACLExpression, aclFourItems],
[
"aclWithSubExpression",
withSubExpressionACLExpression,
aclWithSubExpression,
],
[
"aclWithMultipleSubExpression",
withMultipleSubExpression,
aclWithMultipleSubExpression,
],
[
"aclWithNestedSubExpression",
withNestedSubExpressionACLExpression,
aclWithNestedSubExpression,
],
[
"aclWithComplexSubExpression",
complexExpressionACLExpression,
aclWithComplexSubExpression,
],
])(
it.each(commonACLExpressionForParametricTests)(
"generate -> parse -> generate: %s",
(_, aclExpression, expectedText) => {
(_, expectedText, _infix, aclExpression) => {
expect(
pipe(aclExpression, generate, parse, handleParse, generate)
).toEqual(expectedText);
Expand Down
Loading

0 comments on commit 2287f63

Please sign in to comment.