Skip to content

Commit c9f6e9c

Browse files
committed
Prevent create orgs
1 parent 3fc4f64 commit c9f6e9c

File tree

2 files changed

+80
-11
lines changed

2 files changed

+80
-11
lines changed

models/user/user_system.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,16 @@ func IsGiteaActionsUserName(name string) bool {
4848
// NewActionsUser creates and returns a fake user for running the actions.
4949
func NewActionsUser() *User {
5050
return &User{
51-
ID: ActionsUserID,
52-
Name: ActionsUserName,
53-
LowerName: ActionsUserName,
54-
IsActive: true,
55-
FullName: "Gitea Actions",
56-
Email: ActionsUserEmail,
57-
KeepEmailPrivate: true,
58-
LoginName: ActionsUserName,
59-
Type: UserTypeBot,
60-
AllowCreateOrganization: true,
61-
Visibility: structs.VisibleTypePublic,
51+
ID: ActionsUserID,
52+
Name: ActionsUserName,
53+
LowerName: ActionsUserName,
54+
IsActive: true,
55+
FullName: "Gitea Actions",
56+
Email: ActionsUserEmail,
57+
KeepEmailPrivate: true,
58+
LoginName: ActionsUserName,
59+
Type: UserTypeBot,
60+
Visibility: structs.VisibleTypePublic,
6261
}
6362
}
6463

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package integration
2+
3+
import (
4+
"encoding/base64"
5+
"net/url"
6+
"testing"
7+
8+
actions_model "code.gitea.io/gitea/models/actions"
9+
"code.gitea.io/gitea/models/unittest"
10+
"code.gitea.io/gitea/modules/structs"
11+
"github.com/stretchr/testify/require"
12+
)
13+
14+
func TestActionsJobTokenAccess(t *testing.T) {
15+
onGiteaRun(t, func(t *testing.T, u *url.URL) {
16+
t.Run("Write Access", testActionsJobTokenAccess(u, false))
17+
t.Run("Read Access", testActionsJobTokenAccess(u, true))
18+
})
19+
}
20+
21+
func testActionsJobTokenAccess(u *url.URL, isFork bool) func(t *testing.T) {
22+
return func(t *testing.T) {
23+
task := unittest.AssertExistsAndLoadBean(t, &actions_model.ActionTask{ID: 47})
24+
require.NoError(t, task.GenerateToken())
25+
task.Status = actions_model.StatusRunning
26+
task.IsForkPullRequest = isFork
27+
err := actions_model.UpdateTask(t.Context(), task, "token_hash", "token_salt", "token_last_eight", "status", "is_fork_pull_request")
28+
require.NoError(t, err)
29+
session := emptyTestSession(t)
30+
context := APITestContext{
31+
Session: session,
32+
Token: task.Token,
33+
Username: "user5",
34+
Reponame: "repo4",
35+
}
36+
dstPath := t.TempDir()
37+
38+
u.Path = context.GitPath()
39+
u.User = url.UserPassword("gitea-actions", task.Token)
40+
41+
t.Run("Git Clone", doGitClone(dstPath, u))
42+
43+
t.Run("API Get Repository", doAPIGetRepository(context, func(t *testing.T, r structs.Repository) {
44+
require.EqualValues(t, "repo4", r.Name)
45+
require.EqualValues(t, "user5", r.Owner.UserName)
46+
}))
47+
48+
if isFork {
49+
context.ExpectedCode = 403
50+
}
51+
t.Run("API Create File", doAPICreateFile(context, "test.txt", &structs.CreateFileOptions{
52+
FileOptions: structs.FileOptions{
53+
NewBranchName: "new-branch",
54+
Message: "Create File",
55+
},
56+
ContentBase64: base64.StdEncoding.EncodeToString([]byte(`This is a test file created using job token.`)),
57+
}))
58+
59+
context.ExpectedCode = 500
60+
t.Run("Fail to Create Repository", doAPICreateRepository(context, true))
61+
62+
context.ExpectedCode = 403
63+
t.Run("Fail to Delete Repository", doAPIDeleteRepository(context))
64+
65+
t.Run("Fail to Create Organization", doAPICreateOrganization(context, &structs.CreateOrgOption{
66+
UserName: "actions",
67+
FullName: "Gitea Actions",
68+
}))
69+
}
70+
}

0 commit comments

Comments
 (0)