[英]How to ignore ssl certificate warning or pass a self signed certificate (from inside gruntfile) during accessibility automation?
I am using the grunt-accessibility plugins to automate the reporting for accessibility
errors. 我正在使用grunt-accessibility插件自动报告accessibility
错误。 It works fine for normally, but when I try it on a site which has a self signed certificate
(the kind which shows an interim
page with some certificate security warning and a link to continue to the site if you still wish to), it reports the error on that interim
page itself which is, of course an empty page: 它通常工作正常,但是当我在具有self signed certificate
的网站上尝试它时(显示带有一些证书安全警告的interim
页面的类型以及如果您仍希望继续访问该网站的链接),它会报告interim
页面本身的错误,当然是一个空页面:
<html>
<head></head>
<body></body>
</html>
Obviously I want to bypass this interim page and run accessibility
on the actual page. 显然,我想绕过这个临时页面并在实际页面上运行accessibility
。
What I was trying? 我在尝试什么?
I had tried the following (found from googling and from other SO's
Q&A): 我曾尝试过以下内容(通过谷歌搜索和其他SO's
问答):
The infamous hack 臭名昭着的黑客
npm set strict-ssl false
Adding the imported certification path 添加导入的证书路径
npm config set cafile="C:\\path\\to\\cert.cer"
Adding process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"
(see Grunfile
below) 添加process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"
(参见下面的Grunfile
)
From what I gather, grunt-accessibility
uses AccessSniff
which in turn uses phantomjs
. 从我收集的内容来看, grunt-accessibility
使用的是AccessSniff
,后者又使用了phantomjs
。 Now, phantomjs
has options to ignore such warnings by 现在, phantomjs
可以选择忽略这些警告
--ignore-ssl-errors=[true|false]
ignores SSL errors, such as expired or self-signed certificate errors (default is false).--ignore-ssl-errors=[true|false]
忽略SSL错误,例如过期或自签名证书错误(默认为false)。
Above is the CLI options, which I am not able to pass from Grunfile.js
. 以上是CLI选项,我无法从Grunfile.js
传递。 Can someone help me resolve or suggest another approach for the issue. 有人可以帮我解决或提出另一种方法来解决这个问题。
This is my Gruntfile.js: 这是我的Gruntfile.js:
module.exports = grunt => {
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
grunt.initConfig({
phantomjs: {
// default: {
options: {
"ignore-ssl-errors": true,
// tested here with different instructions as per comments
// below from users on this site, such as
// "--ignore-ssl-errors": true (-- hyphen)
// "ignore-ssl-errors": "true" ("true" as string)
"ssl-protocol": "any",
"ssl-certificates-path": "C:/path/to/cert.cer"
}
// }
},
accessibility: {
options: {
force: true,
accessibilityLevel: 'WCAG2AAA',
browser: true // tested with both true/false, i.e. opt for phantomjs/jsDom
},
test: {
options: {
urls: ['https://self-signed.badssl.com/']
},
src: ['example/test.html']
}
}
});
grunt.loadNpmTasks('grunt-accessibility');
grunt.registerTask('default', ['accessibility']);
};
PS: PS:
test url is an actual self-signed ssl site, so you can copy/paste the above code and test it test url是一个实际的自签名ssl站点,因此您可以复制/粘贴上面的代码并对其进行测试
only dependencies in package.json
只有package.json
依赖项
"devDependencies": { "grunt": "^1.0.1", "grunt-accessibility": "^5.0.0" }
node version v.8.9.0
节点版本v.8.9.0
I don't think you can directly affect how PhantomJS is called from within another Grunt plugin within your own Gruntfile . 我认为你不能直接影响你自己的Gruntfile中另一个Grunt插件中如何调用PhantomJS。
If I'm not mistaken, the only solution is to either commit a change to the grunt-accessibility package that passes an ignore-ssl-errors
option (in the the options you pass to grunt-accessibility) upstream to PhantomJS; 如果我没有弄错的话,唯一的解决方案是提交对grunt-accessibility包的更改,该包将上传的ignore-ssl-errors
选项(在传递给grunt-accessibility的选项中)传递给PhantomJS; or to intercept the call to PhantomJS and inject the ignore-ssl-errors
option. 或截取对PhantomJS的调用并注入ignore-ssl-errors
选项。
I think the second solution will be the quickest and most expedient. 我认为第二种解决方案将是最快捷,最权宜之计。 You'd have to either manually modify the entry point (either node_modules/.bin/phantomjs
or node_modules/phantomjs/index.js
) or write a pre-run script that would modify it. 您必须手动修改入口点( node_modules/.bin/phantomjs
或node_modules/phantomjs/index.js
)或编写一个可以修改它的预运行脚本。 In the modified .js file, you'd inject the ignore-ssl-errors
by adding code to the top of the file that appends it to the process.argv
array: 在修改后的.js文件中,通过将代码添加到将其附加到process.argv
数组的文件顶部来注入ignore-ssl-errors
:
process.argv.push("--ignore-ssl-errors=true");
I always use the strict-ssl command but with a small difference. 我总是使用strict-ssl命令,但差别很小。
Try to insert a config in your command 尝试在命令中插入配置
There will be like npm config set strict-ssl false
会有像npm config set strict-ssl false
Hope this help you. 希望这对你有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.