Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions lib/private/App/AppStore/Fetcher/Fetcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
use OCP\Util;

abstract class Fetcher {
const INVALIDATE_AFTER_SECONDS = 300;
const INVALIDATE_AFTER_SECONDS = 3600;

/** @var IAppData */
protected $appData;
Expand Down Expand Up @@ -97,12 +97,11 @@ protected function fetch($ETag, $content) {

$options = [
'timeout' => 10,
'headers' => ['Accept-Encoding' => 'gzip'],
];

if ($ETag !== '') {
$options['headers'] = [
'If-None-Match' => $ETag,
];
$options['headers']['If-None-Match'] = $ETag;
}

$client = $this->clientService->newClient();
Expand Down Expand Up @@ -152,7 +151,7 @@ public function get() {
// No caching when the version has been updated
if (isset($jsonBlob['ncversion']) && $jsonBlob['ncversion'] === $this->getVersion()) {

// If the timestamp is older than 300 seconds request the files new
// If the timestamp is older than 3600 seconds request the files new
if ((int)$jsonBlob['timestamp'] > ($this->timeFactory->getTime() - self::INVALIDATE_AFTER_SECONDS)) {
return $jsonBlob['data'];
}
Expand Down
61 changes: 49 additions & 12 deletions tests/lib/App/AppStore/Fetcher/FetcherBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ public function testGetWithAlreadyExistingFileAndOutdatedTimestamp() {
$this->timeFactory
->expects($this->at(0))
->method('getTime')
->willReturn(1501);
->willReturn(4801);
$client = $this->createMock(IClient::class);
$this->clientService
->expects($this->once())
Expand All @@ -249,7 +249,15 @@ public function testGetWithAlreadyExistingFileAndOutdatedTimestamp() {
$client
->expects($this->once())
->method('get')
->with($this->endpoint)
->with(
$this->equalTo($this->endpoint),
$this->equalTo([
'timeout' => 10,
'headers' => [
'Accept-Encoding' => 'gzip',
]
])
)
->willReturn($response);
$response
->expects($this->once())
Expand Down Expand Up @@ -342,7 +350,15 @@ public function testGetWithAlreadyExistingFileAndNoVersion() {
$client
->expects($this->once())
->method('get')
->with($this->endpoint)
->with(
$this->equalTo($this->endpoint),
$this->equalTo([
'timeout' => 10,
'headers' => [
'Accept-Encoding' => 'gzip',
]
])
)
->willReturn($response);
$response
->expects($this->once())
Expand Down Expand Up @@ -430,7 +446,15 @@ public function testGetWithAlreadyExistingFileAndOutdatedVersion() {
$client
->expects($this->once())
->method('get')
->with($this->endpoint)
->with(
$this->equalTo($this->endpoint),
$this->equalTo([
'timeout' => 10,
'headers' => [
'Accept-Encoding' => 'gzip',
]
])
)
->willReturn($response);
$response
->expects($this->once())
Expand Down Expand Up @@ -495,7 +519,15 @@ public function testGetWithExceptionInClient() {
$client
->expects($this->once())
->method('get')
->with($this->endpoint)
->with(
$this->equalTo($this->endpoint),
$this->equalTo([
'timeout' => 10,
'headers' => [
'Accept-Encoding' => 'gzip',
]
])
)
->willThrowException(new \Exception());

$this->assertSame([], $this->fetcher->get());
Expand Down Expand Up @@ -533,11 +565,11 @@ public function testGetMatchingETag() {
$this->timeFactory
->expects($this->at(0))
->method('getTime')
->willReturn(1501);
->willReturn(4801);
$this->timeFactory
->expects($this->at(1))
->method('getTime')
->willReturn(1502);
->willReturn(4802);
$client = $this->createMock(IClient::class);
$this->clientService
->expects($this->once())
Expand All @@ -552,14 +584,15 @@ public function testGetMatchingETag() {
$this->equalTo([
'timeout' => 10,
'headers' => [
'If-None-Match' => '"myETag"'
'Accept-Encoding' => 'gzip',
'If-None-Match' => '"myETag"',
]
])
)->willReturn($response);
$response->method('getStatusCode')
->willReturn(304);

$newData = '{"data":[{"id":"MyNewApp","foo":"foo"},{"id":"bar"}],"timestamp":1502,"ncversion":"11.0.0.2","ETag":"\"myETag\""}';
$newData = '{"data":[{"id":"MyNewApp","foo":"foo"},{"id":"bar"}],"timestamp":4802,"ncversion":"11.0.0.2","ETag":"\"myETag\""}';
$file
->expects($this->at(1))
->method('putContent')
Expand Down Expand Up @@ -624,6 +657,7 @@ public function testGetNoMatchingETag() {
$this->equalTo([
'timeout' => 10,
'headers' => [
'Accept-Encoding' => 'gzip',
'If-None-Match' => '"myETag"',
]
])
Expand All @@ -638,7 +672,7 @@ public function testGetNoMatchingETag() {
$response->method('getHeader')
->with($this->equalTo('ETag'))
->willReturn('"newETag"');
$fileData = '{"data":[{"id":"MyNewApp","foo":"foo"},{"id":"bar"}],"timestamp":1502,"ncversion":"11.0.0.2","ETag":"\"newETag\""}';
$fileData = '{"data":[{"id":"MyNewApp","foo":"foo"},{"id":"bar"}],"timestamp":4802,"ncversion":"11.0.0.2","ETag":"\"newETag\""}';
$file
->expects($this->at(1))
->method('putContent')
Expand All @@ -650,11 +684,11 @@ public function testGetNoMatchingETag() {
$this->timeFactory
->expects($this->at(0))
->method('getTime')
->willReturn(1501);
->willReturn(4801);
$this->timeFactory
->expects($this->at(1))
->method('getTime')
->willReturn(1502);
->willReturn(4802);

$expected = [
[
Expand Down Expand Up @@ -710,6 +744,9 @@ public function testFetchAfterUpgradeNoETag() {
$this->equalTo($this->endpoint),
$this->equalTo([
'timeout' => 10,
'headers' => [
'Accept-Encoding' => 'gzip',
],
])
)
->willReturn($response);
Expand Down