SAP/karma-ui5

Use local ui5 server to run test: Certificate issue

Nico31300 opened this issue · 17 comments

Hello,

Context

I'm setting up a devops pipeline for my company with the project piper library. I succeed to build by UI5 application and deployed it on our SAP frontend server.

Now I'm trying to execute QUnit and OPA5 tests in the pipeline. And for this step, I'm using piper step karmaExecuteTests.

I cannot use https://sapui5.hana.ondemand.com because the access to this resource is blocked by the network, that's why i try to use a server who is on the LAN instead.

I cannot use ui5 client SAPUI5 version because the lowest available version is 1.76.0 and we are using SAPUI5 version 1.71.

Issue

When i run the command

 karma start

I have the following errors:

09 03 2021 10:58:57.304:WARN [ui5.framework]: Failed to proxy /base/resources/sap/ui/thirdparty/qunit-2.css (UNABLE_TO_GET_ISSUER_CERT_LOCALLY: unable to get local issuer certificate)
09 03 2021 10:58:57.306:WARN [ui5.framework]: Failed to proxy /base/resources/sap-ui-core.js (UNABLE_TO_GET_ISSUER_CERT_LOCALLY: unable to get local issuer certificate)
09 03 2021 10:58:57.307:WARN [ui5.framework]: Failed to proxy /resources/sap/ui/qunit/qunit-junit.js (UNABLE_TO_GET_ISSUER_CERT_LOCALLY: unable to get local issuer certificate)
09 03 2021 10:58:57.308:WARN [ui5.framework]: Failed to proxy /resources/sap/ui/thirdparty/qunit-2.js (UNABLE_TO_GET_ISSUER_CERT_LOCALLY: unable to get local issuer certificate)
09 03 2021 10:58:57.308:WARN [ui5.framework]: Failed to proxy /resources/sap/ui/qunit/qunit-coverage.js (UNABLE_TO_GET_ISSUER_CERT_LOCALLY: unable to get local issuer certificate)
Complete log
09 03 2021 11:16:45.351:DEBUG [plugin]: Loading karma-* from /home/jenkins/workspace/z2f97_e2e_jenkins_master/node_modules
09 03 2021 11:16:45.353:DEBUG [plugin]: Loading plugin /home/jenkins/workspace/z2f97_e2e_jenkins_master/node_modules/karma-chrome-launcher.
09 03 2021 11:16:45.362:DEBUG [plugin]: Loading plugin /home/jenkins/workspace/z2f97_e2e_jenkins_master/node_modules/karma-junit-reporter.
09 03 2021 11:16:45.378:DEBUG [plugin]: Loading plugin /home/jenkins/workspace/z2f97_e2e_jenkins_master/node_modules/karma-qunit.
09 03 2021 11:16:45.379:DEBUG [plugin]: Loading plugin /home/jenkins/workspace/z2f97_e2e_jenkins_master/node_modules/karma-sinon.
09 03 2021 11:16:45.380:DEBUG [plugin]: Loading plugin /home/jenkins/workspace/z2f97_e2e_jenkins_master/node_modules/karma-ui5.
09 03 2021 11:16:45.587:DEBUG [plugin]: Loading plugin /home/jenkins/workspace/z2f97_e2e_jenkins_master/node_modules/karma-webdriver-launcher.
09 03 2021 11:16:45.752:DEBUG [plugin]: Loading inline plugin defining launcher:chromeSel.
09 03 2021 11:16:45.769:DEBUG [web-server]: Instantiating middleware
09 03 2021 11:16:45.769:DEBUG [reporter]: Trying to load reporter: junit
09 03 2021 11:16:45.771:DEBUG [reporter]: Trying to load color-version of reporter: junit (junit_color)
09 03 2021 11:16:45.771:DEBUG [reporter]: Couldn't load color-version.
09 03 2021 11:16:45.820:INFO [karma-server]: Karma v6.1.2 server started at http://karma:9876/
09 03 2021 11:16:45.821:INFO [launcher]: Launching browsers chromeSel with concurrency unlimited
09 03 2021 11:16:45.826:INFO [launcher]: Starting browser chrome via Remote WebDriver
09 03 2021 11:16:45.827:DEBUG [launcher]: null -> BEING_CAPTURED
09 03 2021 11:16:45.827:DEBUG [temp-dir]: Creating temp dir at /tmp/karma-43332764
09 03 2021 11:16:45.829:DEBUG [WebDriver]: WebDriver config: {"hostname":"selenium","port":4444}
09 03 2021 11:16:45.829:DEBUG [WebDriver]: Browser capabilities: {"platform":"ANY","testName":"Karma test","tags":[],"version":"","base":"WebDriver","browserName":"chrome"}
09 03 2021 11:16:46.349:DEBUG [WebDriver]: Session ID: 59d602f086107e5b387ed66acef4c0b7
09 03 2021 11:16:46.384:DEBUG [web-server]: serving: /home/jenkins/workspace/z2f97_e2e_jenkins_master/node_modules/karma/static/client.html
09 03 2021 11:16:46.485:DEBUG [web-server]: serving: /home/jenkins/workspace/z2f97_e2e_jenkins_master/node_modules/karma/static/karma.js
09 03 2021 11:16:46.734:DEBUG [karma-server]: A browser has connected on socket Z1g9LRU1uqn4vsGnAAAB
09 03 2021 11:16:46.741:DEBUG [web-server]: upgrade /socket.io/?EIO=4&transport=websocket&sid=Cie0KKry2NITA-7DAAAA
09 03 2021 11:16:46.755:DEBUG [web-server]: serving: /home/jenkins/workspace/z2f97_e2e_jenkins_master/node_modules/karma/static/favicon.ico
09 03 2021 11:16:46.786:DEBUG [Chrome 86.0.4240.75 (Linux x86_64)]: undefined -> CONNECTED
09 03 2021 11:16:46.786:INFO [Chrome 86.0.4240.75 (Linux x86_64)]: Connected on socket Z1g9LRU1uqn4vsGnAAAB with id 43332764
09 03 2021 11:16:46.788:DEBUG [launcher]: BEING_CAPTURED -> CAPTURED
09 03 2021 11:16:46.788:DEBUG [launcher]: chrome via Remote WebDriver (id 43332764) captured in 0.967 secs
09 03 2021 11:16:46.788:DEBUG [Chrome 86.0.4240.75 (Linux x86_64)]: CONNECTED -> CONFIGURING
09 03 2021 11:16:46.813:DEBUG [middleware:karma]: custom files null null null
09 03 2021 11:16:46.814:DEBUG [middleware:karma]: Serving static request /context.html
09 03 2021 11:16:46.816:DEBUG [web-server]: serving: /home/jenkins/workspace/z2f97_e2e_jenkins_master/node_modules/karma/static/context.html
09 03 2021 11:16:46.839:DEBUG [middleware:source-files]: Requesting /base/node_modules/karma-ui5/dist/browser-bundle.js?4abf8c17c0f1093b633b1a049781676d34f86ccb
09 03 2021 11:16:46.839:DEBUG [middleware:source-files]: Fetching /home/jenkins/workspace/z2f97_e2e_jenkins_master/node_modules/karma-ui5/dist/browser-bundle.js
09 03 2021 11:16:46.840:DEBUG [web-server]: serving (cached): /home/jenkins/workspace/z2f97_e2e_jenkins_master/node_modules/karma-ui5/dist/browser-bundle.js
09 03 2021 11:16:46.841:DEBUG [web-server]: serving: /home/jenkins/workspace/z2f97_e2e_jenkins_master/node_modules/karma/static/context.js
09 03 2021 11:16:46.897:DEBUG [middleware:source-files]: Requesting /base/webapp/test/unit/unitTests.qunit.html
09 03 2021 11:16:46.897:DEBUG [middleware:source-files]: Fetching /home/jenkins/workspace/z2f97_e2e_jenkins_master/webapp/test/unit/unitTests.qunit.html
09 03 2021 11:16:46.897:DEBUG [web-server]: serving (cached): /home/jenkins/workspace/z2f97_e2e_jenkins_master/webapp/test/unit/unitTests.qunit.html
09 03 2021 11:16:46.918:DEBUG [middleware:source-files]: Requesting /base/resources/sap-ui-core.js
09 03 2021 11:16:46.918:DEBUG [middleware:source-files]: Fetching /home/jenkins/workspace/z2f97_e2e_jenkins_master/resources/sap-ui-core.js
09 03 2021 11:16:46.939:DEBUG [middleware:source-files]: Requesting /base/resources/sap/ui/thirdparty/qunit-2.css
09 03 2021 11:16:46.939:DEBUG [middleware:source-files]: Fetching /home/jenkins/workspace/z2f97_e2e_jenkins_master/resources/sap/ui/thirdparty/qunit-2.css
09 03 2021 11:16:46.942:DEBUG [middleware:source-files]: Requesting /base/webapp/resources/sap/ui/thirdparty/qunit-2.js
09 03 2021 11:16:46.942:DEBUG [middleware:source-files]: Fetching /home/jenkins/workspace/z2f97_e2e_jenkins_master/webapp/resources/sap/ui/thirdparty/qunit-2.js
09 03 2021 11:16:46.944:DEBUG [middleware:source-files]: Requesting /base/webapp/resources/sap/ui/qunit/qunit-junit.js
09 03 2021 11:16:46.945:DEBUG [middleware:source-files]: Fetching /home/jenkins/workspace/z2f97_e2e_jenkins_master/webapp/resources/sap/ui/qunit/qunit-junit.js
09 03 2021 11:16:46.947:DEBUG [middleware:source-files]: Requesting /base/webapp/resources/sap/ui/qunit/qunit-coverage.js
09 03 2021 11:16:46.947:DEBUG [middleware:source-files]: Fetching /home/jenkins/workspace/z2f97_e2e_jenkins_master/webapp/resources/sap/ui/qunit/qunit-coverage.js
09 03 2021 11:16:46.949:DEBUG [middleware:source-files]: Requesting /base/webapp/test/unit/unitTests.qunit.js
09 03 2021 11:16:46.949:DEBUG [middleware:source-files]: Fetching /home/jenkins/workspace/z2f97_e2e_jenkins_master/webapp/test/unit/unitTests.qunit.js
09 03 2021 11:16:46.949:DEBUG [web-server]: serving (cached): /home/jenkins/workspace/z2f97_e2e_jenkins_master/webapp/test/unit/unitTests.qunit.js
09 03 2021 11:16:47.137:WARN [ui5.framework]: Failed to proxy /base/resources/sap-ui-core.js (UNABLE_TO_GET_ISSUER_CERT_LOCALLY: unable to get local issuer certificate)
09 03 2021 11:16:47.139:WARN [ui5.framework]: Failed to proxy /base/resources/sap/ui/thirdparty/qunit-2.css (UNABLE_TO_GET_ISSUER_CERT_LOCALLY: unable to get local issuer certificate)
09 03 2021 11:16:47.139:WARN [ui5.framework]: Failed to proxy /resources/sap/ui/qunit/qunit-junit.js (UNABLE_TO_GET_ISSUER_CERT_LOCALLY: unable to get local issuer certificate)
09 03 2021 11:16:47.140:WARN [ui5.framework]: Failed to proxy /resources/sap/ui/thirdparty/qunit-2.js (UNABLE_TO_GET_ISSUER_CERT_LOCALLY: unable to get local issuer certificate)
09 03 2021 11:16:47.141:WARN [ui5.framework]: Failed to proxy /resources/sap/ui/qunit/qunit-coverage.js (UNABLE_TO_GET_ISSUER_CERT_LOCALLY: unable to get local issuer certificate)
09 03 2021 11:17:16.788:WARN [Chrome 86.0.4240.75 (Linux x86_64)]: Disconnected (0 times) , because no message in 30000 ms.
09 03 2021 11:17:16.789:DEBUG [Chrome 86.0.4240.75 (Linux x86_64)]: CONFIGURING -> DISCONNECTED
09 03 2021 11:17:16.792:DEBUG [launcher]: CAPTURED -> BEING_KILLED
09 03 2021 11:17:16.793:DEBUG [launcher]: BEING_KILLED -> BEING_FORCE_KILLED
09 03 2021 11:17:16.793:DEBUG [Chrome 86.0.4240.75 (Linux x86_64)]: DISCONNECTED -> DISCONNECTED
09 03 2021 11:17:16.793:DEBUG [karma-server]: Run complete, exiting.
09 03 2021 11:17:16.794:DEBUG [launcher]: Disconnecting all browsers
09 03 2021 11:17:16.795:DEBUG [launcher]: BEING_FORCE_KILLED -> BEING_FORCE_KILLED
09 03 2021 11:17:16.795:DEBUG [proxy]: Destroying proxy agents
09 03 2021 11:17:16.858:INFO [WebDriver]: Killed Karma test.
09 03 2021 11:17:16.859:DEBUG [launcher]: Process chrome via Remote WebDriver exited with code 0 and signal null
09 03 2021 11:17:16.859:DEBUG [temp-dir]: Cleaning temp dir /tmp/karma-43332764
09 03 2021 11:17:16.863:DEBUG [launcher]: Finished all browsers
09 03 2021 11:17:16.863:DEBUG [launcher]: BEING_FORCE_KILLED -> FINISHED
09 03 2021 11:17:16.863:DEBUG [launcher]: FINISHED -> FINISHED

Do you have an idea how to solve my issue ? Maybe i'm not going into the good direction.

Thank you very much for your help,

Nicolas

Files

karma.conf.js
module.exports = function (config) {
  config.set({
    //UI5 framework
    frameworks: ["ui5"],    
    
    ui5: {
    	url: "https://sap_domain_on_the_lan/sap/public/bc/ui5_ui5/",
    	htmlrunner: false,
    	testpage: "webapp/test/unit/unitTests.qunit.html",
    	config: {
    		async: true,
    		resourceRoots: {
    			"test.z2f97_e2e_jenkins": "./webapp"
    		}
    	},
    	tests: [
    		"test/z2f97_e2e_jenkins/test/unit/AllTests"
    	]
    },
    // level of logging
    // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
    logLevel: config.LOG_DEBUG,
    proxyValidateSSL: false,
    
    customLaunchers: {
        'chromeSel': {
            base: 'WebDriver',
            config: { hostname: 'selenium', port: 4444 },
            browserName: 'chrome'
        }
    },
    
    hostname: 'karma',
    port: 9876,
    
    // start these browsers
    // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
    browsers: ['chromeSel'],
    
    // Continuous Integration mode
    // if true, Karma captures browsers, runs the tests and exits
    singleRun: true,
    
    browserConsoleLogOptions: {
      level: "debug"
    },
        
    reporters: ['junit'],
    junitReporter: {
        outputFile: 'test-results-karma.xml'
    }
  });
};
package.json
{
  "name": "z2f97_e2e_jenkins",
  "version": "0.0.1",
  "description": "",
  "devDependencies": {
    "@ui5/cli": "latest",
    "@sap/ui5-builder-webide-extension": "1.0.x",
    "bestzip": "latest",
    "karma-chrome-launcher" : "latest",
	"karma-webdriver-launcher" : "latest",
	"karma-ui5" : "latest",
	"karma": "latest",
	"qunit": "latest",
	"sinon" : "latest",
	"karma-qunit" : "latest",
	"karma-sinon" : "latest",
	"karma-junit-reporter" : "latest"
  },
  "scripts": {
  	"build": "ui5 build --clean-dest --include-task=generateManifestBundle generateCachebusterInfo",
    "zip": "cp .Ui5RepositoryUploadParameters dist && cd dist && bestzip dist.zip . && mv dist.zip .. && cd ..",
    "deploy": "npm run build && npm run zip",
	"karma": "karma start"
  },
  "ui5": {
    "dependencies": [
      "@sap/ui5-builder-webide-extension"
    ]
  },
  "private": "true"
}

Hello,

I solved this issue by adding

ui5: {
      url: "https://sap_server.corp"
    },
proxies: {
      '/base/resources': 'https://sap_server.corp/sap/public/bc/ui5_ui5/resources'
    },

But now I have another issue

Fetching C:/Users/...../Downloads/z2f97_e2e_jenkins/webapp/i18n/i18n_en_US.properties
10 03 2021 18:06:55.866:WARN [ui5.framework]: Failed to proxy /i18n/i18n_en_US.properties (UNABLE_TO_GET_ISSUER_CERT_LOCALLY: unable to get local issuer certificate)

Could you please give my an advise who to solve that ? Because karma is waiting an answer for this file and the Opa5 step run in error due to timeout.

Error
Stacktrace
Unable to load the component with the name: undefined
Opa timeout after 15 seconds
This is what Opa logged:
Executing OPA check function on controls null -  sap.ui.test.Opa5
Check function is:
function(){return z;} -  sap.ui.test.Opa5
Result of check function is: false -  sap.ui.test.Opa5
Callstack:
    at f.iStartMyUIComponent (resources/sap/ui/test/Opa5.js:6:2631)
    at f.iStartMyApp (webapp/test/integration/arrangements/Startup.js:15:9)
    at Object.<anonymous> (webapp/test/integration/NavigationJourney.js:13:10)
    at Object.<anonymous> (resources/sap/ui/test/opaQunit.js:6:1706)
    at a (resources/sap/ui/thirdparty/qunit-2.js:11:13824)
    at g1.run (resources/sap/ui/thirdparty/qunit-2.js:11:13642)
    at resources/sap/ui/thirdparty/qunit-2.js:11:16532
Expected: true
Actual: false
    at resources/sap/ui/test/opaQunit.js:6:863
    at Object.<anonymous> (resources/sap/ui/test/opaQunit.js:6:1834)
    at p (resources/sap-ui-core.js:2207:25152)
    at Object.fireWith [as rejectWith] (resources/sap-ui-core.js:2207:26003)
    at Object.b.<computed> [as reject] (resources/sap-ui-core.js:2207:27003)
    at x (resources/sap/ui/test/Opa.js:6:825)

Standard Output
    Chrome 86.0.4240.75 (Linux x86_64) ERROR: '2021-03-10 16:48:40.953504 Unable to load the component with the name: undefined
Opa timeout after 15 seconds
This is what Opa logged:
Executing OPA check function on controls null -  sap.ui.test.Opa5
Check function is:
function(){return z;} -  sap.ui.test.Opa5
Result of check function is: false -  sap.ui.test.Opa5
Callstack:
    at f.iStartMyUIComponent (http://karma:9876/base/resources/sap/ui/test/Opa5.js:6:2631)
    at f.iStartMyApp (http://karma:9876/base/webapp/test/integration/arrangements/Startup.js:15:9)
    at Object.<anonymous> (http://karma:9876/base/webapp/test/integration/NavigationJourney.js:13:10)
    at Object.<anonymous> (http://karma:9876/base/resources/sap/ui/test/opaQunit.js:6:1706)
    at a (http://karma:9876/base/resources/sap/ui/thirdparty/qunit-2.js:11:13824)
    at g1.run (http://karma:9876/base/resources/sap/ui/thirdparty/qunit-2.js:11:13642)
    at http://karma:9876/base/resources/sap/ui/thirdparty/qunit-2.js:11:16532 - Opa sap.ui.test.Opa'

On the beginning i have the error for another file: Component.preload.js, i added the file and i go to the next error. But i cannot add all files manually. Normally the file should be skipped if not found. As it's done in the reality.

Thank you,

Nicolas

I try to add all requested files:

  • i18n_en_US.properties
  • i18n_en.properties
  • Component-preload.js

After that i got

Chrome 88.0.4324.190 (Windows 10): Executed 2 of 2 SUCCESS (0 secs / 5.976 secs)
Chrome 88.0.4324.190 (Windows 10): Executed 2 of 2 SUCCESS (12.667 secs / 5.976 secs)
TOTAL: 2 SUCCES

But do you have an idea to not block the Karma process if i18n files are missing ?

Hi Nicolas, it seems like your proxy destination uses a certificate that is not trusted by Node.js process by default. This is very common for certificates used inside corporate networks and there are ways to add them as trusted in the process.

To verify this, kindly try setting the environment variable NODE_TLS_REJECT_UNAUTHORIZED to 0.
Either in your shell via NODE_TLS_REJECT_UNAUTHORIZED=0 karma start (might be different on Windows) or at the beginning of your karma.conf.js:

process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = 0;

Please note that this is only to identify the root cause. We strongly discourage the use of this variable for anything other than analyzing issues like this. If this indeed resolves your issue, we should look into how you can add your corporation's root certificates as trusted to the proxy.

Hello,

I added the NODE_TLS_REJECT_UNAUTHORIZED=0 in the karma conf and in the logs i can see:

(node:12416) Warning: Setting the NODE_TLS_REJECT_UNAUTHORIZED environment variable to '0' makes TLS connections and HTTPS requests insecure by disabling certificate verification.

But i still have the same issue, if a file is not existing then

18 03 2021 12:24:48.659:DEBUG [middleware:source-files]: Fetching C:/Users/[USER]/Documents/VSCode/z2f97_e2e_jenkins/webapp/manifest.json
18 03 2021 12:24:48.660:DEBUG [web-server]: serving (cached): C:/Users/[USER]/Documents/VSCode/z2f97_e2e_jenkins/webapp/manifest.json
18 03 2021 12:24:48.675:DEBUG [middleware:source-files]: Requesting /base/webapp/i18n/i18n_en_US.properties
18 03 2021 12:24:48.676:DEBUG [middleware:source-files]: Fetching C:/Users/[USER]/Documents/VSCode/z2f97_e2e_jenkins/webapp/i18n/i18n_en_US.properties
18 03 2021 12:24:48.849:WARN [ui5.framework]: Failed to proxy /i18n/i18n_en_US.properties (UNABLE_TO_GET_ISSUER_CERT_LOCALLY: unable to get local issuer certificate)

If i create this file, then everything run fine.

Do you have an idea ?

I found as solution : add a proxy on /base to /base

    proxies: {
      '/base/resources': {
        'target': 'https://sapui5.hana.ondemand.com/1.71.35/resources',
        'changeOrigin': true 
      },
      '/base' : '/base'
    },

But for me it's not optimal, because if i check in debug i can see all request are going through the proxy and i think it's not very good. I changed from my company sap server to sapui5.hana.ondemand.com just for the demo, but it's the same behavior with both.

If you have some remarks, or maybe a better way to achieve my goal :)

Thank you very much for your time.

Nicolas

matz3 commented

With regards to the certificate issue, the changeOrigin setting should usually solve the problem.
I don't quite understand why the proxy from /base to /base helps and that also doesn't sound like a good solution to me.

Which karma-ui5 version are you using? I wonder because the htmlrunner config you are using only existed in the v1.x-beta releases.
A minimal running example would be very helpful for us to reproduce this.

Hello,

The karma-ui5 version is 2.3.3, I don't remember why I used this config parameter htmlrunner but i don't use it.

I prepare you this repo for help you in the investigation
https://github.com/Nico31300/karma-ui5-test

You will see by executing npm run karma in the network tab the request to component-preload.js will be pending.

Hope it will help you.

Thanks and regards,

Nicolas

I did the same test from my personal computer, and everything went well. The only difference I can see is the proxy defined on my company device... i don't know how to go further.

matz3 commented

@Nico31300 thanks for providing the example project.
What I could find out is that the relative paths pointing to the UI5 resources/ folder are one level to "high".

For example, webapp/index.html uses resources/sap-ui-core.js as a path to the UI5 bootstrap, which is correct.
In webapp/test/unit/unitTests.qunit.html the path is ../../../resources/sap-ui-core.js which points to a folder outside of the webapp folder.
After replacing all the findings of ../../../resources/ with ../../resources/ I could successfully run the tests without the need of any proxies configuration. UI5 is loaded from the system provided by the ui5.url path.
You can also checkout the openui5-sample-app for an example on how to relative paths should be.

I hope that this also solves your initial issue with the certificate.
The proxy used within the karma-ui5 plugin (via the ui5.url config) should function the same way as a proxy configured in the karma proxies configuration. Both are using the same proxy module and karma-ui5 is also using the changeOrigin: true config.

@matz3 Thank you for you answer and sorry for the delay in my answer.

I tried to change my relative paths but i still have the same issue, i think we don't have the same behavior because i'm using SAPUI5 resources from a SAP System on premise, and not from https://sapui5.hana.ondemand.com/.

And if i don't use a proxy, then resources are not found by karma.

I will try to clone the openui5-sample-app and use my karma configuration.

          url: "https://sap.system.intra.corp"

I will let you know about my tests.

Thanks & Regards,

Nicolas

It's the same thing with openui5-sample-app application

12 04 2021 20:21:44.991:WARN [ui5.framework]: Failed to proxy /resources/sap/ui/qunit/qunit-redirect.js (SELF_SIGNED_CERT_IN_CHAIN: self signed certificate in certificate chain)

I will try tomorrow to do it on my personal computer not behind a proxy then...

matz3 commented

The error says that the certificate is self-signed and untrusted. Do you also get a warning/error when opening an URL of that system in your browser?

I think this is not an issue with the plugin but with the certificate configuration. Your machine needs to trust the server certificate to get the proxy working.
This is a common issue that can occur with many tools connecting via HTTPS/SSL and usually the certificate validation is enabled.
For Node.js there are different way to solve this, e.g. via the "NODE_EXTRA_CA_CERTS" env var to specify a CA cert or via "NODE_TLS_REJECT_UNAUTHORIZED=0" env var to disable the checks (not recommented).

Hope this helps 👍🏻

Closing this issue, as I don't see an issue with the plugin. It is properly able to proxy HTTPS/SSL requests (e.g. to https://ui5.sap.com or other UI5 hosted endpoints)

Hi @matz3,

The issue come from the http-proxy package.

When you create the proxy server here:
https://github.com/SAP/karma-ui5/blob/14ceb3bb08a9b55511c643547f60c7cb907bd798/lib/framework.js

const {protocol} = parseUrl(url);
		const Agent = protocol === "https:" ? https.Agent : http.Agent;
		const agent = new Agent({keepAlive: true});
		const proxy = httpProxy.createProxyServer({
			target: url,
			changeOrigin: true,
			agent
		});

by default the option secure is to true, i agree it's normal.

I developed a small node program to test it on my network, by copying your createProxySerer block.

const https = require("https");
const http = require("http");
const httpProxy = require("http-proxy");
const {parse: parseUrl} = require("url");
const express = require('express');
const PORT = 3000;
const HOST = "localhost";

const proxy = ( url ) => {
    const {protocol} = parseUrl(url);
    const Agent = protocol === "https:" ? https.Agent : http.Agent;
    const agent = new Agent({keepAlive: true});
    const proxy = httpProxy.createProxyServer({
        target: url,
        changeOrigin: true,
        agent,
        secure: false
    });

    proxy.on("error", (err, req ) => {
        console.log(`Failed to proxy ${req.url} (${err.code}: ${err.message})`);
    });

    proxy.on('proxyRes', function (proxyRes, req, res) {
        console.log('RAW Response from the target', JSON.stringify(proxyRes.headers, true, 2));
    });
    return (req, res) => {
        proxy.web(req, res);
    }
}

// Create Express Server
const app = express();
app.use('/proxy_test', proxy("https://my_url_in_https"));

// Configuration
app.listen(PORT, HOST, () => {
    console.log(`Starting Proxy at ${HOST}:${PORT}`);
});

With the option secure = true i have the error Failed to proxy / (UNABLE_TO_GET_ISSUER_CERT_LOCALLY: unable to get local issuer certificate) and with secure = false i don't have any error.

Do you think it's possible to add to karma-ui5 the possibility to pass this parameter to false ?

Thank you very much for your work and time.

Regards,

Nicolas

matz3 commented

Have you tested the two environment variables that I've mentioned?
If they work, I'd be in favor of them instead of adding a new option.
Especially as providing a CA cert (via NODE_EXTRA_CA_CERTS) sounds like a better solution than to ignore invalid certificates.

Hello,

In fact i think i was using it badly.

In the karma.conf file i added:

process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = 0;

And in the terminal i saw the warning
(node:22788) Warning: Setting the NODE_TLS_REJECT_UNAUTHORIZED environment variable to '0' makes TLS connections and HTTPS requests insecure by disabling certificate verification.
So for me it was taken in to account.

So I did the same and i added

process.env["NODE_EXTRA_CA_CERTS"] = "C:\Users\Documents\1.pem";

But it's not working. I still can see the error Failed to proxy /resources/sap/ui/qunit/qunit-redirect.js

But if I do in the terminal:

$env:NODE_EXTRA_CA_CERTS="C:\Users\Documents\1.pem"; npm run karma

Now i don't see the error anymore.

Do you know how i can pass this configuration (NODE_EXTRA_CA_CERTS="C:\Users\Documents\1.pem") directly in the karma.conf file ?

Thank you, i'm really close to stop annoying you :)

Nicolas

matz3 commented

I think that's because NODE_EXTRA_CA_CERTS gets evaluated by the node binary and thus can't be set from a script executed by Node.js.

npm scripts are executed within a new process, so it should be possible to set the variable from there. cross-env can help doing so while ensuring cross-platform compatiblity.

Thanks @matz3

For the records the following is working:

scripts: {
    "karma": "cross-env NODE_EXTRA_CA_CERTS=C:/Users/Documents/1.pem karma start"
}