-
Notifications
You must be signed in to change notification settings - Fork 53
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
fix(machines): Allow ports at the end of IPMI addresses LP#2087965 #5560
fix(machines): Allow ports at the end of IPMI addresses LP#2087965 #5560
Conversation
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.
LGTM (up to my knowledge of react/ts :) )
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.
QA: Looking good, changed a machine, tried multiple V4 and V6 addresses with and without port.
Code: small edge case nag inline below
); | ||
// We use +2 here to include the `:` before the port number | ||
const port = value.slice(closingBracketIndex + 2); | ||
return isIPv6(ip) && !isNaN(parseInt(port)); |
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 usually works but insane users like myself might try: [aa:cf:f::34fF]: 4 5 6
. Results in a parseInt(" 4 5 6")
which is 4
. I think it's still OK to merge for now but we might want to make this even tighter 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.
That's interesting! By the looks of it, parseInt
ignores any leading whitespace, and ignores anything once it reaches the first whitespace after a number (only if the number is also the first non-whitespace text in the string).
I guess the simplest check for this would just be to check for any whitespace in the input, and treat the value as invalid if there is whitespace.
} else if (value.split(":").length === 2) { | ||
// This is an IPv4 address with a port number | ||
const [ip, port] = value.split(":"); | ||
return isIP(ip) && !isNaN(parseInt(port)); |
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 above. Could error out if the port number has anything but decimals.
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 really wanted to break it. LTGM.
import { isValidPortNumber } from "."; | ||
|
||
it("returns true for any number between 0 and 65535", () => { | ||
for (let i = 0; i <= 65535; i++) { |
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.
That is a computationally expensive test for the function it tests.... Edge cases and some common ports might be enough. But I'm happy to merge if it runs quickly.
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.
Locally it seems to run quickly enough, but thought I'd get your thoughts first.
* @param port The port number to check. | ||
* @returns True if valid, false otherwise. | ||
*/ | ||
export const isValidPortNumber = (port: number): boolean => { |
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 like that its port: number
:)
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.
me too :)
Done
QA steps
[2008:d45::1]:8000
Fixes
Fixes LP#2087965
Fixes MAASENG-4172