Qytera-Gmbh / cypress-xray-plugin

A plugin for uploading Cypress test results to Xray.
https://qytera-gmbh.github.io
MIT License
21 stars 7 forks source link

Jira cloud returns 502 on remote server but not on local machine #315

Closed dekimpeb closed 4 months ago

dekimpeb commented 5 months ago

Hey,

I'm using your plugin and it's really easy to install.

I've set it up locally first in order to get it working. Once working, I commited everything en tried it on our remote server but the plugin doesn't seem to be able to communicate with our jira cloud instance. We retrieve the following error: Error: Failed to establish communication with Jira: https://REDACTED.atlassian.net Request failed with status code 502

On my local machine it works.

I've tried with the following variable but didn't work either.

openSSL: { secureOptions: constants.SSL_OP_LEGACY_SERVER_CONNECT, },

Also tried with rootCAPath but didn't work, which certificate is required here?

Do you have any idea what the problem might be?

Thanks in advance.

Kind Regards, Bart

csvtuda commented 5 months ago

Hi Bart,

thanks for raising this issue. It's interesting that you managed to set it up locally just fine, while still running into errors remotely.

The 502 Bad Gateway makes me think that there's something in between your remote server and the Jira Cloud instance preventing the communication, such as a firewall or other restrictions.

I don't yet think that the plugin is at fault. Can you try the following?

Use curl to ping your Jira Cloud instance from the remote server without using the plugin

For example by executing the following curl command inside a terminal:

#!/bin/sh
curl -I https://REDACTED.atlassian.net/rest/api/latest/myself

# Should print the following if Jira Cloud is reachable:

# HTTP/1.1 401 Unauthorized
# Date: Tue, 30 Apr 2024 15:34:42 GMT
# Content-Type: text/html;charset=UTF-8
# Content-Length: 53
# ...

Use Node.js to ping your Jira Cloud instance from the remote server without using the plugin

For example by running the following script on the remote server:

// getJira.js
const https = require('node:https');

https.get('https://REDACTED.atlassian.net/rest/api/latest/myself', (res) => {
  console.log('statusCode:', res.statusCode);
  console.log('headers:', res.headers);

  res.on('data', (d) => {
    process.stdout.write(d);
  });

}).on('error', (e) => {
  console.error(e);
}); 

Then, inside a terminal:

#!/bin/sh
node getJira.js

# Should print the following if Jira Cloud is reachable:

# statusCode: 401
# headers: {
#   date: 'Tue, 30 Apr 2024 15:51:10 GMT',
#   'content-type': 'text/plain;charset=UTF-8',
#   'content-length': '53',
# ...

Both versions should ideally return 401 Unauthorized instead of 502 Bad Gateway. If the Node.js version fails but the curl command doesn't, then your Node.js installation might not be allowed to communicate with resources outside of your infrastructure.

dekimpeb commented 5 months ago

Hey,

both give an error. curl: (28) Failed to connect to REDACTED.atlassian.net port 443 after 63069 ms: Couldn't connect to server

second: AggregateError [ETIMEDOUT]: at internalConnectMultiple (node:net:1114:18) at afterConnectMultiple (node:net:1667:5) { code: 'ETIMEDOUT',

Error: connect ETIMEDOUT xxx.xxx.xxx.36:443
    at createConnectionError (node:net:1634:14)
    at Timeout.internalConnectMultipleTimeout (node:net:1685:38)
    at listOnTimeout (node:internal/timers:575:11)
    at process.processTimers (node:internal/timers:514:7) {
  errno: -4039,
  code: 'ETIMEDOUT',
  syscall: 'connect',
  address: 'xxx.xxx.xxx.36',
  port: 443
},
Error: connect ETIMEDOUT xxx.xxx.xxx.38:443
    at createConnectionError (node:net:1634:14)
    at Timeout.internalConnectMultipleTimeout (node:net:1685:38)
    at listOnTimeout (node:internal/timers:575:11)
    at process.processTimers (node:internal/timers:514:7) {
  errno: -4039,
  code: 'ETIMEDOUT',
  syscall: 'connect',
  address: 'xxx.xxx.xxx.38',
  port: 443
},
Error: connect ETIMEDOUT xxx.xxx.xxx.37:443
    at createConnectionError (node:net:1634:14)
    at afterConnectMultiple (node:net:1664:40) {
  errno: -4039,
  code: 'ETIMEDOUT',
  syscall: 'connect',
  address: 'xxx.xxx.xxx.37',
  port: 443
}

] }

Kr, Bart

Op di 30 apr 2024 om 17:54 schreef Basti @.***>:

Hi Bart,

thanks for raising this issue. It's interesting that you managed to set it up locally just fine, while still running into errors remotely.

The 502 Bad Gateway makes me think that there's something in between your remote server and the Jira Cloud instance preventing the communication, such as a firewall or other restrictions.

I don't yet think that the plugin is at fault. Can you try the following? Try to reach your Jira Cloud instance from the remote server without using the plugin

For example by executing the following curl command:

Run this in a shell

curl -I https://REDACTED.atlassian.net/rest/api/latest/myself

Should print the following if Jira Cloud is reachable:

HTTP/1.1 401 Unauthorized# Date: Tue, 30 Apr 2024 15:34:42 GMT# Content-Type: text/html;charset=UTF-8# Content-Length: 53# ...

Try to ping your Jira Cloud instance from Node.js without using the plugin

For example by running the following script:

// getJira.jsconst https = require('node:https'); https.get('https://REDACTED.atlassian.net/rest/api/latest/myself', (res) => { console.log('statusCode:', res.statusCode); console.log('headers:', res.headers);

res.on('data', (d) => { process.stdout.write(d); }); }).on('error', (e) => { console.error(e);});

node getJira.js

Should print the following if Jira Cloud is reachable:

statusCode: 401# headers: {# date: 'Tue, 30 Apr 2024 15:51:10 GMT',# 'content-type': 'text/plain;charset=UTF-8',# 'content-length': '53',# ...

If this fails but the curl command doesn't, then your Node.js installation might not be allowed to communicate with resources outside of your infrastructure.

— Reply to this email directly, view it on GitHub https://github.com/Qytera-Gmbh/cypress-xray-plugin/issues/315#issuecomment-2085745868, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAOVWIQWB233RD4UPNSG3HDY765CHAVCNFSM6AAAAABHAJMYA6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAOBVG42DKOBWHA . You are receiving this because you authored the thread.Message ID: @.***>

csvtuda commented 5 months ago

It really looks like something is blocking access to your Jira instance on the remote server. Even if the REDACTED part in your URLs contained a typo, you would still get a 404 Not Found response from Jira. But you're entirely unable to establish connections.

I suggest you talk to the ones responsible for managing the infrastructure in your company and bring up this topic again. Maybe there's an admin for the remote server or a networking/firewall person you could ask.

Apart from that I'm afraid I can't help you further, it's definitely not an issue with the plugin.

I will leave the issue open for now, feel free to close it once the situation is resolved.

dekimpeb commented 5 months ago

Hey,

Yeah I thought something like that.

But the weird thing is, we also use Ranorex (another automation tool) for other stuff and i've written some code there in C# to also update the xray tests in the same Jira instance and that works just fine. I would imagine that if I can reach our jira instance through a RestClient with C# that I also would be able to reach it through NodeJS.

But will look into it.

Thanks anyways!

Kr, Bart

dekimpeb commented 5 months ago

Hey,

I've managed to get the curl-way and the getJira way working.

Curl way through setting the Proxy server and the getJira.js way trough the use of the node-global-proxy package.

But can't seem to get it working in cypress itself, you got any ideas?

Kr, Bart

csvtuda commented 5 months ago

There's official Cypress proxy documentation here: https://docs.cypress.io/guides/references/proxy-configuration

I assume you will need to set up the following environment variable:

#!/bin/sh
HTTP_PROXY=http://username:password@proxy-ip-or-url:port npx cypress run

Unfortunately, even if you manage to get Cypress running, the plugin will not work. It's not (yet) possible to configure a proxy server from outside. I will need to expose the axios HTTP configuration in the options, I guess (see #322).

dekimpeb commented 5 months ago

Yeah, without the plugin Cypress works just fine.

So it won't work right now?

Do you have any idea when you will have time to build in the axios HTTP configuration?

Kr, Bart

Op zo 5 mei 2024 om 01:31 schreef Basti @.***>:

There's official Cypress proxy documentation here: https://docs.cypress.io/guides/references/proxy-configuration

Unfortunately, event if you manage to get Cypress running, the plugin will not work. It's not (yet) possible to configure a proxy server from outside. I will need to expose the axios HTTP configuration https://axios-http.com/docs/req_config in the options, I guess.

— Reply to this email directly, view it on GitHub https://github.com/Qytera-Gmbh/cypress-xray-plugin/issues/315#issuecomment-2094501105, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAOVWIXTTMLRMMUKSJXEN2DZAVVUVAVCNFSM6AAAAABHAJMYA6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAOJUGUYDCMJQGU . You are receiving this because you authored the thread.Message ID: @.***>

csvtuda commented 5 months ago

So it won't work right now?

No, the current version won't work 😕

Do you have any idea when you will have time to build in the axios HTTP configuration?

I think the new version should be released within the next 2-3 days. Your change is basically done already, but:

dekimpeb commented 5 months ago

Hey,

I really want to thank you for the quick answers and that you're willing to provide a solution for my problem!

Kr, Bart

Op zo 5 mei 2024 13:34 schreef Basti @.***>:

So it won't work right now?

No, the current version won't work.

Do you have any idea when you will have time to build in the axios HTTP configuration?

I think the new version should be released within the next 2-3 days. Your change is basically done already, but:

— Reply to this email directly, view it on GitHub https://github.com/Qytera-Gmbh/cypress-xray-plugin/issues/315#issuecomment-2094769960, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAOVWIS22DACSWOEKP5VZVLZAYKMTAVCNFSM6AAAAABHAJMYA6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAOJUG43DSOJWGA . You are receiving this because you authored the thread.Message ID: @.***>

csvtuda commented 4 months ago

Hey @dekimpeb,

sorry for the delay, writing tests for #314 turned out to be a lot more difficult than I had expected.

I just released version 7.0.0, which includes the new http settings. For a list of breaking changes, please see here.


As for your issue, you should now be able to configure proxies:

// ...
async setupNodeEvents(on, config) {
  await configureXrayPlugin(
    on,
    config,
    {
      // ...
      http: {
        proxy: {
          host: "https://example.org",
          port: 1234,
          auth: {
            username: 'john',
            password: 'supersecret'
          }
        }
      }
    }
  );
}

Let me know if the new version works as expected and/or fixes your issue.

dekimpeb commented 4 months ago

Hey,

You really don't need to apologize! I'm really gratefull that you're doing this!

I will try this tomorrow and will let you know. 1 question though, are credentials necessary or are they optional?

Kr, Bart

Op ma 13 mei 2024 21:42 schreef Basti @.***>:

Hey @dekimpeb https://github.com/dekimpeb,

sorry for the delay, writing tests for #314 https://github.com/Qytera-Gmbh/cypress-xray-plugin/issues/314 turned out to be a lot more difficult than I had expected.

I just released version 7.0.0 https://www.npmjs.com/package/cypress-xray-plugin/v/7.0.0, which includes the new http settings.

For a list of breaking changes, please see here https://github.com/Qytera-Gmbh/cypress-xray-plugin/blob/main/CHANGELOG.md#700 .

As for your issue, you should now be able to configure proxies https://qytera-gmbh.github.io/projects/cypress-xray-plugin/section/configuration/http/ :

import { Agent } from "node:https";// ...async setupNodeEvents(on, config) { await configureXrayPlugin( on, config, { // ... http: { proxy: { host: "https://example.org", port: 1234, auth: { username: 'john', password: 'supersecret' } } } } );}

Let me know if the new version works as expected and/or fixes your issue.

— Reply to this email directly, view it on GitHub https://github.com/Qytera-Gmbh/cypress-xray-plugin/issues/315#issuecomment-2108665838, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAOVWIT25HAXLAUVSGD7BQLZCEJUFAVCNFSM6AAAAABHAJMYA6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMBYGY3DKOBTHA . You are receiving this because you were mentioned.Message ID: @.***>

csvtuda commented 4 months ago

1 question though, are credentials necessary or are they optional?

No, not at all necessary. You can configure anything axios allows you to configure. Anything you set there gets passed straight through to axios without further modification.

// ...
async setupNodeEvents(on, config) {
  await configureXrayPlugin(
    on,
    config,
    {
      // ...
      http: {
        proxy: {
          host: "https://example.org",
          port: 1234
        }
      }
    }
  );
}

Even custom HTTP agents:

import { Agent } from "node:https";

// ...
async setupNodeEvents(on, config) {
  await configureXrayPlugin(
    on,
    config,
    {
      // ...
      http: {
        httpsAgent: new Agent({
          // ...
        })
      }
    }
  );
}

It's also possible to specify HTTP options for Jira or Xray only:

// ...
async setupNodeEvents(on, config) {
  await configureXrayPlugin(
    on,
    config,
    {
      // ...
      http: {
        jira: {
          proxy: {
            host: "https://example.org",
            port: 1234
          }
        }
      }
    }
  );
}

I hope the documentation contains all the information you need to solve the problem. If not feel free to ask so I can update it accordingly!

dekimpeb commented 4 months ago

Thanks!

Like I said, will try it out tomorrow. Any way I can thank you?

Kr, Bart

Op ma 13 mei 2024 22:01 schreef Basti @.***>:

1 question though, are credentials necessary or are they optional?

No, not at all. You can configure anything axios allows you to configure. Anything you set there gets passed straight through to axios without further modification.

// ...async setupNodeEvents(on, config) { await configureXrayPlugin( on, config, { // ... http: { proxy: { host: "https://example.org", port: 1234 } } } );}

Even custom HTTP agents:

import { Agent } from "node:https"; // ...async setupNodeEvents(on, config) { await configureXrayPlugin( on, config, { // ... http: { httpsAgent: new Agent({ // ... }) } } );}

It's also possible to specify HTTP options for Jira or Xray only:

// ...async setupNodeEvents(on, config) { await configureXrayPlugin( on, config, { // ... http: { jira: { proxy: { host: "https://example.org", port: 1234 } } } } );}

I hope the documentation contains all the information you need to solve the problem. If not feel free to ask so I can update it accordingly!

— Reply to this email directly, view it on GitHub https://github.com/Qytera-Gmbh/cypress-xray-plugin/issues/315#issuecomment-2108693757, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAOVWIXVIXMI4EN6I5RY3XTZCELYXAVCNFSM6AAAAABHAJMYA6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMBYGY4TGNZVG4 . You are receiving this because you were mentioned.Message ID: @.***>

csvtuda commented 4 months ago

Haha I'd actually say let's wait and see if this really does fix things. Apart from that no, not really. If the plugin makes your life easier then that's all I need to know. And your feedback helped a lot already.

dekimpeb commented 4 months ago

Hey,

I've tried it but with no luck.

When using it like this:

http: { proxy:{ host: 'http://proxy-srv.*****.*****', port: 8080 } }

I get the following error: getaddrinfo ENOTFOUND http://proxy-srv.*****.*****

Kr, Bart

csvtuda commented 4 months ago

Hi, so I think what you need to figure out is how to get the following code snippet running on your remote server:

const axios = require("axios");

async function performRequest() {
    try {
        const { data, headers, status, statusText } = await axios.get("https://your-jira-url.com", {
            // Your options here...
            // See: https://axios-http.com/docs/req_config
        });
        console.log(data, headers, status, statusText);
    } catch (error) {
        console.error(error);
    }
}

void performRequest();

Whatever options you pass to axios there you will also need to configure in the plugin.

To run it, you might want to create a mini project:

#!/bin/sh
mkdir mini-project && cd mini-project
npm init -y
npm i axios
# create request.js script with content from above
# ...
node request.js

I can't do anything here unless:

dekimpeb commented 4 months ago

Thanks, I've tried but couldn't find a way...

The weird thing is though, if I put I do the request through cy;request() I get a status code 200. So that way it seems to be working.

This is the code:

cy.request('https://**ourjirainstance**.atlassian.net').then((response) => {
  cy.log(response.status)
})
csvtuda commented 4 months ago

Sorry to hear that it's not working. But at this point, I can't help you further, you will need to figure it out somehow. There's something either in your Node.js runtime environment or between it and the outside world causing these issues. A firewall rule, a DNS resolver, some gateway... Or axios itself is buggy, I don't know. Maybe check the issues over there?

dekimpeb commented 4 months ago

Hey,

Thanks for trying to help me.

I dont seem to get it working.

I've written my own plugin using the node https library and that works.

So i will close this issue.

Thanks again!