Skip to content

Commit

Permalink
Merge pull request #225 from fingerprintjs/bugfix/INTER-726-invalid-host
Browse files Browse the repository at this point in the history
[INTER-726] Fix invalid host header
  • Loading branch information
TheUnderScorer authored Jun 18, 2024
2 parents 6ccc5c2 + d368209 commit 9a0d3c3
Show file tree
Hide file tree
Showing 8 changed files with 5,222 additions and 4,159 deletions.
15 changes: 12 additions & 3 deletions e2e/infra/frontdoor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
import { KnownSessionAffinityEnabledState } from '@azure/arm-frontdoor'
import invariant from 'tiny-invariant'
import { ExponentialBackoff, handleAll, retry } from 'cockatiel'
import { wait } from '../../shared/wait'

export interface ProvisionFrontDoorParams {
resourceGroup: string
Expand Down Expand Up @@ -155,6 +156,9 @@ export async function provisionFrontDoor({
}
}

// 10 minutes
const ADDITIONAL_WAIT = 600_000

async function waitForFrontDoor(url: string) {
console.info('Waiting for front door to be ready...', url)

Expand All @@ -166,7 +170,7 @@ async function waitForFrontDoor(url: string) {
maxAttempts: 40,
})

return policy.execute(async ({ attempt }) => {
await policy.execute(async ({ attempt }) => {
if (attempt > 1) {
console.info(`Attempt ${attempt}...`)
}
Expand All @@ -181,7 +185,12 @@ async function waitForFrontDoor(url: string) {
if (text.includes('Page not found')) {
throw new Error('Page not found')
}

console.log('Frontdoor is ready!')
})

console.info(
`Frontdoor is ready! Waiting additional ${ADDITIONAL_WAIT / 1000} seconds to make sure it is fully operational...`
)

// Wait additional ADDITIONAL_WAIT ms, to make sure that frontdoor is fully ready. Otherwise it might cause flaky tests.
await wait(ADDITIONAL_WAIT)
}
23 changes: 21 additions & 2 deletions e2e/scripts/mockTests.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { execSync } from 'child_process'
import { readTestInfo } from '../shared/testInfo'
import pkg from '../../package.json'
import { ExponentialBackoff, handleAll, retry } from 'cockatiel'

async function main() {
async function doMockTests() {
let hasError = false
const testInfo = readTestInfo()

Expand All @@ -15,7 +16,7 @@ async function main() {
for (const info of testInfo.tests) {
const agentPath = `${info.routePrefix}/${info.agentDownloadPath}`
const resultPath = `${info.routePrefix}/${info.getResultPath}`
const host = info.functionAppUrl
const host = info.frontdoorUrl

const agentUrl = new URL(host)
agentUrl.pathname = agentPath
Expand All @@ -42,6 +43,24 @@ async function main() {
}

if (hasError) {
throw new Error('One or more tests failed')
}
}

async function main() {
const policy = retry(handleAll, {
backoff: new ExponentialBackoff({
// 5 minutes
maxDelay: 1000 * 60 * 5,
}),
maxAttempts: 5,
})

try {
await policy.execute(doMockTests)
} catch (e) {
console.error(e)

process.exit(1)
}
}
Expand Down
Loading

0 comments on commit 9a0d3c3

Please sign in to comment.