Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create user token API allows creating tokens with the same name #5587

Closed
koaps opened this issue Jan 7, 2019 · 1 comment
Closed

Create user token API allows creating tokens with the same name #5587

koaps opened this issue Jan 7, 2019 · 1 comment
Labels
🔨 enhancement Make it better, faster status: needs feedback Tell me more about it

Comments

@koaps
Copy link

koaps commented Jan 7, 2019

Posting to the user token API (/users/:username/tokens) endpoint multiple times with the same required name creates multiple tokens.

for i in {1..5}; do curl -X POST -H "content-type: application/json" -d '{"name":"test_api_token"}' http://builder:builder@127.0.0.1:10080/api/v1/users/builder/tokens -s | jq .sha1; done


curl http://builder:builder@127.0.0.1:10080/api/v1/users/builder/tokens -s | jq .

[
  {
    "name": "test_api_token",
    "sha1": "7f5a82226a2b01abbf60e648a7553d98879be5f5"
  },
  {
    "name": "test_api_token",
    "sha1": "e617c6a60b31695cd73d5b93b257b540bfaefe1b"
  },
  {
    "name": "test_api_token",
    "sha1": "12f79d7e61945dd6959701e7d0877b68819c7611"
  },
  {
    "name": "test_api_token",
    "sha1": "b7bf07c5341e61342bcc1068b34f5fe75d5a885a"
  },
  {
    "name": "test_api_token",
    "sha1": "f40728c529c01e236bb72a8c2da4cbbab32fa9bf"
  }
]

I would think this should throw a HTTP/1.1 422 Unprocessable Entity error like the repos do

{"message":"repository already exists [uname: builder, name: builder]","url":"https://github.com/gogs/docs-api"}

  • Gogs Version: 0.11.85.1225
  • Git version: 2.18.1
  • Operating system: Alpine 3.8
  • Database (replace [ ] with [x]):
    • PostgreSQL
    • MySQL
    • MSSQL
    • [X ] SQLite
@unknwon unknwon added 🔨 enhancement Make it better, faster 👋 good first issue Good for newcomers labels Jan 31, 2019
richmahn referenced this issue in unfoldingWord/dcs Feb 4, 2019
* fix nil pointer

* remove nil check and just call loadRepo regardless
frodeaa added a commit to frodeaa/gogs that referenced this issue Oct 13, 2019
Fail with 422 Unprocessable Entity if the token name
already exist

ref: gogs#5587
frodeaa added a commit to frodeaa/gogs that referenced this issue Oct 13, 2019
Fail with 422 Unprocessable Entity if the token name
already exist

ref: gogs#5587
frodeaa added a commit to frodeaa/gogs that referenced this issue Oct 13, 2019
Fail with 422 Unprocessable Entity if the token name
already exist

ref: gogs#5587
unknwon pushed a commit that referenced this issue Oct 15, 2019
* api/v1: don't allow multiple tokens with same name

Fail with 422 Unprocessable Entity if the token name
already exist

ref: #5587

* Move new token error type to models/errors/token

* Remove "useless" ListAccessTokensByName function

* Add an i18n entry for token_name_exists
@unknwon unknwon added status: needs feedback Tell me more about it and removed 👋 good first issue Good for newcomers labels Oct 15, 2019
@unknwon
Copy link
Member

unknwon commented Oct 15, 2019

This is claimed to be fixed by merging #5820, please help test on develop branch or https://try.gogs.io.

@unknwon unknwon closed this as completed Oct 19, 2019
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🔨 enhancement Make it better, faster status: needs feedback Tell me more about it
Projects
None yet
Development

No branches or pull requests

2 participants