message: Add validation of odsp snapshot response for trees and blobs
diff: @@ -254,7 +254,8 @@ async function fetchLatestSnapshotCore(
  }
  }
  - const { numTrees, numBlobs, encodedBlobsSize, decodedBlobsSize } = evalBlobsAndTrees(snapshot);
  + const { numTrees, numBlobs, encodedBlobsSize, decodedBlobsSize } =
  + validateAndEvalBlobsAndTrees(snapshot);
  const clientTime = networkTime ? overallTime - networkTime : undefined;
  // There are some scenarios in ODSP where we cannot cache, trees/latest will explicitly tell us when we
  @@ -332,7 +333,11 @@ async function fetchLatestSnapshotCore(
  });
  }
  -function evalBlobsAndTrees(snapshot: IOdspSnapshot) {
  +function validateAndEvalBlobsAndTrees(snapshot: IOdspSnapshot) {
  + assert(Array.isArray(snapshot.trees) && snapshot.trees.length > 0,
  + "Returned odsp snapshot is malformed. No trees!");
  + assert(Array.isArray(snapshot.blobs) && snapshot.blobs.length > 0,
  + "Returned odsp snapshot is malformed. No blobs!");
  let numTrees = 0;
  let numBlobs = 0;
  let encodedBlobsSize = 0;
  @@ -346,12 +351,10 @@ function evalBlobsAndTrees(snapshot: IOdspSnapshot) {
  }
  }
  }
  - if (snapshot.blobs !== undefined) {
  for (const blob of snapshot.blobs) {
  decodedBlobsSize += blob.size;
  encodedBlobsSize += blob.content.length;
  }
  - }
  return { numTrees, numBlobs, encodedBlobsSize, decodedBlobsSize };
  }
  