Skip to content
Snippets Groups Projects
Commit 747acb78 authored by Robin Appelman's avatar Robin Appelman
Browse files

verify app version against binary version on start

parent 748295e5
No related branches found
No related tags found
No related merge requests found
......@@ -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(())
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment