簡體   English   中英

如何在輔助功能自動化期間忽略ssl證書警告或傳遞自簽名證書(來自gruntfile內部)?

[英]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問答):

  1. 臭名昭着的黑客

     npm set strict-ssl false 
  2. 添加導入的證書路徑

     npm config set cafile="C:\\path\\to\\cert.cer" 
  3. 添加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/phantomjsnode_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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM