package appconfig import ( "testing" "github.com/carlosframework/platform/internal/instancekey" "github.com/carlosframework/platform/internal/registry" ) // Ruling 27's fresh check: the digest of the key the bucket's // configuration renders now, from the app's bundle or the host's overlay, // plain or sealed; "" when it renders none. func TestConfiguredKeyDigestReadsTheBucketNow(t *testing.T) { ctx, s, _, _, priv, pub := execKit(t) pk, _ := ParsePrivateKey(priv, "test") pubKey, _ := ParsePublicKey(pub, "test") rt := registry.Route{Host: "shop-au.example.com", Kind: "instance", App: "shop", Account: "acct", Replica: true} check := func(want string) { t.Helper() got, err := ConfiguredKeyDigest(ctx, s, pk, rt) if err != nil || got != want { t.Fatalf("ConfiguredKeyDigest = %q, %v; want %q", got, err, want) } } check("") if err := SetEnv(ctx, s, "acct", "shop", map[string]string{"CARLOS_INSTANCE_KEY": "key-A"}); err != nil { t.Fatal(err) } check(instancekey.Digest("key-A")) if err := SetEnv(ctx, s, "acct", "shop", map[string]string{"CARLOS_INSTANCE_KEY": "key-B"}); err != nil { t.Fatal(err) } check(instancekey.Digest("key-B")) sealed, err := Seal(pubKey, Binding{Account: "acct", App: "shop"}, []byte("key-C")) if err != nil { t.Fatal(err) } if _, _, err := ApplyInstance(ctx, s, "acct", "shop", rt.Host, map[string]Var{"CARLOS_INSTANCE_KEY": {Kind: "secret", Envelope: sealed}}, nil); err != nil { t.Fatal(err) } check(instancekey.Digest("key-C")) }