forked from kevadesu/forgejo
[CHORE] Move captcha library
- This is a fork of https://github.com/dchest/captcha, as https://gitea.com/go-chi/captcha is a fork of github.com/go-macaron/captcha which is a fork (although not properly credited) of a older version of https://github.com/dchest/captcha. Hence why I've just forked the original. - The fork includes some QoL improvements (uses standard library for determistic RNG instead of rolling your own crypto), and removal of audio support (500KiB unused data that bloated the binary otherwise). Flips the image over the x-asis. https://code.forgejo.org/go-chi/captcha/compare/47270f2b55862b38f9f65f615b53c1e04e814ef0..main - This move is needed for the next commit, because gitea.com/go-chi/captcha included the gitea.com/go-chi/cache dependency.
This commit is contained in:
parent
190b5a3859
commit
0404662e99
6 changed files with 83 additions and 17 deletions
|
@ -11,6 +11,7 @@ import (
|
|||
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/cache"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/test"
|
||||
"code.gitea.io/gitea/modules/translation"
|
||||
|
@ -167,3 +168,42 @@ func TestSignupEmailChangeForActiveUser(t *testing.T) {
|
|||
user = unittest.AssertExistsAndLoadBean(t, &user_model.User{Name: "exampleUserY"})
|
||||
assert.Equal(t, "wrong-email-2@example.com", user.Email)
|
||||
}
|
||||
|
||||
func TestSignupImageCaptcha(t *testing.T) {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
defer test.MockVariableValue(&setting.Service.RegisterEmailConfirm, false)()
|
||||
defer test.MockVariableValue(&setting.Service.EnableCaptcha, true)()
|
||||
defer test.MockVariableValue(&setting.Service.CaptchaType, "image")()
|
||||
c := cache.GetCache()
|
||||
|
||||
req := NewRequest(t, "GET", "/user/sign_up")
|
||||
resp := MakeRequest(t, req, http.StatusOK)
|
||||
htmlDoc := NewHTMLParser(t, resp.Body)
|
||||
|
||||
idCaptcha, ok := htmlDoc.Find("input[name='img-captcha-id']").Attr("value")
|
||||
assert.True(t, ok)
|
||||
|
||||
digits, ok := c.Get("captcha:" + idCaptcha).(string)
|
||||
assert.True(t, ok)
|
||||
assert.Len(t, digits, 6)
|
||||
|
||||
digitStr := ""
|
||||
// Convert digits to ASCII digits.
|
||||
for _, digit := range digits {
|
||||
digitStr += string(digit + '0')
|
||||
}
|
||||
|
||||
req = NewRequestWithValues(t, "POST", "/user/sign_up", map[string]string{
|
||||
"user_name": "captcha-test",
|
||||
"email": "captcha-test@example.com",
|
||||
"password": "examplePassword!1",
|
||||
"retype": "examplePassword!1",
|
||||
"img-captcha-id": idCaptcha,
|
||||
"img-captcha-response": digitStr,
|
||||
})
|
||||
MakeRequest(t, req, http.StatusSeeOther)
|
||||
|
||||
loginUserWithPassword(t, "captcha-test", "examplePassword!1")
|
||||
|
||||
unittest.AssertExistsAndLoadBean(t, &user_model.User{Name: "captcha-test", IsActive: true})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue