Repository navigation
fix(typescript-...): Fix basic auth without username or password - #25462
coffeemakr wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
All reported issues were addressed across 9 files
Reply with feedback, questions, or to request a fix.
View guided diff | Re-trigger cubic
Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
There was a problem hiding this comment.
1 issue found across 4 files (changes from recent commits).
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="samples/client/petstore/javascript-apollo/src/ApiClient.js">
<violation number="1" location="samples/client/petstore/javascript-apollo/src/ApiClient.js:151">
P1: `base64` is never imported or declared in this file, so `base64.encode(...)` throws a ReferenceError whenever basic auth credentials are set. This line predates the PR, but the PR now edits it and keeps the broken call. Use Node's `Buffer` instead, which needs no import.</violation>
</file>
Tip: Review your code locally with the cubic CLI to iterate faster.
View guided diff | Re-trigger cubic
| case 'basic': | ||
| if (auth.username || auth.password) { | ||
| fetchOptions.headers['Authorization'] = 'Basic ' + base64.encode(auth.username + ":" + auth.password); | ||
| fetchOptions.headers['Authorization'] = 'Basic ' + base64.encode((auth.username || "") + ":" + (auth.password || "")); |
There was a problem hiding this comment.
P1: base64 is never imported or declared in this file, so base64.encode(...) throws a ReferenceError whenever basic auth credentials are set. This line predates the PR, but the PR now edits it and keeps the broken call. Use Node's Buffer instead, which needs no import.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At samples/client/petstore/javascript-apollo/src/ApiClient.js, line 151:
<comment>`base64` is never imported or declared in this file, so `base64.encode(...)` throws a ReferenceError whenever basic auth credentials are set. This line predates the PR, but the PR now edits it and keeps the broken call. Use Node's `Buffer` instead, which needs no import.</comment>
<file context>
@@ -148,7 +148,7 @@ export default class ApiClient extends RESTDataSource {
case 'basic':
if (auth.username || auth.password) {
- fetchOptions.headers['Authorization'] = 'Basic ' + base64.encode(auth.username + ":" + auth.password);
+ fetchOptions.headers['Authorization'] = 'Basic ' + base64.encode((auth.username || "") + ":" + (auth.password || ""));
}
</file context>
| fetchOptions.headers['Authorization'] = 'Basic ' + base64.encode((auth.username || "") + ":" + (auth.password || "")); | |
| fetchOptions.headers['Authorization'] = 'Basic ' + Buffer.from((auth.username || "") + ":" + (auth.password || "")).toString('base64'); |
There was a problem hiding this comment.
I'm not familiar with apollo, so I would change only the default to an empty string.
|
CC @TiFu (2017/07) @taxpon (2017/07) @sebastianhaas (2017/07) @kenisteward (2017/07) @Vrolijkx (2017/09) @macjohnny (2018/01) @topce (2018/10) @akehir (2019/07) @petejohansonxo (2019/11) @amakhrov (2020/02) @davidgamero (2022/03) @mkusaka (2022/04) @joscha (2024/10) @KannaKim (2026/07) |
Missing password or username in multiple typescript generators concat the undefined to the string resulting in a invalid auth header.
typescript-inversify also misses a 'Basic ' prefix
PR checklist
Commit all changed files.
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*.IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
Summary by cubic
Fixes basic auth in TypeScript and JavaScript generators so a missing username or password no longer produces an invalid
Authorizationheader, and restores the missingBasicprefix in thetypescript-inversifygenerator.undefined.Javascript-Apollo,Javascript-Flowtyped, theJavascriptapollo library,typescript-angular,typescript-fetch,typescript-inversify,typescript-jquery,typescript-nestjs, andtypescript-playwrighttemplates, and regenerates affected samples.Written for commit bd78791. Summary will update on new commits.