Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"absszero/laravel-stackdriver-error-reporting": "^1.9",
"firebase/php-jwt": "^7.0",
"google/recaptcha": "^1.2",
"guzzlehttp/guzzle": "^7.8",
"guzzlehttp/guzzle": "^7.12",
"guzzlehttp/psr7": "^2.9",
"hackzilla/password-generator": "^1.6",
"intervention/image": "^2.5",
Expand Down
50 changes: 26 additions & 24 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions tests/Services/MediaWikiHostResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
use App\Wiki;
use App\WikiDb;
use Faker\Factory;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\RequestException;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Http;

class MediaWikiHostResolverTest extends TestCase {
use RefreshDatabase;
Expand All @@ -23,6 +26,16 @@ public function testResolverRoutesToCorrectHost(): void {
);
}

public function testResolverBuildsBackendUrl(): void {
$domain = (new Factory())->create()->unique()->text(30);
$this->createWiki($domain, 'mw1.43-wbs2');
$resolver = new MediaWikiHostResolver();
$this->assertEquals(
'http://mediawiki-143-app-backend.default.svc.cluster.local',
$resolver->getBackendHostForDomain($domain)
);
}

private function createWiki(string $domain, string $version) {
$wiki = Wiki::factory()->create(['domain' => $domain]);
WikiDb::create([
Expand Down Expand Up @@ -53,4 +66,25 @@ public function testResolverThrowsIfUnableToFindWiki(): void {
UnknownWikiDomainException::class
);
}

public function testGuzzleRejectsSchemelesUrls(): void {
$client = new Client();

// This should throw RequestException about empty scheme
$this->assertThrows(
fn () => $client->get('mediawiki-143-app-backend.default.svc.cluster.local/w/api.php'),
RequestException::class,
'scheme "" is not allowed'
);
}

public function testGuzzleAcceptsSchemeUrls(): void {
Http::fake(['*' => Http::response()]);

$client = new Client();
// This should NOT throw
$response = $client->get('http://mediawiki-143-app-backend.default.svc.cluster.local/w/api.php');

$this->assertTrue($response->getStatusCode() === 200);
}
}
Loading