* Fix STS AssumeRole with POST body param and add integration test * Add STS integration test to CI workflow * Address code review feedback: fix HPP vulnerability and style issues * Refactor: address code review feedback - Fix HTTP Parameter Pollution vulnerability in UnifiedPostHandler - Refactor permission check logic for better readability - Extract test helpers to testutil/docker.go to reduce duplication - Clean up imports and simplify context setting * Add SigV4-style test variant for AssumeRole POST body routing - Added ActionInBodyWithSigV4Style test case to validate real-world scenario - Test confirms routing works correctly for AWS SigV4-signed requests - Addresses code review feedback about testing with SigV4 signatures * Fix: always set identity in context when non-nil - Ensure UnifiedPostHandler always calls SetIdentityInContext when identity is non-nil - Only call SetIdentityNameInContext when identity.Name is non-empty - This ensures downstream handlers (embeddedIam.DoActions) always have access to identity - Addresses potential issue where empty identity.Name would skip context setting
67 lines
1.2 KiB
Go
67 lines
1.2 KiB
Go
package testutil
|
|
|
|
import (
|
|
"context"
|
|
"net"
|
|
"net/http"
|
|
"os/exec"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func HasDocker() bool {
|
|
cmd := exec.Command("docker", "version")
|
|
return cmd.Run() == nil
|
|
}
|
|
|
|
func MustFreePortPair(t *testing.T, name string) (int, int) {
|
|
httpPort, grpcPort, err := findAvailablePortPair()
|
|
if err != nil {
|
|
t.Fatalf("Failed to get free port pair for %s: %v", name, err)
|
|
}
|
|
return httpPort, grpcPort
|
|
}
|
|
|
|
func findAvailablePortPair() (int, int, error) {
|
|
httpPort, err := GetFreePort()
|
|
if err != nil {
|
|
return 0, 0, err
|
|
}
|
|
grpcPort, err := GetFreePort()
|
|
if err != nil {
|
|
return 0, 0, err
|
|
}
|
|
return httpPort, grpcPort, nil
|
|
}
|
|
|
|
func GetFreePort() (int, error) {
|
|
listener, err := net.Listen("tcp", "0.0.0.0:0")
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
defer listener.Close()
|
|
return listener.Addr().(*net.TCPAddr).Port, nil
|
|
}
|
|
|
|
func WaitForService(url string, timeout time.Duration) bool {
|
|
client := &http.Client{Timeout: 2 * time.Second}
|
|
ctx, cancel := context.WithTimeout(context.Background(), timeout)
|
|
defer cancel()
|
|
|
|
ticker := time.NewTicker(500 * time.Millisecond)
|
|
defer ticker.Stop()
|
|
|
|
for {
|
|
select {
|
|
case <-ctx.Done():
|
|
return false
|
|
case <-ticker.C:
|
|
resp, err := client.Get(url)
|
|
if err == nil {
|
|
resp.Body.Close()
|
|
return true
|
|
}
|
|
}
|
|
}
|
|
}
|