2017-04-25 09:24:51 +02:00
|
|
|
// Copyright 2017 The Gitea Authors. All rights reserved.
|
2022-11-27 19:20:29 +01:00
|
|
|
// SPDX-License-Identifier: MIT
|
2017-04-25 09:24:51 +02:00
|
|
|
|
2022-09-02 21:18:23 +02:00
|
|
|
package integration
|
2017-04-25 09:24:51 +02:00
|
|
|
|
|
|
|
import (
|
[GITEA] Add OpenStreetMap URL to Location field in profile
Not too important, but I think that it'd be a pretty neat touch.
(cherry picked from commit 64de4e02f9ed776bc751354d39fc652ea5c2ef19)
Add placeholder text
(cherry picked from commit 1396e2716b57c8cc3f635837696b6c65edda3ea2)
Add test for OSM feature (doesn't work yet)
(cherry picked from commit 2c94e6d56f6444946bcdff3f24776e4532903b8c)
Lint tests (sorry, I'm a bit tired)
(cherry picked from commit 5731fbb4a4f800e1f38eba34a9db98913287928e)
It finally works, will add more tests later.
(cherry picked from commit 4437292622e689ae7afbada9bcc84186560c1cf9)
Improve testing
(cherry picked from commit 56a028ec96e232cfec32956f7c9908f6a059513d)
Introduce new button for OpenStreetMap URL
(cherry picked from commit 852317b46734ca5c929b4b12fb067c14e51d0f1b)
16, "gt-mr-2" in *all* icons
(cherry picked from commit c2c60a01eb0be9062000bc5b8cf7a4fdb534a2f0)
Wait, I forgot about *that* icon
(cherry picked from commit 9930f9b8f2b06d9593b256e4afee0109970a15f8)
Alright, we just made all the icons in that submenu a bit bolder and more consistent.
(cherry picked from commit d5c0009ad01fbf0486620b7c00351a6d1d01b6aa)
Remove | Safe attribute, it does exactly the opposite of what I intended it to.
(cherry picked from commit 1254f2aa9df3ba046d3067ffa49978cf053cdf39)
Make OSM button configurable
(cherry picked from commit ba3d76f5ba1621356390412a3767fc2daa6bfae7)
Fix tests (tested)
(cherry picked from commit 22983c65f8b143d26600d02b2615d4b36b02000f)
Add more tests
(cherry picked from commit 4bbcbd37e138c68d3b9329cb2dbcfd8aad430c79)
Add tooltip
(cherry picked from commit b906008ff1792f6e6e3acaa6e7c71be30c009dd2)
Revert "16, "gt-mr-2" in *all* icons"
This reverts commit c2c60a01eb0be9062000bc5b8cf7a4fdb534a2f0.
(cherry picked from commit 02bb52617dbf93d96bb69183ea8879e7e2e28d50)
Revert "Wait, I forgot about *that* icon"
This reverts commit 9930f9b8f2b06d9593b256e4afee0109970a15f8.
(cherry picked from commit a36d6575090124cac2b46b288cbb6f5c1df482ea)
Revert "Alright, we just made all the icons in that submenu a bit bolder and more consistent."
This reverts commit d5c0009ad01fbf0486620b7c00351a6d1d01b6aa.
(cherry picked from commit 27d8d1c5fc6418cb55430fc3f093a2e02ffaeb93)
2023-07-19 21:29:19 +02:00
|
|
|
"fmt"
|
2017-04-25 09:24:51 +02:00
|
|
|
"net/http"
|
|
|
|
"testing"
|
|
|
|
|
2023-01-17 22:46:03 +01:00
|
|
|
auth_model "code.gitea.io/gitea/models/auth"
|
2022-06-13 11:37:59 +02:00
|
|
|
issues_model "code.gitea.io/gitea/models/issues"
|
2022-04-07 20:59:56 +02:00
|
|
|
repo_model "code.gitea.io/gitea/models/repo"
|
2021-11-16 09:53:21 +01:00
|
|
|
"code.gitea.io/gitea/models/unittest"
|
2021-11-24 10:49:20 +01:00
|
|
|
user_model "code.gitea.io/gitea/models/user"
|
[GITEA] Add OpenStreetMap URL to Location field in profile
Not too important, but I think that it'd be a pretty neat touch.
(cherry picked from commit 64de4e02f9ed776bc751354d39fc652ea5c2ef19)
Add placeholder text
(cherry picked from commit 1396e2716b57c8cc3f635837696b6c65edda3ea2)
Add test for OSM feature (doesn't work yet)
(cherry picked from commit 2c94e6d56f6444946bcdff3f24776e4532903b8c)
Lint tests (sorry, I'm a bit tired)
(cherry picked from commit 5731fbb4a4f800e1f38eba34a9db98913287928e)
It finally works, will add more tests later.
(cherry picked from commit 4437292622e689ae7afbada9bcc84186560c1cf9)
Improve testing
(cherry picked from commit 56a028ec96e232cfec32956f7c9908f6a059513d)
Introduce new button for OpenStreetMap URL
(cherry picked from commit 852317b46734ca5c929b4b12fb067c14e51d0f1b)
16, "gt-mr-2" in *all* icons
(cherry picked from commit c2c60a01eb0be9062000bc5b8cf7a4fdb534a2f0)
Wait, I forgot about *that* icon
(cherry picked from commit 9930f9b8f2b06d9593b256e4afee0109970a15f8)
Alright, we just made all the icons in that submenu a bit bolder and more consistent.
(cherry picked from commit d5c0009ad01fbf0486620b7c00351a6d1d01b6aa)
Remove | Safe attribute, it does exactly the opposite of what I intended it to.
(cherry picked from commit 1254f2aa9df3ba046d3067ffa49978cf053cdf39)
Make OSM button configurable
(cherry picked from commit ba3d76f5ba1621356390412a3767fc2daa6bfae7)
Fix tests (tested)
(cherry picked from commit 22983c65f8b143d26600d02b2615d4b36b02000f)
Add more tests
(cherry picked from commit 4bbcbd37e138c68d3b9329cb2dbcfd8aad430c79)
Add tooltip
(cherry picked from commit b906008ff1792f6e6e3acaa6e7c71be30c009dd2)
Revert "16, "gt-mr-2" in *all* icons"
This reverts commit c2c60a01eb0be9062000bc5b8cf7a4fdb534a2f0.
(cherry picked from commit 02bb52617dbf93d96bb69183ea8879e7e2e28d50)
Revert "Wait, I forgot about *that* icon"
This reverts commit 9930f9b8f2b06d9593b256e4afee0109970a15f8.
(cherry picked from commit a36d6575090124cac2b46b288cbb6f5c1df482ea)
Revert "Alright, we just made all the icons in that submenu a bit bolder and more consistent."
This reverts commit d5c0009ad01fbf0486620b7c00351a6d1d01b6aa.
(cherry picked from commit 27d8d1c5fc6418cb55430fc3f093a2e02ffaeb93)
2023-07-19 21:29:19 +02:00
|
|
|
"code.gitea.io/gitea/modules/setting"
|
2022-04-07 20:59:56 +02:00
|
|
|
api "code.gitea.io/gitea/modules/structs"
|
2017-12-15 22:11:02 +01:00
|
|
|
"code.gitea.io/gitea/modules/test"
|
2022-06-26 16:19:22 +02:00
|
|
|
"code.gitea.io/gitea/modules/translation"
|
2022-09-02 21:18:23 +02:00
|
|
|
"code.gitea.io/gitea/tests"
|
2017-07-01 21:48:29 +02:00
|
|
|
|
2017-04-25 09:24:51 +02:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestViewUser(t *testing.T) {
|
2022-09-02 21:18:23 +02:00
|
|
|
defer tests.PrepareTestEnv(t)()
|
2017-04-25 09:24:51 +02:00
|
|
|
|
2017-06-10 02:41:36 +02:00
|
|
|
req := NewRequest(t, "GET", "/user2")
|
2017-07-07 21:36:47 +02:00
|
|
|
MakeRequest(t, req, http.StatusOK)
|
2017-04-25 09:24:51 +02:00
|
|
|
}
|
2017-07-01 21:48:29 +02:00
|
|
|
|
|
|
|
func TestRenameUsername(t *testing.T) {
|
2022-09-02 21:18:23 +02:00
|
|
|
defer tests.PrepareTestEnv(t)()
|
2017-07-01 21:48:29 +02:00
|
|
|
|
|
|
|
session := loginUser(t, "user2")
|
2017-07-07 21:36:47 +02:00
|
|
|
req := NewRequestWithValues(t, "POST", "/user/settings", map[string]string{
|
2018-05-05 02:28:30 +02:00
|
|
|
"_csrf": GetCSRF(t, session, "/user/settings"),
|
|
|
|
"name": "newUsername",
|
|
|
|
"email": "user2@example.com",
|
2020-12-04 07:20:30 +01:00
|
|
|
"language": "en-US",
|
2017-07-01 21:48:29 +02:00
|
|
|
})
|
2022-03-23 05:54:07 +01:00
|
|
|
session.MakeRequest(t, req, http.StatusSeeOther)
|
2017-07-01 21:48:29 +02:00
|
|
|
|
2021-11-24 10:49:20 +01:00
|
|
|
unittest.AssertExistsAndLoadBean(t, &user_model.User{Name: "newUsername"})
|
|
|
|
unittest.AssertNotExistsBean(t, &user_model.User{Name: "user2"})
|
2017-07-01 21:48:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestRenameInvalidUsername(t *testing.T) {
|
2022-09-02 21:18:23 +02:00
|
|
|
defer tests.PrepareTestEnv(t)()
|
2017-07-01 21:48:29 +02:00
|
|
|
|
|
|
|
invalidUsernames := []string{
|
|
|
|
"%2f*",
|
|
|
|
"%2f.",
|
|
|
|
"%2f..",
|
|
|
|
"%00",
|
|
|
|
"thisHas ASpace",
|
2019-01-24 15:12:17 +01:00
|
|
|
"p<A>tho>lo<gical",
|
2022-11-04 10:04:08 +01:00
|
|
|
".",
|
|
|
|
"..",
|
|
|
|
".well-known",
|
|
|
|
".abc",
|
|
|
|
"abc.",
|
|
|
|
"a..bc",
|
|
|
|
"a...bc",
|
|
|
|
"a.-bc",
|
|
|
|
"a._bc",
|
|
|
|
"a_-bc",
|
|
|
|
"a/bc",
|
|
|
|
"☁️",
|
|
|
|
"-",
|
|
|
|
"--diff",
|
|
|
|
"-im-here",
|
|
|
|
"a space",
|
2017-07-01 21:48:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
session := loginUser(t, "user2")
|
|
|
|
for _, invalidUsername := range invalidUsernames {
|
|
|
|
t.Logf("Testing username %s", invalidUsername)
|
|
|
|
|
2017-07-07 21:36:47 +02:00
|
|
|
req := NewRequestWithValues(t, "POST", "/user/settings", map[string]string{
|
|
|
|
"_csrf": GetCSRF(t, session, "/user/settings"),
|
2017-07-01 21:48:29 +02:00
|
|
|
"name": invalidUsername,
|
|
|
|
"email": "user2@example.com",
|
|
|
|
})
|
2017-07-07 21:36:47 +02:00
|
|
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
|
|
|
htmlDoc := NewHTMLParser(t, resp.Body)
|
2017-07-01 21:48:29 +02:00
|
|
|
assert.Contains(t,
|
|
|
|
htmlDoc.doc.Find(".ui.negative.message").Text(),
|
2022-11-04 10:04:08 +01:00
|
|
|
translation.NewLocale("en-US").Tr("form.username_error"),
|
2017-07-01 21:48:29 +02:00
|
|
|
)
|
|
|
|
|
2021-11-24 10:49:20 +01:00
|
|
|
unittest.AssertNotExistsBean(t, &user_model.User{Name: invalidUsername})
|
2017-07-01 21:48:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRenameReservedUsername(t *testing.T) {
|
2022-09-02 21:18:23 +02:00
|
|
|
defer tests.PrepareTestEnv(t)()
|
2017-07-01 21:48:29 +02:00
|
|
|
|
|
|
|
reservedUsernames := []string{
|
2022-11-04 10:04:08 +01:00
|
|
|
// ".", "..", ".well-known", // The names are not only reserved but also invalid
|
2019-09-24 19:12:56 +02:00
|
|
|
"admin",
|
|
|
|
"api",
|
2022-03-31 06:02:13 +02:00
|
|
|
"assets",
|
2019-09-24 19:12:56 +02:00
|
|
|
"attachments",
|
2022-03-31 06:02:13 +02:00
|
|
|
"avatar",
|
2019-09-24 19:12:56 +02:00
|
|
|
"avatars",
|
2022-03-31 06:02:13 +02:00
|
|
|
"captcha",
|
|
|
|
"commits",
|
|
|
|
"debug",
|
|
|
|
"error",
|
2019-09-24 19:12:56 +02:00
|
|
|
"explore",
|
2022-03-31 06:02:13 +02:00
|
|
|
"favicon.ico",
|
|
|
|
"ghost",
|
2019-09-24 19:12:56 +02:00
|
|
|
"issues",
|
|
|
|
"login",
|
2022-03-31 06:02:13 +02:00
|
|
|
"manifest.json",
|
2019-09-24 19:12:56 +02:00
|
|
|
"metrics",
|
2022-03-31 06:02:13 +02:00
|
|
|
"milestones",
|
|
|
|
"new",
|
2019-09-24 19:12:56 +02:00
|
|
|
"notifications",
|
|
|
|
"org",
|
|
|
|
"pulls",
|
2022-03-31 06:02:13 +02:00
|
|
|
"raw",
|
2019-09-24 19:12:56 +02:00
|
|
|
"repo",
|
2022-03-31 06:02:13 +02:00
|
|
|
"repo-avatars",
|
|
|
|
"robots.txt",
|
2019-11-18 21:03:25 +01:00
|
|
|
"search",
|
2022-03-31 06:02:13 +02:00
|
|
|
"serviceworker.js",
|
|
|
|
"ssh_info",
|
|
|
|
"swagger.v1.json",
|
|
|
|
"user",
|
|
|
|
"v2",
|
2017-07-01 21:48:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
session := loginUser(t, "user2")
|
|
|
|
for _, reservedUsername := range reservedUsernames {
|
|
|
|
t.Logf("Testing username %s", reservedUsername)
|
2017-07-07 21:36:47 +02:00
|
|
|
req := NewRequestWithValues(t, "POST", "/user/settings", map[string]string{
|
2018-05-05 02:28:30 +02:00
|
|
|
"_csrf": GetCSRF(t, session, "/user/settings"),
|
|
|
|
"name": reservedUsername,
|
|
|
|
"email": "user2@example.com",
|
2020-12-04 07:20:30 +01:00
|
|
|
"language": "en-US",
|
2017-07-01 21:48:29 +02:00
|
|
|
})
|
2022-03-23 05:54:07 +01:00
|
|
|
resp := session.MakeRequest(t, req, http.StatusSeeOther)
|
2017-07-01 21:48:29 +02:00
|
|
|
|
2017-12-15 22:11:02 +01:00
|
|
|
req = NewRequest(t, "GET", test.RedirectURL(resp))
|
2017-07-07 21:36:47 +02:00
|
|
|
resp = session.MakeRequest(t, req, http.StatusOK)
|
|
|
|
htmlDoc := NewHTMLParser(t, resp.Body)
|
2017-07-01 21:48:29 +02:00
|
|
|
assert.Contains(t,
|
|
|
|
htmlDoc.doc.Find(".ui.negative.message").Text(),
|
2022-06-26 16:19:22 +02:00
|
|
|
translation.NewLocale("en-US").Tr("user.form.name_reserved", reservedUsername),
|
2017-07-01 21:48:29 +02:00
|
|
|
)
|
|
|
|
|
2021-11-24 10:49:20 +01:00
|
|
|
unittest.AssertNotExistsBean(t, &user_model.User{Name: reservedUsername})
|
2017-07-01 21:48:29 +02:00
|
|
|
}
|
|
|
|
}
|
2019-04-14 18:43:56 +02:00
|
|
|
|
|
|
|
func TestExportUserGPGKeys(t *testing.T) {
|
2022-09-02 21:18:23 +02:00
|
|
|
defer tests.PrepareTestEnv(t)()
|
2022-01-20 18:46:10 +01:00
|
|
|
// Export empty key list
|
2019-04-14 18:43:56 +02:00
|
|
|
testExportUserGPGKeys(t, "user1", `-----BEGIN PGP PUBLIC KEY BLOCK-----
|
2022-03-02 17:32:18 +01:00
|
|
|
Note: This user hasn't uploaded any GPG keys.
|
2019-04-14 18:43:56 +02:00
|
|
|
|
|
|
|
|
|
|
|
=twTO
|
|
|
|
-----END PGP PUBLIC KEY BLOCK-----
|
|
|
|
`)
|
2022-01-20 18:46:10 +01:00
|
|
|
// Import key
|
|
|
|
// User1 <user1@example.com>
|
2019-04-14 18:43:56 +02:00
|
|
|
session := loginUser(t, "user1")
|
Redesign Scoped Access Tokens (#24767)
## Changes
- Adds the following high level access scopes, each with `read` and
`write` levels:
- `activitypub`
- `admin` (hidden if user is not a site admin)
- `misc`
- `notification`
- `organization`
- `package`
- `issue`
- `repository`
- `user`
- Adds new middleware function `tokenRequiresScopes()` in addition to
`reqToken()`
- `tokenRequiresScopes()` is used for each high-level api section
- _if_ a scoped token is present, checks that the required scope is
included based on the section and HTTP method
- `reqToken()` is used for individual routes
- checks that required authentication is present (but does not check
scope levels as this will already have been handled by
`tokenRequiresScopes()`
- Adds migration to convert old scoped access tokens to the new set of
scopes
- Updates the user interface for scope selection
### User interface example
<img width="903" alt="Screen Shot 2023-05-31 at 1 56 55 PM"
src="https://github.com/go-gitea/gitea/assets/23248839/654766ec-2143-4f59-9037-3b51600e32f3">
<img width="917" alt="Screen Shot 2023-05-31 at 1 56 43 PM"
src="https://github.com/go-gitea/gitea/assets/23248839/1ad64081-012c-4a73-b393-66b30352654c">
## tokenRequiresScopes Design Decision
- `tokenRequiresScopes()` was added to more reliably cover api routes.
For an incoming request, this function uses the given scope category
(say `AccessTokenScopeCategoryOrganization`) and the HTTP method (say
`DELETE`) and verifies that any scoped tokens in use include
`delete:organization`.
- `reqToken()` is used to enforce auth for individual routes that
require it. If a scoped token is not present for a request,
`tokenRequiresScopes()` will not return an error
## TODO
- [x] Alphabetize scope categories
- [x] Change 'public repos only' to a radio button (private vs public).
Also expand this to organizations
- [X] Disable token creation if no scopes selected. Alternatively, show
warning
- [x] `reqToken()` is missing from many `POST/DELETE` routes in the api.
`tokenRequiresScopes()` only checks that a given token has the correct
scope, `reqToken()` must be used to check that a token (or some other
auth) is present.
- _This should be addressed in this PR_
- [x] The migration should be reviewed very carefully in order to
minimize access changes to existing user tokens.
- _This should be addressed in this PR_
- [x] Link to api to swagger documentation, clarify what
read/write/delete levels correspond to
- [x] Review cases where more than one scope is needed as this directly
deviates from the api definition.
- _This should be addressed in this PR_
- For example:
```go
m.Group("/users/{username}/orgs", func() {
m.Get("", reqToken(), org.ListUserOrgs)
m.Get("/{org}/permissions", reqToken(), org.GetUserOrgsPermissions)
}, tokenRequiresScopes(auth_model.AccessTokenScopeCategoryUser,
auth_model.AccessTokenScopeCategoryOrganization),
context_service.UserAssignmentAPI())
```
## Future improvements
- [ ] Add required scopes to swagger documentation
- [ ] Redesign `reqToken()` to be opt-out rather than opt-in
- [ ] Subdivide scopes like `repository`
- [ ] Once a token is created, if it has no scopes, we should display
text instead of an empty bullet point
- [ ] If the 'public repos only' option is selected, should read
categories be selected by default
Closes #24501
Closes #24799
Co-authored-by: Jonathan Tran <jon@allspice.io>
Co-authored-by: Kyle D <kdumontnu@gmail.com>
Co-authored-by: silverwind <me@silverwind.io>
2023-06-04 20:57:16 +02:00
|
|
|
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteUser)
|
2019-04-14 18:43:56 +02:00
|
|
|
testCreateGPGKey(t, session.MakeRequest, token, http.StatusCreated, `-----BEGIN PGP PUBLIC KEY BLOCK-----
|
|
|
|
|
|
|
|
mQENBFyy/VUBCADJ7zbM20Z1RWmFoVgp5WkQfI2rU1Vj9cQHes9i42wVLLtcbPeo
|
|
|
|
QzubgzvMPITDy7nfWxgSf83E23DoHQ1ACFbQh/6eFSRrjsusp3YQ/08NSfPPbcu8
|
|
|
|
0M5G+VGwSfzS5uEcwBVQmHyKdcOZIERTNMtYZx1C3bjLD1XVJHvWz9D72Uq4qeO3
|
|
|
|
8SR+lzp5n6ppUakcmRnxt3nGRBj1+hEGkdgzyPo93iy+WioegY2lwCA9xMEo5dah
|
|
|
|
BmYxWx51zyiXYlReTaxlyb3/nuSUt8IcW3Q8zjdtJj4Nu8U1SpV8EdaA1I9IPbHW
|
|
|
|
510OSLmD3XhqHH5m6mIxL1YoWxk3V7gpDROtABEBAAG0GVVzZXIxIDx1c2VyMUBl
|
|
|
|
eGFtcGxlLmNvbT6JAU4EEwEIADgWIQTQEbrYxmXsp1z3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9QeeLJ/+l2DafESNhNTy17+RPmacK6
|
|
|
|
21dccpqchByVw/UMDeHSyjQLiG2lxzt8Gfx2gHmSbrq3aWovTGyz6JTffZvfy/n2
|
|
|
|
0Hm437OBPazO0gZyXhdV2PE5RSUfvAgm44235tcV5EV0d32TJDfv61+Vr2GUbah6
|
|
|
|
7XhJ1v6JYuh8kaYaEz8OpZDeh7f6Ho6PzJrsy/TKTKhGgZNINj1iaPFyOkQgKR5M
|
|
|
|
GrE0MHOxUbc9tbtyk0F1SuzREUBH
|
|
|
|
=DDXw
|
|
|
|
-----END PGP PUBLIC KEY BLOCK-----
|
|
|
|
`)
|
2022-01-20 18:46:10 +01:00
|
|
|
// Export new key
|
2019-04-14 18:43:56 +02:00
|
|
|
testExportUserGPGKeys(t, "user1", `-----BEGIN PGP PUBLIC KEY BLOCK-----
|
|
|
|
|
|
|
|
xsBNBFyy/VUBCADJ7zbM20Z1RWmFoVgp5WkQfI2rU1Vj9cQHes9i42wVLLtcbPeo
|
|
|
|
QzubgzvMPITDy7nfWxgSf83E23DoHQ1ACFbQh/6eFSRrjsusp3YQ/08NSfPPbcu8
|
|
|
|
0M5G+VGwSfzS5uEcwBVQmHyKdcOZIERTNMtYZx1C3bjLD1XVJHvWz9D72Uq4qeO3
|
|
|
|
8SR+lzp5n6ppUakcmRnxt3nGRBj1+hEGkdgzyPo93iy+WioegY2lwCA9xMEo5dah
|
|
|
|
BmYxWx51zyiXYlReTaxlyb3/nuSUt8IcW3Q8zjdtJj4Nu8U1SpV8EdaA1I9IPbHW
|
|
|
|
510OSLmD3XhqHH5m6mIxL1YoWxk3V7gpDROtABEBAAHNGVVzZXIxIDx1c2VyMUBl
|
|
|
|
eGFtcGxlLmNvbT7CwI4EEwEIADgWIQTQEbrYxmXsp1z3j7z9+v0I6RSEHwUCXLL9
|
|
|
|
VQIbAwULCQgHAgYVCgkICwIEFgIDAQIeAQIXgAAKCRD9+v0I6RSEH22YCACFqL5+
|
|
|
|
6M0m18AMC/pumc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437OBPazO0gZyXhdV2PE5RSUfvAgm44235tcV5EV0d32TJDfv61+Vr2GUbah6
|
|
|
|
7XhJ1v6JYuh8kaYaEz8OpZDeh7f6Ho6PzJrsy/TKTKhGgZNINj1iaPFyOkQgKR5M
|
|
|
|
GrE0MHOxUbc9tbtyk0F1SuzREUBH
|
|
|
|
=WFf5
|
|
|
|
-----END PGP PUBLIC KEY BLOCK-----
|
|
|
|
`)
|
|
|
|
}
|
|
|
|
|
|
|
|
func testExportUserGPGKeys(t *testing.T, user, expected string) {
|
|
|
|
session := loginUser(t, user)
|
|
|
|
t.Logf("Testing username %s export gpg keys", user)
|
|
|
|
req := NewRequest(t, "GET", "/"+user+".gpg")
|
|
|
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
2022-01-20 18:46:10 +01:00
|
|
|
// t.Log(resp.Body.String())
|
2019-04-14 18:43:56 +02:00
|
|
|
assert.Equal(t, expected, resp.Body.String())
|
|
|
|
}
|
2022-04-07 20:59:56 +02:00
|
|
|
|
2023-04-07 12:08:36 +02:00
|
|
|
func TestGetUserRss(t *testing.T) {
|
|
|
|
user34 := "the_34-user.with.all.allowedChars"
|
|
|
|
req := NewRequestf(t, "GET", "/%s.rss", user34)
|
|
|
|
resp := MakeRequest(t, req, http.StatusOK)
|
|
|
|
if assert.EqualValues(t, "application/rss+xml;charset=utf-8", resp.Header().Get("Content-Type")) {
|
|
|
|
rssDoc := NewHTMLParser(t, resp.Body).Find("channel")
|
|
|
|
title, _ := rssDoc.ChildrenFiltered("title").Html()
|
|
|
|
assert.EqualValues(t, "Feed of "the_1-user.with.all.allowedChars"", title)
|
|
|
|
description, _ := rssDoc.ChildrenFiltered("description").Html()
|
2023-05-20 23:02:52 +02:00
|
|
|
assert.EqualValues(t, "<p dir="auto">some <a href="https://commonmark.org/" rel="nofollow">commonmark</a>!</p>\n", description)
|
2023-04-07 12:08:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-07 20:59:56 +02:00
|
|
|
func TestListStopWatches(t *testing.T) {
|
2022-09-02 21:18:23 +02:00
|
|
|
defer tests.PrepareTestEnv(t)()
|
2022-04-07 20:59:56 +02:00
|
|
|
|
2022-08-16 04:22:25 +02:00
|
|
|
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
|
|
|
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
|
2022-04-07 20:59:56 +02:00
|
|
|
|
|
|
|
session := loginUser(t, owner.Name)
|
|
|
|
req := NewRequestf(t, "GET", "/user/stopwatches")
|
|
|
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
|
|
|
var apiWatches []*api.StopWatch
|
|
|
|
DecodeJSON(t, resp, &apiWatches)
|
2022-08-16 04:22:25 +02:00
|
|
|
stopwatch := unittest.AssertExistsAndLoadBean(t, &issues_model.Stopwatch{UserID: owner.ID})
|
|
|
|
issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: stopwatch.IssueID})
|
2022-04-07 20:59:56 +02:00
|
|
|
if assert.Len(t, apiWatches, 1) {
|
|
|
|
assert.EqualValues(t, stopwatch.CreatedUnix.AsTime().Unix(), apiWatches[0].Created.Unix())
|
|
|
|
assert.EqualValues(t, issue.Index, apiWatches[0].IssueIndex)
|
|
|
|
assert.EqualValues(t, issue.Title, apiWatches[0].IssueTitle)
|
|
|
|
assert.EqualValues(t, repo.Name, apiWatches[0].RepoName)
|
|
|
|
assert.EqualValues(t, repo.OwnerName, apiWatches[0].RepoOwnerName)
|
2022-06-20 12:02:49 +02:00
|
|
|
assert.Greater(t, apiWatches[0].Seconds, int64(0))
|
2022-04-07 20:59:56 +02:00
|
|
|
}
|
|
|
|
}
|
[GITEA] Add OpenStreetMap URL to Location field in profile
Not too important, but I think that it'd be a pretty neat touch.
(cherry picked from commit 64de4e02f9ed776bc751354d39fc652ea5c2ef19)
Add placeholder text
(cherry picked from commit 1396e2716b57c8cc3f635837696b6c65edda3ea2)
Add test for OSM feature (doesn't work yet)
(cherry picked from commit 2c94e6d56f6444946bcdff3f24776e4532903b8c)
Lint tests (sorry, I'm a bit tired)
(cherry picked from commit 5731fbb4a4f800e1f38eba34a9db98913287928e)
It finally works, will add more tests later.
(cherry picked from commit 4437292622e689ae7afbada9bcc84186560c1cf9)
Improve testing
(cherry picked from commit 56a028ec96e232cfec32956f7c9908f6a059513d)
Introduce new button for OpenStreetMap URL
(cherry picked from commit 852317b46734ca5c929b4b12fb067c14e51d0f1b)
16, "gt-mr-2" in *all* icons
(cherry picked from commit c2c60a01eb0be9062000bc5b8cf7a4fdb534a2f0)
Wait, I forgot about *that* icon
(cherry picked from commit 9930f9b8f2b06d9593b256e4afee0109970a15f8)
Alright, we just made all the icons in that submenu a bit bolder and more consistent.
(cherry picked from commit d5c0009ad01fbf0486620b7c00351a6d1d01b6aa)
Remove | Safe attribute, it does exactly the opposite of what I intended it to.
(cherry picked from commit 1254f2aa9df3ba046d3067ffa49978cf053cdf39)
Make OSM button configurable
(cherry picked from commit ba3d76f5ba1621356390412a3767fc2daa6bfae7)
Fix tests (tested)
(cherry picked from commit 22983c65f8b143d26600d02b2615d4b36b02000f)
Add more tests
(cherry picked from commit 4bbcbd37e138c68d3b9329cb2dbcfd8aad430c79)
Add tooltip
(cherry picked from commit b906008ff1792f6e6e3acaa6e7c71be30c009dd2)
Revert "16, "gt-mr-2" in *all* icons"
This reverts commit c2c60a01eb0be9062000bc5b8cf7a4fdb534a2f0.
(cherry picked from commit 02bb52617dbf93d96bb69183ea8879e7e2e28d50)
Revert "Wait, I forgot about *that* icon"
This reverts commit 9930f9b8f2b06d9593b256e4afee0109970a15f8.
(cherry picked from commit a36d6575090124cac2b46b288cbb6f5c1df482ea)
Revert "Alright, we just made all the icons in that submenu a bit bolder and more consistent."
This reverts commit d5c0009ad01fbf0486620b7c00351a6d1d01b6aa.
(cherry picked from commit 27d8d1c5fc6418cb55430fc3f093a2e02ffaeb93)
2023-07-19 21:29:19 +02:00
|
|
|
|
|
|
|
func TestGetOpenStreetMapLink(t *testing.T) {
|
|
|
|
setting.Service.EnableOSMButton = true
|
|
|
|
defer tests.PrepareTestEnv(t)()
|
|
|
|
|
|
|
|
testLocations := map[string]string{
|
|
|
|
"Αθήνα": "%ce%91%ce%b8%ce%ae%ce%bd%ce%b1",
|
|
|
|
" Αθήνα": "%20%20%ce%91%ce%b8%ce%ae%ce%bd%ce%b1",
|
|
|
|
"Barbarossabrunnen, Düsseldorf": "Barbarossabrunnen%2c%20D%c3%bcsseldorf",
|
|
|
|
"39.91025,116.40753": "39.91025%2c116.40753",
|
|
|
|
"པེ་ཅིང་གྲོང་ཁྱེར།": "%e0%bd%94%e0%bd%ba%e0%bc%8b%e0%bd%85%e0%bd%b2%e0%bd%84%e0%bc%8b%e0%bd%82%e0%be%b2%e0%bd%bc%e0%bd%84%e0%bc%8b%e0%bd%81%e0%be%b1%e0%bd%ba%e0%bd%a2%e0%bc%8d",
|
|
|
|
"Internet Archive": "Internet%20Archive",
|
|
|
|
"Schönhauser Allee 2, Berlin, Deutschland": "Sch%c3%b6nhauser%20Allee%202%2c%20Berlin%2c%20Deutschland",
|
|
|
|
"Miestna knižnica Podunajské Biskupice": "Miestna%20kni%c5%benica%20Podunajsk%c3%a9%20Biskupice",
|
|
|
|
"東京タワー": "%e6%9d%b1%e4%ba%ac%e3%82%bf%e3%83%af%e3%83%bc",
|
|
|
|
"Carnarvon Space & Technology Centre": "Carnarvon%20Space%20%26%20Technology%20Centre",
|
|
|
|
}
|
|
|
|
|
|
|
|
session := loginUser(t, "user2")
|
|
|
|
for location, encodedLocation := range testLocations {
|
|
|
|
t.Run(location, func(t *testing.T) {
|
|
|
|
req := NewRequestWithValues(t, "POST", "/user/settings", map[string]string{
|
|
|
|
"_csrf": GetCSRF(t, session, "/user/settings"),
|
|
|
|
"name": "user2",
|
|
|
|
"email": "user@example.com",
|
|
|
|
"language": "en-US",
|
|
|
|
"location": location,
|
|
|
|
})
|
|
|
|
session.MakeRequest(t, req, http.StatusSeeOther)
|
|
|
|
|
|
|
|
req = NewRequest(t, "GET", "/user2/")
|
|
|
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
|
|
|
htmlDoc := NewHTMLParser(t, resp.Body)
|
|
|
|
|
|
|
|
htmlDoc.AssertElement(t, fmt.Sprintf("a[href='https://www.openstreetmap.org/search?query=%s']", encodedLocation), true)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|