From e204d3417c184fafef13935635d4111bbd0851c3 Mon Sep 17 00:00:00 2001
From: Sebastian Poxhofer <secustor@users.noreply.github.com>
Date: Mon, 29 Jan 2024 11:39:43 +0100
Subject: [PATCH] fix(workers/lookup): handle not fitting version while missing
 lockfile (#26885)

---
 .../repository/process/lookup/index.spec.ts   | 22 +++++++++++++++++++
 .../repository/process/lookup/index.ts        |  7 ++++--
 2 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/lib/workers/repository/process/lookup/index.spec.ts b/lib/workers/repository/process/lookup/index.spec.ts
index d815c166a1..7bef29d6a8 100644
--- a/lib/workers/repository/process/lookup/index.spec.ts
+++ b/lib/workers/repository/process/lookup/index.spec.ts
@@ -11,6 +11,7 @@ import { GithubTagsDatasource } from '../../../../modules/datasource/github-tags
 import { NpmDatasource } from '../../../../modules/datasource/npm';
 import { PackagistDatasource } from '../../../../modules/datasource/packagist';
 import { PypiDatasource } from '../../../../modules/datasource/pypi';
+import { id as composerVersioningId } from '../../../../modules/versioning/composer';
 import { id as debianVersioningId } from '../../../../modules/versioning/debian';
 import { id as dockerVersioningId } from '../../../../modules/versioning/docker';
 import { id as gitVersioningId } from '../../../../modules/versioning/git';
@@ -1848,6 +1849,27 @@ describe('workers/repository/process/lookup/index', () => {
       });
     });
 
+    it('handles no fitting version and no version in lock file', async () => {
+      config.currentValue = '~9.5.0';
+      config.packageName = 'typo3/cms-saltedpasswords';
+      config.datasource = DockerDatasource.id;
+      config.versioning = composerVersioningId;
+      getDockerReleases.mockResolvedValueOnce({
+        releases: [
+          {
+            version: '8.0.0',
+          },
+          {
+            version: '8.1.0',
+          },
+        ],
+      });
+      const res = await lookup.lookupUpdates(config);
+      expect(res).toMatchObject({
+        skipReason: 'invalid-value',
+      });
+    });
+
     it('handles digest pin for non-version', async () => {
       config.currentValue = 'alpine';
       config.packageName = 'node';
diff --git a/lib/workers/repository/process/lookup/index.ts b/lib/workers/repository/process/lookup/index.ts
index 8cc98a26c3..90d68a1e8e 100644
--- a/lib/workers/repository/process/lookup/index.ts
+++ b/lib/workers/repository/process/lookup/index.ts
@@ -257,8 +257,11 @@ export async function lookupUpdates(
           latestVersion!,
           allVersions.map((v) => v.version),
         )!;
-      // istanbul ignore if
-      if (!currentVersion! && config.lockedVersion) {
+
+      if (!currentVersion) {
+        if (!config.lockedVersion) {
+          res.skipReason = 'invalid-value';
+        }
         return res;
       }
 
-- 
GitLab