Skip to content

Commit

Permalink
✅ Add tests for auth header and protected resources
Browse files Browse the repository at this point in the history
Remove http-server in favor of using express which is already a dep. Also add
express-basic-auth as a dev-dep for testing.
  • Loading branch information
wwilsman committed Oct 3, 2019
1 parent 6e54cac commit 38dab7a
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 82 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
"@types/deepmerge": "^2.2.0",
"@types/express": "^4.16.0",
"@types/generic-pool": "^3.1.9",
"@types/http-server": "^0.10.0",
"@types/js-yaml": "^3.11.2",
"@types/mocha": "^5.2.5",
"@types/nock": "^11.1.0",
Expand All @@ -76,7 +75,7 @@
"chai-http": "^4.0.0",
"cheerio": "^1.0.0-rc.3",
"eslint-config-oclif": "^3.0.0",
"http-server": "^0.11.1",
"express-basic-auth": "^1.2.0",
"husky": "^3.0.0",
"interactor.js": "^1.3.1",
"karma": "^4.1.0",
Expand Down
43 changes: 40 additions & 3 deletions test/integration/agent-integration.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as cheerio from 'cheerio'
import * as express from 'express'
import * as basicAuth from 'express-basic-auth'
import { Server } from 'http'
import * as httpServer from 'http-server'
import { describe } from 'mocha'
import * as puppeteer from 'puppeteer'
import { agentJsFilename, postSnapshot } from '../../src/utils/sdk-utils'
Expand Down Expand Up @@ -108,11 +109,14 @@ describe('Integration test', () => {
describe('on local test cases', () => {
const testCaseDir = `${__dirname}/testcases`
const PORT = 8000

let app: express.Application
let server: Server

before(() => {
server = httpServer.createServer({root: testCaseDir}) as Server
server.listen(PORT)
app = express()
app.use(express.static(testCaseDir))
server = app.listen(PORT)
})

after(() => {
Expand All @@ -130,6 +134,39 @@ describe('Integration test', () => {
})
})

describe('protected resources', () => {
const username = 'test'
const password = 'test'

before(async () => {
app.get('/auth/redirected.png', (_, res) => {
res.redirect(301, '/auth/fairy-emojione.png')
})

app.use(
'/auth',
basicAuth({ users: { [username]: password }, challenge: true }),
express.static(testCaseDir),
)

await page.authenticate({ username, password })
await page.goto(`http://localhost:${PORT}/auth/protected-with-basic-auth.html`)
})

it('does not capture protected resources without the correct headers', async () => {
// the snapshot should show missing resources
await snapshot(page, 'Protected assets')
})

it('captures protected resources with the correct headers', async () => {
await snapshot(page, 'Captured protected assets', {
requestHeaders: {
Authorization: `Basic ${Buffer.from(`${username}:${password}`).toString('base64')}`,
},
})
})
})

describe('large resources', () => {
it('snapshots large DOM', async () => {
await page.goto(`http://localhost:${PORT}/exceeds-dom-snapshot-size-limit.html`)
Expand Down
12 changes: 12 additions & 0 deletions test/integration/testcases/protected-with-basic-auth.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!doctype html>
<html>
<head>
<title>Protected resources integration test case</title>
<meta charset="utf-8"/>
</head>
<body>
<p>All requests on this page are protected</p>
<img src="redirected.png" />
<img src="taxi-emojione.png" />
</body>
</html>
96 changes: 19 additions & 77 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1139,13 +1139,6 @@
"@types/minimatch" "*"
"@types/node" "*"

"@types/http-server@^0.10.0":
version "0.10.0"
resolved "https://registry.yarnpkg.com/@types/http-server/-/http-server-0.10.0.tgz#f5fe4a136ac4b2e5b5c25d017bb79310eafe5ece"
integrity sha512-bpuBiQM3GBd89Abzp/Spktt/ZIVSR8ccNBJgqUHf5KNow80t4ZFXfvTxzd96uHrwQQngbTqMulQPWbuFczYdfg==
dependencies:
"@types/connect" "*"

"@types/js-yaml@^3.11.2":
version "3.12.1"
resolved "https://registry.yarnpkg.com/@types/js-yaml/-/js-yaml-3.12.1.tgz#5c6f4a1eabca84792fbd916f0cb40847f123c656"
Expand Down Expand Up @@ -1736,11 +1729,6 @@ async-limiter@~1.0.0:
resolved "https://registry.yarnpkg.com/async-limiter/-/async-limiter-1.0.1.tgz#dd379e94f0db8310b08291f9d64c3209766617fd"
integrity sha512-csOlWGAcRFJaI6m+F2WKdnMKr4HhdhFVBk0H/QbJFMCr+uO2kwohwXQPxw/9OCxp05r5ghVBFSyioixx3gfkNQ==

async@^1.5.2:
version "1.5.2"
resolved "https://registry.yarnpkg.com/async/-/async-1.5.2.tgz#ec6a61ae56480c0c3cb241c95618e20892f9672a"
integrity sha1-7GphrlZIDAw8skHJVhjiCJL5Zyo=

async@^2.6.1, async@^2.6.2:
version "2.6.3"
resolved "https://registry.yarnpkg.com/async/-/async-2.6.3.tgz#d72625e2344a3656e3a3ad4fa749fa83299d82ff"
Expand Down Expand Up @@ -1865,6 +1853,13 @@ base@^0.11.1:
mixin-deep "^1.2.0"
pascalcase "^0.1.1"

basic-auth@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/basic-auth/-/basic-auth-2.0.1.tgz#b998279bf47ce38344b4f3cf916d4679bbf51e3a"
integrity sha512-NF+epuEdnUYVlGuhaxbbq+dvJttwLnGY+YixlXlME5KpQ5W3CnXA5cVTneY3SPbPDRkcjMbifrwmFYcClgOZeg==
dependencies:
safe-buffer "5.1.2"

bcrypt-pbkdf@^1.0.0:
version "1.0.2"
resolved "https://registry.yarnpkg.com/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.2.tgz#a4301d389b6a43f9b67ff3ca11a3f6637e360e9e"
Expand Down Expand Up @@ -3040,11 +3035,6 @@ cors@^2.8.4:
object-assign "^4"
vary "^1"

corser@~2.0.0:
version "2.0.1"
resolved "https://registry.yarnpkg.com/corser/-/corser-2.0.1.tgz#8eda252ecaab5840dcd975ceb90d9370c819ff87"
integrity sha1-jtolLsqrWEDc2XXOuQ2TcMgZ/4c=

cosmiconfig@^5.0.1, cosmiconfig@^5.2.1:
version "5.2.1"
resolved "https://registry.yarnpkg.com/cosmiconfig/-/cosmiconfig-5.2.1.tgz#040f726809c591e77a17c0a3626ca45b4f168b1a"
Expand Down Expand Up @@ -3562,16 +3552,6 @@ ecc-jsbn@~0.1.1:
jsbn "~0.1.0"
safer-buffer "^2.1.0"

ecstatic@^3.0.0:
version "3.3.2"
resolved "https://registry.yarnpkg.com/ecstatic/-/ecstatic-3.3.2.tgz#6d1dd49814d00594682c652adb66076a69d46c48"
integrity sha512-fLf9l1hnwrHI2xn9mEDT7KIi22UDqA2jaCwyCbSUJh9a1V+LEUSL/JO/6TIz/QyuBURWUHrFL5Kg2TtO1bkkog==
dependencies:
he "^1.1.1"
mime "^1.6.0"
minimist "^1.1.0"
url-join "^2.0.5"

editor@~1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/editor/-/editor-1.0.0.tgz#60c7f87bd62bcc6a894fa8ccd6afb7823a24f742"
Expand Down Expand Up @@ -4029,6 +4009,13 @@ expand-tilde@^2.0.0, expand-tilde@^2.0.2:
dependencies:
homedir-polyfill "^1.0.1"

express-basic-auth@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/express-basic-auth/-/express-basic-auth-1.2.0.tgz#a1d40b07721376ba916e73571a60969211224808"
integrity sha512-iJ0h1Gk6fZRrFmO7tP9nIbxwNgCUJASfNj5fb0Hy15lGtbqqsxpt7609+wq+0XlByZjXmC/rslWQtnuSTVRIcg==
dependencies:
basic-auth "^2.0.1"

express@^4.10.7, express@^4.16.3:
version "4.17.1"
resolved "https://registry.yarnpkg.com/express/-/express-4.17.1.tgz#4491fc38605cf51f8629d39c2b5d026f98a4c134"
Expand Down Expand Up @@ -4862,7 +4849,7 @@ hash.js@^1.0.0, hash.js@^1.0.3:
inherits "^2.0.3"
minimalistic-assert "^1.0.1"

[email protected], he@^1.1.1:
[email protected]:
version "1.2.0"
resolved "https://registry.yarnpkg.com/he/-/he-1.2.0.tgz#84ae65fa7eafb165fddb61566ae14baf05664f0f"
integrity sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==
Expand Down Expand Up @@ -4964,7 +4951,7 @@ http-proxy-agent@^2.1.0:
agent-base "4"
debug "3.1.0"

http-proxy@^1.13.0, http-proxy@^1.13.1, http-proxy@^1.8.1:
http-proxy@^1.13.0, http-proxy@^1.13.1:
version "1.17.0"
resolved "https://registry.yarnpkg.com/http-proxy/-/http-proxy-1.17.0.tgz#7ad38494658f84605e2f6db4436df410f4e5be9a"
integrity sha512-Taqn+3nNvYRfJ3bGvKfBSRwy1v6eePlm3oc/aWVxZp57DQr5Eq3xhKJi7Z4hZpS8PC3H4qI+Yly5EmFacGuA/g==
Expand All @@ -4973,20 +4960,6 @@ http-proxy@^1.13.0, http-proxy@^1.13.1, http-proxy@^1.8.1:
follow-redirects "^1.0.0"
requires-port "^1.0.0"

http-server@^0.11.1:
version "0.11.1"
resolved "https://registry.yarnpkg.com/http-server/-/http-server-0.11.1.tgz#2302a56a6ffef7f9abea0147d838a5e9b6b6a79b"
integrity sha512-6JeGDGoujJLmhjiRGlt8yK8Z9Kl0vnl/dQoQZlc4oeqaUoAKQg94NILLfrY3oWzSyFaQCVNTcKE5PZ3cH8VP9w==
dependencies:
colors "1.0.3"
corser "~2.0.0"
ecstatic "^3.0.0"
http-proxy "^1.8.1"
opener "~1.4.0"
optimist "0.6.x"
portfinder "^1.0.13"
union "~0.4.3"

http-signature@~1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/http-signature/-/http-signature-1.2.0.tgz#9aecd925114772f3d95b65a60abb8f7c18fbace1"
Expand Down Expand Up @@ -6579,7 +6552,7 @@ mime-types@^2.1.12, mime-types@~2.1.19, mime-types@~2.1.24:
dependencies:
mime-db "1.40.0"

[email protected], mime@^1.4.1, mime@^1.6.0:
[email protected], mime@^1.4.1:
version "1.6.0"
resolved "https://registry.yarnpkg.com/mime/-/mime-1.6.0.tgz#32cd9e5c64553bd58d19a568af452acff04981b1"
integrity sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg==
Expand Down Expand Up @@ -6678,7 +6651,7 @@ mixin-deep@^1.2.0:
for-in "^1.0.2"
is-extendable "^1.0.1"

[email protected], mkdirp@0.5.x, mkdirp@^0.5.0, mkdirp@^0.5.1, mkdirp@~0.5.0, mkdirp@~0.5.1:
[email protected], mkdirp@^0.5.0, mkdirp@^0.5.1, mkdirp@~0.5.0, mkdirp@~0.5.1:
version "0.5.1"
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.1.tgz#30057438eac6cf7f8c4767f38648d6697d75c903"
integrity sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=
Expand Down Expand Up @@ -7409,12 +7382,7 @@ opener@^1.5.1:
resolved "https://registry.yarnpkg.com/opener/-/opener-1.5.1.tgz#6d2f0e77f1a0af0032aca716c2c1fbb8e7e8abed"
integrity sha512-goYSy5c2UXE4Ra1xixabeVh1guIX/ZV/YokJksb6q2lubWu6UbvPQ20p542/sFIll1nl8JnCyK9oBaOcCWXwvA==

opener@~1.4.0:
version "1.4.3"
resolved "https://registry.yarnpkg.com/opener/-/opener-1.4.3.tgz#5c6da2c5d7e5831e8ffa3964950f8d6674ac90b8"
integrity sha1-XG2ixdflgx6P+jlklQ+NZnSskLg=

[email protected], optimist@^0.6.1:
optimist@^0.6.1:
version "0.6.1"
resolved "https://registry.yarnpkg.com/optimist/-/optimist-0.6.1.tgz#da3ea74686fa21a19a111c326e90eb15a0196686"
integrity sha1-2j6nRob6IaGaERwybpDrFaAZZoY=
Expand Down Expand Up @@ -7863,15 +7831,6 @@ please-upgrade-node@^3.2.0:
dependencies:
semver-compare "^1.0.0"

portfinder@^1.0.13:
version "1.0.23"
resolved "https://registry.yarnpkg.com/portfinder/-/portfinder-1.0.23.tgz#894db4bcc5daf02b6614517ce89cd21a38226b82"
integrity sha512-B729mL/uLklxtxuiJKfQ84WPxNw5a7Yhx3geQZdcA4GjNjZSTSSMMWyoennMVnTWSmAR0lMdzWYN0JLnHrg1KQ==
dependencies:
async "^1.5.2"
debug "^2.2.0"
mkdirp "0.5.x"

posix-character-classes@^0.1.0:
version "0.1.1"
resolved "https://registry.yarnpkg.com/posix-character-classes/-/posix-character-classes-0.1.1.tgz#01eac0fe3b5af71a2a6c02feabb8c1fef7e00eab"
Expand Down Expand Up @@ -8111,11 +8070,6 @@ qs@^6.5.1:
resolved "https://registry.yarnpkg.com/qs/-/qs-6.8.0.tgz#87b763f0d37ca54200334cd57bb2ef8f68a1d081"
integrity sha512-tPSkj8y92PfZVbinY1n84i1Qdx75lZjMQYx9WZhnkofyxzw2r7Ho39G3/aEvSUdebxpnnM4LZJCtvE/Aq3+s9w==

qs@~2.3.3:
version "2.3.3"
resolved "https://registry.yarnpkg.com/qs/-/qs-2.3.3.tgz#e9e85adbe75da0bbe4c8e0476a086290f863b404"
integrity sha1-6eha2+ddoLvkyOBHaghikPhjtAQ=

qs@~6.5.2:
version "6.5.2"
resolved "https://registry.yarnpkg.com/qs/-/qs-6.5.2.tgz#cb3ae806e8740444584ef154ce8ee98d403f3e36"
Expand Down Expand Up @@ -10081,13 +10035,6 @@ union-value@^1.0.0:
is-extendable "^0.1.1"
set-value "^2.0.1"

union@~0.4.3:
version "0.4.6"
resolved "https://registry.yarnpkg.com/union/-/union-0.4.6.tgz#198fbdaeba254e788b0efcb630bc11f24a2959e0"
integrity sha1-GY+9rrolTniLDvy2MLwR8kopWeA=
dependencies:
qs "~2.3.3"

unique-filename@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/unique-filename/-/unique-filename-1.1.1.tgz#1d69769369ada0583103a1e6ae87681b56573230"
Expand Down Expand Up @@ -10172,11 +10119,6 @@ urix@^0.1.0:
resolved "https://registry.yarnpkg.com/urix/-/urix-0.1.0.tgz#da937f7a62e21fec1fd18d49b35c2935067a6c72"
integrity sha1-2pN/emLiH+wf0Y1Js1wpNQZ6bHI=

url-join@^2.0.5:
version "2.0.5"
resolved "https://registry.yarnpkg.com/url-join/-/url-join-2.0.5.tgz#5af22f18c052a000a48d7b82c5e9c2e2feeda728"
integrity sha1-WvIvGMBSoACkjXuCxenC4v7tpyg=

url-join@^4.0.0:
version "4.0.1"
resolved "https://registry.yarnpkg.com/url-join/-/url-join-4.0.1.tgz#b642e21a2646808ffa178c4c5fda39844e12cde7"
Expand Down

0 comments on commit 38dab7a

Please sign in to comment.