9
9
"strings"
10
10
"testing"
11
11
12
+ "code.gitea.io/gitea/models/db"
12
13
"code.gitea.io/gitea/models/unittest"
13
14
user_model "code.gitea.io/gitea/models/user"
14
15
"code.gitea.io/gitea/modules/setting"
@@ -99,34 +100,39 @@ func TestSignupEmailActive(t *testing.T) {
99
100
100
101
// try to sign up and send the activation email
101
102
req := NewRequestWithValues (t , "POST" , "/user/sign_up" , map [string ]string {
102
- "user_name" : "test-user -1" ,
103
- "email" :
"email [email protected] " ,
103
+ "user_name" : "Test-User -1" ,
104
+ "email" :
"EmAiL [email protected] " ,
104
105
"password" : "password1" ,
105
106
"retype" : "password1" ,
106
107
})
107
108
resp := MakeRequest (t , req , http .StatusOK )
108
- assert .
Contains (
t ,
resp .
Body .
String (),
`A new confirmation email has been sent to <b>email [email protected] </b>.` )
109
+ assert .
Contains (
t ,
resp .
Body .
String (),
`A new confirmation email has been sent to <b>EmAiL [email protected] </b>.` )
109
110
110
111
// access "user/activate" means trying to re-send the activation email
111
112
session := loginUserWithPassword (t , "test-user-1" , "password1" )
112
113
resp = session .MakeRequest (t , NewRequest (t , "GET" , "/user/activate" ), http .StatusOK )
113
114
assert .Contains (t , resp .Body .String (), "You have already requested an activation email recently" )
114
115
115
- // access anywhere else will see a "Activate Your Account" prompt, and there is a chance to change email
116
+ // access anywhere else will see an "Activate Your Account" prompt, and there is a chance to change email
116
117
resp = session .MakeRequest (t , NewRequest (t , "GET" , "/user/issues" ), http .StatusOK )
117
118
assert .Contains (t , resp .Body .String (), `<input id="change-email" name="change_email" ` )
118
119
119
120
// post to "user/activate" with a new email
120
121
session .
MakeRequest (
t ,
NewRequestWithValues (
t ,
"POST" ,
"/user/activate" ,
map [
string ]
string {
"change_email" :
"[email protected] " }),
http .
StatusSeeOther )
121
- user := unittest .AssertExistsAndLoadBean (t , & user_model.User {Name : "test-user -1" })
122
+ user := unittest .AssertExistsAndLoadBean (t , & user_model.User {Name : "Test-User -1" })
122
123
assert .
Equal (
t ,
"[email protected] " ,
user .
Email )
123
124
email := unittest .
AssertExistsAndLoadBean (
t ,
& user_model.
EmailAddress {
Email :
"[email protected] " })
124
125
assert .False (t , email .IsActivated )
125
126
assert .True (t , email .IsPrimary )
126
127
128
+ // generate an activation code from lower-cased email
129
+ activationCode := user_model .GenerateUserTimeLimitCode (& user_model.TimeLimitCodeOptions {Purpose : user_model .TimeLimitCodeActivateAccount }, user )
130
+ // and update the user email to case-sensitive, it shouldn't affect the verification later
131
+ _ ,
_ = db .
Exec (
db .
DefaultContext ,
"UPDATE `user` SET email=? WHERE id=?" ,
"[email protected] " ,
user .
ID )
132
+ user = unittest .AssertExistsAndLoadBean (t , & user_model.User {Name : "Test-User-1" })
133
+ assert .
Equal (
t ,
"[email protected] " ,
user .
Email )
134
+
127
135
// access "user/activate" with a valid activation code, then get the "verify password" page
128
- user = unittest .AssertExistsAndLoadBean (t , & user_model.User {Name : "test-user-1" })
129
- activationCode := user .GenerateEmailActivateCode (user .Email )
130
136
resp = session .MakeRequest (t , NewRequest (t , "GET" , "/user/activate?code=" + activationCode ), http .StatusOK )
131
137
assert .Contains (t , resp .Body .String (), `<input id="verify-password"` )
132
138
@@ -138,7 +144,7 @@ func TestSignupEmailActive(t *testing.T) {
138
144
resp = session .MakeRequest (t , req , http .StatusOK )
139
145
assert .Contains (t , resp .Body .String (), `Your password does not match` )
140
146
assert .Contains (t , resp .Body .String (), `<input id="verify-password"` )
141
- user = unittest .AssertExistsAndLoadBean (t , & user_model.User {Name : "test-user -1" })
147
+ user = unittest .AssertExistsAndLoadBean (t , & user_model.User {Name : "Test-User -1" })
142
148
assert .False (t , user .IsActive )
143
149
144
150
// then use a correct password, the user should be activated
@@ -148,6 +154,6 @@ func TestSignupEmailActive(t *testing.T) {
148
154
})
149
155
resp = session .MakeRequest (t , req , http .StatusSeeOther )
150
156
assert .Equal (t , "/" , test .RedirectURL (resp ))
151
- user = unittest .AssertExistsAndLoadBean (t , & user_model.User {Name : "test-user -1" })
157
+ user = unittest .AssertExistsAndLoadBean (t , & user_model.User {Name : "Test-User -1" })
152
158
assert .True (t , user .IsActive )
153
159
}
0 commit comments