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

[RequestMock] Add a warning with a clear message when CORS validation is failed #2482

Closed
davidcunha opened this issue May 31, 2018 · 4 comments
Assignees
Labels
STATE: Auto-locked An issue has been automatically locked by the Lock bot. TYPE: enhancement The accepted proposal for future implementation.
Milestone

Comments

@davidcunha
Copy link

davidcunha commented May 31, 2018

I'm testing to mock a remote API endpoint (http://remote-api.com/api/auth?user_type=customer) that is being called with "isomorphic-fetch" when filling a form and clicking in a simple submit button. It seems that the mock is returning HTTP status 222. Does this means it can be a CORS issue? Or a bug of the RequestMock?

Tested page URL: http://localhost:3000/

Test code

const mock = RequestMock()
  .onRequestTo('http://remote-api.com/api/auth?user_type=customer')
  .respond({
    result: null,
    errors: [
      {
        message: 'Incorrect username or password.',
      },
    ],
  });

fixture('As a customer I want to be able to sign in')
  .page('http://localhost:3000/login')
  .requestHooks(mock);

test('Login with incorrect credentials', async (t) => {
  await t
    .typeText(Selector("input[name='email']"), '[email protected]')
    .typeText(Selector("input[name='password']"), 'password')
    .click(Selector("input[type='submit']"));
  const location = await t.eval(() => window.location);
  await t.expect(location.pathname).eql('/login');
});
  • operating system: Mac OS X 10.13.4
  • testcafe version: 0.20.0
  • node.js version: 8.11.1
@davidcunha
Copy link
Author

davidcunha commented May 31, 2018

By adding nock as dependency, removing RequestMock code, and adding nock standard interceptor with .reply(200, jsonMockedResponse, { 'Access-Control-Allow-Origin': '*'}); the request was correctly intercepted. But it means there must be some bug with RequestMock.

@AndreyBelym AndreyBelym added the STATE: Need clarification An issue lacks information for further research. label Jun 4, 2018
@miherlosev
Copy link
Collaborator

Hi @davidcunha

Yes, your are right. It's a CORS issue. You need to change your code as follows:

const mock = RequestMock()
  .onRequestTo('http://remote-api.com/api/auth?user_type=customer')
  .respond({
    result: null,
    errors: [
      {
        message: 'Incorrect username or password.',
      },
    ],
  }, 200, {'Access-Control-Allow-Origin': '*'});

From our side we will add a warning with a clear message for this case.

@miherlosev miherlosev added TYPE: enhancement The accepted proposal for future implementation. and removed STATE: Need clarification An issue lacks information for further research. labels Jun 4, 2018
@miherlosev miherlosev changed the title RequestMock Remote API [RequestMock] Add a warning with a clear message when CORS validation is failed Jun 4, 2018
@miherlosev miherlosev added this to the Planned milestone Jun 4, 2018
@miherlosev miherlosev modified the milestones: Planned, Sprint #13 Jun 22, 2018
@miherlosev
Copy link
Collaborator

I am working on it

@lock
Copy link

lock bot commented Mar 28, 2019

This thread has been automatically locked since it is closed and there has not been any recent activity. Please open a new issue for related bugs or feature requests. We recommend you ask TestCafe API, usage and configuration inquiries on StackOverflow.

@lock lock bot added the STATE: Auto-locked An issue has been automatically locked by the Lock bot. label Mar 28, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Mar 28, 2019
kirovboris pushed a commit to kirovboris/testcafe-phoenix that referenced this issue Dec 18, 2019
…vExpress#2482) (DevExpress#2613)

* add clear message about failed CORS validation requests (close DevExpress#2482)

* tmp

* formatting

* rename

* add condition

* fix lint
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
STATE: Auto-locked An issue has been automatically locked by the Lock bot. TYPE: enhancement The accepted proposal for future implementation.
Projects
None yet
Development

No branches or pull requests

4 participants