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

Feat/user agent enhancements/auth #11442

Conversation

erinleigh90
Copy link
Contributor

@erinleigh90 erinleigh90 commented Jun 1, 2023

Description of changes

Adds category, action, and framework to Auth calls through amazon-cognito-identity-js.

  • Sets the framework on cognito user agent in the Auth constructor to avoid duplication of framework detection code
  • Sets the Auth category in the Auth constructor both to avoid altering the cognito API surface and/or to avoid creating an internal version of cognito classes.
  • Uses the operation sent to the Cognito Client as the action value, mapped to numerical values in Constants.

Description of how you validated changes

Tested in sample app via package linking and validating the x-amz-user-agent is as expected for each action.
Thorough unit tests on CognitoUser still in progress.

Checklist

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@erinleigh90 erinleigh90 marked this pull request as ready for review June 1, 2023 20:59
@erinleigh90 erinleigh90 requested a review from a team as a code owner June 1, 2023 20:59
@erinleigh90
Copy link
Contributor Author

erinleigh90 commented Jun 1, 2023

Note: bundle size for api-graphql has been addressed in another user-agent-enhancements branch

Copy link
Contributor

@elorzafe elorzafe left a comment

Choose a reason for hiding this comment

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

Looks very good, my only concern if we need to mention this APIs are for internal use only.

Comment on lines +218 to +220
callback.onFailure.mockClear();
callback.onSuccess.mockClear();
callback.customChallenge.mockClear();
Copy link
Contributor

Choose a reason for hiding this comment

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

jest.clearAllMocks() doesnt work?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not for these specifically, that I found. Adding these lines prevented the issues with tests affecting each other. Perhaps because they are nested and imported from a separate file?

Comment on lines +11 to +34
SignUp: '1',
InitiateAuth: '2',
ConfirmSignUp: '3',
ResendConfirmationCode: '4',
GetUser: '5',
SetUserMFAPreference: '6',
SetUserSettings: '7',
AssociateSoftwareToken: '8',
VerifySoftwareToken: '9',
RespondToAuthChallenge: '10',
DeleteUserAttributes: '11',
DeleteUser: '12',
UpdateUserAttributes: '13',
GetUserAttributeVerificationCode: '14',
VerifyUserAttribute: '15',
GlobalSignOut: '16',
RevokeToken: '17',
ChangePassword: '18',
ForgotPassword: '19',
ConfirmForgotPassword: '20',
ConfirmDevice: '21',
UpdateDeviceStatus: '22',
ForgetDevice: '23',
ListDevices: '24',
Copy link
Contributor

Choose a reason for hiding this comment

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

Why strings and not numbers? Just curious

Copy link
Contributor Author

@erinleigh90 erinleigh90 Jun 2, 2023

Choose a reason for hiding this comment

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

It's been the convention we went with. Same for other categories in core/src/Platform/types. I think initially because we were not sure which format we were going to use, then I was concerned about skipping numbers, but that wouldn't actually break anything with enums or this object. We could change them all, but I would want cognito to reflect what is being done in core.

packages/amazon-cognito-identity-js/index.d.ts Outdated Show resolved Hide resolved
@AllanZhengYP AllanZhengYP self-requested a review June 2, 2023 17:26
@codecov-commenter
Copy link

codecov-commenter commented Jun 3, 2023

Codecov Report

Merging #11442 (978269a) into feat/user-agent-enhancements/main (d295bd1) will increase coverage by 0.01%.
The diff coverage is 100.00%.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

@@                          Coverage Diff                          @@
##           feat/user-agent-enhancements/main   #11442      +/-   ##
=====================================================================
+ Coverage                              83.14%   83.15%   +0.01%     
=====================================================================
  Files                                    260      260              
  Lines                                  20429    20437       +8     
  Branches                                4402     4402              
=====================================================================
+ Hits                                   16985    16995      +10     
+ Misses                                  3158     3156       -2     
  Partials                                 286      286              
Impacted Files Coverage Δ
packages/amazon-cognito-identity-js/src/Client.js 51.92% <ø> (+0.96%) ⬆️
...ckages/amazon-cognito-identity-js/src/UserAgent.js 100.00% <100.00%> (ø)
packages/auth/src/Auth.ts 87.51% <100.00%> (+0.03%) ⬆️

... and 1 file with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Contributor

@elorzafe elorzafe left a comment

Choose a reason for hiding this comment

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

Looks good!

Thanks @erinleigh90 🏅 🎶

@erinleigh90 erinleigh90 merged commit e5115ef into aws-amplify:feat/user-agent-enhancements/main Jun 5, 2023
@erinleigh90 erinleigh90 deleted the feat/user-agent-enhancements/auth branch June 5, 2023 18:00
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.

3 participants