1
0
Fork 0
forked from forgejo/forgejo

Convert to url auth to header auth in tests (#28484)

Related #28390
This commit is contained in:
KN4CK3R 2023-12-22 00:59:59 +01:00 committed by GitHub
parent 04b235d094
commit 838db2f891
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
102 changed files with 1715 additions and 1523 deletions

View file

@ -21,7 +21,8 @@ func TestAPIListEmails(t *testing.T) {
session := loginUser(t, normalUsername)
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadUser)
req := NewRequest(t, "GET", "/api/v1/user/emails?token="+token)
req := NewRequest(t, "GET", "/api/v1/user/emails").
AddTokenAuth(token)
resp := MakeRequest(t, req, http.StatusOK)
var emails []*api.Email
@ -52,13 +53,15 @@ func TestAPIAddEmail(t *testing.T) {
Emails: []string{"user101@example.com"},
}
req := NewRequestWithJSON(t, "POST", "/api/v1/user/emails?token="+token, &opts)
req := NewRequestWithJSON(t, "POST", "/api/v1/user/emails", &opts).
AddTokenAuth(token)
MakeRequest(t, req, http.StatusUnprocessableEntity)
opts = api.CreateEmailOption{
Emails: []string{"user2-3@example.com"},
}
req = NewRequestWithJSON(t, "POST", "/api/v1/user/emails?token="+token, &opts)
req = NewRequestWithJSON(t, "POST", "/api/v1/user/emails", &opts).
AddTokenAuth(token)
resp := MakeRequest(t, req, http.StatusCreated)
var emails []*api.Email
@ -74,7 +77,8 @@ func TestAPIAddEmail(t *testing.T) {
opts = api.CreateEmailOption{
Emails: []string{"notAEmail"},
}
req = NewRequestWithJSON(t, "POST", "/api/v1/user/emails?token="+token, &opts)
req = NewRequestWithJSON(t, "POST", "/api/v1/user/emails", &opts).
AddTokenAuth(token)
MakeRequest(t, req, http.StatusUnprocessableEntity)
}
@ -88,16 +92,19 @@ func TestAPIDeleteEmail(t *testing.T) {
opts := api.DeleteEmailOption{
Emails: []string{"user2-3@example.com"},
}
req := NewRequestWithJSON(t, "DELETE", "/api/v1/user/emails?token="+token, &opts)
req := NewRequestWithJSON(t, "DELETE", "/api/v1/user/emails", &opts).
AddTokenAuth(token)
MakeRequest(t, req, http.StatusNotFound)
opts = api.DeleteEmailOption{
Emails: []string{"user2-2@example.com"},
}
req = NewRequestWithJSON(t, "DELETE", "/api/v1/user/emails?token="+token, &opts)
req = NewRequestWithJSON(t, "DELETE", "/api/v1/user/emails", &opts).
AddTokenAuth(token)
MakeRequest(t, req, http.StatusNoContent)
req = NewRequest(t, "GET", "/api/v1/user/emails?token="+token)
req = NewRequest(t, "GET", "/api/v1/user/emails").
AddTokenAuth(token)
resp := MakeRequest(t, req, http.StatusOK)
var emails []*api.Email