Skip to content

Commit 4801b6d

Browse files
authored
Merge pull request #51 from theiiienrique/checklink-failing-for-some-valid-urls
Document solution to checkLink failing for some valid URLs
2 parents b2cd01a + 98f1699 commit 4801b6d

File tree

1 file changed

+95
-9
lines changed

1 file changed

+95
-9
lines changed

docs/get-started/actions/checkLink.md

Lines changed: 95 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ You can also specify
1919
2020
## Examples
2121

22-
Here are a few ways you might you the `checkLink` action:
22+
Here are a few ways you might use the `checkLink` action:
2323

2424
### Check if a link is valid
2525

@@ -29,11 +29,11 @@ Here are a few ways you might you the `checkLink` action:
2929
{
3030
"steps": [
3131
{
32-
"description": "Check if Google is up.",
32+
"description": "Check if Google is up.",
3333
"action": "checkLink",
3434
"url": "https://www.google.com"
3535
}
36-
],
36+
]
3737
}
3838
]
3939
}
@@ -50,11 +50,7 @@ Here are a few ways you might you the `checkLink` action:
5050
"description": "Check if Google is up with extra status codes.",
5151
"action": "checkLink",
5252
"url": "https://www.google.com",
53-
"statusCodes": [
54-
200,
55-
201,
56-
202
57-
]
53+
"statusCodes": [200, 201, 202]
5854
}
5955
]
6056
}
@@ -79,4 +75,94 @@ Here are a few ways you might you the `checkLink` action:
7975
}
8076
]
8177
}
82-
```
78+
```
79+
80+
## Troubleshooting
81+
82+
- [`checkLink` fails due to unrecognized certificates](#checklink-fails-due-to-unrecognized-certificates)
83+
84+
### `checkLink` fails due to unrecognized certificates
85+
86+
If the `checkLink` action fails for a valid URL that loads without redirects, it may be due to an internal or custom certificate that the testing machine doesn't recognize.
87+
88+
#### Example
89+
90+
Consider the following test configuration, which checks the validity of `https://self-signed.badssl.com/`—a website using a self-signed certificate:
91+
92+
```json title="bad-certificate.json"
93+
{
94+
"tests": [
95+
{
96+
"steps": [
97+
{
98+
"description": "Check site with a self-signed certificate",
99+
"action": "checkLink",
100+
"url": "https://self-signed.badssl.com/",
101+
"statusCodes": [200, 201, 202, 301]
102+
}
103+
]
104+
}
105+
]
106+
}
107+
```
108+
109+
To run the test, use the following command:
110+
111+
```bash
112+
npx doc-detective runTests -i bad-certificate.json
113+
```
114+
115+
This command executes the test, but it fails, returning the following response:
116+
117+
```json
118+
{
119+
"result": "FAIL",
120+
"resultDescription": "Invalid or unresolvable URL: https://self-signed.badssl.com/"
121+
}
122+
```
123+
124+
This occurs because the self-signed certificate isn't recognized by the testing machine. This behavior is expected in `axios`, but you can bypass it in Doc Detective by setting an environment variable.
125+
126+
#### Solution
127+
128+
To fix this issue, follow these steps:
129+
130+
1. Create a `.env` file with the following content:
131+
132+
```text title="ignore-certificate-problems.env"
133+
NODE_TLS_REJECT_UNAUTHORIZED=0
134+
```
135+
136+
2. Modify your test configuration to include a `setVariables` action:
137+
138+
```json title="bad-certificate.json" {5-8}
139+
{
140+
"tests": [
141+
{
142+
"steps": [
143+
{
144+
"action": "setVariables",
145+
"path": "ignore-certificate-problems.env"
146+
},
147+
{
148+
"description": "Check self-signed.badssl.com",
149+
"action": "checkLink",
150+
"url": "https://self-signed.badssl.com/",
151+
"statusCodes": [200, 201, 202, 301]
152+
}
153+
]
154+
}
155+
]
156+
}
157+
```
158+
159+
#### Expected result
160+
161+
After applying these changes, the test should pass:
162+
163+
```json
164+
{
165+
"result": "PASS",
166+
"resultDescription": "Returned 200"
167+
}
168+
```

0 commit comments

Comments
 (0)