Skip to content

Commit 9f591e2

Browse files
committed
Merge branch 'main' into lunny/uniform-temp-dir
2 parents d6c9ed3 + 321cbcb commit 9f591e2

File tree

4 files changed

+142
-86
lines changed

4 files changed

+142
-86
lines changed

routers/common/actions.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func DownloadActionsRunJobLogsWithIndex(ctx *context.Base, ctxRepo *repo_model.R
2222
if err = runJobs.LoadRepos(ctx); err != nil {
2323
return fmt.Errorf("LoadRepos: %w", err)
2424
}
25-
if 0 < jobIndex || jobIndex >= int64(len(runJobs)) {
25+
if jobIndex < 0 || jobIndex >= int64(len(runJobs)) {
2626
return util.NewNotExistErrorf("job index is out of range: %d", jobIndex)
2727
}
2828
return DownloadActionsRunJobLogs(ctx, ctxRepo, runJobs[jobIndex])

routers/web/githttp.go

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,12 @@
44
package web
55

66
import (
7-
"net/http"
8-
9-
"code.gitea.io/gitea/modules/setting"
107
"code.gitea.io/gitea/modules/web"
118
"code.gitea.io/gitea/routers/web/repo"
129
"code.gitea.io/gitea/services/context"
1310
)
1411

1512
func addOwnerRepoGitHTTPRouters(m *web.Router) {
16-
reqGitSignIn := func(ctx *context.Context) {
17-
if !setting.Service.RequireSignInView {
18-
return
19-
}
20-
// rely on the results of Contexter
21-
if !ctx.IsSigned {
22-
// TODO: support digit auth - which would be Authorization header with digit
23-
ctx.Resp.Header().Set("WWW-Authenticate", `Basic realm="Gitea"`)
24-
ctx.HTTPError(http.StatusUnauthorized)
25-
}
26-
}
2713
m.Group("/{username}/{reponame}", func() {
2814
m.Methods("POST,OPTIONS", "/git-upload-pack", repo.ServiceUploadPack)
2915
m.Methods("POST,OPTIONS", "/git-receive-pack", repo.ServiceReceivePack)
@@ -36,5 +22,5 @@ func addOwnerRepoGitHTTPRouters(m *web.Router) {
3622
m.Methods("GET,OPTIONS", "/objects/{head:[0-9a-f]{2}}/{hash:[0-9a-f]{38,62}}", repo.GetLooseObject)
3723
m.Methods("GET,OPTIONS", "/objects/pack/pack-{file:[0-9a-f]{40,64}}.pack", repo.GetPackFile)
3824
m.Methods("GET,OPTIONS", "/objects/pack/pack-{file:[0-9a-f]{40,64}}.idx", repo.GetIdxFile)
39-
}, optSignInIgnoreCsrf, reqGitSignIn, repo.HTTPGitEnabledHandler, repo.CorsHandler(), context.UserAssignmentWeb())
25+
}, optSignInIgnoreCsrf, repo.HTTPGitEnabledHandler, repo.CorsHandler(), context.UserAssignmentWeb())
4026
}

tests/integration/actions_log_test.go

Lines changed: 116 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func TestDownloadTaskLogs(t *testing.T) {
3131
testCases := []struct {
3232
treePath string
3333
fileContent string
34-
outcome *mockTaskOutcome
34+
outcome []*mockTaskOutcome
3535
zstdEnabled bool
3636
}{
3737
{
@@ -46,21 +46,44 @@ jobs:
4646
runs-on: ubuntu-latest
4747
steps:
4848
- run: echo job1 with zstd enabled
49+
job2:
50+
runs-on: ubuntu-latest
51+
steps:
52+
- run: echo job2 with zstd enabled
4953
`,
50-
outcome: &mockTaskOutcome{
51-
result: runnerv1.Result_RESULT_SUCCESS,
52-
logRows: []*runnerv1.LogRow{
53-
{
54-
Time: timestamppb.New(now.Add(1 * time.Second)),
55-
Content: " \U0001F433 docker create image",
56-
},
57-
{
58-
Time: timestamppb.New(now.Add(2 * time.Second)),
59-
Content: "job1 zstd enabled",
54+
outcome: []*mockTaskOutcome{
55+
{
56+
result: runnerv1.Result_RESULT_SUCCESS,
57+
logRows: []*runnerv1.LogRow{
58+
{
59+
Time: timestamppb.New(now.Add(1 * time.Second)),
60+
Content: " \U0001F433 docker create image",
61+
},
62+
{
63+
Time: timestamppb.New(now.Add(2 * time.Second)),
64+
Content: "job1 zstd enabled",
65+
},
66+
{
67+
Time: timestamppb.New(now.Add(3 * time.Second)),
68+
Content: "\U0001F3C1 Job succeeded",
69+
},
6070
},
61-
{
62-
Time: timestamppb.New(now.Add(3 * time.Second)),
63-
Content: "\U0001F3C1 Job succeeded",
71+
},
72+
{
73+
result: runnerv1.Result_RESULT_SUCCESS,
74+
logRows: []*runnerv1.LogRow{
75+
{
76+
Time: timestamppb.New(now.Add(1 * time.Second)),
77+
Content: " \U0001F433 docker create image",
78+
},
79+
{
80+
Time: timestamppb.New(now.Add(2 * time.Second)),
81+
Content: "job2 zstd enabled",
82+
},
83+
{
84+
Time: timestamppb.New(now.Add(3 * time.Second)),
85+
Content: "\U0001F3C1 Job succeeded",
86+
},
6487
},
6588
},
6689
},
@@ -78,21 +101,44 @@ jobs:
78101
runs-on: ubuntu-latest
79102
steps:
80103
- run: echo job1 with zstd disabled
104+
job2:
105+
runs-on: ubuntu-latest
106+
steps:
107+
- run: echo job2 with zstd disabled
81108
`,
82-
outcome: &mockTaskOutcome{
83-
result: runnerv1.Result_RESULT_SUCCESS,
84-
logRows: []*runnerv1.LogRow{
85-
{
86-
Time: timestamppb.New(now.Add(4 * time.Second)),
87-
Content: " \U0001F433 docker create image",
109+
outcome: []*mockTaskOutcome{
110+
{
111+
result: runnerv1.Result_RESULT_SUCCESS,
112+
logRows: []*runnerv1.LogRow{
113+
{
114+
Time: timestamppb.New(now.Add(4 * time.Second)),
115+
Content: " \U0001F433 docker create image",
116+
},
117+
{
118+
Time: timestamppb.New(now.Add(5 * time.Second)),
119+
Content: "job1 zstd disabled",
120+
},
121+
{
122+
Time: timestamppb.New(now.Add(6 * time.Second)),
123+
Content: "\U0001F3C1 Job succeeded",
124+
},
88125
},
89-
{
90-
Time: timestamppb.New(now.Add(5 * time.Second)),
91-
Content: "job1 zstd disabled",
92-
},
93-
{
94-
Time: timestamppb.New(now.Add(6 * time.Second)),
95-
Content: "\U0001F3C1 Job succeeded",
126+
},
127+
{
128+
result: runnerv1.Result_RESULT_SUCCESS,
129+
logRows: []*runnerv1.LogRow{
130+
{
131+
Time: timestamppb.New(now.Add(4 * time.Second)),
132+
Content: " \U0001F433 docker create image",
133+
},
134+
{
135+
Time: timestamppb.New(now.Add(5 * time.Second)),
136+
Content: "job2 zstd disabled",
137+
},
138+
{
139+
Time: timestamppb.New(now.Add(6 * time.Second)),
140+
Content: "\U0001F3C1 Job succeeded",
141+
},
96142
},
97143
},
98144
},
@@ -124,54 +170,55 @@ jobs:
124170
opts := getWorkflowCreateFileOptions(user2, repo.DefaultBranch, fmt.Sprintf("create %s", tc.treePath), tc.fileContent)
125171
createWorkflowFile(t, token, user2.Name, repo.Name, tc.treePath, opts)
126172

127-
// fetch and execute task
128-
task := runner.fetchTask(t)
129-
runner.execTask(t, task, tc.outcome)
173+
// fetch and execute tasks
174+
for jobIndex, outcome := range tc.outcome {
175+
task := runner.fetchTask(t)
176+
runner.execTask(t, task, outcome)
130177

131-
// check whether the log file exists
132-
logFileName := fmt.Sprintf("%s/%02x/%d.log", repo.FullName(), task.Id%256, task.Id)
133-
if setting.Actions.LogCompression.IsZstd() {
134-
logFileName += ".zst"
135-
}
136-
_, err := storage.Actions.Stat(logFileName)
137-
assert.NoError(t, err)
178+
// check whether the log file exists
179+
logFileName := fmt.Sprintf("%s/%02x/%d.log", repo.FullName(), task.Id%256, task.Id)
180+
if setting.Actions.LogCompression.IsZstd() {
181+
logFileName += ".zst"
182+
}
183+
_, err := storage.Actions.Stat(logFileName)
184+
assert.NoError(t, err)
138185

139-
// download task logs and check content
140-
runIndex := task.Context.GetFields()["run_number"].GetStringValue()
141-
req := NewRequest(t, "GET", fmt.Sprintf("/%s/%s/actions/runs/%s/jobs/0/logs", user2.Name, repo.Name, runIndex)).
142-
AddTokenAuth(token)
143-
resp := MakeRequest(t, req, http.StatusOK)
144-
logTextLines := strings.Split(strings.TrimSpace(resp.Body.String()), "\n")
145-
assert.Len(t, logTextLines, len(tc.outcome.logRows))
146-
for idx, lr := range tc.outcome.logRows {
147-
assert.Equal(
148-
t,
149-
fmt.Sprintf("%s %s", lr.Time.AsTime().Format("2006-01-02T15:04:05.0000000Z07:00"), lr.Content),
150-
logTextLines[idx],
151-
)
152-
}
186+
// download task logs and check content
187+
runIndex := task.Context.GetFields()["run_number"].GetStringValue()
188+
req := NewRequest(t, "GET", fmt.Sprintf("/%s/%s/actions/runs/%s/jobs/%d/logs", user2.Name, repo.Name, runIndex, jobIndex)).
189+
AddTokenAuth(token)
190+
resp := MakeRequest(t, req, http.StatusOK)
191+
logTextLines := strings.Split(strings.TrimSpace(resp.Body.String()), "\n")
192+
assert.Len(t, logTextLines, len(outcome.logRows))
193+
for idx, lr := range outcome.logRows {
194+
assert.Equal(
195+
t,
196+
fmt.Sprintf("%s %s", lr.Time.AsTime().Format("2006-01-02T15:04:05.0000000Z07:00"), lr.Content),
197+
logTextLines[idx],
198+
)
199+
}
153200

154-
runID, _ := strconv.ParseInt(task.Context.GetFields()["run_id"].GetStringValue(), 10, 64)
201+
runID, _ := strconv.ParseInt(task.Context.GetFields()["run_id"].GetStringValue(), 10, 64)
155202

156-
jobs, err := actions_model.GetRunJobsByRunID(t.Context(), runID)
157-
assert.NoError(t, err)
158-
assert.Len(t, jobs, 1)
159-
jobID := jobs[0].ID
203+
jobs, err := actions_model.GetRunJobsByRunID(t.Context(), runID)
204+
assert.NoError(t, err)
205+
assert.Len(t, jobs, len(tc.outcome))
206+
jobID := jobs[jobIndex].ID
160207

161-
// download task logs from API and check content
162-
req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%s/actions/jobs/%d/logs", user2.Name, repo.Name, jobID)).
163-
AddTokenAuth(token)
164-
resp = MakeRequest(t, req, http.StatusOK)
165-
logTextLines = strings.Split(strings.TrimSpace(resp.Body.String()), "\n")
166-
assert.Len(t, logTextLines, len(tc.outcome.logRows))
167-
for idx, lr := range tc.outcome.logRows {
168-
assert.Equal(
169-
t,
170-
fmt.Sprintf("%s %s", lr.Time.AsTime().Format("2006-01-02T15:04:05.0000000Z07:00"), lr.Content),
171-
logTextLines[idx],
172-
)
208+
// download task logs from API and check content
209+
req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%s/actions/jobs/%d/logs", user2.Name, repo.Name, jobID)).
210+
AddTokenAuth(token)
211+
resp = MakeRequest(t, req, http.StatusOK)
212+
logTextLines = strings.Split(strings.TrimSpace(resp.Body.String()), "\n")
213+
assert.Len(t, logTextLines, len(outcome.logRows))
214+
for idx, lr := range outcome.logRows {
215+
assert.Equal(
216+
t,
217+
fmt.Sprintf("%s %s", lr.Time.AsTime().Format("2006-01-02T15:04:05.0000000Z07:00"), lr.Content),
218+
logTextLines[idx],
219+
)
220+
}
173221
}
174-
175222
resetFunc()
176223
})
177224
}

tests/integration/git_smart_http_test.go

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,19 @@ import (
99
"net/url"
1010
"testing"
1111

12+
"code.gitea.io/gitea/modules/setting"
13+
"code.gitea.io/gitea/modules/test"
1214
"code.gitea.io/gitea/modules/util"
1315

1416
"github.com/stretchr/testify/assert"
1517
"github.com/stretchr/testify/require"
1618
)
1719

1820
func TestGitSmartHTTP(t *testing.T) {
19-
onGiteaRun(t, testGitSmartHTTP)
21+
onGiteaRun(t, func(t *testing.T, u *url.URL) {
22+
testGitSmartHTTP(t, u)
23+
testRenamedRepoRedirect(t)
24+
})
2025
}
2126

2227
func testGitSmartHTTP(t *testing.T, u *url.URL) {
@@ -73,3 +78,21 @@ func testGitSmartHTTP(t *testing.T, u *url.URL) {
7378
})
7479
}
7580
}
81+
82+
func testRenamedRepoRedirect(t *testing.T) {
83+
defer test.MockVariableValue(&setting.Service.RequireSignInView, true)()
84+
85+
// git client requires to get a 301 redirect response before 401 unauthorized response
86+
req := NewRequest(t, "GET", "/user2/oldrepo1/info/refs")
87+
resp := MakeRequest(t, req, http.StatusMovedPermanently)
88+
redirect := resp.Header().Get("Location")
89+
assert.Equal(t, "/user2/repo1/info/refs", redirect)
90+
91+
req = NewRequest(t, "GET", redirect)
92+
resp = MakeRequest(t, req, http.StatusUnauthorized)
93+
assert.Equal(t, "Unauthorized\n", resp.Body.String())
94+
95+
req = NewRequest(t, "GET", redirect).AddBasicAuth("user2")
96+
resp = MakeRequest(t, req, http.StatusOK)
97+
assert.Contains(t, resp.Body.String(), "65f1bf27bc3bf70f64657658635e66094edbcb4d\trefs/tags/v1.1")
98+
}

0 commit comments

Comments
 (0)