Skip to content

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 6 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
rename CheckTaskID to CheckTaskIsRunning
  • Loading branch information
bohde committed Nov 20, 2024
commit 6aafb51f289de2660484165cdfa100528d5d2852
6 changes: 3 additions & 3 deletions services/auth/oauth2.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ func CheckOAuthAccessToken(ctx context.Context, accessToken string) int64 {
return grant.UserID
}

// CheckTaskID verifies that the TaskID corresponds to a running task
func CheckTaskID(ctx context.Context, taskID int64) bool {
// CheckTaskIsRunning verifies that the TaskID corresponds to a running task
func CheckTaskIsRunning(ctx context.Context, taskID int64) bool {
// Verify the task exists
task, err := actions_model.GetTaskByID(ctx, taskID)
if err != nil {
Expand Down Expand Up @@ -112,7 +112,7 @@ func (o *OAuth2) userIDFromToken(ctx context.Context, tokenSHA string, store Dat
if strings.Contains(tokenSHA, ".") {
// First attempt to decode an actions JWT, returning the actions user
if taskID, err := actions.TokenToTaskID(tokenSHA); err == nil {
if CheckTaskID(ctx, taskID) {
if CheckTaskIsRunning(ctx, taskID) {
store.GetData()["IsActionsToken"] = true
store.GetData()["ActionsTaskID"] = taskID
return user_model.ActionsUserID
Expand Down
4 changes: 2 additions & 2 deletions services/auth/oauth2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestUserIDFromToken(t *testing.T) {
})
}

func TestCheckTaskID(t *testing.T) {
func TestCheckTaskIsRunning(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())

cases := map[string]struct {
Expand All @@ -48,7 +48,7 @@ func TestCheckTaskID(t *testing.T) {
for name := range cases {
c := cases[name]
t.Run(name, func(t *testing.T) {
actual := CheckTaskID(context.Background(), c.TaskID)
actual := CheckTaskIsRunning(context.Background(), c.TaskID)
assert.Equal(t, c.Expected, actual)
})
}
Expand Down
Loading