-
Notifications
You must be signed in to change notification settings - Fork 928
feat: Add OIDC authentication #3314
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 all commits
50ee7ad
7eb897a
424579e
a49b491
6eae627
292d9f6
e6619ff
3a20472
5f7176c
c2a4481
4b71655
7b487be
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,7 @@ | |
"mattn", | ||
"mitchellh", | ||
"moby", | ||
"namesgenerator", | ||
"nfpms", | ||
"nhooyr", | ||
"nolint", | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,11 @@ func main() { | |
} | ||
|
||
cmd := exec.Command( | ||
"docker", | ||
"run", | ||
"--rm", | ||
"--network=host", | ||
"postgres:13", | ||
Comment on lines
+34
to
+38
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. This was a bit out of scope, but makes everything use Docker, which makes changing our versions simpler! |
||
"pg_dump", | ||
"--schema-only", | ||
connection, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
CREATE TYPE old_login_type AS ENUM ( | ||
'password', | ||
'github' | ||
); | ||
ALTER TABLE api_keys ALTER COLUMN login_type TYPE old_login_type USING (login_type::text::old_login_type); | ||
DROP TYPE login_type; | ||
ALTER TYPE old_login_type RENAME TO login_type; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
CREATE TYPE new_login_type AS ENUM ( | ||
'password', | ||
'github', | ||
'oidc' | ||
); | ||
ALTER TABLE api_keys ALTER COLUMN login_type TYPE new_login_type USING (login_type::text::new_login_type); | ||
DROP TYPE login_type; | ||
ALTER TYPE new_login_type RENAME TO login_type; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,71 +81,6 @@ func TestRead(t *testing.T) { | |
}) | ||
} | ||
|
||
func TestReadUsername(t *testing.T) { | ||
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. These have been moved to the |
||
t.Parallel() | ||
// Tests whether usernames are valid or not. | ||
testCases := []struct { | ||
Username string | ||
Valid bool | ||
}{ | ||
{"1", true}, | ||
{"12", true}, | ||
{"123", true}, | ||
{"12345678901234567890", true}, | ||
{"123456789012345678901", true}, | ||
{"a", true}, | ||
{"a1", true}, | ||
{"a1b2", true}, | ||
{"a1b2c3d4e5f6g7h8i9j0", true}, | ||
{"a1b2c3d4e5f6g7h8i9j0k", true}, | ||
{"aa", true}, | ||
{"abc", true}, | ||
{"abcdefghijklmnopqrst", true}, | ||
{"abcdefghijklmnopqrstu", true}, | ||
{"wow-test", true}, | ||
|
||
{"", false}, | ||
{" ", 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}, | ||
|
||
{"123456789012345678901234567890123", false}, | ||
{"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", false}, | ||
{"123456789012345678901234567890123123456789012345678901234567890123", false}, | ||
} | ||
type toValidate struct { | ||
Username string `json:"username" validate:"username"` | ||
} | ||
for _, testCase := range testCases { | ||
testCase := testCase | ||
t.Run(testCase.Username, func(t *testing.T) { | ||
t.Parallel() | ||
rw := httptest.NewRecorder() | ||
data, err := json.Marshal(toValidate{testCase.Username}) | ||
require.NoError(t, err) | ||
r := httptest.NewRequest("POST", "/", bytes.NewBuffer(data)) | ||
|
||
var validate toValidate | ||
require.Equal(t, testCase.Valid, httpapi.Read(rw, r, &validate)) | ||
}) | ||
} | ||
} | ||
|
||
func WebsocketCloseMsg(t *testing.T) { | ||
t.Parallel() | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package httpapi | ||
|
||
import ( | ||
"regexp" | ||
"strings" | ||
|
||
"github.com/moby/moby/pkg/namesgenerator" | ||
) | ||
|
||
var ( | ||
usernameValid = regexp.MustCompile("^[a-zA-Z0-9]+(?:-[a-zA-Z0-9]+)*$") | ||
usernameReplace = regexp.MustCompile("[^a-zA-Z0-9-]*") | ||
) | ||
|
||
// UsernameValid returns whether the input string is a valid username. | ||
func UsernameValid(str string) bool { | ||
if len(str) > 32 { | ||
return false | ||
} | ||
if len(str) < 1 { | ||
return false | ||
} | ||
return usernameValid.MatchString(str) | ||
} | ||
|
||
// UsernameFrom returns a best-effort username from the provided string. | ||
// | ||
// It first attempts to validate the incoming string, which will | ||
// be returned if it is valid. It then will attempt to extract | ||
// the username from an email address. If no success happens during | ||
// these steps, a random username will be returned. | ||
func UsernameFrom(str string) string { | ||
if UsernameValid(str) { | ||
return str | ||
} | ||
emailAt := strings.LastIndex(str, "@") | ||
if emailAt >= 0 { | ||
str = str[:emailAt] | ||
} | ||
str = usernameReplace.ReplaceAllString(str, "") | ||
if UsernameValid(str) { | ||
return str | ||
} | ||
return strings.ReplaceAll(namesgenerator.GetRandomName(1), "_", "-") | ||
} |
Uh oh!
There was an error while loading. Please reload this page.