Skip to content

Commit

Permalink
Fix incorrectly setting trusted proxies. Fixes #151
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkaOnLine committed Jul 19, 2018
1 parent ae29726 commit c081760
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
8 changes: 5 additions & 3 deletions src/Http/Controllers/SwaggerController.php
Expand Up @@ -44,9 +44,11 @@ public function api()
Generator::generateDocs();
}

if (config('l5-swagger.proxy')) {
$proxy = Request::server('REMOTE_ADDR');
Request::setTrustedProxies([$proxy]);
if ($proxy = config('l5-swagger.proxy')) {
if (! is_array($proxy)) {
$proxy = [$proxy];
}
Request::setTrustedProxies($proxy, \Illuminate\Http\Request::HEADER_X_FORWARDED_ALL);
}

// Need the / at the end to avoid CORS errors on Homestead systems.
Expand Down
20 changes: 10 additions & 10 deletions tests/GeneratorTest.php
Expand Up @@ -35,12 +35,12 @@ public function canGenerateApiJsonFile()
$this->get(route('l5-swagger.docs'))
->assertSee('L5 Swagger')
->assertSee('my-default-host.com')
->isOk();
->assertStatus(200);

$this->get(route('l5-swagger.docs', ['jsonFile' => config('l5-swagger.paths.docs_yaml')]))
->assertSee('L5 Swagger')
->assertSee('my-default-host.com')
->isOk();
->assertStatus(200);
}

/** @test */
Expand All @@ -63,12 +63,12 @@ public function canGenerateApiJsonFileWithChangedBasePath()
$this->get(route('l5-swagger.docs'))
->assertSee('L5 Swagger')
->assertSee('new_path')
->isOk();
->assertStatus(200);

$this->get(route('l5-swagger.docs', ['jsonFile' => config('l5-swagger.paths.docs_yaml')]))
->assertSee('L5 Swagger')
->assertSee('new_path')
->isOk();
->assertStatus(200);
}

/** @test */
Expand All @@ -92,12 +92,12 @@ public function canGenerateApiJsonFileWithChangedBaseServer()
$this->get(route('l5-swagger.docs'))
->assertSee('https://test-server.url')
->assertDontSee('basePath')
->isOk();
->assertStatus(200);

$this->get(route('l5-swagger.docs', ['jsonFile' => config('l5-swagger.paths.docs_yaml')]))
->assertSee('https://test-server.url')
->assertDontSee('basePath')
->isOk();
->assertStatus(200);
}

/** @test */
Expand All @@ -106,11 +106,11 @@ public function canSetProxy()
$this->setAnnotationsPath();

$cfg = config('l5-swagger');
$cfg['proxy'] = 'http://proxy.dev';
$cfg['proxy'] = '*';
config(['l5-swagger' => $cfg]);

$this->get(route('l5-swagger.api'))
->isOk();
->assertStatus(200);

$this->assertTrue(file_exists($this->jsonDocsFile()));
$this->assertTrue(file_exists($this->yamlDocsFile()));
Expand All @@ -127,11 +127,11 @@ public function canSetValidatorUrl()

$this->get(route('l5-swagger.api'))
->assertSee('validator-url.dev')
->isOk();
->assertStatus(200);

$this->get(route('l5-swagger.api', ['jsonFile' => config('l5-swagger.paths.docs_yaml')]))
->assertSee('validator-url.dev')
->isOk();
->assertStatus(200);

$this->assertTrue(file_exists($this->jsonDocsFile()));
$this->assertTrue(file_exists($this->yamlDocsFile()));
Expand Down

0 comments on commit c081760

Please sign in to comment.