Skip to content

Commit 55e3e9f

Browse files
Allow whitespace in secret header value (#5598)
* Allow whitespace in secret header value * Addressed comments
1 parent b29a977 commit 55e3e9f

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

graphql/e2e/custom_logic/custom_logic_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,8 @@ func TestCustomQueryShouldForwardHeaders(t *testing.T) {
169169
})
170170
}
171171
172-
# Dgraph.Secret Github-Api-Token random-fake-token
173-
# Dgraph.Secret X-App-Token should-be-overriden
172+
# Dgraph.Secret Github-Api-Token "random-fake-token"
173+
# Dgraph.Secret X-App-Token "should-be-overriden"
174174
`
175175
updateSchemaRequireNoGQLErrors(t, schema)
176176
time.Sleep(2 * time.Second)
@@ -936,8 +936,8 @@ func TestCustomFieldsShouldForwardHeaders(t *testing.T) {
936936
)
937937
}
938938
939-
# Dgraph.Secret GITHUB-API-TOKEN some-api-token
940-
# Dgraph.Secret STRIPE-API-KEY some-api-key
939+
# Dgraph.Secret GITHUB-API-TOKEN "some-api-token"
940+
# Dgraph.Secret STRIPE-API-KEY "some-api-key"
941941
`
942942

943943
updateSchemaRequireNoGQLErrors(t, schema)

graphql/schema/schemagen.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,19 @@ func parseSecrets(sch string) (map[string]string, error) {
9696
continue
9797
}
9898
parts := strings.Fields(text)
99-
if len(parts) != 4 {
99+
const doubleQuotesCode = 34
100+
101+
if len(parts) < 4 {
102+
return nil, errors.Errorf("incorrect format for specifying Dgraph secret found for "+
103+
"comment: `%s`, it should be `# Dgraph.Secret key value`", text)
104+
}
105+
val := strings.Join(parts[3:], " ")
106+
if strings.Count(val, `"`) != 2 || val[0] != doubleQuotesCode || val[len(val)-1] != doubleQuotesCode {
100107
return nil, errors.Errorf("incorrect format for specifying Dgraph secret found for "+
101108
"comment: `%s`, it should be `# Dgraph.Secret key value`", text)
102109
}
103110

104-
val := strings.Trim(parts[3], `"`)
111+
val = strings.Trim(val, `"`)
105112
key := strings.Trim(parts[2], `"`)
106113
m[key] = val
107114
}

graphql/schema/wrappers_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -848,7 +848,7 @@ func TestParseSecrets(t *testing.T) {
848848
name: String!
849849
}
850850
851-
# Dgraph.Secret GITHUB_API_TOKEN some-super-secret-token
851+
# Dgraph.Secret GITHUB_API_TOKEN "some-super-secret-token"
852852
# Dgraph.Secret STRIPE_API_KEY "stripe-api-key-value"
853853
`,
854854
map[string]string{"GITHUB_API_TOKEN": "some-super-secret-token",
@@ -858,7 +858,7 @@ func TestParseSecrets(t *testing.T) {
858858
},
859859
{"should be able to parse secret where schema also has other comments.",
860860
`
861-
# Dgraph.Secret GITHUB_API_TOKEN some-super-secret-token
861+
# Dgraph.Secret GITHUB_API_TOKEN "some-super-secret-token"
862862
863863
type User {
864864
id: ID!
@@ -897,7 +897,7 @@ func TestParseSecrets(t *testing.T) {
897897
name: String!
898898
}
899899
900-
# Dgraph.Secret "GITHUB_API_TOKEN" some-super-secret-token
900+
# Dgraph.Secret "GITHUB_API_TOKEN" "some-super-secret-token"
901901
# Dgraph.Authorization X-Test-Dgraph https://dgraph.io/jwt/claims HS256 "key"
902902
# Dgraph.Secret STRIPE_API_KEY "stripe-api-key-value"
903903
`,

0 commit comments

Comments
 (0)