Skip to content

Commit

Permalink
trim whitespace in header names
Browse files Browse the repository at this point in the history
  • Loading branch information
SpencerTorres committed Dec 19, 2023
1 parent ec8a4ec commit 4d7690b
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
9 changes: 5 additions & 4 deletions pkg/plugin/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,10 @@ func loadHttpHeaders(jsonData map[string]interface{}, secureJsonData map[string]
httpHeadersRaw := jsonData["httpHeaders"].([]interface{})

for _, rawHeader := range httpHeadersRaw {
header := rawHeader.(map[string]interface{})
headerName := header["name"].(string)
headerValue := header["value"].(string)
header, _ := rawHeader.(map[string]interface{})
headerName, _ := header["name"].(string)
headerName = strings.TrimSpace(headerName)
headerValue, _ := header["value"].(string)
if headerName != "" && headerValue != "" {
httpHeaders[headerName] = headerValue
}
Expand All @@ -231,7 +232,7 @@ func loadHttpHeaders(jsonData map[string]interface{}, secureJsonData map[string]

for k, v := range secureJsonData {
if v != "" && strings.HasPrefix(k, secureHeaderKeyPrefix) {
headerName := k[len(secureHeaderKeyPrefix):]
headerName := strings.TrimSpace(k[len(secureHeaderKeyPrefix):])
httpHeaders[headerName] = v
}
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/plugin/settings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ func TestLoadSettings(t *testing.T) {
"username": "baz",
"defaultDatabase":"example", "tlsSkipVerify": true, "tlsAuth" : true,
"tlsAuthWithCACert": true, "dialTimeout": "10", "enableSecureSocksProxy": true,
"httpHeaders": [{ "name": "test-plain-1", "value": "value-1", "secure": false }]
"httpHeaders": [{ "name": " test-plain-1 ", "value": "value-1", "secure": false }]
}`),
DecryptedSecureJSONData: map[string]string{
"password": "bar",
"tlsCACert": "caCert", "tlsClientCert": "clientCert", "tlsClientKey": "clientKey",
"secureSocksProxyPassword": "test",
"secureHttpHeaders.test-secure-2": "value-2",
"secureHttpHeaders.test-secure-3": "value-3",
"secureSocksProxyPassword": "test",
"secureHttpHeaders. test-secure-2 ": "value-2",
"secureHttpHeaders.test-secure-3": "value-3",
},
},
},
Expand Down
4 changes: 2 additions & 2 deletions src/components/configEditor/HttpHeadersConfig.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ describe('HttpHeadersConfig', () => {

const headerNameInput = result.getByTestId(selectors.headerNameInput);
expect(headerNameInput).toBeInTheDocument();
fireEvent.change(headerNameInput, { target: { value: 'x-test' } });
fireEvent.change(headerNameInput, { target: { value: 'x-test ' } }); // with space
fireEvent.blur(headerNameInput);
expect(headerNameInput).toHaveValue('x-test');
expect(headerNameInput).toHaveValue('x-test'); // without space
expect(onHttpHeadersChange).toHaveBeenCalledTimes(1);

const headerValueInput = result.getByTestId(selectors.headerValueInput);
Expand Down
2 changes: 1 addition & 1 deletion src/components/configEditor/HttpHeadersConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ const HttpHeaderEditor = (props: HttpHeaderEditorProps) => {
value={name}
disabled={isSecureConfigured}
placeholder={labels.headerNamePlaceholder}
onChange={(e: ChangeEvent<HTMLInputElement>) => setName(e.target.value)}
onChange={(e: ChangeEvent<HTMLInputElement>) => setName((e.target.value || '').trim())}
onBlur={() => onUpdate()}
/>
</Field>
Expand Down

0 comments on commit 4d7690b

Please sign in to comment.