Skip to content

Commit

Permalink
Merge pull request #16 from jcchavezs/adds_no_fs_tag
Browse files Browse the repository at this point in the history
fix: fixes plugin runtime as no_fs_access build tag is included because http-wasm has no fs access.
  • Loading branch information
jcchavezs authored Apr 26, 2024
2 parents c6c3be1 + 8a862d8 commit 60311c8
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/nightly-coraza-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,6 @@ jobs:

- name: Run e2e tests
run: go run mage.go e2e

- name: Run FTW tests
run: go run mage.go ftw
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ require (
github.com/http-wasm/http-wasm-host-go v0.6.0
github.com/mccutchen/go-httpbin/v2 v2.13.4
github.com/stretchr/testify v1.8.4
github.com/tetratelabs/wabin v0.0.0-20230304001439-f6f874872834
github.com/tetratelabs/wazero v1.6.0
github.com/wasilibs/nottinygc v0.4.0
)
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/tetratelabs/wabin v0.0.0-20230304001439-f6f874872834 h1:ZF+QBjOI+tILZjBaFj3HgFonKXUcwgJ4djLb6i42S3Q=
github.com/tetratelabs/wabin v0.0.0-20230304001439-f6f874872834/go.mod h1:m9ymHTgNSEjuxvw8E7WWe4Pl4hZQHXONY8wE6dMLaRk=
github.com/tetratelabs/wazero v1.6.0 h1:z0H1iikCdP8t+q341xqepY4EWvHEw8Es7tlqiVzlP3g=
github.com/tetratelabs/wazero v1.6.0/go.mod h1:0U0G41+ochRKoPKCJlh0jMg1CHkyfK8kDqiirMmKY8A=
github.com/tidwall/gjson v1.17.1 h1:wlYEnwqAHgzmhNUFfw7Xalt2JzQvsMx2Se4PcoFCT/U=
Expand Down
33 changes: 30 additions & 3 deletions magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (

"github.com/magefile/mage/mg"
"github.com/magefile/mage/sh"
"github.com/tetratelabs/wabin/binary"
"github.com/tetratelabs/wabin/wasm"
)

var Default = Build
Expand Down Expand Up @@ -56,7 +58,32 @@ func Build() error {
return err
}

return sh.RunV("tinygo", "build", "-o", filepath.Join("build", "coraza-http-wasm.wasm"), "-opt=2", "-gc=custom", "-tags=custommalloc", "-scheduler=none", "--no-debug", "-target=wasi")
err := sh.RunV("tinygo", "build", "-o", filepath.Join("build", "coraza-http-wasm-raw.wasm"), "-opt=2", "-gc=custom", "-tags='custommalloc no_fs_access'", "-scheduler=none", "--no-debug", "-target=wasi")
if err != nil {
return err
}

return patchWasm(filepath.Join("build", "coraza-http-wasm-raw.wasm"), filepath.Join("build", "coraza-http-wasm.wasm"), 1050)
}

func patchWasm(inPath, outPath string, initialPages int) error {
raw, err := os.ReadFile(inPath)
if err != nil {
return err
}
mod, err := binary.DecodeModule(raw, wasm.CoreFeaturesV2)
if err != nil {
return err
}

mod.MemorySection.Min = uint32(initialPages)

out := binary.EncodeModule(mod)
if err = os.WriteFile(outPath, out, 0644); err != nil {
return err
}

return nil
}

// Test runs all unit tests.
Expand Down Expand Up @@ -85,7 +112,7 @@ func copy(src, dst string) error {
}
defer source.Close()

if err := os.Mkdir(filepath.Dir(dst), 0755); err != nil {
if err := os.MkdirAll(filepath.Dir(dst), 0755); err != nil {
return err
}

Expand All @@ -111,5 +138,5 @@ func FTW() error {
}
defer os.Remove(binDst)

return sh.RunV("go", "test", "./testing/coreruleset")
return sh.RunV("go", "test", "-count=1", "./testing/coreruleset")
}

0 comments on commit 60311c8

Please sign in to comment.