-
Notifications
You must be signed in to change notification settings - Fork 894
feat: Add template display name (backend) #4966
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
Changes from 1 commit
03d8456
e3a1b7d
9c7cae6
5fac8e9
61074d9
dbd96c0
bf26ba9
9a7d35f
4aaff3e
c3532a1
fa778d3
64c6fe2
b2c122b
75c79d3
cfa4ca7
9eb443e
20018f8
53c463d
a24eac4
ed56c3b
7490d45
88c6ddc
01dae76
361a428
d935a41
a837fae
d32247d
2da0147
2301f5c
a3652b2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ import ( | |
"github.com/coder/coder/coderd/httpapi" | ||
) | ||
|
||
func TestValid(t *testing.T) { | ||
func TestUsernameValid(t *testing.T) { | ||
t.Parallel() | ||
// Tests whether usernames are valid or not. | ||
testCases := []struct { | ||
|
@@ -65,6 +65,63 @@ func TestValid(t *testing.T) { | |
} | ||
} | ||
|
||
func TestTemplateDisplayNameValid(t *testing.T) { | ||
t.Parallel() | ||
// Tests whether display names are valid. | ||
testCases := []struct { | ||
Username string | ||
Valid bool | ||
}{ | ||
{"", true}, | ||
{"1", true}, | ||
{"12", true}, | ||
{"1 2", true}, | ||
{"1234 678901234567890", true}, | ||
{"1234567890123 5678901", true}, | ||
{"S", true}, | ||
{"a1", true}, | ||
{"a1K2", true}, | ||
{"a1b2c3 4e5f6g7h8i9j0", true}, | ||
{"a1b2c3d4e5f6g h8i9j0k", true}, | ||
{"aa", true}, | ||
{"aNc", true}, | ||
{"abcdefghijklmnopqrst", true}, | ||
{"abcdefghijklmnopqrstu", true}, | ||
{"Wow Test", true}, | ||
|
||
{" ", false}, | ||
{" a", false}, | ||
{" a ", false}, | ||
{" 1", false}, | ||
{"1 ", false}, | ||
{" aa", false}, | ||
{"aa ", false}, | ||
{" 12", false}, | ||
{"12 ", false}, | ||
{" a1", false}, | ||
{"a1 ", false}, | ||
{"-abcdefghijKLmnopqrstu", false}, | ||
{"abcdefghijklmnopqrstu-", false}, | ||
{"-123456789012345678901", false}, | ||
{"-a1b2c3d4e5f6g7h8i9j0k", false}, | ||
{"a1b2c3d4e5f6g7h8i9j0k-", false}, | ||
{"BANANAS_wow", false}, | ||
{"test--now", false}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are these not valid for a human readable name? I mean, they're not pretty but a user wants what a user wants.. 😂 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh that's basically because of character set There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I replaced the regexp with a more free form:
Although, I'm not sure if it's safe enough... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we need to sanitize the input here, tbh. For instance, what if someone wants for the display name to be a bunch of emojis? Sanitation shouldn't really be a problem in the frontend unless someone is doing something weird with React. Or what say you @coder/frontend? Is it bad if we don't limit display names to "safe" characters? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
That is correct, but should preserve the basic sanitation level. For instance:
.. or customers are writing unsafe characters to logs (e.g. audit or access logs). Using emojis and allowing for a wide set of characters may increase the "shellshock" attack risk. This may not be applicable in our case, but still a security concern. I guess that we perform proper sanitization, so it won't be easy to inject the XSS snippet. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you think about just blocking whitespace at the beginning and ends? I think people will want to use emojis in names (we probably will too). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's an option to introduce this pattern, but then we need to verify if it doesn't introduce any extra risk, something like "shellshock" against audit logs. I believe that we can track this effort in a separate issue. EDIT: It looks like the majority prefers a more permissive pattern, so I adjusted the validation. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some thoughts from the FE:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you, Kira! |
||
|
||
{"123456789012345678901234567890123", false}, | ||
{"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", false}, | ||
{"123456789012345678901234567890123123456789012345678901234567890123", false}, | ||
} | ||
for _, testCase := range testCases { | ||
testCase := testCase | ||
t.Run(testCase.Username, func(t *testing.T) { | ||
t.Parallel() | ||
valid := httpapi.TemplateDisplayNameValid(testCase.Username) | ||
require.Equal(t, testCase.Valid, valid == nil) | ||
}) | ||
} | ||
} | ||
|
||
func TestFrom(t *testing.T) { | ||
t.Parallel() | ||
testCases := []struct { | ||
|
Uh oh!
There was an error while loading. Please reload this page.