You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
it('throws when an API key is not a valid header value',()=>{
182
+
expect(()=>{
183
+
newApolloServer({
184
+
typeDefs,
185
+
resolvers,
186
+
apollo: {
187
+
key: 'bar▒baz▒',
188
+
},
189
+
});
190
+
}).toThrowErrorMatchingInlineSnapshot(
191
+
`"The API key provided to Apollo Server contains characters which are invalid as HTTP header values. The following characters found in the key are invalid: ▒, ▒. Valid header values may only contain ASCII visible characters. If you think there is an issue with your key, please contact Apollo support."`,
192
+
);
193
+
});
194
+
195
+
it('trims whitespace from incoming API keys and logs a warning',()=>{
196
+
constlogger=mockLogger();
197
+
expect(()=>{
198
+
newApolloServer({
199
+
typeDefs,
200
+
resolvers,
201
+
apollo: {
202
+
key: 'barbaz\n',
203
+
},
204
+
logger,
205
+
});
206
+
}).not.toThrow();
207
+
expect(logger.warn).toHaveBeenCalledWith(
208
+
'The provided API key has unexpected leading or trailing whitespace. '+
209
+
'Apollo Server will trim the key value before use.',
`The API key provided to Apollo Server contains characters which are invalid as HTTP header values. The following characters found in the key are invalid: ${invalidChars.join(
91
+
', ',
92
+
)}. Valid header values may only contain ASCII visible characters. If you think there is an issue with your key, please contact Apollo support.`,
0 commit comments