diff --git a/application/controllers/AuthenticationController.php b/application/controllers/AuthenticationController.php index f346f44cc..9068a1d39 100644 --- a/application/controllers/AuthenticationController.php +++ b/application/controllers/AuthenticationController.php @@ -63,7 +63,7 @@ class AuthenticationController extends ActionController $credentials = new Credentials(); $this->view->form = new LoginForm(); $this->view->form->setRequest($this->_request); - + $this->view->title = "Icinga Web Login"; try { $auth = AuthManager::getInstance(null, array( 'writeSession' => $this->modifiesSession diff --git a/application/forms/Authentication/LoginForm.php b/application/forms/Authentication/LoginForm.php index 66c665543..a7d8a31e3 100644 --- a/application/forms/Authentication/LoginForm.php +++ b/application/forms/Authentication/LoginForm.php @@ -43,6 +43,7 @@ class LoginForm extends Form */ protected function create() { + $this->setName('login'); $this->addElement( 'text', 'username', diff --git a/application/layouts/scripts/layout.phtml b/application/layouts/scripts/layout.phtml index 3f842f5cd..02798122a 100755 --- a/application/layouts/scripts/layout.phtml +++ b/application/layouts/scripts/layout.phtml @@ -11,7 +11,7 @@ - + <?= $this->title ? $this->title : 'Icinga Web'; ?> diff --git a/application/layouts/scripts/parts/topbar.phtml b/application/layouts/scripts/parts/topbar.phtml index 1648ea346..35698cb92 100755 --- a/application/layouts/scripts/parts/topbar.phtml +++ b/application/layouts/scripts/parts/topbar.phtml @@ -13,17 +13,19 @@ diff --git a/public/index.php.in b/public/index.php.in deleted file mode 100644 index 9a6cc6689..000000000 --- a/public/index.php.in +++ /dev/null @@ -1,10 +0,0 @@ -dispatch(); diff --git a/test/frontend/cases/historyApiTest.js b/test/frontend/cases/historyApiTest.js deleted file mode 100644 index a346447a9..000000000 --- a/test/frontend/cases/historyApiTest.js +++ /dev/null @@ -1,61 +0,0 @@ - -var i2w = require('./i2w-config'); -var casper = i2w.getTestEnv(); - -casper.start("http://localhost:12999/generic.html"); - -casper.then(function() { - casper.page.evaluate(i2w.setupRequireJs, {icinga: true}); -}); - - -casper.then(function() { - this.test.assertTitle("Icinga test page"); - casper.page.evaluate(function() { - requirejs(["icinga/icinga"], function(icinga) { - icinga.loadUrl("/fragments/testFragment1.html"); - }); - }); - /*this.waitFor(function() { - return document.querySelectorAll("#icinga-main a") ; - }, */ - casper.waitForSelector("div#icinga-main a", onFirstLink); -}); - -var onFirstLink = function() { - var links = casper.page.evaluate(function() { - return document.querySelectorAll("div#icinga-main a"); - }); - // assert no reload - this.test.assertTitle("Icinga test page"); - this.test.assertUrlMatch(/.*testFragment1.html/); - this.test.assertEquals(links.length, 2); - casper.clickLabel('Fragment 2'); - casper.waitForText('Fragment 1', onSecondLink); -}; - -var onSecondLink = function() { - var links = casper.page.evaluate(function() { - return document.querySelectorAll("div#icinga-main a"); - }); - this.test.assertTitle("Icinga test page"); - this.test.assertUrlMatch(/.*testFragment2.html/); - this.test.assertEquals(links.length, 2); - casper.page.evaluate(function() { - requirejs(["icinga/icinga"], function(icinga) { - icinga.loadUrl("/fragments/testFragment3.html?this=is_a_param", "icinga-detail"); - - }); - }); - this.wait(400, function() { - console.log(casper.page.evaluate(function() { - return window.location.href; - })); - - this.test.assertUrlMatch(/testFragment2.html.*testFragment3.html/); - }); -}; - -casper.run(function() { - this.test.done(); -}); diff --git a/test/frontend/cases/loginpageTest.js b/test/frontend/cases/loginpageTest.js new file mode 100644 index 000000000..f56c50d73 --- /dev/null +++ b/test/frontend/cases/loginpageTest.js @@ -0,0 +1,175 @@ +/** + * Test case for the login page + * + * Steps: + * - Request application root path + * - Assert login page to appear + * - Enter invalid credentials + * - Enter valid credentials + * - Reload page without credentials + * - Logout + **/ + +/** + * The icinga util object + * + * @type object + */ +var icinga = require('./icingawebtest'); + +/** + * The casperjs object + * + * @type Casper + */ +var casper = icinga.getTestEnv(); + +/** + * Test whether the login form exists and has valid input elements + * + * @param {testing} The casperjs testing module to perform assertions + */ +var assertLoginFormExists = function(test) { + + test.assertExists( + 'form#login', + 'Test whether the login form exists' + ); + test.assertExists( + 'form#login input#username', + 'Test whether a username input field exists' + ); + test.assertExists( + 'form#login input#password', + 'Test whether a password input field exists' + ); + test.assertExists( + 'form#login input#submit', + 'Test whether a submit input field exists' + ); +}; + +/** + * Request the initial application path + */ +casper.start('/', function() { + if (this.getCurrentUrl() === 'about:blank') { + this.die('Url can\'t be accessed'); + } + this.test.assertTitle( + "Icinga Web Login", + "Test whether the login page (" + this.getCurrentUrl() + ") has a correct title" + ); + assertLoginFormExists(this.test); + this.test.assertDoesntExist( + '#icinga_app_username', + 'Test if no username is set in the frontend after initial page load' + ); +}); + +/** + * Login with invalid credentials + */ +casper.then(function() { + this.fill('form#login', { + 'username' : 'no', + 'password' : 'existing_user' + }); + this.click('form#login input#submit'); +}); + +/** + * Test if login failed and feedback is given + */ +casper.then(function() { + this.test.assertTextExists( + 'Please provide a valid username and password', + 'Test if the user gets a note that authorization failed if providing wrong credentials' + ); + assertLoginFormExists(this.test); + this.test.assertDoesntExist( + '#icinga_app_username', + 'Test if no username is set in the frontend after entering wrong credentials' + ); + +}); + +/** + * Login with valid credentials + */ +casper.then(function() { + this.fill('form#login', icinga.getCredentials()); + this.click('form#login input#submit'); +}); + +/** + * Test if the login suceeded and the username is shown in the navigation bar + */ +casper.then(function() { + this.test.assertTextDoesntExist( + 'Please provide a valid username and password', + 'Test if valid credentials don\'t end cause a note that credentials are wrong to appear' + ); + this.test.assertSelectorHasText( + '#icinga_app_nav_username', + icinga.getCredentials().username, + 'Test if the username is set in the frontend after successful login' + ); +}); + +/** + * Test if session is persisted after reloading the page + */ +casper.thenOpen('/', function() { + this.test.assertSelectorHasText( + '#icinga_app_nav_username', + icinga.getCredentials().username, + 'Test if the username is still set if reloading the page via GET' + ); + + this.test.assertExists( + '#icinga_app_nav_logout', + 'Test if the logout button exists' + ); + + this.test.assertExists( + '#icinga_app_nav_useraction', + 'Test whether the dropdown for user specific actions exists' + ); +}); + +/** + * Test if logout button is displayed when username is clicked and test for correct logout + */ +casper.then(function() { + this.test.assertNotVisible( + '#icinga_app_nav_logout', + 'Test if the logout button is hidden when not clicked' + ); + + this.wait(500, function() { // wait until everything is initialized, sometimes this takes a while + this.click('#icinga_app_nav_useraction'); + this.waitUntilVisible('#icinga_app_nav_logout', function() { + this.click('#icinga_app_nav_logout a'); + this.waitForSelector('form#login', function() { + this.test.assertDoesntExist( + '#icinga_app_username', + 'Test if no username is set in the frontend after logout' + ); + assertLoginFormExists(this.test); + }); + }, function() { + this.test.assertVisible( + '#icinga_app_nav_logout', + 'Test if the logout button is visible when click on username occurs' + ); + }, 500); + }); +}); + +/** + * Run the tests + */ +casper.run(function() { + this.test.done(); +}); diff --git a/test/frontend/cases/static-page-test.js b/test/frontend/cases/static-page-test.js deleted file mode 100644 index 39f94081f..000000000 --- a/test/frontend/cases/static-page-test.js +++ /dev/null @@ -1,21 +0,0 @@ -/** -* -* This test simply checks the icinga build server and tests -* if the title is correct -**/ -i2w = require('./i2w-config'); - -var casper = i2w.getTestEnv(); - -casper.start("http://localhost:12999/empty.html"); - - -casper.then(function() { - this.test.assertTitle("Just an empty page"); -}); - - -casper.run(function() { - this.test.done(); -}); - diff --git a/test/frontend/casperjs.config b/test/frontend/casperjs.config deleted file mode 100644 index 69c9d4a3b..000000000 --- a/test/frontend/casperjs.config +++ /dev/null @@ -1,5 +0,0 @@ -{ - "host": "localhost", - "port": 80, - "path": "icinga2-web" -} diff --git a/test/frontend/i2w-config.js b/test/frontend/i2w-config.js deleted file mode 100644 index 4d72b6d7e..000000000 --- a/test/frontend/i2w-config.js +++ /dev/null @@ -1,158 +0,0 @@ -/** -* Tools for setting up the casperjs tests -* mainly setting host, port and path path -**/ - -// load config files -var fs = require('fs'); -var env = require('system').env; -var args = require('system').args; -var utils = require('utils'); - - -var configFile = fs.absolute('./casperjs.config'); -var host = null; -var port = null; -var path = null; -var verbose = false; - - -if (typeof(env.CASPERJS_HOST) === "string") - host = env.CASPERJS_HOST; -if (typeof(env.CASPERJS_PORT) === "string") - port = parseInt(env.CASPERJS_PORT, 10); -if (typeof(env.CASPERJS_PATH) === "string") - path = env.CASPERJS_PATH; - - -for (var i=0;i - - Just an empty page - - - - diff --git a/test/frontend/static/fragments/testFragment1.html b/test/frontend/static/fragments/testFragment1.html deleted file mode 100644 index 2d6ef70db..000000000 --- a/test/frontend/static/fragments/testFragment1.html +++ /dev/null @@ -1,6 +0,0 @@ -
-

Test fragment

- Fragment 2 - Fragment 3 - -
diff --git a/test/frontend/static/fragments/testFragment2.html b/test/frontend/static/fragments/testFragment2.html deleted file mode 100644 index 4db44e053..000000000 --- a/test/frontend/static/fragments/testFragment2.html +++ /dev/null @@ -1,6 +0,0 @@ -
-

Test fragment 2

- Fragment 1 - Fragment 3 - -
diff --git a/test/frontend/static/fragments/testFragment3.html b/test/frontend/static/fragments/testFragment3.html deleted file mode 100644 index e773f5eff..000000000 --- a/test/frontend/static/fragments/testFragment3.html +++ /dev/null @@ -1,6 +0,0 @@ -
-

Test fragment 3

- Fragment 1 - Fragment 2 - -
diff --git a/test/frontend/static/generic.html b/test/frontend/static/generic.html deleted file mode 100644 index d1e8c301a..000000000 --- a/test/frontend/static/generic.html +++ /dev/null @@ -1,39 +0,0 @@ - - - - - - - - - - - Icinga test page - - - - - - - - - - - - - -
-
-
- -
- - - diff --git a/test/frontend/static/moduleMock.js b/test/frontend/static/moduleMock.js deleted file mode 100644 index aa9c4079f..000000000 --- a/test/frontend/static/moduleMock.js +++ /dev/null @@ -1,4 +0,0 @@ -define([], function() { - "use strict"; - return {}; -}); diff --git a/test/frontend/test.xml b/test/frontend/test.xml deleted file mode 100644 index 68ba1bc3a..000000000 --- a/test/frontend/test.xml +++ /dev/null @@ -1 +0,0 @@ -Page title is: "i4cinga-web test [Jenkins]" \ No newline at end of file