Files
zooqueenandHanzo Dev 06e267f0ca DigitalOcean, the direct mode and every stored provider key are gone: compute never has or stores a naked key (red round 3, H2).
Every cloud whose SDK would authenticate from a key held in this process is removed: Aliyun, Azure, GCP, VMware, KVM, PVE, Lightsail, direct AWS and DigitalOcean with its Kubernetes clusters and node pools, volumes, VPCs and load balancers, the BYOC cost readers and their fee, and the chain providers that committed records with a stored key. What remains, Hetzner and hosted EC2, is reached only through egress; with no carrier every cloud call refuses. A provider row names accounts by their egress label and holds no key: the ClientId, ClientSecret and key-secret fields are gone, a write carrying one is refused, and each database drops the old columns, rewrites rotation keys without their secrets and vacuums when its engine opens. The routes of the removed features are dropped with no successor.

Co-authored-by: Hanzo Dev <[email protected]>
2026-09-24 11:29:41 -07:00

108 lines
4.2 KiB
Go

// Copyright 2025 Hanzo Industries Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package service
import (
"strings"
"testing"
"time"
)
// TestSetScopeRoundTripToComputeUsage proves the whole org > app > project chain:
// a launch that sets a scope (SetScope) lands hanzo-app/hanzo-project as instance
// tags, the tags survive the read-back (tagString into Machine.Tag), and
// EmitCompute records app/project on the compute_usage row — the columns that were
// empty (0/0) before launch injected them.
func TestSetScopeRoundTripToComputeUsage(t *testing.T) {
got := captureDatastore(t)
spec := &CreateMachineSpec{Tags: map[string]string{orgTagKey: "acme"}}
SetScope(spec, "web", "api")
joined := tagString(spec.Tags)
if tagValue(joined, appTagKey) != "web" || tagValue(joined, projectTagKey) != "api" {
t.Fatalf("scope tags not carried onto the machine: %q", joined)
}
m := &Machine{Id: "77", Size: "s-1vcpu-1gb", Tag: joined}
EmitCompute("acme", ComputeLaunched, m, 5)
select {
case c := <-got:
if c.row.Org != "acme" || c.row.App != "web" || c.row.Project != "api" {
t.Fatalf("compute_usage scope = org=%q app=%q project=%q, want acme/web/api", c.row.Org, c.row.App, c.row.Project)
}
case <-time.After(3 * time.Second):
t.Fatal("no datastore insert received")
}
}
// TestNoScopeLeavesProjectEmpty proves the optional-scope invariant: a launch that
// omits app/project neither emits the tags nor breaks org attribution — the row
// carries org and leaves app/project empty, exactly as before the feature.
func TestNoScopeLeavesProjectEmpty(t *testing.T) {
got := captureDatastore(t)
spec := &CreateMachineSpec{Tags: map[string]string{orgTagKey: "acme"}}
SetScope(spec, "", "") // omitted on this launch
joined := tagString(spec.Tags)
if strings.Contains(joined, appTagKey+":") || strings.Contains(joined, projectTagKey+":") {
t.Fatalf("omitted scope must emit no app/project tag, got %q", joined)
}
m := &Machine{Id: "78", Size: "s-1vcpu-1gb", Tag: joined}
EmitCompute("acme", ComputeLaunched, m, 5)
select {
case c := <-got:
if c.row.App != "" || c.row.Project != "" {
t.Fatalf("omitted scope must stay empty, got app=%q project=%q", c.row.App, c.row.Project)
}
if c.row.Org != "acme" {
t.Fatalf("org attribution must still work with no scope, got %q", c.row.Org)
}
case <-time.After(3 * time.Second):
t.Fatal("no datastore insert received")
}
}
// TestSetScopeRejectsUnsafeValue proves scope injection reuses org's safeTagField
// guard: a value carrying the tag read-back's "," / ":" separators is dropped and
// never reaches the spec, so it can fabricate neither a tag boundary nor a fake
// key:value on read-back.
func TestSetScopeRejectsUnsafeValue(t *testing.T) {
spec := &CreateMachineSpec{Tags: map[string]string{orgTagKey: "acme"}}
SetScope(spec, "ev,il", "ok:nope")
if _, ok := spec.Tags[appTagKey]; ok {
t.Fatalf("unsafe app value must not be set on the spec, tags=%v", spec.Tags)
}
if _, ok := spec.Tags[projectTagKey]; ok {
t.Fatalf("unsafe project value must not be set on the spec, tags=%v", spec.Tags)
}
}
// TestMachineScopeReadBack proves MachineApp/MachineProject are the read-back
// counterparts of SetScope (the ?project= list filter reads through them), empty
// when the machine carries no such tag.
func TestMachineScopeReadBack(t *testing.T) {
m := &Machine{Tag: "hanzo-org:acme,hanzo-app:web,hanzo-project:api,"}
if MachineApp(m) != "web" || MachineProject(m) != "api" {
t.Fatalf("scope read-back = app=%q project=%q, want web/api", MachineApp(m), MachineProject(m))
}
bare := &Machine{Tag: "hanzo-org:acme,"}
if MachineApp(bare) != "" || MachineProject(bare) != "" {
t.Fatalf("scopeless machine must read empty, got app=%q project=%q", MachineApp(bare), MachineProject(bare))
}
}