Sensitive output values are rendered to the console intentionally when requesting a single output.
(t *testing.T)
| 79 | // Sensitive output values are rendered to the console intentionally when |
| 80 | // requesting a single output. |
| 81 | func TestOutput_sensitive(t *testing.T) { |
| 82 | testCases := map[string]arguments.ViewType{ |
| 83 | "human": arguments.ViewHuman, |
| 84 | "json": arguments.ViewJSON, |
| 85 | "raw": arguments.ViewRaw, |
| 86 | } |
| 87 | for name, vt := range testCases { |
| 88 | t.Run(name, func(t *testing.T) { |
| 89 | streams, done := terminal.StreamsForTesting(t) |
| 90 | v := NewOutput(arguments.ViewOptions{ViewType: vt}, NewView(streams)) |
| 91 | |
| 92 | outputs := map[string]*states.OutputValue{ |
| 93 | "foo": { |
| 94 | Value: cty.StringVal("secret"), |
| 95 | Sensitive: true, |
| 96 | }, |
| 97 | } |
| 98 | diags := v.Output("foo", outputs) |
| 99 | |
| 100 | if diags.HasErrors() { |
| 101 | t.Fatalf("unexpected diagnostics: %s", diags) |
| 102 | } |
| 103 | |
| 104 | // Test for substring match here because we don't care about exact |
| 105 | // output format in this test, just the presence of the sensitive |
| 106 | // value. |
| 107 | if got, want := done(t).Stdout(), "secret"; !strings.Contains(got, want) { |
| 108 | t.Errorf("wrong result\ngot: %q\nwant: %q", got, want) |
| 109 | } |
| 110 | }) |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | // Showing all outputs is supported by human and JSON output format. |
| 115 | func TestOutput_all(t *testing.T) { |