Skip to content
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

fix(automotive): qr code for launching webex app #4012

Open
wants to merge 1 commit into
base: next
Choose a base branch
from

Conversation

xinhyao
Copy link
Contributor

@xinhyao xinhyao commented Nov 28, 2024

COMPLETES #SPARK-587035

This pull request addresses

It need to generate a QR Code Url as the format like native app, so that when the QRCode is scanning with camera, the QRCode can open webex app automatically.

by making the following changes

< DESCRIBE YOUR CHANGES >

Change Type

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Tooling change
  • Internal code refactor

The following scenarios were tested

< ENUMERATE TESTS PERFORMED, WHETHER MANUAL OR AUTOMATED >

I certified that

  • I have read and followed contributing guidelines

  • I discussed changes with code owners prior to submitting this pull request

  • I have not skipped any automated checks

  • All existing and new tests passed

  • I have updated the documentation accordingly


Make sure to have followed the contributing guidelines before submitting.

Summary by CodeRabbit

  • New Features

    • Introduced a QR code verification URL generation for enhanced login via the Webex app.
    • Improved the QR code login process by ensuring URLs are properly formatted with user codes.
  • Bug Fixes

    • Updated the login method to ensure correct URL generation and handling.
  • Tests

    • Added tests to verify the new QR code functionality and its integration with existing methods.

@xinhyao xinhyao requested a review from a team as a code owner November 28, 2024 02:57
Copy link

coderabbitai bot commented Nov 28, 2024

Walkthrough

The changes introduce a new private method _generateQRCodeVerificationUrl to the AuthorizationBrowserFirstParty class, which constructs a QR code verification URL based on a provided verificationUrl. This method is integrated into the existing initQRCodeLogin method, enhancing the QR code login process. Additionally, corresponding tests are updated to ensure the new functionality is properly validated, while existing logic and error handling remain unchanged.

Changes

File Change Summary
packages/@webex/plugin-authorization-browser-first-party/src/authorization.js Added method _generateQRCodeVerificationUrl(verificationUrl = '') to generate QR code verification URL. Modified initQRCodeLogin to use the new method.
packages/@webex/plugin-authorization-browser-first-party/test/unit/spec/authorization.js Added test for _generateQRCodeVerificationUrl() and modified tests for initQRCodeLogin() to validate the new functionality.

Possibly related PRs

Suggested labels

validated

Suggested reviewers

  • maxinteger
  • mickelr

Poem

🐰 In a world where codes do play,
A QR hop leads the way.
With user codes, we dance and twirl,
Unlocking magic in a whirl.
So scan away, let joy unfold,
In every pixel, a story told! 🌟

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 eslint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

warning [email protected]: This version is no longer supported. Please see https://eslint.org/version-support for other options.
warning eslint > @humanwhocodes/[email protected]: Use @eslint/config-array instead
warning eslint > file-entry-cache > flat-cache > [email protected]: Rimraf versions prior to v4 are no longer supported
warning eslint > @humanwhocodes/config-array > @humanwhocodes/[email protected]: Use @eslint/object-schema instead
warning eslint > file-entry-cache > flat-cache > rimraf > [email protected]: Glob versions prior to v9 are no longer supported
warning eslint > file-entry-cache > flat-cache > rimraf > glob > [email protected]: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
warning eslint-import-resolver-typescript > [email protected]: Glob versions prior to v9 are no longer supported
warning [email protected]: Glob versions prior to v9 are no longer supported
warning intern > [email protected]: Glob versions prior to v9 are no longer supported
warning intern > glob > [email protected]: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
warning jasmine > [email protected]: Glob versions prior to v9 are no longer supported
warning jest > @jest/core > jest-config > [email protected]: Glob versions prior to v9 are no longer supported
warning jest > @jest/core > jest-runtime > [email protected]: Glob versions prior to v9 are no longer supported
warning jest > @jest/core > @jest/reporters > [email protected]: Glob versions prior to v9 are no longer supported
warning jest > @jest/core > @jest/transform > babel-plugin-istanbul > test-exclude > [email protected]: Glob versions prior to v9 are no longer supported
warning mocha > [email protected]: Glob versions prior to v9 are no longer supported
warning mocha > glob > [email protected]: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
warning [email protected]: 16.1.1
warning wd > [email protected]: You or someone you depend on is using Q, the JavaScript Promise library that gave JavaScript developers strong feelings about promises. They can almost certainly migrate to the native JavaScript promise now. Thank you literally everyone for joining me in this bet against the odds. Be excellent to each other.

(For a CapTP with native promises, see @endo/eventual-send and @endo/captp)
warning wd > archiver > [email protected]: Glob versions prior to v9 are no longer supported
warning wd > [email protected]: request has been deprecated, see request/request#3142
warning wd > archiver > archiver-utils > [email protected]: Glob versions prior to v9 are no longer supported
warning wd > request > [email protected]: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details.
warning wd > request > [email protected]: this library is no longer supported
warning @babel/cli > [email protected]: Glob versions prior to v9 are no longer supported
warning @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-async-generator-functions instead.
warning @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-class-properties instead.
warning @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-export-namespace-from instead.
warning @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-nullish-coalescing-operator instead.
warning @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-object-rest-spread instead.
warning @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-optional-chaining instead.
warning @babel/[email protected]: 🚨 This package has been deprecated in favor of separate inclusion of a polyfill and regenerator-runtime (when needed). See the @babel/polyfill docs (https://babeljs.io/docs/en/babel-polyfill) for more information.
warning @babel/polyfill > [email protected]: core-js@<3.23.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Some versions have web compatibility issues. Please, upgrade your dependencies to the actual version of core-js.
warning @babel/runtime-corejs2 > [email protected]: core-js@<3.23.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Some versions have web compatibility issues. Please, upgrade your dependencies to the actual version of core-js.
warning babel-plugin-lodash > [email protected]: Glob versions prior to v9 are no longer supported
warning workspace-aggregator-69ee1b33-0336-4327-9b67-eec4bd2c6d5f > [email protected]: This version is no longer supported. Please see https://eslint.org/version-support for other options.
warning workspace-aggregator-69ee1b33-0336-4327-9b67-eec4bd2c6d5f > [email protected]: Glob versions prior to v9 are no longer supported
warning workspace-aggregator-69ee1b33-0336-4327-9b67-eec4bd2c6d5f > [email protected]: 16.1.1
warning workspace-aggregator-69ee1b33-0336-4327-9b67-eec4bd2c6d5f > @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-async-generator-functions instead.
warning workspace-aggregator-69ee1b33-0336-4327-9b67-eec4bd2c6d5f > @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-class-properties instead.
warning workspace-aggregator-69ee1b33-0336-4327-9b67-eec4bd2c6d5f > @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-export-namespace-from instead.
warning workspace-aggregator-69ee1b33-0336-4327-9b67-eec4bd2c6d5f > @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-nullish-coalescing-operator instead.
warning workspace-aggregator-69ee1b33-0336-4327-9b67-eec4bd2c6d5f > @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-object-rest-spread instead.
warning workspace-aggregator-69ee1b33-0336-4327-9b67-eec4bd2c6d5f > @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-optional-chaining instead.
warning workspace-aggregator-69ee1b33-0336-4327-9b67-eec4bd2c6d5f > @babel/[email protected]: 🚨 This package has been deprecated in favor of separate inclusion of a polyfill and regenerator-runtime (when needed). See the @babel/polyfill docs (https://babeljs.io/docs/en/babel-polyfill) for more information.
error [email protected]: The engine "node" is incompatible with this module. Expected version "^14 || ^16 || ^17 || ^18 || ^19". Got "22.9.0"
error Found incompatible module.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (3)
packages/@webex/plugin-authorization-browser-first-party/src/authorization.js (1)

264-264: Consider making the base URL configurable

The base URL 'https://web.webex.com/deviceAuth' is hardcoded. Consider moving it to configuration to support different environments.

-    const baseUrl = 'https://web.webex.com/deviceAuth';
+    const baseUrl = this.config.qrCodeAuthUrl || 'https://web.webex.com/deviceAuth';
packages/@webex/plugin-authorization-browser-first-party/test/unit/spec/authorization.js (2)

446-490: Enhance test coverage for _generateQRCodeVerificationUrl()

While the current test cases cover the basic scenarios, consider adding the following test cases to improve robustness:

  1. Error handling when oauth-helper service is unavailable
  2. Handling of malformed verification URLs
  3. URL encoding edge cases with special characters in userCode
it('should handle errors when oauth-helper service is unavailable', () => {
  const verificationUrl = 'https://example.com/verify?userCode=123456';
  const webex = makeWebex('http://example.com');
  
  const oauthHelperSpy = sinon.stub(webex.internal.services, 'get').throws(new Error('Service unavailable'));
  const result = webex.authorization._generateQRCodeVerificationUrl(verificationUrl);
  
  assert.equal(result, verificationUrl);
  oauthHelperSpy.restore();
});

it('should handle malformed verification URLs', () => {
  const verificationUrl = 'invalid-url';
  const webex = makeWebex('http://example.com');
  
  const result = webex.authorization._generateQRCodeVerificationUrl(verificationUrl);
  
  assert.equal(result, verificationUrl);
});

526-526: Strengthen assertions in initQRCodeLogin() test

The test verifies that _generateQRCodeVerificationUrl is called, but it should also verify:

  1. The correct parameters are passed to the method
  2. The returned URL is used appropriately in the subsequent flow

Add these assertions after line 535:

assert.calledWithExactly(webex.authorization._generateQRCodeVerificationUrl, sampleData.verification_uri);
const generatedUrl = webex.authorization._generateQRCodeVerificationUrl.firstCall.returnValue;
assert.equal(emitSpy.getCall(0).args[1].verificationUrl, generatedUrl);

Also applies to: 535-535

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between c4ba3e5 and 8bfab67.

📒 Files selected for processing (2)
  • packages/@webex/plugin-authorization-browser-first-party/src/authorization.js (2 hunks)
  • packages/@webex/plugin-authorization-browser-first-party/test/unit/spec/authorization.js (3 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
packages/@webex/plugin-authorization-browser-first-party/src/authorization.js

[error] 272-272: Illegal return statement outside of a function

(parse)


[error] 274-274: Illegal return statement outside of a function

(parse)

🔇 Additional comments (2)
packages/@webex/plugin-authorization-browser-first-party/src/authorization.js (1)

310-316: 🛠️ Refactor suggestion

Verify error handling for malformed verification URLs

The code needs to handle cases where verification_uri_complete is malformed or undefined. Consider adding error handling:

Also, verify that consumers of the qRCodeLogin event can handle potentially undefined verificationUriComplete.

-        const verificationUriComplete = this._generateQRCodeVerificationUrl(verification_uri_complete);
+        let verificationUriComplete;
+        try {
+          verificationUriComplete = this._generateQRCodeVerificationUrl(verification_uri_complete);
+        } catch (error) {
+          this.logger.warn('Failed to generate QR code verification URL', error);
+          verificationUriComplete = verification_uri_complete;
+        }
packages/@webex/plugin-authorization-browser-first-party/test/unit/spec/authorization.js (1)

Line range hint 1-1017: Overall test implementation looks good!

The test suite is well-structured with good coverage of the QR code functionality. The suggested improvements would enhance the robustness of the tests, but the current implementation is solid.

Comment on lines +256 to +276
/**
* Generate a QR code URL to launch the Webex app when scanning with the camera
* @instance
* @memberof AuthorizationBrowserFirstParty
* @param {String} verificationUrl
* @returns {String}
*/
_generateQRCodeVerificationUrl(verificationUrl = '') {
const baseUrl = 'https://web.webex.com/deviceAuth';
const match = verificationUrl.match(/[?&]userCode=([^&]+)/);
const userCode = match ? match[1] : null;

if (userCode) {
const {services} = this.webex.internal;
const oauthHelperUrl = services.get('oauth-helper');
const params = `usercode=${userCode}&oauthhelper=${oauthHelperUrl}`;
return `${baseUrl}?${encodeURIComponent(params)}`;
} else {
return verificationUrl;
}
},
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Security: Improve URL handling and parameter encoding

The URL construction needs several security improvements:

  1. Input validation for verificationUrl
  2. Proper URL encoding for all parameters
  3. Use URL constructor instead of string concatenation

Consider this safer implementation:

 _generateQRCodeVerificationUrl(verificationUrl = '') {
   const baseUrl = 'https://web.webex.com/deviceAuth';
   const match = verificationUrl.match(/[?&]userCode=([^&]+)/);
   const userCode = match ? match[1] : null;

   if (userCode) {
     const {services} = this.webex.internal;
     const oauthHelperUrl = services.get('oauth-helper');
-    const params = `usercode=${userCode}&oauthhelper=${oauthHelperUrl}`;
-    return `${baseUrl}?${encodeURIComponent(params)}`;
+    const url = new URL(baseUrl);
+    url.searchParams.set('usercode', userCode);
+    url.searchParams.set('oauthhelper', oauthHelperUrl);
+    return url.toString();
   } else {
     return verificationUrl;
   }
 },
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
/**
* Generate a QR code URL to launch the Webex app when scanning with the camera
* @instance
* @memberof AuthorizationBrowserFirstParty
* @param {String} verificationUrl
* @returns {String}
*/
_generateQRCodeVerificationUrl(verificationUrl = '') {
const baseUrl = 'https://web.webex.com/deviceAuth';
const match = verificationUrl.match(/[?&]userCode=([^&]+)/);
const userCode = match ? match[1] : null;
if (userCode) {
const {services} = this.webex.internal;
const oauthHelperUrl = services.get('oauth-helper');
const params = `usercode=${userCode}&oauthhelper=${oauthHelperUrl}`;
return `${baseUrl}?${encodeURIComponent(params)}`;
} else {
return verificationUrl;
}
},
/**
* Generate a QR code URL to launch the Webex app when scanning with the camera
* @instance
* @memberof AuthorizationBrowserFirstParty
* @param {String} verificationUrl
* @returns {String}
*/
_generateQRCodeVerificationUrl(verificationUrl = '') {
const baseUrl = 'https://web.webex.com/deviceAuth';
const match = verificationUrl.match(/[?&]userCode=([^&]+)/);
const userCode = match ? match[1] : null;
if (userCode) {
const {services} = this.webex.internal;
const oauthHelperUrl = services.get('oauth-helper');
const url = new URL(baseUrl);
url.searchParams.set('usercode', userCode);
url.searchParams.set('oauthhelper', oauthHelperUrl);
return url.toString();
} else {
return verificationUrl;
}
},
🧰 Tools
🪛 Biome (1.9.4)

[error] 272-272: Illegal return statement outside of a function

(parse)


[error] 274-274: Illegal return statement outside of a function

(parse)

Copy link

This pull request is automatically being deployed by Amplify Hosting (learn more).

Access this pull request here: https://pr-4012.d3m3l2kee0btzx.amplifyapp.com

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant