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

Query RelationshipTemplates for password protection #353

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

Magnus-Kuhn
Copy link
Contributor

Readiness checklist

  • I added/updated tests.
  • I ensured that the PR title is good enough for the changelog.
  • I labeled the PR.
  • I self-reviewed the PR.

@Magnus-Kuhn Magnus-Kuhn added wip Work in Progress (blocks mergify from auto update the branch) enhancement New feature or request labels Nov 29, 2024
Copy link

codecov bot commented Nov 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Files with missing lines Coverage Δ
packages/runtime/src/useCases/common/Schemas.ts 100.00% <100.00%> (ø)
.../relationshipTemplates/GetRelationshipTemplates.ts 100.00% <100.00%> (ø)

... and 2 files with indirect coverage changes

@Magnus-Kuhn Magnus-Kuhn removed the wip Work in Progress (blocks mergify from auto update the branch) label Nov 29, 2024
@Magnus-Kuhn Magnus-Kuhn marked this pull request as ready for review November 29, 2024 16:49
Comment on lines +60 to +74
[`${nameof<RelationshipTemplateDTO>((r) => r.passwordProtection)}.password`]: (query: any, input: string) => {
query[`${nameof<RelationshipTemplate>((t) => t.passwordProtection)}.${nameof<PasswordProtection>((t) => t.password)}`] = input;
},
[`${nameof<RelationshipTemplateDTO>((t) => t.passwordProtection)}.passwordIsPin`]: (query: any, input: string) => {
if (input === "true") {
query[`${nameof<RelationshipTemplate>((t) => t.passwordProtection)}.${nameof<PasswordProtection>((t) => t.passwordType)}`] = {
$regex: "^pin"
};
}
if (input === "!true") {
query[`${nameof<RelationshipTemplate>((t) => t.passwordProtection)}.${nameof<PasswordProtection>((t) => t.passwordType)}`] = {
$in: ["pw", undefined]
};
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see a need for a custom filter here, just add aliases.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

password needs a custom filter, because PINs are otherwise turned into numbers (and I can't switch this off since then the maxNumberOfAllocations would be a problem).

And we don't store passwordIsPin, only passwordType in the database, so the custom filter does that mapping

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

argh, I see. Then we'll have to discuss on how to align these custom thingies to our query translator.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it could be enough to do ! instead of !true

Comment on lines +331 to +393
test("password query", async () => {
const passwordProtectedTemplate = await createTemplate(runtimeServices1.transport, undefined, { password: "password" });

const pinProtectedTemplate = await createTemplate(runtimeServices1.transport, undefined, { password: "1234", passwordIsPin: true });

const passwordProtectedTemplates = (
await runtimeServices1.transport.relationshipTemplates.getRelationshipTemplates({
query: {
"passwordProtection.password": "password"
}
})
).value;
const passwordProtectedTemplateIds = passwordProtectedTemplates.map((t) => t.id);

expect(passwordProtectedTemplateIds).toContain(passwordProtectedTemplate.id);
expect(passwordProtectedTemplateIds).not.toContain(pinProtectedTemplate.id);

const pinProtectedTemplates = (
await runtimeServices1.transport.relationshipTemplates.getRelationshipTemplates({
query: {
"passwordProtection.password": "1234"
}
})
).value;
const pinProtectedTemplateIds = pinProtectedTemplates.map((t) => t.id);

expect(pinProtectedTemplateIds).not.toContain(passwordProtectedTemplate.id);
expect(pinProtectedTemplateIds).toContain(pinProtectedTemplate.id);
});

test("passwordIsPin query", async () => {
const passwordProtectedTemplate = await createTemplate(runtimeServices1.transport, undefined, { password: "password" });

const pinProtectedTemplate = await createTemplate(runtimeServices1.transport, undefined, { password: "1234", passwordIsPin: true });

const unprotectedTemplate = await createTemplate(runtimeServices1.transport);

const templatesWithoutPin = (
await runtimeServices1.transport.relationshipTemplates.getRelationshipTemplates({
query: {
"passwordProtection.passwordIsPin": "!true"
}
})
).value;
const templateIdsWithoutPin = templatesWithoutPin.map((t) => t.id);

expect(templateIdsWithoutPin).toContain(passwordProtectedTemplate.id);
expect(templateIdsWithoutPin).not.toContain(pinProtectedTemplate.id);
expect(templateIdsWithoutPin).toContain(unprotectedTemplate.id);

const templatesWithPin = (
await runtimeServices1.transport.relationshipTemplates.getRelationshipTemplates({
query: {
"passwordProtection.passwordIsPin": "true"
}
})
).value;
const templateIdsWithPin = templatesWithPin.map((t) => t.id);

expect(templateIdsWithPin).not.toContain(passwordProtectedTemplate.id);
expect(templateIdsWithPin).toContain(pinProtectedTemplate.id);
expect(templateIdsWithPin).not.toContain(unprotectedTemplate.id);
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please see the other tests that do querying, we have a fabulous tester for querystrings :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants