Skip to content

Commit

Permalink
Ngrok 3
Browse files Browse the repository at this point in the history
  • Loading branch information
jn-jairo committed Jan 13, 2023
1 parent b12f664 commit 7a72547
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 11 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG-2.x.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Changelog

## [Unreleased](https://github.com/jn-jairo/laravel-ngrok/compare/v2.0.3...2.x)
## [Unreleased](https://github.com/jn-jairo/laravel-ngrok/compare/v2.0.4...2.x)

## [v2.0.4 (2023-01-13)](https://github.com/jn-jairo/laravel-ngrok/compare/v2.0.3...v2.0.4)

### Added
- Ngrok 3 support

## [v2.0.3 (2022-03-03)](https://github.com/jn-jairo/laravel-ngrok/compare/v2.0.2...v2.0.3)

Expand Down
2 changes: 1 addition & 1 deletion src/NgrokCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ private function runProcess(Process $process) : int
if ($webServiceStarted && ! $tunnelStarted) {
$tunnels = $webService->getTunnels();

if (! empty($tunnels) && count($tunnels) > 1) {
if (! empty($tunnels)) {
$tunnelStarted = true;

foreach ($tunnels as $tunnel) {
Expand Down
2 changes: 2 additions & 0 deletions src/NgrokServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ private function extractOriginalHost(Request $request) : string
{
if ($request->hasHeader('x-original-host')) {
$host = $request->header('x-original-host');
} elseif ($request->hasHeader('x-forwarded-host')) {
$host = $request->header('x-forwarded-host');
} else {
$host = $request->getHost();
}
Expand Down
53 changes: 44 additions & 9 deletions tests/NgrokServiceProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,26 @@ class NgrokServiceProviderTest extends TestCase
{
use ProphecyTrait;

public function test_boot_valid_ngrok_url() : void
public function bootValidNgrokUrlProvider() : array
{
return [
'ngrok_2' => [
[
'HTTP_X_ORIGINAL_HOST' => '0000-0000.ngrok.io',
],
],
'ngrok_3' => [
[
'HTTP_X_FORWARDED_HOST' => '0000-0000.ngrok.io',
],
],
];
}

/**
* @dataProvider bootValidNgrokUrlProvider
*/
public function test_boot_valid_ngrok_url(array $headers) : void
{
$urlGenerator = $this->prophesize(UrlGenerator::class);
$urlGenerator->forceScheme('http')->shouldBeCalled();
Expand All @@ -36,9 +55,7 @@ public function test_boot_valid_ngrok_url() : void
['foo' => 'bar'],
[],
[],
[
'HTTP_X_ORIGINAL_HOST' => '0000-0000.ngrok.io',
]
$headers,
);

$app = $this->prophesize(Application::class);
Expand All @@ -52,7 +69,28 @@ public function test_boot_valid_ngrok_url() : void
$this->assertSame('http://0000-0000.ngrok.io/foo', Paginator::resolveCurrentPath());
}

public function test_boot_valid_secure_ngrok_url() : void
public function bootValidSecureNgrokUrlProvider() : array
{
return [
'ngrok_2' => [
[
'HTTP_X_ORIGINAL_HOST' => '0000-0000.ngrok.io',
'HTTP_X_FORWARDED_PROTO' => 'https',
],
],
'ngrok_3' => [
[
'HTTP_X_FORWARDED_HOST' => '0000-0000.ngrok.io',
'HTTP_X_FORWARDED_PROTO' => 'https',
],
],
];
}

/**
* @dataProvider bootValidSecureNgrokUrlProvider
*/
public function test_boot_valid_secure_ngrok_url(array $headers) : void
{
$urlGenerator = $this->prophesize(UrlGenerator::class);
$urlGenerator->forceScheme('https')->shouldBeCalled();
Expand All @@ -69,10 +107,7 @@ public function test_boot_valid_secure_ngrok_url() : void
['foo' => 'bar'],
[],
[],
[
'HTTP_X_ORIGINAL_HOST' => '0000-0000.ngrok.io',
'HTTP_X_FORWARDED_PROTO' => 'https',
]
$headers,
);

$app = $this->prophesize(Application::class);
Expand Down

0 comments on commit 7a72547

Please sign in to comment.