Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
353b319
test: add integration tracing
alegrey91 Aug 29, 2024
096bd58
test: fix command in pipeline
alegrey91 Aug 29, 2024
7b6abcd
test: check for errors in test files
alegrey91 Aug 29, 2024
012b194
test: add integration test directory
alegrey91 Aug 29, 2024
76e6bfa
test: fix pipeline command
alegrey91 Aug 29, 2024
789ea55
fix pipeline command
alegrey91 Sep 6, 2024
1496fbc
fix pipeline command
alegrey91 Sep 6, 2024
a607552
fix pipeline command
alegrey91 Sep 6, 2024
b5b824c
add flag.commandline before parse
alegrey91 Sep 6, 2024
df02bf1
add flag.commandline before parse
alegrey91 Sep 6, 2024
6e23d1c
add flag.commandline before parse
alegrey91 Sep 6, 2024
df6b894
remove tracing flag
alegrey91 Sep 6, 2024
cac5f80
remove tracing flag
alegrey91 Sep 6, 2024
5cbe235
remove tracing flag
alegrey91 Sep 6, 2024
3847030
refactor code
alegrey91 Sep 6, 2024
1f71884
refactor code
alegrey91 Sep 6, 2024
fd55dad
refactor code
alegrey91 Sep 6, 2024
3bdbc7b
increase wait time before check for forwards
alegrey91 Sep 6, 2024
adfb694
increase wait time before check for forwards
alegrey91 Sep 6, 2024
8cf2c3d
fix build command
alegrey91 Sep 6, 2024
537f51e
create other tests
alegrey91 Sep 6, 2024
b9a9fa1
remove negation to exec command in trace tests
alegrey91 Sep 6, 2024
c3f3dc2
remove negation to exec command in trace tests
alegrey91 Sep 6, 2024
8cb3487
fix fwdctl generate cmd
alegrey91 Sep 6, 2024
d70b437
fix generate command
alegrey91 Sep 6, 2024
f603422
fix generate command
alegrey91 Sep 6, 2024
4f2ee4b
fix generate commands
alegrey91 Sep 6, 2024
975ff6f
fix version tests
alegrey91 Sep 6, 2024
6fffcdd
fix version tests
alegrey91 Sep 6, 2024
924a4df
fix version tests
alegrey91 Sep 6, 2024
43a1409
keep directory for next step
alegrey91 Sep 6, 2024
311b1d5
check directory
alegrey91 Sep 6, 2024
96a66d3
check directory
alegrey91 Sep 6, 2024
d8e2004
copy artifact outside
alegrey91 Sep 6, 2024
5f39de6
copy artifact outside
alegrey91 Sep 6, 2024
8acb43d
copy artifact outside
alegrey91 Sep 6, 2024
905b5b8
copy artifact outside
alegrey91 Sep 7, 2024
2633bc2
copy artifact outside
alegrey91 Sep 7, 2024
572f907
copy artifact outside
alegrey91 Sep 7, 2024
d134284
copy artifact outside
alegrey91 Sep 7, 2024
f3258cd
copy artifact outside
alegrey91 Sep 7, 2024
d1dad58
copy artifact outside
alegrey91 Sep 7, 2024
5ea3153
connect pipelines
alegrey91 Sep 7, 2024
6446550
remove unused commands
alegrey91 Sep 7, 2024
74dcd71
set work dir
alegrey91 Sep 7, 2024
a420a07
set work dir
alegrey91 Sep 7, 2024
7b37283
set work dir
alegrey91 Sep 7, 2024
1c574d2
add readme
alegrey91 Sep 7, 2024
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
84 changes: 73 additions & 11 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,37 +64,37 @@ jobs:
-exec sudo \
-cover \
-v ./... \
-run TestFwdctl/apply \
-run TestFwdctl/apply$ \
-args -test.gocoverdir=/tmp/integration/
go test \
-exec sudo \
-cover \
-v ./... \
-run TestFwdctl/create \
-run TestFwdctl/create$ \
-args -test.gocoverdir=/tmp/integration/
go test \
-exec sudo \
-cover \
-v ./... \
-run TestFwdctl/delete \
-run TestFwdctl/delete$ \
-args -test.gocoverdir=/tmp/integration/
go test \
-exec sudo \
-cover \
-v ./... \
-run TestFwdctl/list \
-run TestFwdctl/list$ \
-args -test.gocoverdir=/tmp/integration/
go test \
-exec sudo \
-cover \
-v ./... \
-run TestFwdctl/daemon \
-run TestFwdctl/daemon$ \
-args -test.gocoverdir=/tmp/integration/
go test \
-exec sudo \
-cover \
-v ./... \
-run TestFwdctl/version \
-run TestFwdctl/version$ \
-args -test.gocoverdir=/tmp/integration/

- name: Upload cover profiles
Expand Down Expand Up @@ -188,10 +188,70 @@ jobs:
name: unit-test-syscalls
path: unit-test-syscalls

trace-integration-test:

runs-on: ubuntu-latest
needs: [integration-test]
steps:
- uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # ratchet:actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # ratchet:actions/setup-go@v4
with:
go-version: '1.22'

- name: Install iptables
run: |
sudo apt update
sudo apt install -y iptables

- name: Build coverage-instrumented binary
run: |
make build && sudo make -B install

- name: Install harpoon
run: |
curl -s https://raw.githubusercontent.com/alegrey91/harpoon/main/install | sudo sh

- name: Run integration test
run: |
mkdir -p integration-test-syscalls
go test \
-exec sudo \
-v ./... \
-run TestFwdctl/apply_trace
go test \
-exec sudo \
-v ./... \
-run TestFwdctl/create_trace
go test \
-exec sudo \
-v ./... \
-run TestFwdctl/delete_trace
go test \
-exec sudo \
-v ./... \
-run TestFwdctl/generate_trace
go test \
-exec sudo \
-v ./... \
-run TestFwdctl/list_trace
go test \
-exec sudo \
-v ./... \
-run TestFwdctl/version_trace
shell: bash

- name: Upload cover profiles
uses: actions/upload-artifact@v3
with:
name: integration-test-syscalls
path: integration-test-syscalls

build-seccomp-profile:

runs-on: ubuntu-latest
needs: [trace-unit-test]
needs: [trace-unit-test, trace-integration-test]
steps:
- uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # ratchet:actions/checkout@v3

Expand All @@ -200,14 +260,15 @@ jobs:
name: unit-test-syscalls
path: unit-test-syscalls

# - uses: actions/download-artifact@v3
# with:
# name: integration-test
# path: ./integration-test
- uses: actions/download-artifact@v3
with:
name: integration-test-syscalls
path: ./integration-test-syscalls

- name: list files
run: |
ls -lah ./unit-test-syscalls
ls -lah ./integration-test-syscalls

- name: Set up Go
uses: actions/setup-go@v4
Expand All @@ -222,6 +283,7 @@ jobs:
run: |
mkdir -p harpoon
mv unit-test-syscalls/* harpoon/
mv integration-test-syscalls/* harpoon/

- name: Build Seccomp Profile
run: |
Expand Down
10 changes: 5 additions & 5 deletions cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ limitations under the License.
package cmd

import (
"fmt"

"github.com/spf13/cobra"
)

Expand All @@ -28,14 +30,12 @@ var generateCmd = &cobra.Command{
Short: "generates templated files",
Long: `generates templated file for fwdtcl
`,
Run: func(cmd *cobra.Command, args []string) {
_ = cmd.Help()
RunE: func(cmd *cobra.Command, args []string) error {
fmt.Println(cmd.Help())
return nil
},
}

func init() {
rootCmd.AddCommand(generateCmd)

generateCmd.PersistentFlags().StringVarP(&outputFile, "output-path", "O", "", "output path")
_ = generateCmd.MarkPersistentFlagRequired("output-path")
}
3 changes: 3 additions & 0 deletions cmd/generate_rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,7 @@ var generateRulesCmd = &cobra.Command{

func init() {
generateCmd.AddCommand(generateRulesCmd)

generateRulesCmd.PersistentFlags().StringVarP(&outputFile, "output-path", "O", "", "output path")
_ = generateRulesCmd.MarkPersistentFlagRequired("output-path")
}
7 changes: 5 additions & 2 deletions cmd/generate_systemd.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ var generateSystemdCmd = &cobra.Command{
if err != nil {
return fmt.Errorf("cannot create systemd service: %v", err)
}
if err = template.GenerateTemplate(systemd, outputFile);err != nil {

if err = template.GenerateTemplate(systemd, outputFile); err != nil {
return fmt.Errorf("generating templated file: %v", err)
}
return nil
Expand All @@ -52,4 +52,7 @@ func init() {
generateSystemdCmd.Flags().StringVarP(&installationPath, "installation-path", "p", "/usr/local/bin", "fwdctl installation path")
generateSystemdCmd.Flags().StringVarP(&c.RulesFile, "file", "f", "rules.yml", "rules file path")
generateSystemdCmd.Flags().StringVarP(&serviceType, "type", "t", "oneshot", "systemd service type [oneshot, fork]")

generateSystemdCmd.PersistentFlags().StringVarP(&outputFile, "output-path", "O", "", "output path")
_ = generateSystemdCmd.MarkPersistentFlagRequired("output-path")
}
3 changes: 1 addition & 2 deletions main_test.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package main

import (
"flag"
"testing"

"github.com/rogpeppe/go-internal/testscript"
)

func TestFwdctl(t *testing.T) {
flag.Parse()
testscript.Run(t, testscript.Params{
TestWork: true,
Dir: "tests",
Cmds: customCommands(),
RequireExplicitExec: true,
Expand Down
41 changes: 41 additions & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Integration Tests

This directory is dedicated to host integration tests written with [`testscript`](https://pkg.go.dev/github.com/rogpeppe/go-internal/testscript).

## Converting from test to trace file

As you can see, for each command we have a couple of files (eg. `apply.txtar`, `apply_trace.txtar`).

The `<command>.txtar` file is used for testing purposes and is run at the beginning of the pipeline to ensure the binary is behave like we expect.

The `<command>_trace.txtar`, on the other side, is used for tracing purposes. This means that we re-run the same commands of the previous file, tracing them with [`harpoon`](https://github.com/alegrey91/harpoon) under the hood.

The file content are quite similar, there are just few differences to follow:

* Each `exec` of the command under test (eg. `fwdctl apply`) have to be replaced with `exec_cmd`.

`exec_cmd` is a custom testscript function to trace the command using `harpoon`.

* If the `exec` of the command under test had a negation (`!`), this should not be added in the command used with `exec_cmd`.

This because in this case we don't care about the result of `harpoon` that will execute the real command.

Here's an example:

```txt
# command.txtar

# normal execution of command
exec command list -a
# -x flag doesn't exists, so this should handle the error
! exec command list -x
```

Should be converted into this:

```txt
# command_trace.txtar

exec_cmd command list -a
exec_cmd command list -x
```
Loading
Loading