mirror of
https://code.forgejo.org/forgejo/runner.git
synced 2025-08-31 18:30:58 +00:00
<!--start release-notes-assistant--> <!--URL:https://code.forgejo.org/forgejo/runner--> - other - [PR](https://code.forgejo.org/forgejo/runner/pulls/844): <!--number 844 --><!--line 0 --><!--description Y2hvcmU6IHVzZSB0LkNvbnRleHQgZm9yIHRlc3RzLCBhY3RpdmF0ZSB1c2V0ZXN0aW5nIGZvciBsaW50ICsgYWRkIHQuVGVtcERpciBhbmQgdC5DaGRpciBbc2tpcCBjYXNjYWRlXQ==-->chore: use t.Context for tests, activate usetesting for lint + add t.TempDir and t.Chdir [skip cascade]<!--description--> <!--end release-notes-assistant--> Reviewed-on: https://code.forgejo.org/forgejo/runner/pulls/844 Reviewed-by: Gusted <gusted@noreply.code.forgejo.org> Co-authored-by: Earl Warren <contact@earl-warren.org> Co-committed-by: Earl Warren <contact@earl-warren.org>
76 lines
1.5 KiB
Go
76 lines
1.5 KiB
Go
package runner
|
|
|
|
import (
|
|
"archive/tar"
|
|
"bytes"
|
|
"io"
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
//nolint:gosec
|
|
func TestActionCache(t *testing.T) {
|
|
a := assert.New(t)
|
|
cache := &GoGitActionCache{
|
|
Path: os.TempDir(),
|
|
}
|
|
ctx := t.Context()
|
|
cacheDir := "nektos/act-test-actions"
|
|
repo := "https://code.forgejo.org/forgejo/act-test-actions"
|
|
refs := []struct {
|
|
Name string
|
|
CacheDir string
|
|
Repo string
|
|
Ref string
|
|
}{
|
|
{
|
|
Name: "Fetch Branch Name",
|
|
CacheDir: cacheDir,
|
|
Repo: repo,
|
|
Ref: "main",
|
|
},
|
|
{
|
|
Name: "Fetch Branch Name Absolutely",
|
|
CacheDir: cacheDir,
|
|
Repo: repo,
|
|
Ref: "refs/heads/main",
|
|
},
|
|
{
|
|
Name: "Fetch HEAD",
|
|
CacheDir: cacheDir,
|
|
Repo: repo,
|
|
Ref: "HEAD",
|
|
},
|
|
{
|
|
Name: "Fetch Sha",
|
|
CacheDir: cacheDir,
|
|
Repo: repo,
|
|
Ref: "de984ca37e4df4cb9fd9256435a3b82c4a2662b1",
|
|
},
|
|
}
|
|
for _, c := range refs {
|
|
t.Run(c.Name, func(t *testing.T) {
|
|
sha, err := cache.Fetch(ctx, c.CacheDir, c.Repo, c.Ref, "")
|
|
if !a.NoError(err) || !a.NotEmpty(sha) {
|
|
return
|
|
}
|
|
atar, err := cache.GetTarArchive(ctx, c.CacheDir, sha, "js")
|
|
if !a.NoError(err) || !a.NotEmpty(atar) {
|
|
return
|
|
}
|
|
mytar := tar.NewReader(atar)
|
|
th, err := mytar.Next()
|
|
if !a.NoError(err) || !a.NotEqual(0, th.Size) {
|
|
return
|
|
}
|
|
buf := &bytes.Buffer{}
|
|
// G110: Potential DoS vulnerability via decompression bomb (gosec)
|
|
_, err = io.Copy(buf, mytar)
|
|
a.NoError(err)
|
|
str := buf.String()
|
|
a.NotEmpty(str)
|
|
})
|
|
}
|
|
}
|