| 1 | package appconfig |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | |
| 6 | "github.com/carlosframework/platform/internal/instancekey" |
| 7 | "github.com/carlosframework/platform/internal/registry" |
| 8 | ) |
| 9 | |
| 10 | // Ruling 27's fresh check: the digest of the key the bucket's |
| 11 | // configuration renders now, from the app's bundle or the host's overlay, |
| 12 | // plain or sealed; "" when it renders none. |
| 13 | func TestConfiguredKeyDigestReadsTheBucketNow(t *testing.T) { |
| 14 | ctx, s, _, _, priv, pub := execKit(t) |
| 15 | pk, _ := ParsePrivateKey(priv, "test") |
| 16 | pubKey, _ := ParsePublicKey(pub, "test") |
| 17 | rt := registry.Route{Host: "shop-au.example.com", Kind: "instance", App: "shop", Account: "acct", Replica: true} |
| 18 | check := func(want string) { |
| 19 | t.Helper() |
| 20 | got, err := ConfiguredKeyDigest(ctx, s, pk, rt) |
| 21 | if err != nil || got != want { |
| 22 | t.Fatalf("ConfiguredKeyDigest = %q, %v; want %q", got, err, want) |
| 23 | } |
| 24 | } |
| 25 | check("") |
| 26 | if err := SetEnv(ctx, s, "acct", "shop", map[string]string{"CARLOS_INSTANCE_KEY": "key-A"}); err != nil { |
| 27 | t.Fatal(err) |
| 28 | } |
| 29 | check(instancekey.Digest("key-A")) |
| 30 | if err := SetEnv(ctx, s, "acct", "shop", map[string]string{"CARLOS_INSTANCE_KEY": "key-B"}); err != nil { |
| 31 | t.Fatal(err) |
| 32 | } |
| 33 | check(instancekey.Digest("key-B")) |
| 34 | sealed, err := Seal(pubKey, Binding{Account: "acct", App: "shop"}, []byte("key-C")) |
| 35 | if err != nil { |
| 36 | t.Fatal(err) |
| 37 | } |
| 38 | if _, _, err := ApplyInstance(ctx, s, "acct", "shop", rt.Host, map[string]Var{"CARLOS_INSTANCE_KEY": {Kind: "secret", Envelope: sealed}}, nil); err != nil { |
| 39 | t.Fatal(err) |
| 40 | } |
| 41 | check(instancekey.Digest("key-C")) |
| 42 | } |
| 43 | |