Backport #21520 Added checks for logged user token. Some builds fail at unrelated tests, due to missing token. Co-authored-by: Vladimir Yakovlev <nagos@inbox.ru> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
parent
556e2d5506
commit
8043fbce09
@ -21,6 +21,7 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync/atomic"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -430,19 +431,19 @@ var tokenCounter int64
|
|||||||
|
|
||||||
func getTokenForLoggedInUser(t testing.TB, session *TestSession) string {
|
func getTokenForLoggedInUser(t testing.TB, session *TestSession) string {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
tokenCounter++
|
|
||||||
req := NewRequest(t, "GET", "/user/settings/applications")
|
req := NewRequest(t, "GET", "/user/settings/applications")
|
||||||
resp := session.MakeRequest(t, req, http.StatusOK)
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
||||||
doc := NewHTMLParser(t, resp.Body)
|
doc := NewHTMLParser(t, resp.Body)
|
||||||
req = NewRequestWithValues(t, "POST", "/user/settings/applications", map[string]string{
|
req = NewRequestWithValues(t, "POST", "/user/settings/applications", map[string]string{
|
||||||
"_csrf": doc.GetCSRF(),
|
"_csrf": doc.GetCSRF(),
|
||||||
"name": fmt.Sprintf("api-testing-token-%d", tokenCounter),
|
"name": fmt.Sprintf("api-testing-token-%d", atomic.AddInt64(&tokenCounter, 1)),
|
||||||
})
|
})
|
||||||
resp = session.MakeRequest(t, req, http.StatusSeeOther)
|
resp = session.MakeRequest(t, req, http.StatusSeeOther)
|
||||||
req = NewRequest(t, "GET", "/user/settings/applications")
|
req = NewRequest(t, "GET", "/user/settings/applications")
|
||||||
resp = session.MakeRequest(t, req, http.StatusOK)
|
resp = session.MakeRequest(t, req, http.StatusOK)
|
||||||
htmlDoc := NewHTMLParser(t, resp.Body)
|
htmlDoc := NewHTMLParser(t, resp.Body)
|
||||||
token := htmlDoc.doc.Find(".ui.info p").Text()
|
token := htmlDoc.doc.Find(".ui.info p").Text()
|
||||||
|
assert.NotEmpty(t, token)
|
||||||
return token
|
return token
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user