This PR alters the siteUrl function in our Playwright tests to strip out consecutive slashes from URL paths in URLs being requested by Playwright during testing. These consecutive slashes are filtered out both by hugo server and the nginx fronted Minio instance run by ocw-studio, so the problematic behavior that this causes is not seen locally unless you set PLAYWRIGHT_BASE_URL to point at a site that doesn't handle consecutive slashes. Our Fastly fronted AWS S3 buckets are an example of this. The URL is passed through from Fastly to S3 without any modification. S3 interprets double slashes as just another part of the key, as S3 does not have a true directory structure. The URL path (or "key," in AWS terminology) can include any amount of legal characters, which includes consecutive backslashes. So, where most web servers will strip these out and assume you are building a path, AWS does not strip these out and assumes that they are part of the key. This results in a 404 for the resource, because the key does not match exactly.
Modify line 155 of tests-e2e/LocalOcw.ts and set RESOURCE_BASE_URL: "https://test-qa.ocw.mit.edu/"
Run yarn test:e2e, which we will expect to fail the first time around. The purpose of doing this is to generate test site fixtures with the test-qa.ocw.mit.edu domain
The Playwright tests in fixtures.spec.ts, as they are, currently compare a set of static fixtures against built Hugo JSON output. When PLAYWRIGHT_BASE_URL is set, a Hugo build is not done locally as it is assumed that you are testing against an already built site. However, if you set PLAYWRIGHT_BASE_URL to an external URL and run the tests without following the steps above, all tests aside from the one in fixtures.spec.ts will pass. This is because the fixture test code takes into account RESOURCE_BASE_URL and assumes that this value was used when building the test site that it is running against. If the values are not the same, the test will fail.
What are the relevant tickets?
Closes https://github.com/mitodl/ocw-hugo-themes/issues/1289
Description (What does it do?)
This PR alters the
siteUrl
function in our Playwright tests to strip out consecutive slashes from URL paths in URLs being requested by Playwright during testing. These consecutive slashes are filtered out both byhugo server
and the nginx fronted Minio instance run byocw-studio
, so the problematic behavior that this causes is not seen locally unless you setPLAYWRIGHT_BASE_URL
to point at a site that doesn't handle consecutive slashes. Our Fastly fronted AWS S3 buckets are an example of this. The URL is passed through from Fastly to S3 without any modification. S3 interprets double slashes as just another part of the key, as S3 does not have a true directory structure. The URL path (or "key," in AWS terminology) can include any amount of legal characters, which includes consecutive backslashes. So, where most web servers will strip these out and assume you are building a path, AWS does not strip these out and assumes that they are part of the key. This results in a 404 for the resource, because the key does not match exactly.How can this be tested?
tests-e2e/LocalOcw.ts
and setRESOURCE_BASE_URL: "https://test-qa.ocw.mit.edu/"
yarn test:e2e
, which we will expect to fail the first time around. The purpose of doing this is to generate test site fixtures with thetest-qa.ocw.mit.edu
domainnow set
PLAYWRIGHT_BASE_URL: "https://test-qa.ocw.mit.edu/"yarn test:e2e
again and all tests should passAdditional Context
The Playwright tests in
fixtures.spec.ts
, as they are, currently compare a set of static fixtures against built Hugo JSON output. WhenPLAYWRIGHT_BASE_URL
is set, a Hugo build is not done locally as it is assumed that you are testing against an already built site. However, if you setPLAYWRIGHT_BASE_URL
to an external URL and run the tests without following the steps above, all tests aside from the one infixtures.spec.ts
will pass. This is because the fixture test code takes into accountRESOURCE_BASE_URL
and assumes that this value was used when building the test site that it is running against. If the values are not the same, the test will fail.