mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-12 16:44:08 -08:00
Merge pull request #14834 from bryanlopezinc/AddAppUrlTest
Added test for app url config
This commit is contained in:
commit
c641b733e1
|
@ -67,28 +67,9 @@ class SettingsController extends Controller
|
||||||
$start_settings['db_error'] = $e->getMessage();
|
$start_settings['db_error'] = $e->getMessage();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (array_key_exists("HTTP_X_FORWARDED_PROTO", $_SERVER)) {
|
$start_settings['url_config'] = trim(config('app.url'), '/'). '/setup';
|
||||||
$protocol = $_SERVER["HTTP_X_FORWARDED_PROTO"] . "://";
|
$start_settings['real_url'] = request()->url();
|
||||||
} elseif (array_key_exists('HTTPS', $_SERVER) && ('on' == $_SERVER['HTTPS'])) {
|
$start_settings['url_valid'] = $start_settings['url_config'] === $start_settings['real_url'];
|
||||||
$protocol = "https://";
|
|
||||||
} else {
|
|
||||||
$protocol = "http://";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (array_key_exists("HTTP_X_FORWARDED_HOST", $_SERVER)) {
|
|
||||||
$host = $_SERVER["HTTP_X_FORWARDED_HOST"];
|
|
||||||
} else {
|
|
||||||
$host = array_key_exists('SERVER_NAME', $_SERVER) ? $_SERVER['SERVER_NAME'] : null;
|
|
||||||
$port = array_key_exists('SERVER_PORT', $_SERVER) ? $_SERVER['SERVER_PORT'] : null;
|
|
||||||
if (('http://' === $protocol && '80' != $port) || ('https://' === $protocol && '443' != $port)) {
|
|
||||||
$host .= ':'.$port;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$pageURL = $protocol.$host.$_SERVER['REQUEST_URI'];
|
|
||||||
|
|
||||||
$start_settings['url_config'] = config('app.url').'/setup';
|
|
||||||
$start_settings['url_valid'] = ($start_settings['url_config'] === $pageURL);
|
|
||||||
$start_settings['real_url'] = $pageURL;
|
|
||||||
$start_settings['php_version_min'] = true;
|
$start_settings['php_version_min'] = true;
|
||||||
|
|
||||||
// Curl the .env file to make sure it's not accessible via a browser
|
// Curl the .env file to make sure it's not accessible via a browser
|
||||||
|
|
|
@ -25,13 +25,6 @@ class ShowSetUpPageTest extends TestCase
|
||||||
*/
|
*/
|
||||||
protected bool $preventStrayRequest = true;
|
protected bool $preventStrayRequest = true;
|
||||||
|
|
||||||
protected function setUp(): void
|
|
||||||
{
|
|
||||||
parent::setUp();
|
|
||||||
|
|
||||||
$_SERVER['REQUEST_URI'] = '/setup';
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function getSetUpPageResponse(): TestResponse
|
protected function getSetUpPageResponse(): TestResponse
|
||||||
{
|
{
|
||||||
if ($this->preventStrayRequest) {
|
if ($this->preventStrayRequest) {
|
||||||
|
@ -234,4 +227,44 @@ class ShowSetUpPageTest extends TestCase
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testWillShowErrorMessageWhenAppUrlIsNotSameWithPageUrl(): void
|
||||||
|
{
|
||||||
|
config(['app.url' => 'http://www.github.com']);
|
||||||
|
|
||||||
|
$this->getSetUpPageResponse()->assertOk();
|
||||||
|
|
||||||
|
$this->assertSeeAppUrlMisconfigurationErrorMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function assertSeeAppUrlMisconfigurationErrorMessage(bool $shouldSee = true): void
|
||||||
|
{
|
||||||
|
$url = URL::to('setup');
|
||||||
|
|
||||||
|
$errorMessage = "Uh oh! Snipe-IT thinks your URL is http://www.github.com/setup, but your real URL is {$url}";
|
||||||
|
$successMessage = 'That URL looks right! Good job!';
|
||||||
|
|
||||||
|
if ($shouldSee) {
|
||||||
|
self::$latestResponse->assertSee($errorMessage)->assertDontSee($successMessage);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
self::$latestResponse->assertSee($successMessage)->assertDontSee($errorMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testWillNotShowErrorMessageWhenAppUrlIsSameWithPageUrl(): void
|
||||||
|
{
|
||||||
|
$this->getSetUpPageResponse()->assertOk();
|
||||||
|
|
||||||
|
$this->assertSeeAppUrlMisconfigurationErrorMessage(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testWhenAppUrlContainsTrailingSlash(): void
|
||||||
|
{
|
||||||
|
config(['app.url' => 'http://www.github.com/']);
|
||||||
|
|
||||||
|
$this->getSetUpPageResponse()->assertOk();
|
||||||
|
|
||||||
|
$this->assertSeeAppUrlMisconfigurationErrorMessage();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue