|
| 1 | +// Copyright (c) 2020 The Jaeger Authors. |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +package app |
| 16 | + |
| 17 | +import ( |
| 18 | + "net/http" |
| 19 | + "net/http/httptest" |
| 20 | + "testing" |
| 21 | + |
| 22 | + "github.com/stretchr/testify/assert" |
| 23 | +) |
| 24 | + |
| 25 | +func TestAdditionalHeadersHandler(t *testing.T) { |
| 26 | + |
| 27 | + additionalHeaders := http.Header{} |
| 28 | + additionalHeaders.Add("Access-Control-Allow-Origin", "https://mozilla.org") |
| 29 | + additionalHeaders.Add("Access-Control-Expose-Headers", "X-My-Custom-Header") |
| 30 | + additionalHeaders.Add("Access-Control-Expose-Headers", "X-Another-Custom-Header") |
| 31 | + additionalHeaders.Add("Access-Control-Request-Headers", "field1, field2") |
| 32 | + |
| 33 | + emptyHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 34 | + w.Write([]byte{}) |
| 35 | + }) |
| 36 | + |
| 37 | + handler := additionalHeadersHandler(emptyHandler, additionalHeaders) |
| 38 | + server := httptest.NewServer(handler) |
| 39 | + defer server.Close() |
| 40 | + |
| 41 | + req, err := http.NewRequest("GET", server.URL, nil) |
| 42 | + assert.NoError(t, err) |
| 43 | + |
| 44 | + resp, err := httpClient.Do(req) |
| 45 | + assert.NoError(t, err) |
| 46 | + |
| 47 | + for k, v := range additionalHeaders { |
| 48 | + assert.Equal(t, v, resp.Header[k]) |
| 49 | + } |
| 50 | +} |
0 commit comments