Merge branch 'feature/module-enable-4092' of ssh://git.icinga.org/icinga2-web into feature/module-enable-4092

This commit is contained in:
Jannis Moßhammer 2013-06-26 16:52:25 +02:00
commit 39fff006de
32 changed files with 380 additions and 292 deletions

3
.gitignore vendored
View File

@ -12,3 +12,6 @@ config.log
# cmd tester
test/php/bin/extcmd_test
# misc test output
test/frontend/static/public

View File

@ -6,8 +6,9 @@
# namespace Icinga\Application\Controllers;
use Icinga\Web\ActionController;
use Icinga\Authentication\Auth;
use Icinga\Web\Notification;
use Icinga\Authentication\Credentials as Credentials;
use Icinga\Authentication\Manager as AuthManager;
use Icinga\Form\Builder as FormBuilder;
/**
* Class AuthenticationController
@ -25,13 +26,67 @@ class AuthenticationController extends ActionController
*/
protected $modifiesSession = true;
private function getAuthForm()
{
return array(
'username' => array(
'text',
array(
'label' => t('Username'),
'required' => true,
)
),
'password' => array(
'password',
array(
'label' => t('Password'),
'required' => true
)
),
'submit' => array(
'submit',
array(
'label' => t('Login'),
'class' => 'pull-right'
)
)
);
}
/**
*
*/
public function loginAction()
{
$this->replaceLayout = true;
$this->view->form = $this->widget('form', array('name' => 'login'));
$credentials = new Credentials();
$this->view->form = FormBuilder::fromArray(
$this->getAuthForm(),
array(
"CSRFProtection" => false, // makes no sense here
"model" => &$credentials
)
);
try {
$auth = AuthManager::getInstance(null, array(
"writeSession" => true
));
if ($auth->isAuthenticated()) {
$this->redirectNow('index?_render=body');
}
if ($this->getRequest()->isPost() && $this->view->form->isSubmitted()) {
$this->view->form->repopulate();
if ($this->view->form->isValid()) {
if (!$auth->authenticate($credentials)) {
$this->view->form->getElement('password')->addError(t('Please provide a valid username and password'));
} else {
$this->redirectNow('index?_render=body');
}
}
}
} catch (\Icinga\Exception\ConfigurationError $configError) {
$this->view->errorInfo = $configError->getMessage();
}
}
/**
@ -39,11 +94,13 @@ class AuthenticationController extends ActionController
*/
public function logoutAction()
{
$auth = AuthManager::getInstance(null, array(
"writeSession" => true
));
$this->replaceLayout = true;
Auth::getInstance()->forgetAuthentication();
Notification::success('You have been logged out');
$auth->removeAuthorization();
$this->_forward('login');
}
}
// @codingStandardsIgnoreEnd
// @codingStandardsIgnoreEnd

View File

@ -12,7 +12,7 @@
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown"><?php echo
$this->escape($this->auth()->getUsername())
$this->escape($this->auth()->getUser()->getUsername())
?> <i class="icon-user icon-white" style="margin-top:0.2em"></i>
<b class="caret"></b>
</a>

View File

@ -1 +1,10 @@
<?php echo $this->form ?>
<div class="well" style="margin:auto;width: 40%;max-width:25em;margin-top:10%;">
<h1> Login </h1>
<?php echo $this->form->render() ?>
<?php if (isset($this->errorInfo)): ?>
<div class="alert alert-error">
<?= $this->errorInfo ?>
</div>
<?php endif ?>
</div>

View File

@ -1,2 +1,9 @@
[users]
backend=ldap
hostname=localhost
root_dn="ou=people,dc=icinga,dc=org"
bind_dn="cn=admin,cn=config"
bind_pw=admin
user_class=inetOrgPerson
user_name_attribute=uid

View File

@ -38,7 +38,6 @@ class Web extends ApplicationBootstrap
return $this->loadConfig()
->configureErrorHandling()
->setTimezone()
->configureSession()
->configureCache()
->prepareZendMvc()
->loadTranslations()
@ -91,16 +90,6 @@ class Web extends ApplicationBootstrap
$this->dispatchFrontController();
}
/**
* Configure web session settings
*
* @return self
*/
protected function configureSession()
{
Manager::getInstance();
return $this;
}
protected function loadTranslations()
{

View File

@ -6,6 +6,9 @@ namespace Icinga\Authentication;
class Backend
{
/**
* @var UserBackend
*/
protected $userBackend;
public function __construct($config)

View File

@ -5,7 +5,10 @@
namespace Icinga\Authentication\Backend;
use Icinga\Authentication\User as User;
use Icinga\Authentication\UserBackend;
use Icinga\Authentication\Credentials;
use Icinga\Protocol\Ldap;
use Icinga\Application\Config;
class LdapUserBackend implements UserBackend
{
@ -16,14 +19,11 @@ class LdapUserBackend implements UserBackend
$this->connection = new Ldap\Connection($config);
}
public function hasUsername($username)
public function hasUsername(Credentials $credential)
{
if (!$username) {
return false;
}
return $this->connection->fetchOne(
$this->selectUsername($username)
) === $username;
$this->selectUsername($credential->getUsername())
) === $credential->getUsername();
}
protected function stripAsterisks($string)
@ -34,23 +34,28 @@ class LdapUserBackend implements UserBackend
protected function selectUsername($username)
{
return $this->connection->select()
->from('user', array('sAMAccountName'))
->where('sAMAccountName', $this->stripAsterisks($username));
->from(
Config::getInstance()->authentication->users->user_class,
array(
Config::getInstance()->authentication->users->user_name_attribute
)
)
->where(
Config::getInstance()->authentication->users->user_name_attribute,
$this->stripAsterisks($username)
);
}
public function authenticate($username, $password = null)
public function authenticate(Credentials $credentials)
{
if (empty($username) || empty($password)) {
return false;
}
if (!$this->connection->testCredentials(
$this->connection->fetchDN($this->selectUsername($username)),
$password
) ) {
$this->connection->fetchDN($this->selectUsername($credentials->getUsername())),
$credentials->getPassword()
)
) {
return false;
}
$user = new User($username);
$user = new User($credentials->getUsername());
return $user;
}

View File

@ -6,6 +6,7 @@ namespace Icinga\Authentication;
use Icinga\Application\Logger as Logger;
use Icinga\Application\Config as Config;
use Icinga\Exception\ConfigurationError as ConfigError;
class Manager
{
@ -25,7 +26,6 @@ class Manager
if ($config === null) {
$config = Config::getInstance()->authentication;
}
if (isset($options["userBackendClass"])) {
$this->userBackend = $options["userBackendClass"];
} elseif ($config->users !== null) {
@ -77,6 +77,15 @@ class Manager
public function authenticate(Credentials $credentials, $persist = true)
{
if (!$this->userBackend) {
Logger::error("No authentication backend provided, your users will never be able to login.");
throw new ConfigError(
"No authentication backend set - login will never succeed as icinga-web ".
"doesn't know how to determine your user. \n".
"To fix this error, setup your authentication.ini with a valid authentication backend."
);
return false;
}
if (!$this->userBackend->hasUsername($credentials)) {
Logger::info("Unknown user %s tried to log in", $credentials->getUsername());
return false;
@ -115,7 +124,7 @@ class Manager
public function removeAuthorization()
{
$this->user = null;
$this->session->delete();
$this->session->purge();
}
public function getUser()

View File

@ -28,7 +28,6 @@ class PhpSession extends Session
private static $DEFAULT_COOKIEOPTIONS = array(
'use_trans_sid' => false,
'use_cookies' => true,
'use_only_cooies' => true,
'cookie_httponly' => true,
'use_only_cookies' => true,
'hash_function' => true,
@ -51,6 +50,9 @@ class PhpSession extends Session
);
}
}
if (!is_writable(session_save_path())) {
throw new \Icinga\Exception\ConfigurationError("Can't save session");
}
}
private function sessionCanBeChanged()
@ -78,12 +80,7 @@ class PhpSession extends Session
}
session_name(PhpSession::SESSION_NAME);
/*
* @todo This is not right
*/
\Zend_Session::start();
// session_start();
session_start();
$this->isOpen = true;
$this->setAll($_SESSION);
return true;
@ -138,16 +135,18 @@ class PhpSession extends Session
public function purge()
{
if ($this->ensureOpen() && !$this->isFlushed) {
if ($this->ensureOpen()) {
$_SESSION = array();
session_destroy();
$this->clearCookies();
$this->close();
}
}
private function clearCookies()
{
if (ini_get("session.use_cookies")) {
Logger::debug("Clearing cookies");
$params = session_get_cookie_params();
setcookie(
session_name(),

View File

@ -20,15 +20,15 @@ namespace Icinga\Authentication;
*/
class User
{
private $username = "";
private $firstname = "";
private $lastname = "";
private $email = "";
private $domain = "";
private $additionalInformation = array();
public $username = "";
public $firstname = "";
public $lastname = "";
public $email = "";
public $domain = "";
public $additionalInformation = array();
private $permissions = array();
private $groups = array();
public $permissions = array();
public $groups = array();
public function __construct($username, $firstname = null, $lastname = null, $email = null)
{

View File

@ -1,15 +1,28 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}}
namespace Icinga\Authentication;
interface UserBackend
{
/**
* Creates a new object
* @param $config
*/
public function __construct($config);
/**
* Test if the username exists
* @param Credentials $credentials
* @return boolean
*/
public function hasUsername(Credentials $credentials);
/**
* Authenticate
* @param Credentials $credentials
* @return User
*/
public function authenticate(Credentials $credentials);
}

View File

@ -4,6 +4,7 @@
namespace Icinga\Protocol\Ldap;
use Icinga\Exception\ConfigurationError as ConfigError;
use Icinga\Application\Platform;
use Icinga\Application\Config;
use Icinga\Application\Logger as Log;
@ -69,6 +70,10 @@ class Connection
// '1.3.6.1.1.8' => '8', // Cancel Extended Request
);
protected $use_tls = false;
protected $force_tls = false;
/**
* @var array
*/
@ -116,7 +121,8 @@ class Connection
$this->bind_dn = $config->bind_dn;
$this->bind_pw = $config->bind_pw;
$this->root_dn = $config->root_dn;
$this->use_tls = isset($config->tls) ? $config->tls : false;
$this->force_tls = $this->use_tls;
}
/**
@ -266,6 +272,7 @@ class Connection
// We do not support pagination right now, and there is no chance to
// do so for PHP < 5.4. Warnings about "Sizelimit exceeded" will
// therefore not be hidden right now.
Log::debug("Query: %s", $query->__toString());
$results = ldap_search(
$this->ds,
$this->root_dn,
@ -405,7 +412,6 @@ class Connection
if (isset($result->supportedExtension)) {
foreach ($result->supportedExtension as $oid) {
if (array_key_exists($oid, $this->ldap_extension)) {
echo $this->ldap_extension[$oid] . "\n";
// STARTTLS -> läuft mit OpenLDAP
}
}
@ -429,23 +435,23 @@ class Connection
if ($this->ds !== null) {
return;
}
$use_tls = true;
$force_tls = true;
if ($use_tls) {
if ($this->use_tls) {
$this->prepareTlsEnvironment();
}
Log::debug("Trying to connect to %s", $this->hostname);
$this->ds = ldap_connect($this->hostname, 389);
$this->discoverCapabilities();
Log::debug("Trying ldap_start_tls()");
if (ldap_start_tls($this->ds)) {
Log::debug("Trying ldap_start_tls() succeeded");
} else {
Log::warn(
"ldap_start_tls() failed: %s. Does your ldap_ca.conf point to the certificate? ",
ldap_error($this->ds)
);
if ($this->use_tls) {
Log::debug("Trying ldap_start_tls()");
if (@ldap_start_tls($this->ds)) {
Log::debug("Trying ldap_start_tls() succeeded");
} else {
Log::warn(
"ldap_start_tls() failed: %s. Does your ldap_ca.conf point to the certificate? ",
ldap_error($this->ds)
);
}
}
@ -470,12 +476,10 @@ class Connection
'***',
ldap_error($this->ds)
);
throw new Exception(
throw new ConfigError(
sprintf(
'LDAP connection (%s / %s) failed: %s',
$this->bind_dn,
'***' /* $this->bind_pw */,
ldap_error($this->ds)
'Could not connect to the authentication server, please '.
'review your LDAP connection settings.'
)
);
}

View File

@ -110,10 +110,6 @@ class ActionController extends ZfController
* @todo remove this!
*/
$this->allowAccess = true;
$this->init();
return null;
if ($this->handlesAuthentication() ||
Manager::getInstance(
@ -338,48 +334,4 @@ class ActionController extends ZfController
}*/
}
/**
* Whether the token parameter is valid
*
* TODO: Could this make use of Icinga\Web\Session once done?
*
* @param int $maxAge Max allowed token age
* @param string $sessionId A specific session id (useful for tests?)
* @return bool
*/
public function hasValidToken($maxAge = 600, $sessionId = null)
{
$sessionId = $sessionId ? $sessionId : session_id();
$seed = $this->_getParam('seed');
if (!is_numeric($seed)) {
return false;
}
// Remove quantitized timestamp portion so maxAge applies
$seed -= (intval(time() / $maxAge) * $maxAge);
$token = $this->_getParam('token');
return $token === hash('sha256', $sessionId . $seed);
}
/**
* Get a new seed/token pair
*
* TODO: Could this make use of Icinga\Web\Session once done?
*
* @param int $maxAge Max allowed token age
* @param string $sessionId A specific session id (useful for tests?)
*
* @return array
*/
public function getSeedTokenPair($maxAge = 600, $sessionId = null)
{
$sessionId = $sessionId ? $sessionId : session_id();
$seed = mt_rand();
$hash = hash('sha256', $sessionId . $seed);
// Add quantitized timestamp portion to apply maxAge
$seed += (intval(time() / $maxAge) * $maxAge);
return array($seed, $hash);
}
}

View File

@ -7,7 +7,6 @@ namespace Icinga\Web;
use Icinga\Exception\ProgrammingError;
use Icinga\Application\Platform;
use Icinga\Application\Logger as Log;
use Zend_Session_Namespace as SessionNamespace;
/**
* Class Notification
@ -149,10 +148,10 @@ class Notification
*/
final private function __construct()
{
$this->session = new SessionNamespace('IcingaNotification');
if (!is_array($this->session->messages)) {
//$this->session = new SessionNamespace('IcingaNotification');
//if (!is_array($this->session->messages)) {
$this->session->messages = array();
}
//}
if (Platform::isCli()) {
$this->cliFlag = true;

View File

@ -1,86 +0,0 @@
/*global Icinga:false, $: false, document: false, define:false require:false base_url:false console:false */
/**
This prototype encapsulates the behaviours registered in the behaviour folder
**/
(function() {
"use strict";
var loaded = {};
define(['logging'],function(log) {
var registerBehaviourFunctions = function(behaviour) {
var enableFn = behaviour.enable, disableFn = behaviour.disable;
behaviour.enable = (function(root) {
root = root || document;
for (var jqMatcher in this.eventHandler) {
for (var event in this.eventHandler[jqMatcher]) {
log.debug("Registered behaviour: ","'"+event+"'", jqMatcher);
$(root).on(event,jqMatcher,this.eventHandler[jqMatcher][event]);
}
}
if(enableFn) {
enableFn.apply(this,arguments);
}
}).bind(behaviour);
behaviour.disable = (function(root) {
for (var jqMatcher in this.eventHandler) {
for (var event in this.eventHandler[jqMatcher]) {
log.debug("Unregistered behaviour: ","'"+event+"'", jqMatcher);
$(root).off(event,jqMatcher,this.eventHandler[jqMatcher][event]);
}
}
if (disableFn) {
disableFn.apply(this,arguments);
}
}).bind(behaviour);
};
var CallInterface = function() {
/**
* Loads a behaviour and calls successCallback with the behaviour as the parameter on success, otherwise
* the errorCallback with the errorstring as the first parameter
*
* @param name
* @param errorCallback
* @param successCallback
*/
this.enableBehaviour = function(name,errorCallback,successCallback) {
require([name],function(behaviour) {
if (typeof behaviour.eventHandler === "object") {
registerBehaviourFunctions(behaviour);
}
if (typeof behaviour.enable === "function") {
behaviour.enable();
}
loaded[name] = {
behaviour: behaviour,
active: true
};
if (typeof successCallback === "function") {
successCallback(behaviour);
}
},function(err) {
errorCallback("Could not load behaviour "+name+" "+err,err);
});
};
this.disableBehaviour = function(name) {
if(loaded[name] && loaded[name].active) {
loaded[name].disable();
}
};
};
return new CallInterface();
});
})();

View File

@ -17,8 +17,8 @@ requirejs.config({
});
define(['jquery','Holder'], function ($) {
require(['bootstrap']);
require(['icinga/icinga'], function (Icinga) {
requirejs(['bootstrap']);
requirejs(['icinga/icinga'], function (Icinga) {
window.$ = $;
window.jQuery = $;
window.Icinga = Icinga;

1
public/js/vendor/history.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,61 @@
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();
});

View File

@ -7,11 +7,13 @@ i2w = require('./i2w-config');
var casper = i2w.getTestEnv();
casper.start("http://build.icinga.org/jenkins");
casper.start("http://localhost:12999/empty.html");
casper.then(function() {
this.test.assertTitle("icinga-web test [Jenkins]", "The jenkins page");
this.test.assertTitle("Just an empty page");
});
casper.run(function() {
this.test.done();

View File

@ -93,6 +93,14 @@ if (path === null)
var openFromBase = function(url, options) {
return copenFrom.apply(casper,[this.getBaseURL(url), options]);
};
casper.on('remote.message', function(message) {
console.log(message);
});
casper.on('page.error', function(message, trace) {
console.error(message, JSON.stringify(trace));
});
exports.getTestEnv = function() {
casper.getBaseURL = getBaseURL;
@ -102,6 +110,49 @@ if (path === null)
return casper;
};
exports.setupRequireJs = function(libraries) {
if (typeof libraries === "undefined") {
libraries = {
jquery: 'vendor/jquery-1.8.3',
bootstrap: 'vendor/bootstrap.min',
eve: 'vendor/raphael/eve'
};
} else {
libraries = libraries || {};
libraries.logging = 'icinga/util/logging';
libraries.jquery = 'vendor/jquery-1.8.3';
libraries["modules/list"] = "/moduleMock";
if (libraries.bootstrap || libraries.icinga) {
libraries.bootstrap = 'vendor/bootstrap.min';
libraries.history = 'vendor/history';
libraries.eve = 'vendor/raphael/eve';
libraries.raphael = 'vendor/raphael/raphael.amd';
libraries["raphael.core"] = 'vendor/raphael/raphael.core';
libraries["raphael.svg"] = 'vendor/raphael/raphael.svg';
libraries["raphael.vml"] = 'vendor/raphael/raphael.vml';
}
if (libraries.ace) {
libraries.ace = 'vendor/ace/ace';
}
}
var bootstrap = libraries.icinga;
delete(libraries.icinga);
requirejs.config({
baseUrl: window.base_url + '/js',
paths: libraries
});
if (bootstrap) {
requirejs(['jquery', 'history']);
requirejs(['bootstrap']);
requirejs(['icinga/icinga'], function (Icinga) {
window.$ = $;
window.jQuery = $;
window.Icinga = Icinga;
window.History = History;
});
}
};
})();

View File

@ -16,6 +16,11 @@ if [ ! -x $CASPER ]; then
"Take a look at http://casperjs.org/installation.html to see how the installation works for your system"
exit 1
fi;
if [ ! -e "${DIR}/static/public" ]; then
echo "!"
ln -s "${DIR}/../../public" "${DIR}/static/public"
fi;
PARAM="0"
for arg in $@;do
@ -109,7 +114,16 @@ if [ "$EXCLUDE" != "" ];then
FILELIST=`echo $FILELIST | grep -v "$NAME"`
fi;
cd $DIR/static
PROC=`ps ax|grep "SimpleHTTPServer 12999"|awk '{ print $1 }'`
if [ "$PROC" != "" ]; then
kill $PROC
fi;
python -m SimpleHTTPServer 12999&
PID=$!
cd $DIR
echo $EXEC $FILELIST
$EXEC $FILELIST
kill $PID
exit 0

View File

@ -0,0 +1,7 @@
<html>
<head>
<title>Just an empty page</title>
</head>
<body>
</body>
</html>

View File

@ -0,0 +1,6 @@
<div>
<h1>Test fragment</h1>
<a href="/fragments/testFragment2.html?this=istesting">Fragment 2</a>
<a href="/fragments/testFragment3.html">Fragment 3</a>
</div>

View File

@ -0,0 +1,6 @@
<div>
<h1>Test fragment 2</h1>
<a href="/fragments/testFragment1.html">Fragment 1</a>
<a href="/fragments/testFragment3.html">Fragment 3</a>
</div>

View File

@ -0,0 +1,6 @@
<div>
<h1>Test fragment 3</h1>
<a href="/fragments/testfragment1.html">Fragment 1</a>
<a href="/fragments/testfragment2.html">Fragment 2</a>
</div>

View File

@ -0,0 +1,39 @@
<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!-->
<html class="no-js"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta content="width=320; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Icinga test page</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width">
<script>
window.base_url = "/public";
</script>
<link rel="stylesheet" href="/public/css/normalize.min.css">
<link rel="stylesheet" href="/public/css/vendor/bootstrap.css">
<link rel="stylesheet" href="/public/css/main.css">
<link rel="stylesheet" href="/public/css/vendor/jquery.qtip.min.css">
<script src="/public/js/vendor/modernizr-2.6.2.min.js"></script>
<link rel="stylesheet" href="/public/css/icinga.css">
<link rel="stylesheet" href="/public/css/vendor/bootstrap-responsive.min.css">
<script src="/public/js/vendor/require.js"></script>
</head>
<body class="cranberry">
<div class="main">
<div class="tabbable tabs-left" style="height:100%;">
</div>
<div class="layout-main-detail collapsed">
<div id="icinga-main" container-id="icinga-main" class="icinga-container">
</div>
<div id="icinga-detail" class="icinga-container " container-id="icinga-detail">
</div><!-- End of icinga-detail -->
</div><!-- End of layout-main-detail -->
</div><!-- End of main -->
</body>
</html>

View File

@ -0,0 +1,4 @@
define([], function() {
"use strict";
return {};
});

1
test/frontend/test.xml Normal file
View File

@ -0,0 +1 @@
<testsuite time="0"><testcase classname="cases/static-page-test" name="The jenkins page" time="0.626"><failure type="assertTitle">Page title is: "i4cinga-web test [Jenkins]"</failure></testcase></testsuite>

View File

@ -4,7 +4,7 @@
require_once('Zend/View/Helper/Abstract.php');
require_once('Zend/View.php');
require('../../application/views/helpers/Qlink.php');
require_once('../../application/views/helpers/Qlink.php');
/**

View File

@ -7,6 +7,7 @@ namespace Tests\Icinga\Authentication;
require_once("../../library/Icinga/Authentication/Session.php");
require_once("../../library/Icinga/Authentication/PhpSession.php");
require_once("../../library/Icinga/Application/Logger.php");
require_once("../../library/Icinga/Exception/ConfigurationError.php");
require_once("Zend/Log.php");
use Icinga\Authentication\PhpSession as PhpSession;

View File

@ -1,80 +1,6 @@
<?php
namespace Tests\Icinga\Web\ActionController;
use Icinga\Web\ActionController as Action;
require_once('Zend/Controller/Action.php');
require_once('../../library/Icinga/Web/ActionController.php');
/**
* This is not a nice hack, but doesn't affect the behaviour of
* the tested methods, allowing us to avoid bootstrapping
* the request/response System for every test
*
* Class ActionTestWrap
* @package Tests\Icinga\Mvc\Controller
*/
class ActionTestWrap extends Action {
private $args;
public function __construct(\Zend_Controller_Request_Abstract $request = null,
\Zend_Controller_Response_Abstract $response = null, array $invokeArgs = array())
{}
public function setArguments($args) {
$this->args = $args;
}
protected function _getParam($paramName, $default = null) {
if(isset($this->args[$paramName]))
return $this->args[$paramName];
return $default;
}
}
class ActionTest extends \PHPUnit_Framework_TestCase
{
public function testSeedGeneration()
{
$action = new ActionTestWrap();
list($seed1,$token1) = $action->getSeedTokenPair(600,"test");
list($seed2,$token2) = $action->getSeedTokenPair(600,"test");
list($seed3,$token3) = $action->getSeedTokenPair(600,"test");
$this->assertTrue($seed1 != $seed2 && $seed2 != $seed3 && $seed1 != $seed3);
$this->assertTrue($token1 != $token2 && $token2 != $token3 && $token1 != $token3);
}
public function testSeedValidation()
{
$action = new ActionTestWrap();
list($seed,$token) = $action->getSeedTokenPair(600,"test");
$action->setArguments(array(
"seed" => $seed,
"token" => $token
));
$this->assertTrue($action->hasValidToken(600,"test"));
$this->assertFalse($action->hasValidToken(600,"test2"));
$action->setArguments(array(
"seed" => $seed."ds",
"token" => $token
));
$this->assertFalse($action->hasValidToken(600,"test"));
$action->setArguments(array(
"seed" => $seed,
"token" => $token."afs"
));
$this->assertFalse($action->hasValidToken(600,"test"));
}
public function testMaxAge()
{
$action = new ActionTestWrap();
list($seed,$token) = $action->getSeedTokenPair(1,"test");
$action->setArguments(array(
"seed" => $seed,
"token" => $token
));
$this->assertTrue($action->hasValidToken(1,"test"));
sleep(1);
$this->assertFalse($action->hasValidToken(1,"test"));
}
}