|
1 | 1 | package serviceoffercontroller |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "context" |
4 | 5 | "encoding/json" |
5 | 6 | "strings" |
6 | 7 | "testing" |
7 | 8 |
|
8 | 9 | "github.com/ObolNetwork/obol-stack/internal/monetizeapi" |
| 10 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
9 | 11 | ) |
10 | 12 |
|
11 | 13 | // TestBuildAgentNetworkPolicy_IsolationInvariants pins the security shape |
@@ -122,3 +124,32 @@ func TestAgentManifests_IncludesNetworkPolicy(t *testing.T) { |
122 | 124 | t.Error("agentManifests must include the agent-isolation NetworkPolicy") |
123 | 125 | } |
124 | 126 | } |
| 127 | + |
| 128 | +// TestResourceFor_NetworkPolicyUsesNetworkPolicyGVR guards the rc16 regression: |
| 129 | +// buildAgentNetworkPolicy added a NetworkPolicy to the agent manifest set, but |
| 130 | +// resourceFor had no case for it and fell through to the ConfigMap default. On |
| 131 | +// a real apiserver that fails ("NetworkPolicy cannot be handled as a |
| 132 | +// ConfigMap") and wedges every agent reconcile, so the remote-signer (and the |
| 133 | +// agent's wallet) never provision. A fake client tolerates the wrong GVR, so |
| 134 | +// the regression hid in unit tests — this asserts the object lands under the |
| 135 | +// NetworkPolicy GVR, not ConfigMap. |
| 136 | +func TestResourceFor_NetworkPolicyUsesNetworkPolicyGVR(t *testing.T) { |
| 137 | + agent := &monetizeapi.Agent{} |
| 138 | + agent.Name = "quant" |
| 139 | + agent.Namespace = "agent-quant" |
| 140 | + c := newProvisioningTestController(t, agent) |
| 141 | + |
| 142 | + np := buildAgentNetworkPolicy(agent) |
| 143 | + if _, err := c.resourceFor(np).Create(context.Background(), np, metav1.CreateOptions{}); err != nil { |
| 144 | + t.Fatalf("create agent NetworkPolicy via resourceFor: %v", err) |
| 145 | + } |
| 146 | + |
| 147 | + if _, err := c.client.Resource(monetizeapi.NetworkPolicyGVR).Namespace("agent-quant"). |
| 148 | + Get(context.Background(), "agent-isolation", metav1.GetOptions{}); err != nil { |
| 149 | + t.Fatalf("agent-isolation not stored under NetworkPolicyGVR — resourceFor mis-mapped it: %v", err) |
| 150 | + } |
| 151 | + if _, err := c.client.Resource(monetizeapi.ConfigMapGVR).Namespace("agent-quant"). |
| 152 | + Get(context.Background(), "agent-isolation", metav1.GetOptions{}); err == nil { |
| 153 | + t.Fatal("agent-isolation was created as a ConfigMap — resourceFor regressed to the ConfigMap default") |
| 154 | + } |
| 155 | +} |
0 commit comments