-
Notifications
You must be signed in to change notification settings - Fork 0
e2e tests #60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
e2e tests #60
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,176 @@ | ||
package e2e_tests | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"fmt" | ||
"os" | ||
"os/exec" | ||
"path/filepath" | ||
"strings" | ||
"testing" | ||
"time" | ||
|
||
"github.com/coder/boundary/util" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
// findProjectRoot finds the project root by looking for go.mod file | ||
func findProjectRoot(t *testing.T) string { | ||
cwd, err := os.Getwd() | ||
require.NoError(t, err, "Failed to get current working directory") | ||
|
||
// Start from current directory and walk up until we find go.mod | ||
dir := cwd | ||
for { | ||
goModPath := filepath.Join(dir, "go.mod") | ||
if _, err := os.Stat(goModPath); err == nil { | ||
return dir | ||
} | ||
|
||
parent := filepath.Dir(dir) | ||
if parent == dir { | ||
// Reached filesystem root | ||
t.Fatalf("Could not find go.mod file starting from %s", cwd) | ||
} | ||
dir = parent | ||
} | ||
} | ||
|
||
// getNamespaceName gets the single network namespace name | ||
// Fails if there are 0 or multiple namespaces | ||
func getNamespaceName(t *testing.T) string { | ||
cmd := exec.Command("ip", "netns", "list") | ||
output, err := cmd.Output() | ||
require.NoError(t, err, "Failed to list network namespaces") | ||
|
||
lines := strings.Split(string(output), "\n") | ||
var namespaces []string | ||
|
||
for _, line := range lines { | ||
line = strings.TrimSpace(line) | ||
if line != "" { | ||
// Extract namespace name (first field) | ||
parts := strings.Fields(line) | ||
if len(parts) > 0 { | ||
namespaces = append(namespaces, parts[0]) | ||
} | ||
} | ||
} | ||
|
||
require.Len(t, namespaces, 1, "Expected exactly one network namespace, found %d: %v", len(namespaces), namespaces) | ||
return namespaces[0] | ||
} | ||
|
||
func TestBoundaryIntegration(t *testing.T) { | ||
// Find project root by looking for go.mod file | ||
projectRoot := findProjectRoot(t) | ||
|
||
// Build the boundary binary | ||
buildCmd := exec.Command("go", "build", "-o", "/tmp/boundary-test", "./cmd/...") | ||
buildCmd.Dir = projectRoot | ||
err := buildCmd.Run() | ||
require.NoError(t, err, "Failed to build boundary binary") | ||
|
||
// Create context for boundary process | ||
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second) | ||
defer cancel() | ||
|
||
// Start boundary process with sudo | ||
boundaryCmd := exec.CommandContext(ctx, "/tmp/boundary-test", | ||
"--allow", "dev.coder.com", | ||
"--allow", "jsonplaceholder.typicode.com", | ||
"--log-level", "debug", | ||
"--", "bash", "-c", "sleep 10 && echo 'Test completed'") | ||
|
||
// Suppress output to prevent terminal corruption | ||
boundaryCmd.Stdout = os.Stdout // Let it go to /dev/null | ||
boundaryCmd.Stderr = os.Stderr | ||
|
||
// Start the process | ||
err = boundaryCmd.Start() | ||
require.NoError(t, err, "Failed to start boundary process") | ||
|
||
// Give boundary time to start | ||
time.Sleep(2 * time.Second) | ||
|
||
// Get the namespace name that boundary created | ||
namespaceName := getNamespaceName(t) | ||
|
||
// Test HTTP request through boundary (from inside the jail) | ||
t.Run("HTTPRequestThroughBoundary", func(t *testing.T) { | ||
// Run curl directly in the namespace using ip netns exec | ||
curlCmd := exec.Command("sudo", "ip", "netns", "exec", namespaceName, | ||
"curl", "http://jsonplaceholder.typicode.com/todos/1") | ||
|
||
// Capture stderr separately | ||
var stderr bytes.Buffer | ||
curlCmd.Stderr = &stderr | ||
output, err := curlCmd.Output() | ||
|
||
if err != nil { | ||
t.Fatalf("curl command failed: %v, stderr: %s, output: %s", err, stderr.String(), string(output)) | ||
} | ||
|
||
// Verify response contains expected content | ||
expectedResponse := `{ | ||
"userId": 1, | ||
"id": 1, | ||
"title": "delectus aut autem", | ||
"completed": false | ||
}` | ||
require.Equal(t, expectedResponse, string(output)) | ||
}) | ||
|
||
// Test HTTPS request through boundary (from inside the jail) | ||
t.Run("HTTPSRequestThroughBoundary", func(t *testing.T) { | ||
_, _, _, _, configDir := util.GetUserInfo() | ||
certPath := fmt.Sprintf("%v/ca-cert.pem", configDir) | ||
|
||
// Run curl directly in the namespace using ip netns exec | ||
curlCmd := exec.Command("sudo", "ip", "netns", "exec", namespaceName, | ||
"env", fmt.Sprintf("SSL_CERT_FILE=%v", certPath), "curl", "-s", "https://dev.coder.com/api/v2") | ||
|
||
// Capture stderr separately | ||
var stderr bytes.Buffer | ||
curlCmd.Stderr = &stderr | ||
output, err := curlCmd.Output() | ||
|
||
if err != nil { | ||
t.Fatalf("curl command failed: %v, stderr: %s, output: %s", err, stderr.String(), string(output)) | ||
} | ||
|
||
// Verify response contains expected content | ||
expectedResponse := `{"message":"👋"} | ||
` | ||
require.Equal(t, expectedResponse, string(output)) | ||
}) | ||
|
||
// Test blocked domain (from inside the jail) | ||
t.Run("BlockedDomainTest", func(t *testing.T) { | ||
// Run curl directly in the namespace using ip netns exec | ||
curlCmd := exec.Command("sudo", "ip", "netns", "exec", namespaceName, | ||
"curl", "-s", "http://example.com") | ||
|
||
// Capture stderr separately | ||
var stderr bytes.Buffer | ||
curlCmd.Stderr = &stderr | ||
output, err := curlCmd.Output() | ||
|
||
if err != nil { | ||
t.Fatalf("curl command failed: %v, stderr: %s, output: %s", err, stderr.String(), string(output)) | ||
} | ||
require.Contains(t, string(output), "Request Blocked by Boundary") | ||
}) | ||
|
||
// Clean up | ||
cancel() // This will terminate the boundary process | ||
err = boundaryCmd.Wait() // Wait for process to finish | ||
if err != nil { | ||
t.Logf("Boundary process finished with error: %v", err) | ||
} | ||
|
||
// Clean up binary | ||
err = os.Remove("/tmp/boundary-test") | ||
require.NoError(t, err, "Failed to remove /tmp/boundary-test") | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think some additional documentation explaining this would be really good
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree, I'll do it in a follow-up PR