Skip to content

Commit eb68e5f

Browse files
authored
Return an error when additional headers conflicts (#910)
1 parent b5564ea commit eb68e5f

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

cmd/src/main.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ var (
5858
// The following arguments are deprecated which is why they are no longer documented
5959
configPath = flag.String("config", "", "")
6060
endpoint = flag.String("endpoint", "", "")
61+
62+
errConfigMerge = errors.New("when using a configuration file, zero or all environment variables must be set")
63+
errConfigAuthorizationConflict = errors.New("when passing an 'Authorization' additional headers, SRC_ACCESS_TOKEN must never be set")
6164
)
6265

6366
// commands contains all registered subcommands.
@@ -154,6 +157,11 @@ func readConfig() (*config, error) {
154157
}
155158

156159
cfg.AdditionalHeaders = parseAdditionalHeaders()
160+
// Ensure that we're not clashing additonal headers
161+
_, hasAuthorizationAdditonalHeader := cfg.AdditionalHeaders["authorization"]
162+
if cfg.AccessToken != "" && hasAuthorizationAdditonalHeader {
163+
return nil, errConfigAuthorizationConflict
164+
}
157165

158166
// Lastly, apply endpoint flag if set
159167
if endpoint != nil && *endpoint != "" {
@@ -168,5 +176,3 @@ func readConfig() (*config, error) {
168176
func cleanEndpoint(urlStr string) string {
169177
return strings.TrimSuffix(urlStr, "/")
170178
}
171-
172-
var errConfigMerge = errors.New("when using a configuration file, zero or all environment variables must be set")

cmd/src/main_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,13 @@ func TestReadConfig(t *testing.T) {
151151
AdditionalHeaders: map[string]string{"foo-bar": "bar-baz", "foo": "bar"},
152152
},
153153
},
154+
{
155+
name: "additional headers SRC_HEADERS_AUTHORIZATION and SRC_ACCESS_TOKEN",
156+
envToken: "abc",
157+
envEndpoint: "https://override.com",
158+
envHeaders: "Authorization:Bearer",
159+
wantErr: errConfigAuthorizationConflict.Error(),
160+
},
154161
}
155162

156163
for _, test := range tests {

0 commit comments

Comments
 (0)