|
| 1 | +// Copyright 2026 NetApp, Inc. All Rights Reserved. |
| 2 | + |
| 3 | +package v1 |
| 4 | + |
| 5 | +import ( |
| 6 | + "encoding/json" |
| 7 | + "testing" |
| 8 | + |
| 9 | + "github.com/stretchr/testify/require" |
| 10 | + "k8s.io/apimachinery/pkg/runtime" |
| 11 | +) |
| 12 | + |
| 13 | +func TestTridentBackendConfigSpec_ToString_redactsGCNVAPIKey(t *testing.T) { |
| 14 | + specJSON := `{ |
| 15 | + "version": 1, |
| 16 | + "storageDriverName": "ontap-nas", |
| 17 | + "credentials": {"name": "gcnv-sa-secret", "type": "secret"}, |
| 18 | + "gcnv": { |
| 19 | + "proxyURL": "https://netapp.googleapis.com", |
| 20 | + "apiKey": { |
| 21 | + "type": "service_account", |
| 22 | + "private_key": "FAKE-PRIVATE-KEY-VALUE", |
| 23 | + "private_key_id": "key-id-123" |
| 24 | + }, |
| 25 | + "wipCredential": {"audience": "test", "serviceAccountEmail": "sa@test"} |
| 26 | + } |
| 27 | + }` |
| 28 | + |
| 29 | + spec := &TridentBackendConfigSpec{ |
| 30 | + RawExtension: runtime.RawExtension{Raw: json.RawMessage(specJSON)}, |
| 31 | + } |
| 32 | + out := spec.ToString() |
| 33 | + |
| 34 | + require.NotContains(t, out, "SECRET") |
| 35 | + require.NotContains(t, out, "key-id-123") |
| 36 | + require.NotContains(t, out, "gcnv-sa-secret") |
| 37 | + require.Contains(t, out, "credentials:<REDACTED>") |
| 38 | + require.Contains(t, out, "apiKey:<REDACTED>") |
| 39 | + require.Contains(t, out, "wipCredential:<REDACTED>") |
| 40 | + require.Contains(t, out, "proxyURL:https://netapp.googleapis.com") |
| 41 | +} |
| 42 | + |
| 43 | +func TestTridentBackendConfigSpec_ToString_redactsNativeGCNVAPIKey(t *testing.T) { |
| 44 | + specJSON := `{ |
| 45 | + "version": 1, |
| 46 | + "storageDriverName": "gcnv-nas", |
| 47 | + "apiKey": {"private_key": "native-secret", "private_key_id": "native-id"}, |
| 48 | + "wipCredentialConfig": {"audience": "a"} |
| 49 | + }` |
| 50 | + |
| 51 | + spec := &TridentBackendConfigSpec{ |
| 52 | + RawExtension: runtime.RawExtension{Raw: json.RawMessage(specJSON)}, |
| 53 | + } |
| 54 | + out := spec.ToString() |
| 55 | + |
| 56 | + require.NotContains(t, out, "native-secret") |
| 57 | + require.NotContains(t, out, "native-id") |
| 58 | + require.Contains(t, out, "apiKey:<REDACTED>") |
| 59 | + require.Contains(t, out, "wipCredentialConfig:<REDACTED>") |
| 60 | +} |
| 61 | + |
| 62 | +func TestTridentBackendConfigSpec_ToString_redactsNestedWIPCredential(t *testing.T) { |
| 63 | + specJSON := `{ |
| 64 | + "version": 1, |
| 65 | + "storageDriverName": "ontap-nas", |
| 66 | + "gcnv": { |
| 67 | + "proxyURL": "https://netapp.googleapis.com", |
| 68 | + "wipCredential": { |
| 69 | + "audience": "//iam.googleapis.com/projects/123", |
| 70 | + "credentialSource": {"file": "/var/run/secrets/token"}, |
| 71 | + "subjectTokenType": "urn:ietf:params:oauth:token-type:jwt", |
| 72 | + "tokenURL": "https://sts.googleapis.com/v1/token", |
| 73 | + "type": "external_account" |
| 74 | + } |
| 75 | + } |
| 76 | + }` |
| 77 | + |
| 78 | + spec := &TridentBackendConfigSpec{ |
| 79 | + RawExtension: runtime.RawExtension{Raw: json.RawMessage(specJSON)}, |
| 80 | + } |
| 81 | + out := spec.ToString() |
| 82 | + |
| 83 | + require.NotContains(t, out, "/var/run/secrets/token") |
| 84 | + require.NotContains(t, out, "sts.googleapis.com") |
| 85 | + require.Contains(t, out, "wipCredential:<REDACTED>") |
| 86 | +} |
0 commit comments