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

wizrad: add validation to ssh key field (HMS-5349) #2764

Closed
wants to merge 0 commits into from

Conversation

mgold1234
Copy link
Collaborator

@mgold1234 mgold1234 commented Jan 19, 2025

this commit add validation to ssh key field

JIRA: HMS-5349

@mgold1234
Copy link
Collaborator Author

/jira-epic HMS-4181

@schutzbot schutzbot changed the title wizrad: add validation to ssh key field wizrad: add validation to ssh key field (HMS-5349) Jan 19, 2025
Copy link

codecov bot commented Jan 19, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.76%. Comparing base (0f86336) to head (2b90b58).

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2764      +/-   ##
==========================================
+ Coverage   84.75%   84.76%   +0.01%     
==========================================
  Files         187      187              
  Lines       21270    21285      +15     
  Branches     2088     2095       +7     
==========================================
+ Hits        18027    18042      +15     
  Misses       3221     3221              
  Partials       22       22              
Files with missing lines Coverage Δ
...ents/CreateImageWizard/utilities/useValidation.tsx 97.96% <100.00%> (+0.08%) ⬆️
src/Components/CreateImageWizard/validators.ts 95.00% <100.00%> (+0.37%) ⬆️

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0f86336...2b90b58. Read the comment docs.

@mgold1234 mgold1234 force-pushed the add_ssh_valid branch 7 times, most recently from 1018e74 to f10fad2 Compare January 20, 2025 19:40
Copy link
Collaborator

@regexowl regexowl left a comment

Choose a reason for hiding this comment

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

Added some comments

src/Components/CreateImageWizard/validators.ts Outdated Show resolved Hide resolved
export const isSshKeyValid = (sshKey: string) => {
const isLengthValid = sshKey !== undefined && sshKey.length >= 2;
const isPatternValid =
/^(ssh-(rsa|dss|ed25519)|ecdsa-sha2-nistp(256|384|521)) \S+/.test(sshKey);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do you have any source for the regex? If so, could you please add it to a comment so we can reference it if needed?

I wonder if we should try do to a full match instead of a partial one, should be safer that way. We would need to add a few more things to allow for the label part of the key. So maybe something like:

^(ssh-(rsa|dss|ed25519)|ecdsa-sha2-nistp(256|384|521))\s+[A-Za-z0-9+\/=]+\s+\S+$

What do you think?

Copy link
Collaborator Author

@mgold1234 mgold1234 Jan 22, 2025

Choose a reason for hiding this comment

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

I tried this - 'ssh-rsa d' value with your suggestion and it isnt valid.
I took this pattern from 'edge' , they also check the ssh key validation

Copy link
Collaborator

@regexowl regexowl Jan 22, 2025

Choose a reason for hiding this comment

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

Hmm, comment might be optional doesn't it 🤔 this should work then

^(ssh-(rsa|dss|ed25519)|ecdsa-sha2-nistp(256|384|521))\s+[A-Za-z0-9+\/=]+(\s+\S+)?$

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

do you think about this comment?
// 1. Key types: ssh-rsa, ssh-dss, ssh-ed25519, or ecdsa-sha2-nistp(256|384|521).
// 2. Base64-encoded key material.
// 3. Optional comment at the end.

Copy link
Collaborator

@regexowl regexowl left a comment

Choose a reason for hiding this comment

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

Looks good! One more nitpick

@regexowl
Copy link
Collaborator

Noticed on more thing, very nit picky 😅 the two describe blocks 'User request generated correctly' and 'Users edit mode' are nested inside 'Step Users'. In other unit tests they're the same level as the 'Step Users'. Could you move those please?

image
vs how it's in other test files
image

@mgold1234 mgold1234 force-pushed the add_ssh_valid branch 3 times, most recently from 2902012 to 0b5fdf7 Compare January 23, 2025 10:26
@regexowl
Copy link
Collaborator

regexowl commented Jan 23, 2025

Just a heads up, #2772 got merged yesterday so lint autofix should work again without adding unwanted changes :)

@mgold1234 mgold1234 closed this Jan 23, 2025
@mgold1234 mgold1234 deleted the add_ssh_valid branch January 23, 2025 10:46
@regexowl
Copy link
Collaborator

Did you close the PR on purpose?

@mgold1234 mgold1234 restored the add_ssh_valid branch January 23, 2025 11:01
@mgold1234
Copy link
Collaborator Author

I meant to delete the brach and close it by mistake

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

Successfully merging this pull request may close these issues.

2 participants