diff --git a/.env.dusk.testing b/.env.dusk.testing new file mode 100644 index 0000000000..50cb7aa4c4 --- /dev/null +++ b/.env.dusk.testing @@ -0,0 +1,5 @@ +APP_URL=http://localhost:8000 +APP_KEY=base64:FSjpEaK3F9HnO40orj7FlbRI0loi1vtB3dVBcB9XaDk= +APP_ENV=testing +APP_DEBUG=true +#DB_CONNECTION=memory diff --git a/.travis.yml b/.travis.yml index 6ec7198ba7..cc4e02119b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,14 +1,19 @@ sudo: required language: php +addons: + chrome: stable services: - mysql +env: + global: + APP_ENV=testing matrix: fast_finish: true include: - php: 7.3 env: SKIP_STYLE_CHECK=1 - php: 7.2 - env: SKIP_UNIT_CHECK=1 + env: SKIP_UNIT_CHECK=1 BROWSER_TEST=1 - php: 7.1 env: SKIP_STYLE_CHECK=1 EXECUTE_BUILD_DOCS=true @@ -25,18 +30,23 @@ before_install: - cp tests/config/config.test.php config.php install: - - composer install --prefer-dist --no-interaction - - pip install --user snmpsim pylint mysql-python + - travis_retry composer install --no-interaction --prefer-dist --no-suggest + - pip3 install --user snmpsim + - pip install --user mysql-python pylint after_failure: - tail /tmp/snmpsimd.log +before_script: + - test -z "$BROWSER_TEST" || php artisan serve --env=dusk.testing 2>/dev/null & + script: - set -e - export FILES=$(git diff --diff-filter=d --name-only master | tr '\n' ' '|sed 's/,*$//g') - php scripts/pre-commit.php -q -l - php scripts/pre-commit.php -q -s - php scripts/pre-commit.php -u --db --snmpsim --fail-fast + - test -z "$BROWSER_TEST" || php artisan dusk - bash -n daily.sh - pylint -E poller-wrapper.py discovery-wrapper.py - bash scripts/deploy-docs.sh diff --git a/app/Application.php b/app/Application.php new file mode 100644 index 0000000000..1a87ff06be --- /dev/null +++ b/app/Application.php @@ -0,0 +1,35 @@ +. + * + * @package LibreNMS + * @link http://librenms.org + * @copyright 2018 Tony Murray + * @author Tony Murray + */ + +namespace App; + +class Application extends \Illuminate\Foundation\Application +{ + public function publicPath() + { + // override the public path + return $this->basePath.DIRECTORY_SEPARATOR.'html'; + } +} diff --git a/bootstrap/app.php b/bootstrap/app.php index 037e17df03..ae8c1ee0ca 100644 --- a/bootstrap/app.php +++ b/bootstrap/app.php @@ -11,7 +11,7 @@ | */ -$app = new Illuminate\Foundation\Application( +$app = new App\Application( $_ENV['APP_BASE_PATH'] ?? dirname(__DIR__) ); diff --git a/composer.json b/composer.json index 699d1cd948..8443892970 100644 --- a/composer.json +++ b/composer.json @@ -52,18 +52,19 @@ "doctrine/dbal": "^2.9" }, "require-dev": { + "barryvdh/laravel-debugbar": "^3.2", + "barryvdh/laravel-ide-helper": "^2.5", "beyondcode/laravel-dump-server": "^1.0", "filp/whoops": "^2.0", "fzaninotto/faker": "^1.4", + "jakub-onderka/php-console-highlighter": "*", + "jakub-onderka/php-parallel-lint": "*", + "justinrainbow/json-schema": "^5.2", + "laravel/dusk": "^5.0", "mockery/mockery": "^1.0", "nunomaduro/collision": "^2.0", "phpunit/phpunit": "^7.0", - "squizlabs/php_codesniffer": "^2.9.1", - "jakub-onderka/php-parallel-lint": "*", - "jakub-onderka/php-console-highlighter": "*", - "barryvdh/laravel-ide-helper": "^2.5", - "barryvdh/laravel-debugbar": "^3.2", - "justinrainbow/json-schema": "^5.2" + "squizlabs/php_codesniffer": "^2.9.1" }, "suggest": { "ext-memcached": "Required if you utilize distributed polling", diff --git a/composer.lock b/composer.lock index 102757b46f..2f1646b51f 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "89499eb92892d605e890132cd59dfd9d", + "content-hash": "e914d23478621df28362563f06165c49", "packages": [ { "name": "amenadiel/jpgraph", @@ -5078,6 +5078,66 @@ ], "time": "2017-07-22T11:58:36+00:00" }, + { + "name": "facebook/webdriver", + "version": "1.6.0", + "source": { + "type": "git", + "url": "https://github.com/facebook/php-webdriver.git", + "reference": "bd8c740097eb9f2fc3735250fc1912bc811a954e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/facebook/php-webdriver/zipball/bd8c740097eb9f2fc3735250fc1912bc811a954e", + "reference": "bd8c740097eb9f2fc3735250fc1912bc811a954e", + "shasum": "" + }, + "require": { + "ext-curl": "*", + "ext-json": "*", + "ext-mbstring": "*", + "ext-zip": "*", + "php": "^5.6 || ~7.0", + "symfony/process": "^2.8 || ^3.1 || ^4.0" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "^2.0", + "jakub-onderka/php-parallel-lint": "^0.9.2", + "php-coveralls/php-coveralls": "^2.0", + "php-mock/php-mock-phpunit": "^1.1", + "phpunit/phpunit": "^5.7", + "sebastian/environment": "^1.3.4 || ^2.0 || ^3.0", + "squizlabs/php_codesniffer": "^2.6", + "symfony/var-dumper": "^3.3 || ^4.0" + }, + "suggest": { + "ext-SimpleXML": "For Firefox profile creation" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-community": "1.5-dev" + } + }, + "autoload": { + "psr-4": { + "Facebook\\WebDriver\\": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "description": "A PHP client for Selenium WebDriver", + "homepage": "https://github.com/facebook/php-webdriver", + "keywords": [ + "facebook", + "php", + "selenium", + "webdriver" + ], + "time": "2018-05-16T17:37:13+00:00" + }, { "name": "filp/whoops", "version": "2.3.1", @@ -5351,6 +5411,67 @@ ], "time": "2019-01-14T23:55:14+00:00" }, + { + "name": "laravel/dusk", + "version": "v5.0.0", + "source": { + "type": "git", + "url": "https://github.com/laravel/dusk.git", + "reference": "590480abf75bf052873d7ff16deb5736cf749a55" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/laravel/dusk/zipball/590480abf75bf052873d7ff16deb5736cf749a55", + "reference": "590480abf75bf052873d7ff16deb5736cf749a55", + "shasum": "" + }, + "require": { + "facebook/webdriver": "^1.3", + "illuminate/console": "~5.7.0|~5.8.0", + "illuminate/support": "~5.7.0|~5.8.0", + "nesbot/carbon": "^1.20|^2.0", + "php": ">=7.1.0", + "symfony/console": "^4.0", + "symfony/process": "^4.0" + }, + "require-dev": { + "mockery/mockery": "^1.0", + "phpunit/phpunit": "^7.0|^8.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.0-dev" + }, + "laravel": { + "providers": [ + "Laravel\\Dusk\\DuskServiceProvider" + ] + } + }, + "autoload": { + "psr-4": { + "Laravel\\Dusk\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Taylor Otwell", + "email": "taylor@laravel.com" + } + ], + "description": "Laravel Dusk provides simple end-to-end testing and browser automation.", + "keywords": [ + "laravel", + "testing", + "webdriver" + ], + "time": "2019-02-12T14:17:11+00:00" + }, { "name": "maximebf/debugbar", "version": "v1.15.0", diff --git a/config/database.php b/config/database.php index 6959a4b38d..6dd714d32f 100644 --- a/config/database.php +++ b/config/database.php @@ -94,6 +94,12 @@ return [ 'prefix_indexes' => true, ], + 'memory' => [ + 'driver' => 'sqlite', + 'database' => ':memory:', + 'prefix' => '', + ] + ], /* diff --git a/database/factories/ModelFactory.php b/database/factories/ModelFactory.php index 0cbbb2a597..5349bd3f38 100644 --- a/database/factories/ModelFactory.php +++ b/database/factories/ModelFactory.php @@ -16,14 +16,27 @@ use Carbon\Carbon; use LibreNMS\Util\IPv4; -$factory->define(App\User::class, function (Faker\Generator $faker) { +$factory->define(App\Models\User::class, function (Faker\Generator $faker) { static $password; return [ - 'name' => $faker->name, - 'email' => $faker->unique()->safeEmail, + 'username' => $faker->unique()->userName, + 'realname' => $faker->name, + 'email' => $faker->safeEmail, 'password' => $password ?: $password = bcrypt('secret'), - 'remember_token' => str_random(10), + 'level' => 1, + ]; +}); + +$factory->state(App\Models\User::class, 'admin', function ($faker) { + return [ + 'level' => '10', + ]; +}); + +$factory->state(App\Models\User::class, 'read', function ($faker) { + return [ + 'level' => '5', ]; }); diff --git a/database/migrations/2018_07_03_091314_create_alert_schedulables_table.php b/database/migrations/2018_07_03_091314_create_alert_schedulables_table.php index 5ed9fbfda9..0d040fb029 100644 --- a/database/migrations/2018_07_03_091314_create_alert_schedulables_table.php +++ b/database/migrations/2018_07_03_091314_create_alert_schedulables_table.php @@ -29,6 +29,6 @@ class CreateAlertSchedulablesTable extends Migration */ public function down() { - Schema::drop('alert_schedule_items'); + Schema::drop('alert_schedulables'); } } diff --git a/database/migrations/2018_07_03_091322_add_foreign_keys_to_sensors_to_state_indexes_table.php b/database/migrations/2018_07_03_091322_add_foreign_keys_to_sensors_to_state_indexes_table.php index 4c6589541c..1ab48d951b 100644 --- a/database/migrations/2018_07_03_091322_add_foreign_keys_to_sensors_to_state_indexes_table.php +++ b/database/migrations/2018_07_03_091322_add_foreign_keys_to_sensors_to_state_indexes_table.php @@ -27,7 +27,7 @@ class AddForeignKeysToSensorsToStateIndexesTable extends Migration public function down() { Schema::table('sensors_to_state_indexes', function (Blueprint $table) { - $table->dropForeign('sensors_to_state_indexes_ibfk_2'); + $table->dropForeign('sensors_to_state_indexes_ibfk_1'); $table->dropForeign('sensors_to_state_indexes_sensor_id_foreign'); }); } diff --git a/phpunit.xml b/phpunit.xml index 9edf9f2e84..0b30615671 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -23,6 +23,7 @@ + browser mibs diff --git a/resources/views/auth/login-form.blade.php b/resources/views/auth/login-form.blade.php index c8bd358b6c..a71e63b7a6 100644 --- a/resources/views/auth/login-form.blade.php +++ b/resources/views/auth/login-form.blade.php @@ -39,7 +39,7 @@
-
diff --git a/server.php b/server.php index 5fb6379e71..b5687a740d 100644 --- a/server.php +++ b/server.php @@ -14,8 +14,8 @@ $uri = urldecode( // This file allows us to emulate Apache's "mod_rewrite" functionality from the // built-in PHP web server. This provides a convenient way to test a Laravel // application without having installed a "real" web server software here. -if ($uri !== '/' && file_exists(__DIR__.'/public'.$uri)) { +if ($uri !== '/' && file_exists(__DIR__.'/html'.$uri)) { return false; } -require_once __DIR__.'/public/index.php'; +require_once __DIR__.'/html/index.php'; diff --git a/tests/Browser/LoginTest.php b/tests/Browser/LoginTest.php new file mode 100644 index 0000000000..21354175f9 --- /dev/null +++ b/tests/Browser/LoginTest.php @@ -0,0 +1,40 @@ +browse(function (Browser $browser) { + $password = 'some_password'; + $user = factory(User::class)->create([ + 'password' => password_hash($password, PASSWORD_DEFAULT) + ]); + + $browser->visit(new LoginPage()) + ->type('username', $user->username) + ->type('password', $password) + ->press('#login') + ->assertPathIs('/'); + + $user->delete(); + }); + } +} diff --git a/tests/Browser/Pages/LoginPage.php b/tests/Browser/Pages/LoginPage.php new file mode 100644 index 0000000000..f6cce413d9 --- /dev/null +++ b/tests/Browser/Pages/LoginPage.php @@ -0,0 +1,41 @@ +assertPathIs($this->url()); + } + + /** + * Get the element shortcuts for the page. + * + * @return array + */ + public function elements() + { + return [ + '@element' => '#selector', + ]; + } +} diff --git a/tests/Browser/Pages/Page.php b/tests/Browser/Pages/Page.php new file mode 100644 index 0000000000..599117e092 --- /dev/null +++ b/tests/Browser/Pages/Page.php @@ -0,0 +1,20 @@ + '#selector', + ]; + } +} diff --git a/tests/Browser/console/.gitignore b/tests/Browser/console/.gitignore new file mode 100644 index 0000000000..76bedaeabb --- /dev/null +++ b/tests/Browser/console/.gitignore @@ -0,0 +1,5 @@ +# Ignore everything in this directory +* +# Except this file +!.gitignore + diff --git a/tests/Browser/screenshots/.gitignore b/tests/Browser/screenshots/.gitignore new file mode 100644 index 0000000000..76bedaeabb --- /dev/null +++ b/tests/Browser/screenshots/.gitignore @@ -0,0 +1,5 @@ +# Ignore everything in this directory +* +# Except this file +!.gitignore + diff --git a/tests/DuskTestCase.php b/tests/DuskTestCase.php new file mode 100644 index 0000000000..04f98a27fd --- /dev/null +++ b/tests/DuskTestCase.php @@ -0,0 +1,40 @@ +setCapability( + ChromeOptions::CAPABILITY, + (new ChromeOptions)->addArguments([ + '--disable-gpu', + '--headless' + ]) + )); + } +}