diff --git a/Storage/tests/System/StorageTestCase.php b/Storage/tests/System/StorageTestCase.php index dd3b69db48f7..db13a7495ee6 100644 --- a/Storage/tests/System/StorageTestCase.php +++ b/Storage/tests/System/StorageTestCase.php @@ -35,6 +35,7 @@ class StorageTestCase extends SystemTestCase protected static $bucket; protected static $client; protected static $unauthenticatedClient; + protected static $universeDomainClient; protected static $pubsubClient; protected static $object; protected static $mainBucketName; @@ -53,6 +54,11 @@ public static function setUpTestFixtures(): void self::$unauthenticatedClient = new StorageClient([ 'credentialsFetcher' => new AnonymousCredentials() ]); + self::$universeDomainClient = new StorageClient([ + 'keyFilePath' => getenv('TEST_UNIVERSE_DOMAIN_CREDENTIAL'), + 'projectId' => getenv('TEST_UNIVERSE_PROJECT_ID'), + 'universeDomain' => getenv('TEST_UNIVERSE_DOMAIN') + ]); self::$pubsubClient = new PubSubClient($config); self::$mainBucketName = getenv('BUCKET') ?: uniqid(self::TESTING_PREFIX); diff --git a/Storage/tests/System/UniverseDomainTest.php b/Storage/tests/System/UniverseDomainTest.php new file mode 100644 index 000000000000..6ec8fbdcca24 --- /dev/null +++ b/Storage/tests/System/UniverseDomainTest.php @@ -0,0 +1,68 @@ + getenv('TEST_UNIVERSE_LOCATION') + ] + ); + $this->assertEquals(self::$bucketName, self::$universeDomainBucket->info()['name']); + } + + /** + * Test uploading and retrieving objects to a bucket using universe domain credentials. + */ + public function testListsObjectsWithUniverseDomain() + { + $foundObjects = []; + $objectsToCreate = [ + uniqid(self::TESTING_PREFIX), + uniqid(self::TESTING_PREFIX) + ]; + + foreach ($objectsToCreate as $objectToCreate) { + self::$universeDomainBucket->upload('data', ['name' => $objectToCreate]); + } + + $objects = self::$universeDomainBucket->objects(['prefix' => self::TESTING_PREFIX]); + + foreach ($objects as $object) { + foreach ($objectsToCreate as $key => $objectToCreate) { + if ($object->name() === $objectToCreate) { + $foundObjects[$key] = $object->name(); + } + } + } + $this->assertEquals($objectsToCreate, $foundObjects); + } + } + ?>