fix cicd issues
Build & Push / Pipeline Tests (push) Successful in 2m1s
Test / Type Check (all packages) (push) Successful in 55s
Build & Push / Build & Push Docker Image (push) Successful in 3m30s
Test / API Unit Tests (push) Successful in 1m16s
Test / Homepage Unit Tests (push) Successful in 50s
Test / Carplace Unit Tests (push) Successful in 43s
Test / Admin Unit Tests (push) Successful in 42s
Test / Dashboard Unit Tests (push) Successful in 46s
Test / API Integration Tests (push) Successful in 1m10s
Build & Push / Pipeline Tests (push) Successful in 2m1s
Test / Type Check (all packages) (push) Successful in 55s
Build & Push / Build & Push Docker Image (push) Successful in 3m30s
Test / API Unit Tests (push) Successful in 1m16s
Test / Homepage Unit Tests (push) Successful in 50s
Test / Carplace Unit Tests (push) Successful in 43s
Test / Admin Unit Tests (push) Successful in 42s
Test / Dashboard Unit Tests (push) Successful in 46s
Test / API Integration Tests (push) Successful in 1m10s
This commit is contained in:
@@ -37,10 +37,10 @@ function request(input: string, options: { token?: string; headers?: Record<stri
|
||||
}
|
||||
}
|
||||
|
||||
async function loadMiddleware(websiteUrl = 'https://market.example.com') {
|
||||
async function loadProxy(websiteUrl = 'https://market.example.com') {
|
||||
vi.resetModules()
|
||||
process.env.NEXT_PUBLIC_WEBSITE_URL = websiteUrl
|
||||
return import('./middleware')
|
||||
return import('./proxy')
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
@@ -53,19 +53,19 @@ afterEach(() => {
|
||||
vi.resetModules()
|
||||
})
|
||||
|
||||
describe('dashboard middleware', () => {
|
||||
describe('dashboard proxy', () => {
|
||||
it('redirects duplicate dashboard prefixes to the clean dashboard URL', async () => {
|
||||
const { default: middleware } = await loadMiddleware()
|
||||
const { default: proxy } = await loadProxy()
|
||||
|
||||
const response = middleware(request('https://workspace.example.com/dashboard/dashboard?x=1') as never)
|
||||
const response = proxy(request('https://workspace.example.com/dashboard/dashboard?x=1') as never)
|
||||
|
||||
expect(response).toEqual({ kind: 'redirect', url: 'https://workspace.example.com/dashboard?x=1' })
|
||||
})
|
||||
|
||||
it('rejects middleware subrequest headers at the app layer', async () => {
|
||||
const { default: middleware } = await loadMiddleware()
|
||||
const { default: proxy } = await loadProxy()
|
||||
|
||||
const response = middleware(request('https://workspace.example.com/dashboard', {
|
||||
const response = proxy(request('https://workspace.example.com/dashboard', {
|
||||
headers: { 'x-middleware-subrequest': 'middleware:middleware' },
|
||||
}) as never)
|
||||
|
||||
@@ -73,25 +73,25 @@ describe('dashboard middleware', () => {
|
||||
})
|
||||
|
||||
it('redirects unauthenticated protected internal-host requests to homepage sign-in on the website origin', async () => {
|
||||
const { default: middleware } = await loadMiddleware('https://rentaldrivego.example')
|
||||
const { default: proxy } = await loadProxy('https://rentaldrivego.example')
|
||||
|
||||
const response = middleware(request('http://dashboard:3001/dashboard/team') as never)
|
||||
const response = proxy(request('http://dashboard:3001/dashboard/team') as never)
|
||||
|
||||
expect(response).toEqual({ kind: 'redirect', url: 'https://rentaldrivego.example/en/dark/sign-in?redirect=%2Fdashboard%2Fteam' })
|
||||
})
|
||||
|
||||
it('redirects unprefixed internal app paths with a public dashboard return path', async () => {
|
||||
const { default: middleware } = await loadMiddleware('https://rentaldrivego.example')
|
||||
const { default: proxy } = await loadProxy('https://rentaldrivego.example')
|
||||
|
||||
const response = middleware(request('http://dashboard:3001/reservations') as never)
|
||||
const response = proxy(request('http://dashboard:3001/reservations') as never)
|
||||
|
||||
expect(response).toEqual({ kind: 'redirect', url: 'https://rentaldrivego.example/en/dark/sign-in?redirect=%2Fdashboard%2Freservations' })
|
||||
})
|
||||
|
||||
it('ignores spoofed forwarded host/proto when building the dashboard sign-in redirect', async () => {
|
||||
const { default: middleware } = await loadMiddleware('https://market.example.com')
|
||||
const { default: proxy } = await loadProxy('https://market.example.com')
|
||||
|
||||
const response = middleware(request('http://dashboard:3001/dashboard/billing', {
|
||||
const response = proxy(request('http://dashboard:3001/dashboard/billing', {
|
||||
headers: {
|
||||
'x-forwarded-host': 'workspace.customer.example',
|
||||
'x-forwarded-proto': 'https',
|
||||
@@ -102,9 +102,9 @@ describe('dashboard middleware', () => {
|
||||
})
|
||||
|
||||
it('ignores internal forwarded hosts when building the dashboard sign-in redirect', async () => {
|
||||
const { default: middleware } = await loadMiddleware('https://market.example.com')
|
||||
const { default: proxy } = await loadProxy('https://market.example.com')
|
||||
|
||||
const response = middleware(request('http://dashboard:3001/dashboard/fleet', {
|
||||
const response = proxy(request('http://dashboard:3001/dashboard/fleet', {
|
||||
headers: {
|
||||
'x-forwarded-host': 'api:4000',
|
||||
'x-forwarded-proto': 'https',
|
||||
@@ -115,34 +115,34 @@ describe('dashboard middleware', () => {
|
||||
})
|
||||
|
||||
it('redirects legacy dashboard sign-in requests to the localized homepage sign-in route', async () => {
|
||||
const { default: middleware } = await loadMiddleware('https://market.example.com')
|
||||
const { default: proxy } = await loadProxy('https://market.example.com')
|
||||
|
||||
const response = middleware(request('https://workspace.example.com/dashboard/sign-in?redirect=/dashboard/fleet&lang=fr&theme=dark') as never)
|
||||
const response = proxy(request('https://workspace.example.com/dashboard/sign-in?redirect=/dashboard/fleet&lang=fr&theme=dark') as never)
|
||||
|
||||
expect(response).toEqual({ kind: 'redirect', url: 'https://market.example.com/fr/dark/sign-in?redirect=%2Fdashboard%2Ffleet' })
|
||||
})
|
||||
|
||||
it('redirects signed-in users away from the sign-in page', async () => {
|
||||
const { default: middleware } = await loadMiddleware()
|
||||
const { default: proxy } = await loadProxy()
|
||||
|
||||
const response = middleware(request('https://workspace.example.com/dashboard/sign-in?redirect=/dashboard/fleet', { token: 'employee-token' }) as never)
|
||||
const response = proxy(request('https://workspace.example.com/dashboard/sign-in?redirect=/dashboard/fleet', { token: 'employee-token' }) as never)
|
||||
|
||||
expect(response).toEqual({ kind: 'redirect', url: 'https://market.example.com/dashboard' })
|
||||
})
|
||||
|
||||
it('allows public dashboard auth pages without a token', async () => {
|
||||
const { default: middleware } = await loadMiddleware()
|
||||
const { default: proxy } = await loadProxy()
|
||||
|
||||
const response = middleware(request('https://workspace.example.com/dashboard/forgot-password') as never)
|
||||
const response = proxy(request('https://workspace.example.com/dashboard/forgot-password') as never)
|
||||
|
||||
expect(response).toEqual({ kind: 'next' })
|
||||
expect(nextServer.next).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('allows dashboard API requests through so auth endpoints can set and read cookies', async () => {
|
||||
const { default: middleware } = await loadMiddleware()
|
||||
const { default: proxy } = await loadProxy()
|
||||
|
||||
const response = middleware(request('https://workspace.example.com/dashboard/api/v1/auth/employee/login') as never)
|
||||
const response = proxy(request('https://workspace.example.com/dashboard/api/v1/auth/employee/login') as never)
|
||||
|
||||
expect(response).toEqual({ kind: 'next' })
|
||||
expect(nextServer.redirect).not.toHaveBeenCalled()
|
||||
@@ -88,7 +88,7 @@ function isProtectedRoute(req: NextRequest) {
|
||||
return pathname === '/' || (pathname.startsWith('/') && !pathname.startsWith('/_next'))
|
||||
}
|
||||
|
||||
function localJwtMiddleware(req: NextRequest): NextResponse {
|
||||
function localJwtProxy(req: NextRequest): NextResponse {
|
||||
const token = req.cookies.get('employee_session')?.value
|
||||
const pathname = toDashboardAppPath(req.nextUrl.pathname)
|
||||
|
||||
@@ -109,7 +109,7 @@ function localJwtMiddleware(req: NextRequest): NextResponse {
|
||||
return NextResponse.next()
|
||||
}
|
||||
|
||||
export default function middleware(req: NextRequest) {
|
||||
export default function proxy(req: NextRequest) {
|
||||
if (req.headers.has('x-middleware-subrequest')) {
|
||||
return new NextResponse('Unsupported internal request header', { status: 400 })
|
||||
}
|
||||
@@ -121,7 +121,7 @@ export default function middleware(req: NextRequest) {
|
||||
return NextResponse.redirect(redirectUrl)
|
||||
}
|
||||
|
||||
return localJwtMiddleware(req)
|
||||
return localJwtProxy(req)
|
||||
}
|
||||
|
||||
export const config = {
|
||||
Reference in New Issue
Block a user