-
Notifications
You must be signed in to change notification settings - Fork 1
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
PIN-4810 clear tenant mail address #985
Open
rGregnanin
wants to merge
11
commits into
main
Choose a base branch
from
PIN-4810-clearTenantMailAddress
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
332cc69
added email sanitization
rGregnanin 42c1093
Merge branch 'main' into PIN-4818-clearTenantMailAddress
rGregnanin 0ae095d
Added validation to selfcareUpsertTenant
rGregnanin 3a7e704
Merge branch 'main' into PIN-4818-clearTenantMailAddress
rGregnanin 30fe3b8
Merge branch 'main' into PIN-4810-clearTenantMailAddress
rGregnanin 75a8c7a
Merge branch 'main' into PIN-4810-clearTenantMailAddress
rGregnanin fd4aece
Merge branch 'main' into PIN-4810-clearTenantMailAddress
rGregnanin 5ad5693
Merge branch 'main' into PIN-4810-clearTenantMailAddress
rGregnanin 9c8a986
Merge branch 'main' into PIN-4810-clearTenantMailAddress
rGregnanin 69ccbc7
Merge branch 'main' into PIN-4810-clearTenantMailAddress
rGregnanin 2d9799d
Merge branch 'main' into PIN-4810-clearTenantMailAddress
rGregnanin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ import { tenantApi } from "pagopa-interop-api-clients"; | |
import { getMockTenant } from "pagopa-interop-commons-test"; | ||
import { | ||
mailAlreadyExists, | ||
notValidMailAddress, | ||
tenantNotFound, | ||
} from "../src/model/domain/errors.js"; | ||
import { addOneTenant, postgresDB, tenantService } from "./utils.js"; | ||
|
@@ -77,6 +78,53 @@ describe("addTenantMail", async () => { | |
}; | ||
expect(writtenPayload.tenant).toEqual(toTenantV2(updatedTenant)); | ||
}); | ||
it("Should correctly add email by cleaning the address from unwanted characters", async () => { | ||
const mailSeedWithStrangeCharacters: tenantApi.MailSeed = { | ||
kind: "CONTACT_EMAIL", | ||
address: " test#°¶^ Mail@test.$%*it", | ||
description: "mail description", | ||
}; | ||
await addOneTenant(mockTenant); | ||
await tenantService.addTenantMail( | ||
{ | ||
tenantId: mockTenant.id, | ||
mailSeed: mailSeedWithStrangeCharacters, | ||
organizationId: mockTenant.id, | ||
correlationId: generateId(), | ||
}, | ||
genericLogger | ||
); | ||
const writtenEvent = await readLastEventByStreamId( | ||
mockTenant.id, | ||
"tenant", | ||
postgresDB | ||
); | ||
|
||
expect(writtenEvent).toMatchObject({ | ||
stream_id: mockTenant.id, | ||
version: "1", | ||
type: "TenantMailAdded", | ||
event_version: 2, | ||
}); | ||
|
||
const writtenPayload: TenantMailAddedV2 | undefined = protobufDecoder( | ||
TenantMailAddedV2 | ||
).parse(writtenEvent.data); | ||
|
||
const updatedTenant: Tenant = { | ||
...mockTenant, | ||
mails: [ | ||
{ | ||
...mailSeed, | ||
id: writtenPayload.mailId, | ||
createdAt: new Date(), | ||
}, | ||
], | ||
updatedAt: new Date(), | ||
}; | ||
expect(writtenPayload.tenant).toEqual(toTenantV2(updatedTenant)); | ||
}); | ||
|
||
it("Should throw tenantNotFound if the tenant doesn't exists", async () => { | ||
expect( | ||
tenantService.addTenantMail( | ||
|
@@ -132,4 +180,26 @@ describe("addTenantMail", async () => { | |
) | ||
).rejects.toThrowError(mailAlreadyExists()); | ||
}); | ||
|
||
it("Should throw notValidMailAddress if the address doesn't respect the valid pattern", async () => { | ||
const mailSeedWithStrangeCharacters: tenantApi.MailSeed = { | ||
kind: "CONTACT_EMAIL", | ||
address: " test#°¶^ Mail@test.$%*@@it", | ||
description: "mail description", | ||
}; | ||
await addOneTenant(mockTenant); | ||
expect( | ||
tenantService.addTenantMail( | ||
{ | ||
tenantId: mockTenant.id, | ||
mailSeed: mailSeedWithStrangeCharacters, | ||
organizationId: mockTenant.id, | ||
correlationId: generateId(), | ||
}, | ||
genericLogger | ||
) | ||
).rejects.toThrowError( | ||
notValidMailAddress(mailSeedWithStrangeCharacters.address) | ||
); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO there are too many steps in order to validate a mail, are these really necessary?
With the regex we don't need the extra steps of removing characters and spaces since it's already included.
I suggest to use this one:
^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$
(taken from here)? Note: the regex must be case insensitive for it to work properly.There's no perfect regex for validating a mail, but this one is simpler and covers most of the cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer to leave
emailPattern
as it is so that it is aligned with the frontend as well, since it is the same pattern they use