【发布时间】:2018-01-10 19:17:32
【问题描述】:
我正在使用grunt-accessibility 插件来自动报告accessibility 错误。它正常工作,但是当我在一个有 self signed certificate 的网站上尝试它时(那种显示带有一些证书安全警告的 interim 页面的类型,如果你仍然愿意,还有一个链接可以继续到该站点),它在interim 页面本身报告错误,当然这是一个空页面:
<html>
<head></head>
<body></body>
</html>
显然我想绕过这个临时页面并在实际页面上运行accessibility。
我在尝试什么?
我尝试了以下方法(从谷歌搜索和其他 SO's Q&A 中找到):
-
臭名昭著的黑客攻击
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']);
};
附注:
test url是一个实际的自签名ssl站点,所以你可以复制/粘贴上面的代码进行测试
-
仅在
package.json中的依赖项"devDependencies": { "grunt": "^1.0.1", "grunt-accessibility": "^5.0.0" } 节点版本
v.8.9.0
【问题讨论】:
-
好问题!如果您尝试像这样设置 PhantomJS 选项会怎样:
options: { "--ignore-ssl-errors": true, "--ssl-protocol": "any" }(是双破折号?) -
测试过了,但是没有用。
-
@Vaviloff 还有什么建议吗?
-
也许将
true中的ignore-ssl-errors设为字符串?"ignore-ssl-errors": "true",也应该尝试使用--前缀来忽略 SSL 错误,因为 grunt-phantom 似乎只是连接命令行参数,而 PhantomJS 等待带有双破折号的开关。 -
再试一次,还是不行。
标签: javascript node.js gruntjs phantomjs