|
1 | 1 | import { Hono } from 'hono' |
2 | 2 | import request from 'supertest' |
3 | | -import { chmodSync, statSync } from 'node:fs' |
| 3 | +import { chmodSync, rmSync, statSync, symlinkSync } from 'node:fs' |
4 | 4 | import path from 'node:path' |
5 | 5 | import { serveStatic } from './../src/serve-static' |
6 | 6 | import { createAdaptorServer } from './../src/server' |
@@ -198,6 +198,22 @@ describe('Serve Static Middleware', () => { |
198 | 198 | expect(res.status).toBe(404) |
199 | 199 | }) |
200 | 200 |
|
| 201 | + it('Should follow symlinks', async () => { |
| 202 | + const symlinkPath = path.join(__dirname, 'assets', 'static', 'symlink.html') |
| 203 | + const symlinkTarget = path.join(__dirname, 'assets', 'static', 'index.html') |
| 204 | + try { |
| 205 | + // force: true so it doesn't throw if the symlink doesn't exist |
| 206 | + rmSync(symlinkPath, { force: true }) |
| 207 | + symlinkSync(symlinkTarget, symlinkPath) |
| 208 | + |
| 209 | + const res = await request(server).get('/static/symlink.html') |
| 210 | + expect(res.status).toBe(200) |
| 211 | + expect(res.text).toBe('<h1>Hello Hono</h1>') |
| 212 | + } finally { |
| 213 | + rmSync(symlinkPath, { force: true }) |
| 214 | + } |
| 215 | + }) |
| 216 | + |
201 | 217 | it('Should handle URIError thrown while decoding URI component', async () => { |
202 | 218 | const res = await request(server).get('/static/%c0%afsecret.txt') |
203 | 219 | expect(res.status).toBe(404) |
|
0 commit comments