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

Error message being raised by amplyfy authenticate v6 in cypress tests - not in production #5021

Closed
4 tasks done
s5b opened this issue Feb 20, 2024 · 16 comments
Closed
4 tasks done
Labels
question General question

Comments

@s5b
Copy link

s5b commented Feb 20, 2024

Before creating a new issue, please confirm:

On which framework/platform are you having an issue?

Vue

Which UI component?

Authenticator

How is your app built?

Vite

What browsers are you seeing the problem on?

Chrome

Which region are you seeing the problem in?

cognito-idp.ap-southeast-2.amazonaws.com

Please describe your bug.

Trying to update an integration test running with cypress.io. This test worked with Amplify V5, but pops up a dialog in the browser saying "Unknown error occurred.", and provides no other information in the console; no stack trace. This error is raised after the first POST request is sent from the browser to AWS Cognito for authentication. This application works outside of cypress. I notice one difference that outside of cypress the protocol is using http/2.0, while cypress is using http/1.1 - I don't know whether this is relevant. I realise that this error is specific to using cypress, but the failure is inside the Amplify library code. Any ideas gratefully accepted. Thanks for reading. @aws-amplify/ui-vue: 4.2.0; vue: 3.4.18; aws-amplify: 6.0.16; cypress/vue: 5.0.5; cypress: 13.6.4; chrome: 121.0.6167.139.

What's the expected behaviour?

I expect the login to succeed without throwing an unknown error in the amplify code, like it did with v5.

Help us reproduce the bug!

The following code snippet show how the Amplify code is integrated with the application. Followed by a cutdown version of the test that fails.

Again, I know this is a failure in testing, but the failure appears to be happening in the amplify code.

Code Snippet

Integration of Amplify

import {getCurrentUser, fetchAuthSession} from 'aws-amplify/auth';
import {AuthUser} from 'aws-amplify/auth/cognito';

export const getAuthUser = async (): Promise<AuthUser | undefined> => {
  return await getCurrentUser().catch(() => undefined);
};

export const getAuthToken = async (): Promise<string | undefined> => {
  return await fetchAuthSession().then((authSession) => authSession.tokens?.idToken?.toString()).catch(() => undefined);
};

Cypress test

describe('Login Smoke Tests', () => {
  it('allows login, logout, login, then navigation across navigation items.', () => {
    cy.intercept('GET', '/').as('landing-page');
    cy.intercept('GET', '/dashboard/home').as('dashboard-home');
    cy.visit('/');

    cy.wait('@landing-page');

    cy.get('input.amplify-input[name="username"]').type(Cypress.env('ADMIN_TEST_USER_ONE_USERNAME'));
    cy.get('input.amplify-input[name="password"]').type(Cypress.env('ADMIN_TEST_USER_ONE_PASSWORD'), {force: true});
    cy.get('button.amplify-button--primary').click();
    
    cy.wait('@dashboard-home');
    
    cy.get('h1').contains('Dashboard');
  });
});

Console log output

There is no console log output.

Additional information and screenshots

No response

@github-actions github-actions bot added the pending-triage Issue is pending triage label Feb 20, 2024
@esauerbo esauerbo added the being-investigated An issue or a feature-request is being investigated label Feb 20, 2024
@esauerbo
Copy link
Contributor

Hi @s5b, thanks for creating this issue. Can you provide a code snippet of your usage of the Authenticator component?

@esauerbo esauerbo added pending-response Issue is pending response from the issue requestor and removed pending-triage Issue is pending triage labels Feb 22, 2024
@esauerbo
Copy link
Contributor

Also, fyi here is our cypress implementation: https://github.com/aws-amplify/amplify-ui/tree/main/packages/e2e/cypress
if this is helpful as a reference.

@s5b
Copy link
Author

s5b commented Feb 22, 2024

Thank you for the reference. I'll have a closer look at the examples.

In the meantime, this is a code snippet for how we're integrating the UI component into our Vue application:

<script setup lang="ts">
  import {Authenticator} from '@aws-amplify/ui-vue';

  const formFields = {
    signIn: {
      username: {
        placeholder: 'Enter your email here.',
        isRequired: true,
        label: 'Email'
      },
    },
  };
</script>

<template>
  <authenticator :form-fields="formFields" :hide-sign-up="true">
    <template v-slot:sign-in-header>
      <el-alert title="You are logging into the Borrower Portal admin interface." type="warning" center show-icon />
    </template>
  </authenticator>
</template>

<style scoped lang="scss">
</style>

The el-alert is simply adding a message to the sign-in form header section using a component from the Element Plus UI library, to warn the user that they're signing in to the administration user interface of our application.

This interaction with Amplify is processed by the following code in our application:

import {getCurrentUser, fetchAuthSession} from 'aws-amplify/auth';
import { AuthUser } from 'aws-amplify/auth/cognito';

export const getAuthUser = async (): Promise<AuthUser | undefined> => {
  return await getCurrentUser().catch(() => {
    return undefined;
  });
};

export const getAuthToken = async (): Promise<string | undefined> => {
  return await fetchAuthSession().then((authSession) => {
    return authSession.tokens?.idToken?.toString();
  }).catch(() => {
    return undefined;
  });
};

I don't think we're doing anything fancy or out of the ordinary with this code.

For reference, this is the output from running npx envinfo --system --binaries --browsers --npmPackages --duplicates --npmGlobalPackages on the project:

System:
    OS: macOS 14.3.1
    CPU: (10) arm64 Apple M1 Max
    Memory: 146.33 MB / 64.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.11.0 - ~/.volta/tools/image/node/20.11.0/bin/node
    Yarn: 1.22.19 - ~/.volta/tools/image/yarn/1.22.19/bin/yarn
    npm: 10.4.0 - ~/.volta/tools/image/npm/10.4.0/bin/npm
    pnpm: 6.29.1 - ~/.volta/bin/pnpm
  Browsers:
    Chrome: 121.0.6167.139
    Safari: 17.3.1
  npmPackages:
    @aws-amplify/ui-vue: ^4.2.0 => 4.2.0
    @babel/core: 7.23.2 => 7.23.2
    @cypress/angular:  0.0.0-development
    @cypress/mount-utils:  0.0.0-development
    @cypress/react:  0.0.0-development
    @cypress/react18:  0.0.0-development
    @cypress/svelte:  0.0.0-development
    @cypress/vue: ^6.0.0 => 0.0.0-development (6.0.0)
    @cypress/vue2:  0.0.0-development
    @typescript-eslint/eslint-plugin: ^6.21.0 => 6.21.0
    @typescript-eslint/parser: ^6.21.0 => 6.21.0
    @vitejs/plugin-vue: ^5.0.4 => 5.0.4
    @vitest/coverage-istanbul: ^1.2.2 => 1.2.2
    @vue/test-utils: ^2.4.4 => 2.4.4
    aws-amplify: ^6.0.16 => 6.0.16
    aws-amplify/adapter-core:  undefined ()
    aws-amplify/analytics:  undefined ()
    aws-amplify/analytics/kinesis:  undefined ()
    aws-amplify/analytics/kinesis-firehose:  undefined ()
    aws-amplify/analytics/personalize:  undefined ()
    aws-amplify/analytics/pinpoint:  undefined ()
    aws-amplify/api:  undefined ()
    aws-amplify/api/server:  undefined ()
    aws-amplify/auth:  undefined ()
    aws-amplify/auth/cognito:  undefined ()
    aws-amplify/auth/cognito/server:  undefined ()
    aws-amplify/auth/enable-oauth-listener:  undefined ()
    aws-amplify/auth/server:  undefined ()
    aws-amplify/datastore:  undefined ()
    aws-amplify/in-app-messaging:  undefined ()
    aws-amplify/in-app-messaging/pinpoint:  undefined ()
    aws-amplify/push-notifications:  undefined ()
    aws-amplify/push-notifications/pinpoint:  undefined ()
    aws-amplify/storage:  undefined ()
    aws-amplify/storage/s3:  undefined ()
    aws-amplify/storage/s3/server:  undefined ()
    aws-amplify/storage/server:  undefined ()
    aws-amplify/utils:  undefined ()
    axios: 0.26.0 => 0.26.0
    big.js: ^6.1.5 => 6.2.1
    cypress: ^13.6.4 => 13.6.4
    date-fns: ^2.30.0 => 2.30.0
    element-plus: ^2.4.1 => 2.5.5
    eslint: ^8.56.0 => 8.56.0
    eslint-plugin-cypress: ^2.15.1 => 2.15.1
    eslint-plugin-vue: ^9.21.1 => 9.21.1
    flush-promises: ^1.0.2 => 1.0.2
    jsdom: ^24.0.0 => 24.0.0
    sass: ^1.70.0 => 1.70.0
    typescript: ^5.3.3 => 5.3.3
    vite: ^5.1.1 => 5.1.2
    vite-plugin-istanbul: ^5.0.0 => 5.0.0
    vite-tsconfig-paths: ^4.3.1 => 4.3.1
    vitest: ^1.2.2 => 1.2.2
    vue: ^3.4.19 => 3.4.19
    vue-router: ^4.2.5 => 4.2.5
    vue-tsc: ^1.8.27 => 1.8.27
  npmGlobalPackages:
    corepack: 0.23.0
    npm: 10.2.4

Again, thanks for your reply; very much appreciated.

@reesscot
Copy link
Contributor

@s5b Are you sure there is no stack trace or error message? Any error showing in the terminal when running cypress? One thing that does stick out to me is this line:
@cypress/vue: ^6.0.0 => 0.0.0-development (6.0.0)
Is this a stable release of @cypress/vue? Wonder if downgrading to 5.x could help?

@s5b
Copy link
Author

s5b commented Feb 23, 2024

Thanks for your response.

According to npmjs, it appears that this version of @cypress/vue was released at least six months ago. It doesn't appear to be marked as a beta, but as a regular release. I haven't tried downgrading to a version 5 release, but may give that a go when I'm back at work on Monday.

In the meantime, I've created a video of the application running firstly outside of Cypress in Chrome (doing a normal login, like the test), and then inside the Cypress test environment with Chrome, showing the failure. In both scenarios, the browser console is open to show any stack trace or additional error messages that may arise. The console remains the same - error free - for both scenarios.

This is the terminal output when running the test, which appears to be error free:

> borrower-admin@1.0.0 e2e:init
> npx cypress install


Cypress 13.6.4 is installed in /Users/<redacted>/Library/Caches/Cypress/13.6.4

Skipping installation:

  Pass the --force option if you'd like to reinstall anyway.

DevTools listening on ws://127.0.0.1:53595/devtools/browser/a8eecdd0-631e-47e6-bea8-9fc57528c40b
2024-02-23 23:45:00.370 Cypress[14050:1031924] WARNING: Secure coding is not enabled for restorable state! Enable secure coding by implementing NSApplicationDelegate.applicationSupportsSecureRestorableState: and returning YES.
(node:14095) ExperimentalWarning: `--experimental-loader` may be removed in the future; instead use `register()`:
--import 'data:text/javascript,import { register } from "node:module"; import { pathToFileURL } from "node:url"; register("file%3A///Users/<redacted>/Library/Caches/Cypress/13.6.4/Cypress.app/Contents/Resources/app/node_modules/ts-node/esm/transpile-only.mjs", pathToFileURL("./"));'
(Use `node --trace-warnings ...` to show where the warning was created)
GET /__/ 200 1.612 ms - -
GET /__/assets/index-bda26968.css 200 1.449 ms - -
GET /__/assets/polyfills-3023ae52.js 200 4.601 ms - -
GET /__/assets/index-660b7eaf.js 200 1.027 ms - -
GET /__cypress/runner/cypress_runner.css 200 1.167 ms - -
GET /__/assets/route-block-c0a8bdd8.js 200 1.604 ms - 45
GET /__/assets/Specs-2abe81ec.js 200 2.037 ms - 523
GET /__/assets/InlineCodeFragment-63f519c9.css 200 3.197 ms - 310
GET /__/assets/Index-f90bad12.css 200 2.829 ms - -
GET /__/assets/TrackedBanner.vue_vue_type_script_setup_true_lang-676f89b0.js 200 2.405 ms - -
GET /__/assets/InlineCodeFragment.vue_vue_type_script_setup_true_lang-302af7b0.js 200 2.350 ms - -
GET /__/assets/box-open_x48-8c0e3696.js 200 2.143 ms - -
GET /__/assets/SpecPatterns.vue_vue_type_script_setup_true_lang-f9fdfb91.js 200 2.234 ms - -
GET /__/assets/graphql-bf8001e6.js 200 1.069 ms - 535
GET /__/assets/Index-7eb97707.js 200 2.737 ms - -
GET /__/assets/SpecNameDisplay.vue_vue_type_script_setup_true_lang-88c3364d.js 200 2.655 ms - -
GET /__/assets/settings_x16-a4cabc7e.js 200 1.862 ms - -
GET /__/assets/PromoHeader.vue_vue_type_script_setup_true_lang-63e792ce.js 200 2.178 ms - -
GET /__/assets/cypress_s-29af549a.png 200 0.590 ms - 4425
GET /__/assets/chrome-98045c79.svg 200 1.908 ms - -
GET /__/assets/electron-fb07f5cc.svg 200 1.051 ms - -
GET /__/assets/edge-e54a3dc2.svg 200 1.382 ms - -
GET /__/assets/firefox-developer-edition-8f88b864.svg 200 0.688 ms - -
GET /__cypress/runner/cypress_runner.js 200 2.051 ms - -
GET /chrome-variations/seed?osname=mac&channel=stable&milestone=122 304 2376.395 ms - -
POST /ListAccounts?gpsia=1&source=ChromiumBrowser&json=standard 200 2509.827 ms - -
GET /v1/pages/ChRDaHJvbWUvMTIyLjAuNjI2MS42ORIZCXMBIJJbHGg9EgUNE1Cf1CG2B-AHwEdT2Q==?alt=proto 200 2338.857 ms - -
GET /__/assets/refresh_x16-5729131e.js 200 1.653 ms - -
GET /__/assets/Switch.vue_vue_type_script_setup_true_lang-032c0a3d.js 200 2.333 ms - -
GET /__/assets/Runner-d26b5796.css 200 2.328 ms - -
GET /__/assets/Runner-6079dcc2.js 200 2.720 ms - -
GET /__cypress/iframes/test%2Fe2e%2Fspecs%2Fsmoke.cy.ts?browserFamily=chromium 200 2.422 ms - -
GET /__cypress/tests?p=test/e2e/specs/smoke.cy.ts 200 383.416 ms - -
GET /__cypress/tests?p=test/e2e/support/e2e.ts 200 414.639 ms - -
GET /__cypress/runner/fonts/fa-solid-900.woff2 200 0.717 ms - 126828
GET / 200 154.916 ms - -
GET / 200 5.789 ms - -
GET /assets/environment.js 200 34.579 ms - -
GET /assets/thirdPartyIntegration.js 200 102.353 ms - -
GET /assets/index-DPHYc7t9.css 200 129.998 ms - -
GET /assets/index-CiFSUo0C.js 200 133.460 ms - -
GET /css2?family=Roboto:ital,wght@0,400;0,500;0,700;1,400;1,500;1,700&display=swap 200 290.778 ms - -
GET /assets/logo-DzVVxW0P.svg 404 44.773 ms - -
GET /s/roboto/v30/KFOmCnqEu92Fr1Mu4mxKKTU1Kg.woff2 200 182.224 ms - -
GET /s/roboto/v30/KFOlCnqEu92Fr1MmEU9fBBc4AMP6lQ.woff2 200 195.257 ms - -
GET /s/roboto/v30/KFOlCnqEu92Fr1MmWUlfBBc4AMP6lQ.woff2 200 191.133 ms - -
GET /v1/pages/ChRDaHJvbWUvMTIyLjAuNjI2MS42ORIgCR4zwI7mQxzWEgUNN5ze0xIFDZFhlU4hT2h6_4GpAjk=?alt=proto 200 2154.237 ms - -
OPTIONS / 204 2.762 ms - -
POST / 200 280.327 ms - -
GET /v1/pages/ChRDaHJvbWUvMTIyLjAuNjI2MS42ORIuCQ-FnzSD4NO3EgUNN5ze0xIFDZFhlU4SBQ3njUAOEgUNzkFMeiG2HFIYYjpr2xIgCR4zwI7mQxzWEgUNN5ze0xIFDZFhlU4hthxSGGI6a9sSIAmOEg4nq3z9rBIFDeeNQA4SBQ3OQUx6IbYcUhhiOmvb?alt=proto 200 2163.066 ms - -
POST /v1:GetModels?key=REDACTED 200 2275.424 ms - -

And I've run the Cypress test using Firefox Developer Edition, and get the same results as for Chrome.

Cheers, S t u a r t .

@reesscot
Copy link
Contributor

Hi @s5b,
We noticed that there was a Google API key in your comment above:

POST /v1:GetModels?key=REDACTED 200 2275.424 ms - -

I've edited the comment above to redact the key, but please be advised that should probably rotate and revoke that API key.

@reesscot
Copy link
Contributor

@s5b Are you trying to inject or mock the Amplify Auth config into the cypress session? Not quick sure what you're trying to do with your "integration of Amplify" code sample above. Are you trying to override some config?

I'm not really sure how to help here since this is only happening in cypress. My best guess is there is some environment difference between running Amplify in your cypress and prod environments.

@s5b
Copy link
Author

s5b commented Feb 27, 2024

Thank you for bring this to my attention, and for making the redaction. I redacted most of the other identifying information but obviously missed that one.

I'm not sure what is initiating that POST. Looking through our secrets store implementation, I can't find a matching secret. And searching on the Internet brings up other pages with log listings using the same key.

@reesscot
Copy link
Contributor

Watching your video, one thing that comes to mind is you may not be inspecting the right window. I believe that Cypress runs your tests in an iframe, so you should see if you can make devtools target the iframe and maybe you'll see the full error message.

@s5b
Copy link
Author

s5b commented Feb 27, 2024

@reesscot I'm deliberately not trying to mock anything in this test. It's aimed at being a smoke test for the deployed application, so it's meant to run just as it does for end-users. The endpoint for the test is the same as the endpoint that is used in the manual run of the website in the video. The only difference between the two interactions is that Cypress is doing the clickety-clinking, and not me in the automated test.

@s5b
Copy link
Author

s5b commented Feb 27, 2024

I've had a look at the available contexts in the Chrome console for the running test, and I don't see any additional information in the about the error. There are four contexts in the console, including the root page. None of them appear to have any additional information.

2024-02-27-cypressBugConsole

Further, when clicking the "Forgot your password?" link on the sign-in form , you're taken to a dialog box for you to enter your username. Submitting this form gives the following error in the dialog box, and nothing in the browser console.

2024-02-27-cypressForgotPasswordBug

It appears that all interactions with AWS Amplify Cognito are affected in this environment.

The password reset interaction works when running the website directly (outside of Cypress).

@reesscot reesscot added question General question and removed being-investigated An issue or a feature-request is being investigated pending-response Issue is pending response from the issue requestor labels Mar 4, 2024
@reesscot
Copy link
Contributor

reesscot commented Mar 5, 2024

@s5b What does the Routes dropdown say in Cypress?
CleanShot 2024-03-05 at 08 45 03

@s5b
Copy link
Author

s5b commented Mar 5, 2024

@reesscot There appears to be two entries in the routes section:
2024-03-06-cypressIssue-routesPanel

@reesscot
Copy link
Contributor

reesscot commented Mar 5, 2024

@s5b Are you seeing any network requests in devtools?

@s5b
Copy link
Author

s5b commented Mar 7, 2024

@reesscot This is the view in the network panel of the devtools. The failed network call is for the site logo, which I know is missing. The two final calls to cognito-idp.ap-southeast-2.amazonaws.com both return success (2xx) statuses. It's interesting that the initiator of the last request is from cypress_runner.js:144793. 🤔

image

@reesscot
Copy link
Contributor

Hi @s5b,
I'm going to close this issue out as there isn't much else we can help with here. It seems to be a Cypress issue, and we've been unable to reproduce it on our end. Feel free to open another issue if you need assistance with anything else.

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

No branches or pull requests

3 participants