doc-detective / doc-detective.github.io

Doc Detective docs!
https://doc-detective.com
MIT License
6 stars 6 forks source link

checkLink failing for some valid URLs #28

Closed ecormany closed 3 days ago

ecormany commented 5 months ago

The checkLink action is failing for some valid URLs. For example, I saved this standalone test as help-center.json:

{
  "tests": [
    {
      "steps": [
        {
          "description": "Check Help Center.",   
          "action": "checkLink",
          "url": "https://support.opentrons.com/s/",
          "statusCodes": [200, 201, 202, 301]
        }
      ]
    }
  ]
}

Running it produces a failure.

npx doc-detective runTests -i help-center.json
(INFO) Doc Detective collects basic anonymous telemetry to understand product issues and usage. To disable telemetry, set 'telemetry.send' to 'false' in your .doc-detective.json config file.
(INFO) Running test specs.
(INFO) RESULTS:
(INFO)
{
  "summary": {
    "specs": {
      "pass": 0,
      "fail": 1,
      "warning": 0,
      "skipped": 0
    },
    "tests": {
      "pass": 0,
      "fail": 1,
      "warning": 0,
      "skipped": 0
    },
    "contexts": {
      "pass": 0,
      "fail": 1,
      "warning": 0,
      "skipped": 0
    },
    "steps": {
      "pass": 0,
      "fail": 1,
      "warning": 0,
      "skipped": 0
    }
  },
  "specs": [
    {
      "result": "FAIL",
      "tests": [
        {
          "result": "FAIL",
          "contexts": [
            {
              "result": "FAIL",
              "app": "firefox",
              "platform": "mac",
              "steps": [
                {
                  "result": "FAIL",
                  "resultDescription": "Invalid or unresolvable URL: https://support.opentrons.com/s/",
                  "description": "Check Help Center.",
                  "action": "checkLink",
                  "url": "https://support.opentrons.com/s/",
                  "statusCodes": [
                    200,
                    201,
                    202,
                    301
                  ],
                  "id": "7a5bad88-3ad7-4952-82c2-4620e2511134"
                }
              ]
            }
          ]
        }
      ]
    }
  ]
}
(INFO) Cleaning up and finishing post-processing.
(INFO)
##########################################################################
# Thanks for using Doc Detective! If this project was helpful to you,    #
# please consider starring the repo on GitHub or sponsoring the project: #
# - GitHub Sponsors: https://github.com/sponsors/doc-detective           #
# - Open Collective: https://opencollective.com/doc-detective            #
##########################################################################
See results at /Users/edwardcormany/opentrons/api/docs/v2/tests/testResults-1713130553267.json

The page is a valid URL and loads without redirects.

Other URL checking services get a 200 response for the page, e.g. https://www.pemavor.com/solution/http-status-code-checker/

image
ecormany commented 5 months ago

Solved it! It's failing for sites with bad (but still functional) certificates. This is intended axios behavior and can be circumvented in Doc Detective with an environment variable.

I added this to my test from above:

        {
          "action": "setVariables",
          "path": "ignore-certificate-problems.env"
        },

And put this in the .env file:

NODE_TLS_REJECT_UNAUTHORIZED=0

It works 🎉

                {
                  "result": "PASS",
                  "resultDescription": "Returned 200",
                  "description": "Check Help Center.",
                  "action": "checkLink",
                  "url": "https://support.opentrons.com/s/",
                  "statusCodes": [
                    200,
                    201,
                    202,
                    301
                  ],
                  "id": "ce639aff-cb40-4b66-90c1-35dc29a35ff5"
                }
hawkeyexl commented 5 months ago

Reopening the issue and transferring to the docs repo. You may be the first to run into this issue, but you won't be the last.

Out of curiosity, is the cert issue known or intentional? Or are you simply wanting to test it regardless of certificate validity?

hawkeyexl commented 5 months ago

Need to create an example of running a checkLint action against a URL with an internal or custom certificate that may not be recognized on the machine doing the testing but is nonetheless valid.