Skip to content

Commit 30662b3

Browse files
m0n1keranelson-unl
andauthored
Fix MDQ cache file bugs (#2200)
* Ensure MDQ JSON cache is decoded properly * Ensure MDQ JSON cache is overwritten not appended to * Update MDQ cache file extension --------- Co-authored-by: Alan Nelson <alan.nelson@nebraska.edu>
1 parent 052492f commit 30662b3

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

  • src/SimpleSAML/Metadata/Sources

src/SimpleSAML/Metadata/Sources/MDQ.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ private function getCacheFilename(string $set, string $entityId): string
130130
}
131131

132132
$cachekey = sha1($entityId);
133-
return $this->cacheDir . '/' . $set . '-' . $cachekey . '.cached.xml';
133+
return $this->cacheDir . '/' . $set . '-' . $cachekey . '.cached.json';
134134
}
135135

136136

@@ -183,7 +183,8 @@ private function getFromCache(string $set, string $entityId): ?array
183183
));
184184
}
185185

186-
$data = json_decode($rawData);
186+
// ensure json is decoded as an associative array not an object
187+
$data = json_decode($rawData, true);
187188
if ($data === false) {
188189
throw new Exception(
189190
sprintf('%s: error unserializing cached data from file "%s".', __CLASS__, strval($file)),
@@ -217,8 +218,8 @@ private function writeToCache(string $set, string $entityId, array $data): void
217218

218219
Logger::debug(sprintf('%s: Writing cache [%s] => [%s]', __CLASS__, $entityId, $cacheFileName));
219220

220-
/** @psalm-suppress TooManyArguments */
221-
$this->fileSystem->appendToFile($cacheFileName, json_encode($data), true);
221+
// using dumpFile instead of appendToFile here to replace any existing cache data
222+
$this->fileSystem->dumpFile($cacheFileName, json_encode($data));
222223
}
223224

224225

0 commit comments

Comments
 (0)