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

@ -36,8 +36,8 @@ func testAPICreateOAuth2Application(t *testing.T) {
ConfidentialClient: true,
}
req := NewRequestWithJSON(t, "POST", "/api/v1/user/applications/oauth2", &appBody)
req = AddBasicAuthHeader(req, user.Name)
req := NewRequestWithJSON(t, "POST", "/api/v1/user/applications/oauth2", &appBody).
AddBasicAuth(user.Name)
resp := MakeRequest(t, req, http.StatusCreated)
var createdApp *api.OAuth2Application
@ -66,8 +66,8 @@ func testAPIListOAuth2Applications(t *testing.T) {
ConfidentialClient: true,
})
urlStr := fmt.Sprintf("/api/v1/user/applications/oauth2?token=%s", token)
req := NewRequest(t, "GET", urlStr)
req := NewRequest(t, "GET", "/api/v1/user/applications/oauth2").
AddTokenAuth(token)
resp := MakeRequest(t, req, http.StatusOK)
var appList api.OAuth2ApplicationList
@ -93,14 +93,16 @@ func testAPIDeleteOAuth2Application(t *testing.T) {
Name: "test-app-1",
})
urlStr := fmt.Sprintf("/api/v1/user/applications/oauth2/%d?token=%s", oldApp.ID, token)
req := NewRequest(t, "DELETE", urlStr)
urlStr := fmt.Sprintf("/api/v1/user/applications/oauth2/%d", oldApp.ID)
req := NewRequest(t, "DELETE", urlStr).
AddTokenAuth(token)
MakeRequest(t, req, http.StatusNoContent)
unittest.AssertNotExistsBean(t, &auth_model.OAuth2Application{UID: oldApp.UID, Name: oldApp.Name})
// Delete again will return not found
req = NewRequest(t, "DELETE", urlStr)
req = NewRequest(t, "DELETE", urlStr).
AddTokenAuth(token)
MakeRequest(t, req, http.StatusNotFound)
}
@ -118,8 +120,8 @@ func testAPIGetOAuth2Application(t *testing.T) {
ConfidentialClient: true,
})
urlStr := fmt.Sprintf("/api/v1/user/applications/oauth2/%d?token=%s", existApp.ID, token)
req := NewRequest(t, "GET", urlStr)
req := NewRequest(t, "GET", fmt.Sprintf("/api/v1/user/applications/oauth2/%d", existApp.ID)).
AddTokenAuth(token)
resp := MakeRequest(t, req, http.StatusOK)
var app api.OAuth2Application
@ -157,8 +159,8 @@ func testAPIUpdateOAuth2Application(t *testing.T) {
}
urlStr := fmt.Sprintf("/api/v1/user/applications/oauth2/%d", existApp.ID)
req := NewRequestWithJSON(t, "PATCH", urlStr, &appBody)
req = AddBasicAuthHeader(req, user.Name)
req := NewRequestWithJSON(t, "PATCH", urlStr, &appBody).
AddBasicAuth(user.Name)
resp := MakeRequest(t, req, http.StatusOK)
var app api.OAuth2Application