Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorChristoph Wurst <christoph@winzerhof-wurst.at>2021-10-21 15:12:36 +0300
committerbackportbot[bot] <backportbot[bot]@users.noreply.github.com>2021-10-22 12:16:05 +0300
commit4e416381018309ed7173eb44ee66c7679ce70b9b (patch)
tree99facaafbee861c43ea2f3f012cd90718160025a /tests
parent759c5a762b5c222d57b6eb0fd7837b62539117f1 (diff)
Prevent duplicate auth token activity updates
The auth token activity logic works as follows * Read auth token * Compare last activity time stamp to current time * Update auth token activity if it's older than x seconds This works fine in isolation but with concurrency that means that occasionally the same token is read simultaneously by two processes and both of these processes will trigger an update of the same row. Affectively the second update doesn't add much value. It might set the time stamp to the exact same time stamp or one a few seconds later. But the last activity is no precise science, we don't need this accuracy. This patch changes the UPDATE query to include the expected value in a comparison with the current data. This results in an affected row when the data in the DB still has an old time stamp, but won't affect a row if the time stamp is (nearly) up to date. This is a micro optimization and will possibly not show any significant performance improvement. Yet in setups with a DB cluster it means that the write node has to send fewer changes to the read nodes due to the lower number of actual changes. Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/Authentication/Token/PublicKeyTokenProviderTest.php13
1 files changed, 6 insertions, 7 deletions
diff --git a/tests/lib/Authentication/Token/PublicKeyTokenProviderTest.php b/tests/lib/Authentication/Token/PublicKeyTokenProviderTest.php
index f27100b5d78..486660f17c6 100644
--- a/tests/lib/Authentication/Token/PublicKeyTokenProviderTest.php
+++ b/tests/lib/Authentication/Token/PublicKeyTokenProviderTest.php
@@ -100,10 +100,10 @@ class PublicKeyTokenProviderTest extends TestCase {
public function testUpdateToken() {
$tk = new PublicKeyToken();
- $tk->setLastActivity($this->time - 200);
$this->mapper->expects($this->once())
- ->method('update')
- ->with($tk);
+ ->method('updateActivity')
+ ->with($tk, $this->time);
+ $tk->setLastActivity($this->time - 200);
$this->tokenProvider->updateTokenActivity($tk);
@@ -112,16 +112,15 @@ class PublicKeyTokenProviderTest extends TestCase {
public function testUpdateTokenDebounce() {
$tk = new PublicKeyToken();
-
$this->config->method('getSystemValueInt')
->willReturnCallback(function ($value, $default) {
return $default;
});
-
$tk->setLastActivity($this->time - 30);
+
$this->mapper->expects($this->never())
- ->method('update')
- ->with($tk);
+ ->method('updateActivity')
+ ->with($tk, $this->time);
$this->tokenProvider->updateTokenActivity($tk);
}