carlos / platform Public

console: keep raw cloud errors out of the media boot log

Astra round 1 on the media wiring.

A cloud failure at boot now logs the failing step and a safe cause from
mediaaws.SafeCause: an AWS error code and status, or that the request
failed. The SDK's own text can quote request URLs and service answers,
so it never reaches the log. errors.Is(err, errMediaCloud) still holds.

ParseConfig refuses a security group or subnet that is not the prefix
and 8 or 17 lower-case hex characters.

TestEngineS3RequestsAreCounted no longer inherits service endpoints,
profiles or shared config from the environment running it.

The claim authority census gains the two AWS clients media.go builds.
Both were missing from the wiring commit.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 1f63dfc2cff0ffcd74197006f093336b221e1463 parent 5144700
8 files changed, +213 −29
  • cmd/console/media.go +10 −3
  • cmd/console/media_serve_test.go +31 −2
  • cmd/console/media_test.go +109 −7
  • docs/superpowers/notes/media-conversion-copy-deck.md +1 −1
  • internal/console/claim_authority_census_test.go +5 −0
  • internal/console/testdata/claim-authority-sites.txt +2 −0
  • internal/mediaaws/config.go +12 −4
  • internal/mediaaws/mediaaws_test.go +43 −12
diff --git a/cmd/console/media.go b/cmd/console/media.go
index 2461a8a8f..aac8c7316 100644
--- a/cmd/console/media.go
+++ b/cmd/console/media.go
@@ -35,6 +35,13 @@ const mediaOffAtBoot = "console: media conversion is off until the next start: %
// client could not be built. mediaConfig boots past it with media off.
var errMediaCloud = errors.New("the cloud account could not be reached")
+// mediaCloudFailure is errMediaCloud for one step. The cause is
+// mediaaws.SafeCause and never err's own text: an SDK error can quote a
+// request URL or the service's response, and this line goes to the boot log.
+func mediaCloudFailure(step string, err error) error {
+ return fmt.Errorf("%w: %s: %s", errMediaCloud, step, mediaaws.SafeCause(err))
+}
+
// storeEnv is the part of CARLOS_STORE_* media wiring compares the engine
// with: storeBackend's checked values, Backend "" on a deployment with no
// object storage.
@@ -166,7 +173,7 @@ func mediaFromEnv(ctx context.Context, getenv func(string) string, store storeEn
account, err := clients.identity(ctx, store.Region)
if err != nil {
- return console.MediaConfig{}, fmt.Errorf("%w: %v", errMediaCloud, err)
+ return console.MediaConfig{}, mediaCloudFailure("sts GetCallerIdentity", err)
}
if account == "" {
return console.MediaConfig{}, fmt.Errorf("%w: sts GetCallerIdentity answered no account", errMediaCloud)
@@ -176,7 +183,7 @@ func mediaFromEnv(ctx context.Context, getenv func(string) string, store storeEn
}
s3Client, err := clients.newS3(ctx, store.Region, store.Endpoint)
if err != nil {
- return console.MediaConfig{}, fmt.Errorf("%w: %v", errMediaCloud, err)
+ return console.MediaConfig{}, mediaCloudFailure("build the S3 client", err)
}
cfg := console.MediaConfig{
StoreConversion: true,
@@ -188,7 +195,7 @@ func mediaFromEnv(ctx context.Context, getenv func(string) string, store storeEn
}
cfg.MediaEngine, cfg.MediaGrants, err = clients.newEngine(ctx, engine)
if err != nil {
- return console.MediaConfig{}, fmt.Errorf("%w: %v", errMediaCloud, err)
+ return console.MediaConfig{}, mediaCloudFailure("build the conversion engine", err)
}
cfg.MediaLimits = limits
cfg.MediaRegion = engine.Region
diff --git a/cmd/console/media_serve_test.go b/cmd/console/media_serve_test.go
index 28dbe038a..e18243205 100644
--- a/cmd/console/media_serve_test.go
+++ b/cmd/console/media_serve_test.go
@@ -25,7 +25,12 @@ import (
"github.com/carlosframework/platform/internal/mediaaws"
)
-const mediaWitnessOperator = "operator@example.com"
+const (
+ mediaWitnessOperator = "operator@example.com"
+ // mediaCloudSecret is planted in what a failing cloud answers, and must
+ // never reach the console's output.
+ mediaCloudSecret = "hunter2-cloud-secret"
+)
// mediaCloudStub stands in for AWS: the built console's every AWS client is
// pointed here by AWS_ENDPOINT_URL. It answers sts:GetCallerIdentity and
@@ -79,7 +84,7 @@ func (s *mediaCloudStub) serve(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/xml")
if s.denyIdent {
w.WriteHeader(http.StatusForbidden)
- fmt.Fprint(w, `<ErrorResponse><Error><Type>Sender</Type><Code>InvalidClientTokenId</Code><Message>stub</Message></Error></ErrorResponse>`)
+ fmt.Fprintf(w, `<ErrorResponse><Error><Type>Sender</Type><Code>InvalidClientTokenId</Code><Message>%[1]s</Message></Error><RequestId>%[1]s</RequestId></ErrorResponse>`, mediaCloudSecret)
return
}
fmt.Fprintf(w, `<GetCallerIdentityResponse xmlns="https://sts.amazonaws.com/doc/2011-06-15/"><GetCallerIdentityResult><Arn>arn:aws:iam::%[1]s:role/console</Arn><UserId>stub</UserId><Account>%[1]s</Account></GetCallerIdentityResult><ResponseMetadata><RequestId>stub</RequestId></ResponseMetadata></GetCallerIdentityResponse>`, s.account)
@@ -402,6 +407,28 @@ func TestServeMediaWiring(t *testing.T) {
if got := c.operatorStatus(t, carlos); got != "engine not configured\n" {
t.Fatalf("carlos system media status printed %q", got)
}
+ if strings.Contains(c.output(), mediaCloudSecret) {
+ t.Fatalf("the boot log repeats the cloud's answer:\n%s", c.output())
+ }
+ if !strings.Contains(c.output(), "sts GetCallerIdentity: InvalidClientTokenId (HTTP 403)") {
+ t.Fatalf("the boot log does not name the step and the code:\n%s", c.output())
+ }
+ })
+
+ t.Run("a transport failure keeps its URL out of the log", func(t *testing.T) {
+ w := mediaWitness{bin: bin, stub: newMediaCloudStub(t)}
+ // Nothing listens here, and the SDK's error quotes the request URL.
+ c := w.boot(t, "CARLOS_STORE_CONVERSION=1", "CARLOS_MEDIA_ENGINE="+testMediaEngine(t, nil),
+ "AWS_ENDPOINT_URL_STS=http://"+freeLoopbackAddr(t)+"/"+mediaCloudSecret)
+ if got := c.status(t); got.Configured {
+ t.Fatalf("status = %+v", got)
+ }
+ if n := strings.Count(c.output(), strings.TrimSuffix(mediaOffAtBoot, "%v")); n != 1 {
+ t.Fatalf("the boot log says media is off %d times, want once:\n%s", n, c.output())
+ }
+ if strings.Contains(c.output(), mediaCloudSecret) {
+ t.Fatalf("the boot log repeats the request URL:\n%s", c.output())
+ }
})
t.Run("bad settings stop the boot", func(t *testing.T) {
@@ -424,6 +451,8 @@ func TestServeMediaWiring(t *testing.T) {
{"another prefix", []string{"CARLOS_STORE_CONVERSION=1", "CARLOS_MEDIA_ENGINE=" + testMediaEngine(t, func(c *mediaaws.Config) { c.StorePrefix = "other-" })}, "CARLOS_STORE_BUCKET_PREFIX"},
{"another account", []string{"CARLOS_STORE_CONVERSION=1", "CARLOS_MEDIA_ENGINE=" + testMediaEngine(t, foreign)}, "account"},
{"custom store endpoint", []string{"CARLOS_STORE_CONVERSION=1", "CARLOS_STORE_ENDPOINT=http://127.0.0.1:9", "CARLOS_MEDIA_ENGINE=" + testMediaEngine(t, nil)}, "CARLOS_STORE_ENDPOINT"},
+ {"malformed security group", []string{"CARLOS_STORE_CONVERSION=1", "CARLOS_MEDIA_ENGINE=" + testMediaEngine(t, func(c *mediaaws.Config) { c.SecurityGroup = "sg-1" })}, "security_group"},
+ {"malformed subnet", []string{"CARLOS_STORE_CONVERSION=1", "CARLOS_MEDIA_ENGINE=" + testMediaEngine(t, func(c *mediaaws.Config) { c.Subnets = []string{"subnet-1"} })}, "subnet"},
{"malformed limits", []string{"CARLOS_STORE_CONVERSION=1", "CARLOS_MEDIA_ENGINE=" + testMediaEngine(t, nil), "CARLOS_MEDIA_LIMITS=short=none"}, "CARLOS_MEDIA_LIMITS"},
{"conversion misspelt", []string{"CARLOS_STORE_CONVERSION=yes"}, "CARLOS_STORE_CONVERSION"},
} {
diff --git a/cmd/console/media_test.go b/cmd/console/media_test.go
index f32d64f42..ffd21060c 100644
--- a/cmd/console/media_test.go
+++ b/cmd/console/media_test.go
@@ -9,11 +9,14 @@ import (
"net/http"
"net/http/httptest"
"os"
+ "path/filepath"
"strings"
"sync"
"testing"
"time"
+ "github.com/aws/smithy-go"
+
"github.com/carlosframework/platform/internal/console"
"github.com/carlosframework/platform/internal/media"
"github.com/carlosframework/platform/internal/media/mediatest"
@@ -43,8 +46,8 @@ func testMediaConfig() mediaaws.Config {
Region: testMediaRegion,
Cluster: "media",
TaskDefinitions: defs,
- Subnets: []string{"subnet-1"},
- SecurityGroup: "sg-1",
+ Subnets: []string{"subnet-0123456789abcdef0"},
+ SecurityGroup: "sg-0123456789abcdef0",
ConversionRole: "arn:aws:iam::" + testMediaAccount + ":role/media-conversion",
ResultsBucket: "carlos-media-results",
StorePrefix: testMediaPrefix,
@@ -354,6 +357,109 @@ func TestMediaFromEnvCloudFailures(t *testing.T) {
}
}
+// mediaInheritedAWSEnv are the variables through which the environment running
+// a test could send an AWS client somewhere other than its stub, or hand it
+// another identity.
+var mediaInheritedAWSEnv = []string{
+ "AWS_ENDPOINT_URL_STS",
+ "AWS_ENDPOINT_URL_S3",
+ "AWS_ENDPOINT_URL_ECS",
+ "AWS_IGNORE_CONFIGURED_ENDPOINT_URLS",
+ "AWS_PROFILE",
+ "AWS_DEFAULT_PROFILE",
+ "AWS_SESSION_TOKEN",
+ "AWS_ROLE_ARN",
+ "AWS_WEB_IDENTITY_TOKEN_FILE",
+}
+
+// isolateMediaAWSEnv holds this process's AWS clients to endpoint, whatever
+// the environment running the test has set: a service-specific endpoint
+// variable outranks AWS_ENDPOINT_URL.
+func isolateMediaAWSEnv(t *testing.T, endpoint string) {
+ t.Helper()
+ dir := t.TempDir()
+ for _, name := range []string{"config", "credentials"} {
+ if err := os.WriteFile(filepath.Join(dir, name), nil, 0o600); err != nil {
+ t.Fatal(err)
+ }
+ }
+ for _, key := range mediaInheritedAWSEnv {
+ t.Setenv(key, "")
+ }
+ t.Setenv("HOME", dir)
+ t.Setenv("AWS_CONFIG_FILE", filepath.Join(dir, "config"))
+ t.Setenv("AWS_SHARED_CREDENTIALS_FILE", filepath.Join(dir, "credentials"))
+ t.Setenv("AWS_ENDPOINT_URL", endpoint)
+ t.Setenv("AWS_ACCESS_KEY_ID", "AKIASTUBSTUBSTUBSTUB")
+ t.Setenv("AWS_SECRET_ACCESS_KEY", "stub")
+ t.Setenv("AWS_EC2_METADATA_DISABLED", "true")
+}
+
+// Whatever the environment holds, isolateMediaAWSEnv leaves none of it for a
+// client to read.
+func TestIsolateMediaAWSEnv(t *testing.T) {
+ for _, key := range mediaInheritedAWSEnv {
+ t.Setenv(key, "inherited")
+ }
+ t.Setenv("AWS_CONFIG_FILE", "/inherited/config")
+ t.Setenv("AWS_SHARED_CREDENTIALS_FILE", "/inherited/credentials")
+ isolateMediaAWSEnv(t, "http://127.0.0.1:1")
+ for _, key := range mediaInheritedAWSEnv {
+ if v := os.Getenv(key); v != "" {
+ t.Errorf("%s = %q survives", key, v)
+ }
+ }
+ for _, key := range []string{"AWS_CONFIG_FILE", "AWS_SHARED_CREDENTIALS_FILE"} {
+ b, err := os.ReadFile(os.Getenv(key))
+ if err != nil || len(b) != 0 {
+ t.Errorf("%s = %q: %d bytes, %v; want an empty file", key, os.Getenv(key), len(b), err)
+ }
+ }
+ if got := os.Getenv("AWS_ENDPOINT_URL"); got != "http://127.0.0.1:1" {
+ t.Errorf("AWS_ENDPOINT_URL = %q", got)
+ }
+}
+
+// What a cloud failure says is the step and a safe cause, never the error's
+// own text: an SDK error can quote a request URL or the service's answer.
+func TestMediaFromEnvCloudFailuresPrintNoRawError(t *testing.T) {
+ const secret = "hunter2-do-not-print"
+ env := func(t *testing.T) func(string) string {
+ return mediaEnv(map[string]string{"CARLOS_STORE_CONVERSION": "1", "CARLOS_MEDIA_ENGINE": testMediaEngine(t, nil)})
+ }
+ transport := errors.New(`Post "https://sts.example.com/` + secret + `": dial tcp: refused`)
+ for _, tc := range []struct {
+ name string
+ breakIt func(*fakeMediaClients)
+ want string
+ }{
+ {"identity, transport", func(f *fakeMediaClients) { f.identityErr = transport }, "sts GetCallerIdentity: the request failed before an answer came back"},
+ {"identity, service", func(f *fakeMediaClients) {
+ f.identityErr = &smithy.GenericAPIError{Code: "AccessDenied", Message: secret}
+ }, "sts GetCallerIdentity: AccessDenied"},
+ {"identity, a code that is not a code", func(f *fakeMediaClients) {
+ f.identityErr = &smithy.GenericAPIError{Code: "https://example.com/" + secret, Message: secret}
+ }, "sts GetCallerIdentity: the request failed before an answer came back"},
+ {"s3 client", func(f *fakeMediaClients) { f.s3Err = transport }, "build the S3 client: "},
+ {"engine", func(f *fakeMediaClients) { f.engineErr = transport }, "build the conversion engine: "},
+ } {
+ t.Run(tc.name, func(t *testing.T) {
+ f := newFakeMediaClients()
+ tc.breakIt(f)
+ _, err := mediaFromEnv(context.Background(), env(t), testStoreEnv(), f.clients())
+ if !errors.Is(err, errMediaCloud) {
+ t.Fatalf("err = %v, want errMediaCloud", err)
+ }
+ if strings.Contains(err.Error(), secret) {
+ t.Fatalf("the error repeats the raw failure: %q", err)
+ }
+ if !strings.Contains(err.Error(), tc.want) {
+ t.Fatalf("error %q does not say %q", err, tc.want)
+ }
+ })
+ }
+}
+
// The boot's one log line is the deck's row.
func TestMediaOffAtBootIsTheDecksWording(t *testing.T) {
deck, err := os.ReadFile("../../docs/superpowers/notes/media-conversion-copy-deck.md")
@@ -398,11 +504,7 @@ func TestEngineS3RequestsAreCounted(t *testing.T) {
}
}))
defer stub.Close()
- t.Setenv("HOME", t.TempDir())
- t.Setenv("AWS_ENDPOINT_URL", stub.URL)
- t.Setenv("AWS_ACCESS_KEY_ID", "AKIASTUBSTUBSTUBSTUB")
- t.Setenv("AWS_SECRET_ACCESS_KEY", "stub")
- t.Setenv("AWS_EC2_METADATA_DISABLED", "true")
+ isolateMediaAWSEnv(t, stub.URL)
rec := new(perf.Recorder)
_, grants, err := realMediaClients(rec, mediaaws.WithS3Endpoint(stub.URL)).newEngine(context.Background(), testMediaConfig())
diff --git a/docs/superpowers/notes/media-conversion-copy-deck.md b/docs/superpowers/notes/media-conversion-copy-deck.md
index ad3ecdbdb..ec3655d39 100644
--- a/docs/superpowers/notes/media-conversion-copy-deck.md
+++ b/docs/superpowers/notes/media-conversion-copy-deck.md
@@ -690,4 +690,4 @@ for whoever deploys the console and are not listed here.
| `engine.aws.grant.request` | `the execution is not 32 hex characters`, `the source key is not valid`, `the source ETag is not valid`, `the output prefix is not a directory under derived/`, `the grant does not name %d outputs`, `an output's name or content type is not one the engine writes` (pending Luna pass; plan 3 Task 9) |
| `engine.aws.grant.presign` | `the presigned transfers do not share one credential`, `an output's URL is not under the output prefix`, `a presigned URL does not have the expected shape`, `a presigned URL does not sign the expected headers` (pending Luna pass; plan 3 Task 9) |
| `engine.aws.rejected` | The reason in `engine rejected the launch: %s`: an AWS error code, `HTTP 429`, the reason ECS gave, `no task definition for this class`, `no task and no failure reported`, `no reason reported`, `a reason that cannot be shown`, or `the API refused the request` (pending Luna pass; plan 3 Task 9) |
-| `console.media.off_at_boot` | `console: media conversion is off until the next start: %v`, logged once at boot when the cloud account cannot be read or a client cannot be built. `%v` starts `the cloud account could not be reached: ` and goes on to the failure (pending Luna pass; plan 3 Task 10 fix 1) |
+| `console.media.off_at_boot` | `console: media conversion is off until the next start: %v`, logged once at boot when the cloud account cannot be read or a client cannot be built. `%v` is `the cloud account could not be reached: <step>: <cause>`. The step is `sts GetCallerIdentity`, `build the S3 client` or `build the conversion engine`; the cause is one of the `engine.aws.cause.*` texts, never the error's own message (pending Luna pass; plan 3 Task 10 fix 2) |
diff --git a/internal/console/claim_authority_census_test.go b/internal/console/claim_authority_census_test.go
index 6a295d3f0..d6425e4cf 100644
--- a/internal/console/claim_authority_census_test.go
+++ b/internal/console/claim_authority_census_test.go
@@ -27,6 +27,11 @@ import (
// and uploads to the durable operation's exact snapshot key. No request path
// selects this file. TestDemoClaimFreshSeed and the snapshot refusal tests
// cover this boundary; the open adds no root or bucket-constructor authority.
+// callerAccount (cmd/console/media.go) builds an STS client for one
+// GetCallerIdentity at boot and reads no app state. realMediaClients builds
+// the S3 client behind Config.StoreBuckets, which reads and sets store bucket
+// settings. Its only callers are the media and store uploads doors and the
+// media pass, and all of them refuse on a host-claim console.
func claimAuthoritySites(t *testing.T) []string {
t.Helper()
selected := map[string]bool{
diff --git a/internal/console/testdata/claim-authority-sites.txt b/internal/console/testdata/claim-authority-sites.txt
index f54897ec6..16dc54d85 100644
--- a/internal/console/testdata/claim-authority-sites.txt
+++ b/internal/console/testdata/claim-authority-sites.txt
@@ -6,6 +6,8 @@
../../cmd/console/main.go|serve|mail.NewAWSProvisioner(ctx, region, mailBoundary)
../../cmd/console/main.go|storeBackend|objstore.NewAWSProvisionerWith(context.Background(), region, endpoint, boundary, console.TimeS3HTTP(rec))
../../cmd/console/main.go|storeScannerFor|objstore.NewClamAVScanner(context.Background(), d.Region, d.Endpoint, addr, maxBytes, signer)
+../../cmd/console/media.go|callerAccount|sts.NewFromConfig(cfg)
+../../cmd/console/media.go|realMediaClients|objstore.S3ClientFor(ctx, region, endpoint)
../hostops/app_mutation_runner.go|RunAppMutation|b.control.BeginExclusive(ctx, account, app, a.Value.AppID, AppOperation{ID: id, Kind: OpAppMutation, AppID: a.Value.AppID, Phase: "issued", Intent: intent}, owner)
../hostops/ingest.go|RecoverIngest|w.RecoverSQLTransaction(ctx, account, app, appID, e.ID, local)
../hostops/ingest.go|RecoverSQLTransaction|local.FenceSQL(ctx, sc)
diff --git a/internal/mediaaws/config.go b/internal/mediaaws/config.go
index ad9fc635f..b585ba566 100644
--- a/internal/mediaaws/config.go
+++ b/internal/mediaaws/config.go
@@ -54,6 +54,9 @@ var (
accountPattern = regexp.MustCompile(`^[0-9]{12}$`)
digestPattern = regexp.MustCompile(`^sha256:[0-9a-f]{64}$`)
bucketPattern = regexp.MustCompile(`^[a-z0-9][a-z0-9.-]{1,61}[a-z0-9]$`)
+ // AWS issues these ids with 8 or 17 lower-case hex characters.
+ securityGroupPattern = regexp.MustCompile(`^sg-([0-9a-f]{8}|[0-9a-f]{17})$`)
+ subnetPattern = regexp.MustCompile(`^subnet-([0-9a-f]{8}|[0-9a-f]{17})$`)
)
// configClasses are the four classes a config must name, exactly.
@@ -99,8 +102,8 @@ func (c Config) validate() error {
return errors.New("account_id is not 12 digits")
case strings.TrimSpace(c.Cluster) == "":
return errors.New("cluster is empty")
- case strings.TrimSpace(c.SecurityGroup) == "":
- return errors.New("security_group is empty")
+ case !securityGroupPattern.MatchString(c.SecurityGroup):
+ return errors.New("security_group is not a security group id")
case !bucketPattern.MatchString(c.ResultsBucket):
return errors.New("results_bucket is not a bucket name")
case strings.TrimSpace(c.StorePrefix) == "":
@@ -111,8 +114,8 @@ func (c Config) validate() error {
return errors.New("no subnets")
}
for _, s := range c.Subnets {
- if strings.TrimSpace(s) == "" {
- return errors.New("a subnet is empty")
+ if !subnetPattern.MatchString(s) {
+ return errors.New("a subnet is not a subnet id")
}
}
role := regexp.MustCompile(`^arn:aws[a-z-]*:iam::` + c.AccountID + `:role/[A-Za-z0-9+=,.@_/-]+$`)
@@ -263,6 +266,11 @@ func opError(op string, err error) error {
return out
}
+// SafeCause names err in words safe for a log: the context's end, an AWS error
+// code and HTTP status, or that the request failed. It never repeats err's own
+// text, which can hold a request URL or the service's response.
+func SafeCause(err error) string { return describe(err) }
+
// describe names err without quoting it: the context's end, or an API code
// and HTTP status, or a bare status, or that the request failed.
func describe(err error) string {
diff --git a/internal/mediaaws/mediaaws_test.go b/internal/mediaaws/mediaaws_test.go
index 973a957cb..d71f2d70b 100644
--- a/internal/mediaaws/mediaaws_test.go
+++ b/internal/mediaaws/mediaaws_test.go
@@ -65,8 +65,8 @@ func testConfig() Config {
"audio-aac/short": revisionARN("media-audio-short", 3),
"audio-aac/long": revisionARN("media-audio-long", 3),
},
- Subnets: []string{"subnet-aaa", "subnet-bbb"},
- SecurityGroup: "sg-123",
+ Subnets: []string{"subnet-0123abcd", "subnet-0123456789abcdef0"},
+ SecurityGroup: "sg-0123456789abcdef0",
ConversionRole: "arn:aws:iam::" + testAccount + ":role/media-conversion",
ResultsBucket: testResults,
StorePrefix: "carlos-store-",
@@ -302,6 +302,22 @@ func grantRequest() media.GrantRequest {
return r
}
+// AWS issues security group and subnet ids in two lengths, and both are valid.
+func TestParseConfigAcceptsBothIDLengths(t *testing.T) {
+ for _, hex := range []string{"0123abcd", "0123456789abcdef0"} {
+ c := testConfig()
+ c.SecurityGroup = "sg-" + hex
+ c.Subnets = []string{"subnet-" + hex}
+ b, err := json.Marshal(c)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if _, err := ParseConfig(string(b)); err != nil {
+ t.Errorf("%d hex characters refused: %v", len(hex), err)
+ }
+ }
+}
+
func TestParseConfig(t *testing.T) {
good, err := json.Marshal(testConfig())
if err != nil {
@@ -324,16 +340,31 @@ func TestParseConfig(t *testing.T) {
return string(b)
}
bad := map[string]string{
- "empty": "",
- "not json": "{",
- "unknown field": strings.Replace(string(good), `{"v":1`, `{"extra":1,"v":1`, 1),
- "trailing data": string(good) + "{}",
- "version 0": mutate(func(c *Config) { c.V = 0 }),
- "version 2": mutate(func(c *Config) { c.V = 2 }),
- "no region": mutate(func(c *Config) { c.Region = "" }),
- "no cluster": mutate(func(c *Config) { c.Cluster = "" }),
- "class missing": mutate(func(c *Config) { delete(c.TaskDefinitions, "audio-aac/long") }),
- "class unknown": mutate(func(c *Config) { c.TaskDefinitions["video-1080p/short"] = revisionARN("x", 1) }),
+ "empty": "",
+ "not json": "{",
+ "unknown field": strings.Replace(string(good), `{"v":1`, `{"extra":1,"v":1`, 1),
+ "trailing data": string(good) + "{}",
+ "version 0": mutate(func(c *Config) { c.V = 0 }),
+ "version 2": mutate(func(c *Config) { c.V = 2 }),
+ "no region": mutate(func(c *Config) { c.Region = "" }),
+ "no cluster": mutate(func(c *Config) { c.Cluster = "" }),
+ "security group blank": mutate(func(c *Config) { c.SecurityGroup = " " }),
+ "security group prefix": mutate(func(c *Config) { c.SecurityGroup = "subnet-0123abcd" }),
+ "security group upper case": mutate(func(c *Config) { c.SecurityGroup = "sg-0123ABCD" }),
+ "security group not hex": mutate(func(c *Config) { c.SecurityGroup = "sg-0123abcg" }),
+ "security group 7 hex": mutate(func(c *Config) { c.SecurityGroup = "sg-0123abc" }),
+ "security group 9 hex": mutate(func(c *Config) { c.SecurityGroup = "sg-0123abcde" }),
+ "security group 18 hex": mutate(func(c *Config) { c.SecurityGroup = "sg-0123456789abcdef01" }),
+ "security group newline": mutate(func(c *Config) { c.SecurityGroup = "sg-0123abcd\n" }),
+ "subnet blank": mutate(func(c *Config) { c.Subnets = []string{" "} }),
+ "subnet prefix": mutate(func(c *Config) { c.Subnets = []string{"sg-0123abcd"} }),
+ "subnet upper case": mutate(func(c *Config) { c.Subnets = []string{"subnet-0123ABCD"} }),
+ "subnet not hex": mutate(func(c *Config) { c.Subnets = []string{"subnet-0123abcg"} }),
+ "subnet 7 hex": mutate(func(c *Config) { c.Subnets = []string{"subnet-0123abc"} }),
+ "subnet 18 hex": mutate(func(c *Config) { c.Subnets = []string{"subnet-0123456789abcdef01"} }),
+ "second subnet malformed": mutate(func(c *Config) { c.Subnets = []string{"subnet-0123abcd", "subnet-1"} }),
+ "class missing": mutate(func(c *Config) { delete(c.TaskDefinitions, "audio-aac/long") }),
+ "class unknown": mutate(func(c *Config) { c.TaskDefinitions["video-1080p/short"] = revisionARN("x", 1) }),
"class renamed": mutate(func(c *Config) {
delete(c.TaskDefinitions, "audio-aac/long")
c.TaskDefinitions["audio-aac/huge"] = revisionARN("x", 1)