(t *testing.T)
| 138 | } |
| 139 | |
| 140 | func TestGetRedactedAuthHeader(t *testing.T) { |
| 141 | testCases := []struct { |
| 142 | name string |
| 143 | authHeader string |
| 144 | expected string |
| 145 | }{ |
| 146 | { |
| 147 | "normal length token partially readable for debugging", |
| 148 | "token ghp_61b296fb898349778e20532cb65ce38e", |
| 149 | "token ghp_********************************", |
| 150 | }, |
| 151 | { |
| 152 | "short token redacted", |
| 153 | "token ghp_61b29", |
| 154 | "token *********", |
| 155 | }, |
| 156 | { |
| 157 | "short header fully redacted", |
| 158 | "token xyz", |
| 159 | "*********", |
| 160 | }, |
| 161 | { |
| 162 | "no token returns empty string", |
| 163 | "", |
| 164 | "", |
| 165 | }, |
| 166 | } |
| 167 | |
| 168 | for _, testCase := range testCases { |
| 169 | t.Run(testCase.name, func(t *testing.T) { |
| 170 | req, err := http.NewRequest(http.MethodGet, "https://example.com", nil) |
| 171 | assert.NoError(t, err) |
| 172 | req.Header.Add("Authorization", testCase.authHeader) |
| 173 | assert.Equal(t, testCase.expected, getRedactedAuthHeader(req)) |
| 174 | }) |
| 175 | } |
| 176 | } |
nothing calls this directly
no test coverage detected