Prepare settings for the API in the admin page and during the install
API settings: - api.enabled - api.secret The API settings will be initialized (and the secret generated) with an update method.
This commit is contained in:
parent
624f999fb7
commit
cbfdcff261
7 changed files with 142 additions and 2 deletions
tests
|
@ -271,7 +271,7 @@ $GLOBALS[\'privateLinkByDefault\'] = true;';
|
|||
public function testEscapeConfig()
|
||||
{
|
||||
$sandbox = 'sandbox/config';
|
||||
copy(self::$configFile .'.json.php', $sandbox .'.json.php');
|
||||
copy(self::$configFile . '.json.php', $sandbox . '.json.php');
|
||||
$this->conf = new ConfigManager($sandbox);
|
||||
$title = '<script>alert("title");</script>';
|
||||
$headerLink = '<script>alert("header_link");</script>';
|
||||
|
@ -286,7 +286,43 @@ $GLOBALS[\'privateLinkByDefault\'] = true;';
|
|||
$this->assertEquals(escape($title), $this->conf->get('general.title'));
|
||||
$this->assertEquals(escape($headerLink), $this->conf->get('general.header_link'));
|
||||
$this->assertEquals(escape($redirectorUrl), $this->conf->get('redirector.url'));
|
||||
unlink($sandbox .'.json.php');
|
||||
unlink($sandbox . '.json.php');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test updateMethodApiSettings(): create default settings for the API (enabled + secret).
|
||||
*/
|
||||
public function testUpdateApiSettings()
|
||||
{
|
||||
$confFile = 'sandbox/config';
|
||||
copy(self::$configFile .'.json.php', $confFile .'.json.php');
|
||||
$conf = new ConfigManager($confFile);
|
||||
$updater = new Updater(array(), array(), $conf, true);
|
||||
|
||||
$this->assertFalse($conf->exists('api.enabled'));
|
||||
$this->assertFalse($conf->exists('api.secret'));
|
||||
$updater->updateMethodApiSettings();
|
||||
$conf->reload();
|
||||
$this->assertTrue($conf->get('api.enabled'));
|
||||
$this->assertTrue($conf->exists('api.secret'));
|
||||
unlink($confFile .'.json.php');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test updateMethodApiSettings(): already set, do nothing.
|
||||
*/
|
||||
public function testUpdateApiSettingsNothingToDo()
|
||||
{
|
||||
$confFile = 'sandbox/config';
|
||||
copy(self::$configFile .'.json.php', $confFile .'.json.php');
|
||||
$conf = new ConfigManager($confFile);
|
||||
$conf->set('api.enabled', false);
|
||||
$conf->set('api.secret', '');
|
||||
$updater = new Updater(array(), array(), $conf, true);
|
||||
$updater->updateMethodApiSettings();
|
||||
$this->assertFalse($conf->get('api.enabled'));
|
||||
$this->assertEmpty($conf->get('api.secret'));
|
||||
unlink($confFile .'.json.php');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -253,4 +253,21 @@ class UtilsTest extends PHPUnit_Framework_TestCase
|
|||
is_session_id_valid('c0ZqcWF3VFE2NmJBdm1HMVQ0ZHJ3UmZPbTFsNGhkNHI=')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test generateSecretApi.
|
||||
*/
|
||||
public function testGenerateSecretApi()
|
||||
{
|
||||
$this->assertEquals(12, strlen(generate_api_secret('foo', 'bar')));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test generateSecretApi with invalid parameters.
|
||||
*/
|
||||
public function testGenerateSecretApiInvalid()
|
||||
{
|
||||
$this->assertFalse(generate_api_secret('', ''));
|
||||
$this->assertFalse(generate_api_secret(false, false));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue