github.com/google/syzkaller@v0.0.0-20240517125934-c0f1611a36d6/pkg/asset/backend_gcs_test.go (about) 1 // Copyright 2023 syzkaller project authors. All rights reserved. 2 // Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. 3 4 package asset 5 6 import ( 7 "testing" 8 9 "github.com/google/syzkaller/pkg/debugtracer" 10 "github.com/stretchr/testify/assert" 11 ) 12 13 func TestCloudGetPaths(t *testing.T) { 14 obj := &cloudStorageBackend{ 15 client: nil, // we won't need it 16 bucket: "my_bucket", 17 tracer: &debugtracer.NullTracer{}, 18 } 19 // Test a public download URL. 20 url, _ := obj.downloadURL("folder/file.txt", true) 21 assert.Equal(t, `https://storage.googleapis.com/my_bucket/folder/file.txt`, url) 22 // Test a non-public download URL. 23 url, _ = obj.downloadURL("folder/file.txt", false) 24 assert.Equal(t, `https://storage.cloud.google.com/my_bucket/folder/file.txt`, url) 25 } 26 27 func TestCloudParsePaths(t *testing.T) { 28 obj := &cloudStorageBackend{ 29 client: nil, // we won't need it 30 bucket: `my_bucket`, 31 tracer: &debugtracer.NullTracer{}, 32 } 33 // Parse a public download URL. 34 path, err := obj.getPath(`https://storage.googleapis.com/my_bucket/folder/file.txt`) 35 assert.NoError(t, err) 36 assert.Equal(t, `folder/file.txt`, path) 37 // Parse a non-public download URL. 38 path, err = obj.getPath(`https://storage.cloud.google.com/my_bucket/folder/file.txt`) 39 assert.NoError(t, err) 40 assert.Equal(t, `folder/file.txt`, path) 41 // Error: unknown domain. 42 _, err = obj.getPath(`https://unknown-host.com/my_bucket/folder/file.txt`) 43 assert.ErrorContains(t, err, `not allowed host: unknown-host.com`) 44 // Error: unknown bucket. 45 _, err = obj.getPath(`https://storage.cloud.google.com/not_my_bucket/folder/file.txt`) 46 assert.ErrorIs(t, err, ErrUnknownBucket) 47 }