-
Notifications
You must be signed in to change notification settings - Fork 105
fix: support authentication field in push notification config #259
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Summary of ChangesHello @Soolan, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request resolves issue #239 by implementing crucial support for the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request adds support for Bearer and Basic authentication for push notifications, which is a great enhancement. The implementation correctly handles individual authentication schemes. However, there is a logic flaw when multiple schemes are provided in the configuration, where one will always overwrite the other regardless of the intended preference. I've provided a suggestion to fix this by establishing a clear precedence. Additionally, the corresponding integration test should be strengthened to assert the specific, correct behavior.
| if (schemes.includes('Bearer')) { | ||
| headers['Authorization'] = `Bearer ${credentials}`; | ||
| } | ||
| if (schemes.includes('Basic')) { | ||
| headers['Authorization'] = `Basic ${credentials}`; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current implementation for handling authentication schemes has a flaw. If both Bearer and Basic schemes are present in the schemes array, the Authorization header will always be set to Basic because its check comes after Bearer, overwriting any previously set value. This behavior is non-obvious and likely not what's intended, as the order in the schemes array is ignored.
To make the behavior explicit and prefer one scheme over the other (e.g., Bearer is generally preferred over Basic), you should use an if-else if structure. This ensures only one authentication header is set, with a clear precedence.
if (schemes.includes('Bearer')) {
headers['Authorization'] = `Bearer ${credentials}`;
} else if (schemes.includes('Basic')) {
headers['Authorization'] = `Basic ${credentials}`;
}|
|
||
| // Check the last notification (completed) | ||
| const notification = receivedNotifications[1]; | ||
|
|
||
| // Verify Authorization header | ||
| // Since both are present, we check if at least one is present or how it behaves. | ||
| // The implementation plan says: | ||
| // if (schemes.includes("Bearer")) { headers["Authorization"] = `Bearer ${credentials}`; } | ||
| // if (schemes.includes("Basic")) { headers["Authorization"] = `Basic ${credentials}`; } | ||
| // So if both are present, Basic will overwrite Bearer. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test case for multiple authentication schemes is not specific enough. It only asserts the existence of an Authorization header, and the comments explain the implementation's flawed behavior (where Basic overwrites Bearer).
Tests should be deterministic and explicitly assert the expected outcome. Once the implementation logic is corrected to handle scheme precedence, this test should be updated to assert the exact value of the Authorization header. The explanatory comments should be removed in favor of a clear assertion.
For example, if Bearer is given precedence, the assertion should be:
assert.equal(notification.headers['authorization'], 'Bearer test-credentials');
Description
This PR fixes issue #239 by implementing support for the
authenticationfield in the push notification configuration, which was previously ignored. It adds support forBearerandBasicauthentication schemes in the [Authorization]Tests added to:
test/server/push_notification_integration.spec.ts
All 10 tests pass by running:
npm test test/server/push_notification_integration.spec.tsOutput:
Fixes #239 🦕