-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
allow the actions user to login via the jwt token #32527
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
91b01ea
allow the actions user to login via the jwt token
bohde 6e876cc
incorporate logic into userIDFromToken instead of a standalone function
bohde f5c0b53
add tests for new functionality in auth/oauth.go
bohde 77c7056
lint
bohde 6aafb51
rename CheckTaskID to CheckTaskIsRunning
bohde 68289a2
Merge branch 'main' into rb/fix-actions-jwt
wxiaoguang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,55 @@ | ||
| // Copyright 2024 The Gitea Authors. All rights reserved. | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| package auth | ||
|
|
||
| import ( | ||
| "context" | ||
| "testing" | ||
|
|
||
| "code.gitea.io/gitea/models/unittest" | ||
| user_model "code.gitea.io/gitea/models/user" | ||
| "code.gitea.io/gitea/modules/web/middleware" | ||
| "code.gitea.io/gitea/services/actions" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| func TestUserIDFromToken(t *testing.T) { | ||
| assert.NoError(t, unittest.PrepareTestDatabase()) | ||
|
|
||
| t.Run("Actions JWT", func(t *testing.T) { | ||
| const RunningTaskID = 47 | ||
| token, err := actions.CreateAuthorizationToken(RunningTaskID, 1, 2) | ||
| assert.NoError(t, err) | ||
|
|
||
| ds := make(middleware.ContextData) | ||
|
|
||
| o := OAuth2{} | ||
| uid := o.userIDFromToken(context.Background(), token, ds) | ||
| assert.Equal(t, int64(user_model.ActionsUserID), uid) | ||
| assert.Equal(t, ds["IsActionsToken"], true) | ||
| assert.Equal(t, ds["ActionsTaskID"], int64(RunningTaskID)) | ||
| }) | ||
| } | ||
|
|
||
| func TestCheckTaskID(t *testing.T) { | ||
| assert.NoError(t, unittest.PrepareTestDatabase()) | ||
|
|
||
| cases := map[string]struct { | ||
| TaskID int64 | ||
| Expected bool | ||
| }{ | ||
| "Running": {TaskID: 47, Expected: true}, | ||
| "Missing": {TaskID: 1, Expected: false}, | ||
| "Cancelled": {TaskID: 46, Expected: false}, | ||
| } | ||
|
|
||
| for name := range cases { | ||
| c := cases[name] | ||
| t.Run(name, func(t *testing.T) { | ||
| actual := CheckTaskID(context.Background(), c.TaskID) | ||
| assert.Equal(t, c.Expected, actual) | ||
| }) | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.