Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an automatic check that URL redirects work #1089

Closed
StevenMaude opened this issue Jan 11, 2023 · 2 comments
Closed

Add an automatic check that URL redirects work #1089

StevenMaude opened this issue Jan 11, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@StevenMaude
Copy link
Contributor

StevenMaude commented Jan 11, 2023

In #1064, I found that some redirects I added weren't working as expected. I'm still not sure why that is yet.

Depending on the reason for it (are we encountering a limit? or is it something more subtle?) we might want to add a scheduled check that:

  • at minimum, the URL being redirected gives the redirect code specified
  • and, maybe even that the URL being redirected gets redirected to the correct destination
@StevenMaude StevenMaude added the enhancement New feature or request label Jan 11, 2023
@StevenMaude StevenMaude changed the title Add an automatic check that redirects work Add an automatic check that URL redirects work Jan 11, 2023
@StevenMaude
Copy link
Contributor Author

StevenMaude commented Jan 12, 2023

As a semi-automated process:

test $(cut -f1 -d' ' _redirects | awk '{print "https://3b9cf57d.opensafely-docs.pages.dev"$0}' | xargs -n1 curl -o /dev/null --silent --head --write-out '%{url_effective} '%{http_code}' \n' | grep "404" | wc -l) -eq 0

displays the URL and status code for each redirect, assuming a 404 catches every issue (which it possibly doesn't).

The better approach would be to compare the status code from the _redirects file with that from cURL.

StevenMaude added a commit that referenced this issue Jan 12, 2023
I have no idea why the ordering has an effect, but it does.

The redirects were checked by eye using a variant of the bash one-liner in #1089:

```sh
cut -f1 -d' ' _redirects | awk '{print "$OPENSAFELY_PREVIEW_URL"$0}' | xargs -n1 curl -o /dev/null --silent --head --write-out '%{url_effective} '%{http_code}' \n'
```

The preview URL depends on the deployment, which depends on the commit,
so can't easily get the actual URL in there.
StevenMaude added a commit that referenced this issue Jan 12, 2023
I have no idea why the ordering has an effect, but it does.

The redirects were checked by eye using a variant of the bash one-liner in #1089:

```sh
cut -f1 -d' ' _redirects | awk '{print "$OPENSAFELY_PREVIEW_URL"$0}' | xargs -n1 curl -o /dev/null --silent --head --write-out '%{url_effective} '%{http_code}' \n'
```

The preview URL depends on the deployment, which depends on the commit,
so can't easily get the actual URL in there.
@StevenMaude
Copy link
Contributor Author

This was completed in #1094.

See also #1207, where using a MkDocs plugin for redirects is proposed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant