chore: prepare GoodBuddy 0.8.2
Cross-platform packages / Validate source (push) Waiting to run
Cross-platform packages / ${{ matrix.platform }} ${{ matrix.arch }} (arm64, macos, macos-15) (push) Blocked by required conditions
Cross-platform packages / ${{ matrix.platform }} ${{ matrix.arch }} (arm64, windows, windows-2025) (push) Blocked by required conditions
Cross-platform packages / ${{ matrix.platform }} ${{ matrix.arch }} (x64, linux, ubuntu-24.04) (push) Blocked by required conditions
Cross-platform packages / ${{ matrix.platform }} ${{ matrix.arch }} (x64, macos, macos-15-intel) (push) Blocked by required conditions
Cross-platform packages / ${{ matrix.platform }} ${{ matrix.arch }} (x64, windows, windows-2025) (push) Blocked by required conditions
Cross-platform packages / Publish GitHub Release (push) Blocked by required conditions
Cross-platform packages / ${{ matrix.platform }} ${{ matrix.arch }} (arm64, linux, ubuntu-24.04-arm) (push) Blocked by required conditions
Cross-platform packages / Validate source (push) Waiting to run
Cross-platform packages / ${{ matrix.platform }} ${{ matrix.arch }} (arm64, macos, macos-15) (push) Blocked by required conditions
Cross-platform packages / ${{ matrix.platform }} ${{ matrix.arch }} (arm64, windows, windows-2025) (push) Blocked by required conditions
Cross-platform packages / ${{ matrix.platform }} ${{ matrix.arch }} (x64, linux, ubuntu-24.04) (push) Blocked by required conditions
Cross-platform packages / ${{ matrix.platform }} ${{ matrix.arch }} (x64, macos, macos-15-intel) (push) Blocked by required conditions
Cross-platform packages / ${{ matrix.platform }} ${{ matrix.arch }} (x64, windows, windows-2025) (push) Blocked by required conditions
Cross-platform packages / Publish GitHub Release (push) Blocked by required conditions
Cross-platform packages / ${{ matrix.platform }} ${{ matrix.arch }} (arm64, linux, ubuntu-24.04-arm) (push) Blocked by required conditions
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { setIntranetCompatibilityReader } from '../intranet-compatibility-policy'
|
||||
import {
|
||||
isPublicAddress,
|
||||
normalizeSourceUrl,
|
||||
@@ -7,6 +8,14 @@ import {
|
||||
|
||||
const publicAddress = [{ address: '93.184.216.34', family: 4 }]
|
||||
|
||||
beforeEach(() => {
|
||||
setIntranetCompatibilityReader(() => false)
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
setIntranetCompatibilityReader(() => true)
|
||||
})
|
||||
|
||||
describe('URL importer', () => {
|
||||
it('rejects local protocols, hosts and private address ranges', async () => {
|
||||
expect(() => normalizeSourceUrl('file:///etc/passwd')).toThrow('HTTP')
|
||||
@@ -16,6 +25,10 @@ describe('URL importer', () => {
|
||||
expect(isPublicAddress('127.0.0.1')).toBe(false)
|
||||
expect(isPublicAddress('10.0.0.1')).toBe(false)
|
||||
expect(isPublicAddress('169.254.169.254')).toBe(false)
|
||||
expect(isPublicAddress('192.0.2.1')).toBe(false)
|
||||
expect(isPublicAddress('198.18.0.1')).toBe(false)
|
||||
expect(isPublicAddress('198.51.100.1')).toBe(false)
|
||||
expect(isPublicAddress('203.0.113.1')).toBe(false)
|
||||
expect(isPublicAddress('::1')).toBe(false)
|
||||
expect(isPublicAddress('fc00::1')).toBe(false)
|
||||
expect(isPublicAddress('93.184.216.34')).toBe(true)
|
||||
@@ -42,6 +55,64 @@ describe('URL importer', () => {
|
||||
).rejects.toThrow('私网')
|
||||
})
|
||||
|
||||
it('imports private intranet URLs in compatibility mode', async () => {
|
||||
setIntranetCompatibilityReader(() => true)
|
||||
const transport = vi.fn(async () => ({
|
||||
status: 200,
|
||||
headers: { 'content-type': 'text/plain' },
|
||||
body: Buffer.from('内部知识')
|
||||
}))
|
||||
const importer = new UrlImporter({
|
||||
lookup: async () => [{ address: '192.168.10.25', family: 4 }],
|
||||
transport
|
||||
})
|
||||
|
||||
await expect(
|
||||
importer.import(
|
||||
'http://knowledge.internal/guide',
|
||||
new AbortController().signal
|
||||
)
|
||||
).resolves.toMatchObject({
|
||||
url: 'http://knowledge.internal/guide',
|
||||
contentType: 'text/plain'
|
||||
})
|
||||
expect(transport).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ hostname: 'knowledge.internal' }),
|
||||
{ address: '192.168.10.25', family: 4 },
|
||||
expect.any(AbortSignal),
|
||||
expect.any(Number)
|
||||
)
|
||||
})
|
||||
|
||||
it('keeps metadata, link-local and mixed answers blocked in compatibility mode', async () => {
|
||||
setIntranetCompatibilityReader(() => true)
|
||||
expect(() =>
|
||||
normalizeSourceUrl('http://metadata.google.internal/latest')
|
||||
).toThrow('不允许')
|
||||
expect(() =>
|
||||
normalizeSourceUrl('http://user:secret@knowledge.internal')
|
||||
).toThrow('不允许')
|
||||
|
||||
for (const addresses of [
|
||||
[{ address: '169.254.169.254', family: 4 }],
|
||||
[
|
||||
{ address: '10.0.0.2', family: 4 },
|
||||
{ address: '93.184.216.34', family: 4 }
|
||||
]
|
||||
]) {
|
||||
const importer = new UrlImporter({
|
||||
lookup: async () => addresses,
|
||||
transport: vi.fn()
|
||||
})
|
||||
await expect(
|
||||
importer.import(
|
||||
'http://knowledge.internal',
|
||||
new AbortController().signal
|
||||
)
|
||||
).rejects.toThrow('私网')
|
||||
}
|
||||
})
|
||||
|
||||
it('imports HTML and discovers only same-origin links', async () => {
|
||||
const transport = vi.fn(async () => ({
|
||||
status: 200,
|
||||
|
||||
Reference in New Issue
Block a user