mirror of
https://github.com/BookStackApp/BookStack.git
synced 2026-07-16 21:31:53 +03:00
Adds a more substantial URL check, via a new class which is shared and used in other parts of the app for consistency. Thanks to mfk25 for reporting.
61 lines
1.9 KiB
PHP
61 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace Tests\Util;
|
|
|
|
use BookStack\Util\UrlComparison;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class UrlComparisonTest extends TestCase
|
|
{
|
|
public function test_origins_match()
|
|
{
|
|
$good = [
|
|
['http://localhost/a/b', 'http://localhost#cat'],
|
|
['example.com/a/b', 'example.com?cat=dog'],
|
|
['https://example.com:5050/a/b', 'https://example.com:5050/a/b'],
|
|
];
|
|
|
|
$bad = [
|
|
['http://localhost/a/b', 'http://localh0st#cat'],
|
|
['https://example.com/a/b', 'http://example.com?cat=dog'],
|
|
['https://example.com:5051/a/b', 'https://example.com:5050/a/b'],
|
|
];
|
|
|
|
foreach ($good as [$a, $b]) {
|
|
$comparison = new UrlComparison($a, $b);
|
|
$this->assertTrue($comparison->originsMatch());
|
|
}
|
|
|
|
foreach ($bad as [$a, $b]) {
|
|
$comparison = new UrlComparison($a, $b);
|
|
$this->assertFalse($comparison->originsMatch());
|
|
}
|
|
}
|
|
|
|
public function test_paths_overlap()
|
|
{
|
|
$good = [
|
|
['https://example.com', 'https://example.com/a/b/c'],
|
|
['https://example.com/', 'https://example.com/a/b/c'],
|
|
['https://example.com/a/b', 'https://example.com/a/b/c'],
|
|
['https://example.com/a/b/c', 'https://example.com/a'],
|
|
['http://donk.com/a/b/c?a=b#cat', 'https://example.com:5005/a/b#hello'],
|
|
];
|
|
|
|
$bad = [
|
|
['https://example.com/a/c', 'https://example.com/a/b/c/d'],
|
|
['https://example.com/a/c', 'https://example.com/d/a/c'],
|
|
];
|
|
|
|
foreach ($good as [$a, $b]) {
|
|
$comparison = new UrlComparison($a, $b);
|
|
$this->assertTrue($comparison->pathsOverlap());
|
|
}
|
|
|
|
foreach ($bad as [$a, $b]) {
|
|
$comparison = new UrlComparison($a, $b);
|
|
$this->assertFalse($comparison->pathsOverlap());
|
|
}
|
|
}
|
|
}
|