From e00f4e59b39cabc3e33823a957d3623dce06f9c4 Mon Sep 17 00:00:00 2001
From: "James E. Blair" <jim@acmegating.com>
Date: Sat, 18 Mar 2023 16:45:35 -0700
Subject: [PATCH] Add testinfra for registry.zuul-ci.org

This tests some canary URLs for the registry.  Full functional
testing is handled by a test playbook.

Change-Id: I9a19709df6711e5f4dea21906608c34ac3e8a2b4
---
 testinfra/test_static.py | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/testinfra/test_static.py b/testinfra/test_static.py
index bf9c93161b..eb9fc24c13 100644
--- a/testinfra/test_static.py
+++ b/testinfra/test_static.py
@@ -236,3 +236,27 @@ def test_ci_openstack_org(host, path, target):
                    ' https://ci.openstack.org%s' % path)
     assert '301 Moved Permanently' in cmd.stdout
     assert target in cmd.stdout
+
+def test_registry_zuul_ci_org(host):
+    # The functional test does an actual pull; here we just check some
+    # specific URLs work.  In particular, we want to make sure that we
+    # don't proxy /v2/.
+
+    cmd = host.run('curl --resolve registry.zuul-ci.org:443:127.0.0.1'
+                   ' https://registry.zuul-ci.org/v2/')
+    assert '301 Moved Permanently' not in cmd.stdout
+    assert '302 Found' not in cmd.stdout
+    assert cmd.stdout.strip() == ""
+
+    cmd = host.run('curl --resolve registry.zuul-ci.org:443:127.0.0.1'
+                   ' -I https://registry.zuul-ci.org/v2/zuul/manifests/8.2.0')
+    assert '302 Found' in cmd.stdout
+    assert 'Location: https://quay.io/v2/corvus/zuul/manifests/8.2.0' in cmd.stdout
+
+    cmd = host.run('curl --resolve registry.zuul-ci.org:443:127.0.0.1'
+                   ' https://registry.zuul-ci.org/v2/zuul/blobs/'
+                   'sha256:5dda314a937ad03f8beac81c714da74e459b6174301368e0903ef586a68ae150')
+    assert '302 Found' in cmd.stdout
+    assert ('https://quay.io/v2/corvus/zuul/blobs/'
+            'sha256:5dda314a937ad03f8beac81c714da74e459b6174301368e0903ef586a68ae150'
+            in cmd.stdout)