Skip to content

Commit

Permalink
integration: Add a new networking integration test suite
Browse files Browse the repository at this point in the history
This commit introduces a new integration test suite aimed at testing
networking features like inter-container communication, network
isolation, port mapping, etc... and how they interact with daemon-level
and network-level parameters.

So far, there's pretty much no tests making sure our networks are well
configured: 1. there're a few tests for port mapping, but they don't
cover all use cases ; 2. there're a few tests that check if a specific
iptables rule exist, but that doesn't prevent that specific iptables
rule to be wrong in the first place.

As we're planning to refactor how iptables rules are written, and change
some of them to fix known security issues, we need a way to test all
combinations of parameters. So far, this was done by hand, which is
particularly painful and time consuming. As such, this new test suite is
foundational to upcoming work.

Signed-off-by: Albin Kerouanton <albinker@gmail.com>
  • Loading branch information
akerouanton committed Nov 3, 2023
1 parent f44b085 commit 409ea70
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions integration/networking/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package networking

import (
"context"
"os"
"strings"
"testing"

"github.com/docker/docker/testutil"
"github.com/docker/docker/testutil/environment"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/codes"
)

var (
testEnv *environment.Execution
baseContext context.Context
)

func TestMain(m *testing.M) {
shutdown := testutil.ConfigureTracing()
ctx, span := otel.Tracer("").Start(context.Background(), "integration/networking.TestMain")
baseContext = ctx

var err error
testEnv, err = environment.New(ctx)
if err != nil {
span.SetStatus(codes.Error, err.Error())
span.End()
shutdown(ctx)
panic(err)
}

err = environment.EnsureFrozenImagesLinux(ctx, testEnv)
if err != nil {
span.SetStatus(codes.Error, err.Error())
span.End()
shutdown(ctx)
panic(err)
}

testEnv.Print()
code := m.Run()
if code != 0 {
span.SetStatus(codes.Error, "m.Run() returned non-zero exit code")
}
span.End()
shutdown(ctx)
os.Exit(code)
}

func setupTest(t *testing.T) context.Context {
ctx := testutil.StartSpan(baseContext, t)
environment.ProtectAll(ctx, t, testEnv)
t.Cleanup(func() { testEnv.Clean(ctx, t) })
return ctx
}

func sanitizeCtrName(name string) string {
r := strings.NewReplacer("/", "-", "=", "-")
return r.Replace(name)
}

0 comments on commit 409ea70

Please sign in to comment.