Skip to content

Commit

Permalink
allow dashes in site ID when validating email auth request
Browse files Browse the repository at this point in the history
As discovered in #1477, dashes are expected to work in the site ID
and do work everywhere but in email auth. That change makes
the behaviour consistent: site ID now allows dashes.
  • Loading branch information
paskal authored and umputun committed Sep 12, 2022
1 parent 0f7ac51 commit 695d0ea
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion backend/app/rest/api/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ func subscribersOnly(enable bool) func(http.Handler) http.Handler {
func validEmailAuth() func(http.Handler) http.Handler {

reUser := regexp.MustCompile(`^[\p{L}\d\s_]{4,64}$`) // matches ui side validation, adding min/max limitation
reSite := regexp.MustCompile(`^[a-zA-Z\d\s_]{1,64}$`)
reSite := regexp.MustCompile(`^[a-zA-Z\d\s_-]{1,64}$`)

return func(h http.Handler) http.Handler {
fn := func(w http.ResponseWriter, r *http.Request) {
Expand Down
3 changes: 2 additions & 1 deletion backend/app/rest/api/rest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,12 +372,13 @@ func TestRest_subscribersOnly(t *testing.T) {
}
}

func Test_validEmaiAuth(t *testing.T) {
func Test_validEmailAuth(t *testing.T) {
tbl := []struct {
req string
status int
}{
{"/auth/email/login?site=remark42&address=umputun%example.com&user=someone", http.StatusOK},
{"/auth/email/login?site=site-with-dash_and_underscore&address=umputun%example.com&user=someone", http.StatusOK},
{"/auth/email/login?site=remark42&address=umputun%example.com&user=someone+blah", http.StatusOK},
{"/auth/email/login?site=remark42&address=umputun%example.com&user=Евгений+Умпутун", http.StatusOK},
{"/auth/email/login?site=remark42&address=umputun%example.com&user=12", http.StatusForbidden},
Expand Down

0 comments on commit 695d0ea

Please sign in to comment.