verify app version against binary version on start

This commit is contained in:
Robin Appelman 2021-02-09 13:27:07 +01:00
Родитель 748295e5ec
Коммит 747acb78c7
4 изменённых файлов: 63 добавлений и 4 удалений

Просмотреть файл

@ -33,6 +33,11 @@ return [
'url' => '/test/remote',
'verb' => 'GET',
],
[
'name' => 'test#version',
'url' => '/test/version',
'verb' => 'POST',
],
[
'name' => 'Auth#preAuth',
'url' => '/pre_auth',

Просмотреть файл

@ -23,6 +23,9 @@ declare(strict_types=1);
namespace OCA\NotifyPush\Controller;
use OCA\NotifyPush\Queue\IQueue;
use OCA\NotifyPush\Queue\RedisQueue;
use OCP\App\IAppManager;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\DataDisplayResponse;
use OCP\AppFramework\Http\DataResponse;
@ -31,22 +34,27 @@ use OCP\IRequest;
class TestController extends Controller {
private $config;
private $queue;
private $appManager;
public function __construct(
IRequest $request,
IConfig $config
IConfig $config,
IQueue $queue,
IAppManager $appManager
) {
parent::__construct('notify_push', $request);
$this->config = $config;
$this->queue = $queue;
$this->appManager = $appManager;
}
/**
* @NoAdminRequired
* @PublicPage
* @NoCSRFRequired
* @return DataResponse
*/
public function cookie() {
public function cookie(): DataResponse {
return new DataResponse((int)$this->config->getAppValue('notify_push', 'cookie', '0'));
}
@ -55,7 +63,18 @@ class TestController extends Controller {
* @PublicPage
* @NoCSRFRequired
*/
public function remote() {
public function remote(): DataDisplayResponse {
return new DataDisplayResponse($this->request->getRemoteAddress());
}
/**
* @NoAdminRequired
* @PublicPage
* @NoCSRFRequired
*/
public function version() {
if ($this->queue instanceof RedisQueue) {
$this->queue->getConnection()->set("notify_push_app_version", $this->appManager->getAppVersion('notify_push'));
}
}
}

Просмотреть файл

@ -101,6 +101,29 @@ impl App {
.get_users_for_storage_path(1, "")
.await
.wrap_err("Failed to test database access")?;
let mut redis = self.redis.get_async_connection().await?;
redis
.del("notify_push_app_version")
.await
.wrap_err("Failed to clear app version")?;
self.nc_client
.request_app_version()
.await
.wrap_err("Failed to request app version")?;
let version: String = redis
.get("notify_push_app_version")
.await
.wrap_err("Failed to get app version")?;
log::debug!("app is running version {}", version);
if version != env!("NOTIFY_PUSH_VERSION") {
log::warn!(
"push server (version {}) is not the same version as the app (version {})",
env!("NOTIFY_PUSH_VERSION"),
version
);
}
Ok(())
}

Просмотреть файл

@ -84,4 +84,16 @@ impl Client {
.await?
.parse()?)
}
/// Ask the app to put it's version number into redis under 'notify_push_app_version'
pub async fn request_app_version(&self) -> Result<()> {
self.http
.post(
self.base_url
.join("index.php/apps/notify_push/test/version")?,
)
.send()
.await?;
Ok(())
}
}