-
Notifications
You must be signed in to change notification settings - Fork 8
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
Allow using username
and email
in SMTP configuration
#3398
base: development
Are you sure you want to change the base?
Conversation
username
or email
in SMTP configuration
username
or email
in SMTP configurationusername
and email
in SMTP configuration
Co-authored-by: Zainab Elgohary <[email protected]>
Co-authored-by: Zainab Elgohary <[email protected]>
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
please mention the idea behind the validation rules, 69 characters, and the regex of the username |
Co-authored-by: Omar Kassem <[email protected]>
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.
Please add unit tests
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.
done
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 think we need to include those changes in manual Please open an issue for it in https://github.com/threefoldtech/info_grid
}, | ||
validators.required('Email or Username is required.'), | ||
(v: string) => { | ||
return validators.isValidSmtp(v); |
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.
as we accepts a username now i think we should add min char validation to be at least two chars
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.
@AhmedHanafy725 agree?
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 discussed it with him earlier today, you can go a head :D
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.
done
I see all mail server apps in the manual don't mention anything about validation, it is just about filling fields, I don't think it's necessary |
what i mean is to mention that we accepts username not only email, |
@0oM4R you mean the |
- Add space checker in validator function - Add unit test for smtp validation function
* @returns {{ message: string }} - An object with an error message if the input is invalid, or undefined if the input is valid. | ||
*/ | ||
|
||
export function isValidSmtp(input: string) { |
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.
1- where is the return type of the function?
2-if the function is named isX
is expect it to return a boolean
. True if X and false if not. To return null that may denote a failure e.g failure to allocate memory, or no data available in such context.
So we have multiple options
1- return a boolean (and discard the error messages, keep it constant to invalid smtp information)
2- return a boolean with a context, e.g boolean, null
in case of success and boolean and error string
in case of failure so [boolean, string|null] 3- return a boolean (success) or an error message (failure)
boolean | string`
4- return a new type e.g Result that encapsulates the success/failure status, and message/error fields
type Result<T> = {
success: true;
value: T;
} | {
success: false;
error: string;
};
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.
good point. the function is deleted now and the validation is created in the input validation rules.
|
||
import { isValidSmtp } from "../../src/utils/validators"; | ||
|
||
describe("isValidSmtp", () => { |
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.
Probably need more cases e.g empty string, multiple invalid forms of email as well, usage of special characters
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.
as the function is deleted, the test case is deleted too and you could check it in the current rules.
/** | ||
* Validates an SMTP input string. | ||
* | ||
* Checks if the input string is a valid email address and does not contain special characters. |
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.
Is it only email? if so change the input parameter to email
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.
It now accepts usernames and email in the same input and it can validate each.
export function isValidSmtp(input: string) { | ||
const emailValidation = isEmail("Please provide a valid email address.")(input); | ||
const username = /[!@#$%^&*()\s_+\-={}:<>?,./]/.test(input); | ||
if (username && emailValidation) { |
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 don't understand this condition, does that mean if it's email and a username (doesn't have special characters) then it's true?
shouldn't it be like that
const isValidEmail = isEmail("Please provide a valid email address.")(input);
const hasSpecialCharacters = /[!@#$%^&*()\s_+\-={}:<>?,./]/.test(input);
if (hasSpecialCharacters && isValidEmail) {
return { message: "Please provide a valid username or email" };
}
Which I still don't understand.
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 meant here it could accept both and validate if it's not a valid email or username with a special character.
|
||
export function isValidSmtp(input: string) { | ||
const emailValidation = isEmail("Please provide a valid email address.")(input); | ||
const username = /[!@#$%^&*()\s_+\-={}:<>?,./]/.test(input); |
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.
This could have been simplified instead of matching against special characters
you could have just made it match against valid characters
which are a-z[A-Z0-9]+
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.
This could have been simplified instead of
matching against special characters
you could have just made itmatch against valid characters
which area-z[A-Z0-9]+
Please note this is the right way, given there's a very long of list of unhandled utf8 input, that's why you should state the allowed ones as long as you can iterate them, instead of chasing a very long list of symbols.
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.
thanks, the regex was implemented separately in the validator function and used in the input validation.
import { isValidSmtp } from "../../src/utils/validators"; | ||
|
||
describe("isValidSmtp", () => { | ||
it("returns nothing for valid username and email", () => { |
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 truly don't understand can you point out the username
and the email
because there's only just one input name input
which looks like an email.
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.
done in the current validation rules.
}); | ||
|
||
it("returns an error message for special characters in username", () => { | ||
const input = "invalid_email"; |
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.
_
is not the only special character
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.
Of course not but I used one of them to test as I can't test all of them (too many cases).
}); | ||
|
||
it("returns an error message for white spaces in username", () => { | ||
const input = "invalid username"; |
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.
there're more types of spaces beyond " "
there's is \t
and \v
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.
noted in the current validation.
- Accept usernames that contain dashs and underscores and it must start with an alphabetical character and validate them
return isDiscourse ? undefined : validators.isEmail('Please provide a valid email address.')(v); | ||
validators.required('Email or Username is required.'), | ||
validators.minLength('Username must be at least 2 characters.', 2), | ||
validators.maxLength('Username must be at least 50 characters.', 50), |
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.
we shouldn't use the at least
on max length
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.
also is this validation on user name only? what if the email exceeds the 50 char ? the length validation message will appear
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.
Description
isDiscourse
check and apply adding email or username for all apps with SMTP.sendgrid
documentationChanges
Related Issues
Tested Scenarios
Documentation PR
SMTP Server
docs info_grid#645Checklist