|
7 | 7 | "github.com/stretchr/testify/assert" |
8 | 8 |
|
9 | 9 | "github.com/argoproj/gitops-engine/pkg/health" |
| 10 | + "github.com/argoproj/gitops-engine/pkg/sync/common" |
10 | 11 |
|
11 | 12 | . "github.com/argoproj/argo-cd/v3/pkg/apis/application/v1alpha1" |
12 | 13 | . "github.com/argoproj/argo-cd/v3/test/e2e/fixture" |
|
56 | 57 | assert.False(t, sensitiveData.MatchString(diff)) |
57 | 58 | }) |
58 | 59 | } |
| 60 | + |
| 61 | +// Secret values shouldn't be exposed in error messages and the diff view |
| 62 | +// when invalid secret is synced. |
| 63 | +func TestMaskValuesInInvalidSecret(t *testing.T) { |
| 64 | + sensitiveData := regexp.MustCompile(`SECRETVAL|U0VDUkVUVkFM|12345`) |
| 65 | + |
| 66 | + Given(t). |
| 67 | + Path("empty-dir"). |
| 68 | + When(). |
| 69 | + // valid secret |
| 70 | + AddFile("secrets.yaml", `apiVersion: v1 |
| 71 | +kind: Secret |
| 72 | +metadata: |
| 73 | + name: secret |
| 74 | + annotations: |
| 75 | + app: test |
| 76 | +stringData: |
| 77 | + username: SECRETVAL |
| 78 | +data: |
| 79 | + password: U0VDUkVUVkFM |
| 80 | +`). |
| 81 | + CreateApp(). |
| 82 | + Sync(). |
| 83 | + Then(). |
| 84 | + Expect(SyncStatusIs(SyncStatusCodeSynced)). |
| 85 | + Expect(HealthIs(health.HealthStatusHealthy)). |
| 86 | + // secret data shouldn't be exposed in manifests output |
| 87 | + And(func(app *Application) { |
| 88 | + mnfs, _ := RunCli("app", "manifests", app.Name) |
| 89 | + assert.False(t, sensitiveData.MatchString(mnfs)) |
| 90 | + }). |
| 91 | + When(). |
| 92 | + // invalidate secret |
| 93 | + PatchFile("secrets.yaml", `[{"op": "replace", "path": "/data/password", "value": 12345}]`). |
| 94 | + Refresh(RefreshTypeHard). |
| 95 | + IgnoreErrors(). |
| 96 | + Sync(). |
| 97 | + Then(). |
| 98 | + Expect(SyncStatusIs(SyncStatusCodeOutOfSync)). |
| 99 | + Expect(OperationPhaseIs(common.OperationFailed)). |
| 100 | + // secret data shouldn't be exposed in manifests, diff & error output for invalid secret |
| 101 | + And(func(app *Application) { |
| 102 | + mnfs, _ := RunCli("app", "manifests", app.Name) |
| 103 | + assert.False(t, sensitiveData.MatchString(mnfs)) |
| 104 | + |
| 105 | + diff, _ := RunCli("app", "diff", app.Name) |
| 106 | + assert.False(t, sensitiveData.MatchString(diff)) |
| 107 | + |
| 108 | + msg := app.Status.OperationState.Message |
| 109 | + assert.False(t, sensitiveData.MatchString(msg)) |
| 110 | + }) |
| 111 | +} |
0 commit comments