-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ability to delete a token (#4235)
Fix #4234
- Loading branch information
1 parent
1675fc4
commit ab55ca7
Showing
7 changed files
with
138 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright 2018 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package integrations | ||
|
||
import ( | ||
"net/http" | ||
"testing" | ||
|
||
"code.gitea.io/gitea/models" | ||
api "code.gitea.io/sdk/gitea" | ||
) | ||
|
||
// TestAPICreateAndDeleteToken tests that token that was just created can be deleted | ||
func TestAPICreateAndDeleteToken(t *testing.T) { | ||
prepareTestEnv(t) | ||
user := models.AssertExistsAndLoadBean(t, &models.User{ID: 1}).(*models.User) | ||
|
||
req := NewRequestWithJSON(t, "POST", "/api/v1/users/user1/tokens", map[string]string{ | ||
"name": "test-key-1", | ||
}) | ||
req = AddBasicAuthHeader(req, user.Name) | ||
resp := MakeRequest(t, req, http.StatusCreated) | ||
|
||
var newAccessToken api.AccessToken | ||
DecodeJSON(t, resp, &newAccessToken) | ||
models.AssertExistsAndLoadBean(t, &models.AccessToken{ | ||
ID: newAccessToken.ID, | ||
Name: newAccessToken.Name, | ||
Sha1: newAccessToken.Sha1, | ||
UID: user.ID, | ||
}) | ||
|
||
req = NewRequestf(t, "DELETE", "/api/v1/users/user1/tokens/%d", newAccessToken.ID) | ||
req = AddBasicAuthHeader(req, user.Name) | ||
MakeRequest(t, req, http.StatusNoContent) | ||
|
||
models.AssertNotExistsBean(t, &models.AccessToken{ID: newAccessToken.ID}) | ||
} | ||
|
||
// TestAPIDeleteMissingToken ensures that error is thrown when token not found | ||
func TestAPIDeleteMissingToken(t *testing.T) { | ||
prepareTestEnv(t) | ||
user := models.AssertExistsAndLoadBean(t, &models.User{ID: 1}).(*models.User) | ||
|
||
req := NewRequestf(t, "DELETE", "/api/v1/users/user1/tokens/%d", models.NonexistentID) | ||
req = AddBasicAuthHeader(req, user.Name) | ||
MakeRequest(t, req, http.StatusNotFound) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.