Skip to content

Commit ed11671

Browse files
authored
Merge pull request #722 from cvvz/fix103
e2e test for sas token
2 parents a5f1c9a + 2add298 commit ed11671

File tree

5 files changed

+475
-320
lines changed

5 files changed

+475
-320
lines changed

pkg/blob/blob.go

+10-9
Original file line numberDiff line numberDiff line change
@@ -283,10 +283,10 @@ func GetContainerInfo(id string) (string, string, string, string, error) {
283283
}
284284

285285
// A container name must be a valid DNS name, conforming to the following naming rules:
286-
// 1. Container names must start with a letter or number, and can contain only letters, numbers, and the dash (-) character.
287-
// 2. Every dash (-) character must be immediately preceded and followed by a letter or number; consecutive dashes are not permitted in container names.
288-
// 3. All letters in a container name must be lowercase.
289-
// 4. Container names must be from 3 through 63 characters long.
286+
// 1. Container names must start with a letter or number, and can contain only letters, numbers, and the dash (-) character.
287+
// 2. Every dash (-) character must be immediately preceded and followed by a letter or number; consecutive dashes are not permitted in container names.
288+
// 3. All letters in a container name must be lowercase.
289+
// 4. Container names must be from 3 through 63 characters long.
290290
//
291291
// See https://docs.microsoft.com/en-us/rest/api/storageservices/naming-and-referencing-containers--blobs--and-metadata#container-names
292292
func getValidContainerName(volumeName, protocol string) string {
@@ -315,9 +315,10 @@ func checkContainerNameBeginAndEnd(containerName string) bool {
315315
return false
316316
}
317317

318-
// isSASToken checks if the key contains the patterns. Because a SAS Token must have these strings, use them to judge.
318+
// isSASToken checks if the key contains the patterns.
319+
// SAS token format could refer to https://docs.microsoft.com/en-us/rest/api/eventhub/generate-sas-token
319320
func isSASToken(key string) bool {
320-
return strings.Contains(key, "?sv=")
321+
return strings.HasPrefix(key, "?")
321322
}
322323

323324
// GetAuthEnv return <accountName, containerName, authEnv, error>
@@ -681,9 +682,9 @@ func setAzureCredentials(kubeClient kubernetes.Interface, accountName, accountKe
681682
}
682683

683684
// GetStorageAccesskey get Azure storage account key from
684-
// 1. secrets (if not empty)
685-
// 2. use k8s client identity to read from k8s secret
686-
// 3. use cluster identity to get from storage account directly
685+
// 1. secrets (if not empty)
686+
// 2. use k8s client identity to read from k8s secret
687+
// 3. use cluster identity to get from storage account directly
687688
func (d *Driver) GetStorageAccesskey(ctx context.Context, accountOptions *azure.AccountOptions, secrets map[string]string, secretName, secretNamespace string) (string, string, error) {
688689
if len(secrets) > 0 {
689690
return getStorageAccount(secrets)

test/e2e/pre_provisioning_test.go

+37
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"sigs.k8s.io/blob-csi-driver/test/e2e/driver"
2525
"sigs.k8s.io/blob-csi-driver/test/e2e/testsuites"
2626

27+
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
2728
"github.com/container-storage-interface/spec/lib/go/csi"
2829
"github.com/onsi/ginkgo"
2930
v1 "k8s.io/api/core/v1"
@@ -290,6 +291,42 @@ var _ = ginkgo.Describe("[blob-csi-e2e] Pre-Provisioned", func() {
290291
}
291292
test.Run(cs, ns)
292293
})
294+
295+
ginkgo.It("should use SAS token", func() {
296+
req := makeCreateVolumeReq("pre-provisioned-sas-token", ns.Name)
297+
resp, err := blobDriver.CreateVolume(context.Background(), req)
298+
if err != nil {
299+
ginkgo.Fail(fmt.Sprintf("create volume error: %v", err))
300+
}
301+
volumeID = resp.Volume.VolumeId
302+
ginkgo.By(fmt.Sprintf("Successfully provisioned blob volume: %q\n", volumeID))
303+
304+
pods := []testsuites.PodDetails{
305+
{
306+
Cmd: "echo 'hello world' > /mnt/test-1/data && grep 'hello world' /mnt/test-1/data",
307+
Volumes: []testsuites.VolumeDetails{
308+
{
309+
VolumeID: volumeID,
310+
FSType: "ext4",
311+
ClaimSize: fmt.Sprintf("%dGi", defaultVolumeSize),
312+
ReclaimPolicy: to.Ptr(v1.PersistentVolumeReclaimRetain),
313+
VolumeBindingMode: to.Ptr(storagev1.VolumeBindingImmediate),
314+
VolumeMount: testsuites.VolumeMountDetails{
315+
NameGenerate: "test-volume-",
316+
MountPathGenerate: "/mnt/test-",
317+
},
318+
},
319+
},
320+
},
321+
}
322+
323+
test := testsuites.PreProvisionedSASTokenTest{
324+
CSIDriver: testDriver,
325+
Pods: pods,
326+
Driver: blobDriver,
327+
}
328+
test.Run(cs, ns)
329+
})
293330
})
294331

295332
func makeCreateVolumeReq(volumeName, secretNamespace string) *csi.CreateVolumeRequest {

0 commit comments

Comments
 (0)