[英]How to ignore ssl certificate warning or pass a self signed certificate (from inside gruntfile) during accessibility automation?
我正在使用grunt-accessibility插件自动报告accessibility
错误。 它通常工作正常,但是当我在具有self signed certificate
的网站上尝试它时(显示带有一些证书安全警告的interim
页面的类型以及如果您仍希望继续访问该网站的链接),它会报告interim
页面本身的错误,当然是一个空页面:
<html>
<head></head>
<body></body>
</html>
显然,我想绕过这个临时页面并在实际页面上运行accessibility
。
我在尝试什么?
我曾尝试过以下内容(通过谷歌搜索和其他SO's
问答):
臭名昭着的黑客
npm set strict-ssl false
添加导入的证书路径
npm config set cafile="C:\\path\\to\\cert.cer"
添加process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"
(参见下面的Grunfile
)
从我收集的内容来看, grunt-accessibility
使用的是AccessSniff
,后者又使用了phantomjs
。 现在, phantomjs
可以选择忽略这些警告
--ignore-ssl-errors=[true|false]
忽略SSL错误,例如过期或自签名证书错误(默认为false)。
以上是CLI选项,我无法从Grunfile.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:
test url是一个实际的自签名ssl站点,因此您可以复制/粘贴上面的代码并对其进行测试
只有package.json
依赖项
"devDependencies": { "grunt": "^1.0.1", "grunt-accessibility": "^5.0.0" }
节点版本v.8.9.0
我认为你不能直接影响你自己的Gruntfile中另一个Grunt插件中如何调用PhantomJS。
如果我没有弄错的话,唯一的解决方案是提交对grunt-accessibility包的更改,该包将上传的ignore-ssl-errors
选项(在传递给grunt-accessibility的选项中)传递给PhantomJS; 或截取对PhantomJS的调用并注入ignore-ssl-errors
选项。
我认为第二种解决方案将是最快捷,最权宜之计。 您必须手动修改入口点( node_modules/.bin/phantomjs
或node_modules/phantomjs/index.js
)或编写一个可以修改它的预运行脚本。 在修改后的.js文件中,通过将代码添加到将其附加到process.argv
数组的文件顶部来注入ignore-ssl-errors
:
process.argv.push("--ignore-ssl-errors=true");
我总是使用strict-ssl命令,但差别很小。
尝试在命令中插入配置
会有像npm config set strict-ssl false
希望这对你有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.