Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed treatment of SAS in new e2e test framework to include container and path names #2577

Merged
merged 8 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 31 additions & 13 deletions e2etest/newe2e_resource_manager_azstorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type AzureAccountResourceManager struct {
armClient *ARMStorageAccount
}

func (acct *AzureAccountResourceManager) ApplySAS(URI string, loc common.Location, optList ...GetURIOptions) string {
func (acct *AzureAccountResourceManager) ApplySAS(URI string, loc common.Location, et common.EntityType, optList ...GetURIOptions) string {
if acct == nil {
panic("Account must not be nil to generate a SAS token.")
}
Expand All @@ -30,47 +30,65 @@ func (acct *AzureAccountResourceManager) ApplySAS(URI string, loc common.Locatio
return URI
}

sasVals := opts.AzureOpts.SASValues
if sasVals == nil {

var sasVals GenericServiceSignatureValues
if opts.AzureOpts.SASValues == nil {
sasVals = GenericServiceSignatureValues{}
} else {
sasVals = opts.AzureOpts.SASValues.(GenericServiceSignatureValues)
}

switch loc {
case common.ELocation.Blob():
skc, err := blobservice.NewSharedKeyCredential(acct.accountName, acct.accountKey)
parts, err := blobsas.ParseURL(URI)
common.PanicIfErr(err)

p, err := sasVals.AsBlob().SignWithSharedKey(skc)
skc, err := blobservice.NewSharedKeyCredential(acct.accountName, acct.accountKey)
common.PanicIfErr(err)

parts, err := blobsas.ParseURL(URI)
sasVals.ContainerName = parts.ContainerName
sasVals.ObjectName = parts.BlobName

p, err := sasVals.AsBlob().SignWithSharedKey(skc)
common.PanicIfErr(err)

parts.SAS = p
parts.Scheme = common.Iff(opts.RemoteOpts.Scheme != "", opts.RemoteOpts.Scheme, "https")
return parts.String()
case common.ELocation.File():
skc, err := fileservice.NewSharedKeyCredential(acct.accountName, acct.accountKey)
parts, err := filesas.ParseURL(URI)
common.PanicIfErr(err)

p, err := sasVals.AsFile().SignWithSharedKey(skc)
skc, err := fileservice.NewSharedKeyCredential(acct.accountName, acct.accountKey)
common.PanicIfErr(err)

parts, err := filesas.ParseURL(URI)
sasVals.ContainerName = parts.ShareName
if et == common.EEntityType.Folder() {
sasVals.DirectoryPath = parts.DirectoryOrFilePath
} else {
sasVals.ObjectName = parts.DirectoryOrFilePath
}

p, err := sasVals.AsFile().SignWithSharedKey(skc)
common.PanicIfErr(err)

parts.SAS = p
parts.Scheme = common.Iff(opts.RemoteOpts.Scheme != "", opts.RemoteOpts.Scheme, "https")
return parts.String()
case common.ELocation.BlobFS():
skc, err := blobfscommon.NewSharedKeyCredential(acct.accountName, acct.accountKey)
parts, err := datalakeSAS.ParseURL(URI)
common.PanicIfErr(err)

p, err := sasVals.AsDatalake().SignWithSharedKey(skc)
skc, err := blobfscommon.NewSharedKeyCredential(acct.accountName, acct.accountKey)
common.PanicIfErr(err)

parts, err := datalakeSAS.ParseURL(URI)
sasVals.ContainerName = parts.FileSystemName
if et == common.EEntityType.Folder() {
sasVals.DirectoryPath = parts.PathName
} else {
sasVals.ObjectName = parts.PathName
}

p, err := sasVals.AsDatalake().SignWithSharedKey(skc)
common.PanicIfErr(err)

parts.SAS = p
Expand Down
2 changes: 2 additions & 0 deletions e2etest/newe2e_resource_manager_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ type RemoteURIOpts struct {
type AzureURIOpts struct {
// Must be manually specified
WithSAS bool
// As DirectoryPath in SASValues
AsDirectory bool
// Defaults to a resource-level specific minimally permissioned SAS token.
SASValues GenericSignatureValues
}
Expand Down
6 changes: 3 additions & 3 deletions e2etest/newe2e_resource_managers_blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func (b *BlobServiceResourceManager) ListContainers(a Asserter) []string {

func (b *BlobServiceResourceManager) URI(opts ...GetURIOptions) string {
base := blobStripSAS(b.internalClient.URL())
base = b.internalAccount.ApplySAS(base, b.Location(), opts...)
base = b.internalAccount.ApplySAS(base, b.Location(), common.EEntityType, opts...)

return base
}
Expand Down Expand Up @@ -342,7 +342,7 @@ func (b *BlobContainerResourceManager) Level() cmd.LocationLevel {

func (b *BlobContainerResourceManager) URI(opts ...GetURIOptions) string {
base := blobStripSAS(b.internalClient.URL())
base = b.internalAccount.ApplySAS(base, b.Location(), opts...)
base = b.internalAccount.ApplySAS(base, b.Location(), common.EEntityType, opts...)

return base
}
Expand Down Expand Up @@ -666,7 +666,7 @@ func (b *BlobObjectResourceManager) Level() cmd.LocationLevel {

func (b *BlobObjectResourceManager) URI(opts ...GetURIOptions) string {
base := blobStripSAS(b.internalClient.URL())
base = b.internalAccount.ApplySAS(base, b.Location(), opts...)
base = b.internalAccount.ApplySAS(base, b.Location(), b.EntityType(), opts...)

return base
}
Expand Down
6 changes: 3 additions & 3 deletions e2etest/newe2e_resource_managers_blobfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (b *BlobFSServiceResourceManager) Level() cmd.LocationLevel {

func (b *BlobFSServiceResourceManager) URI(opts ...GetURIOptions) string {
base := dfsStripSAS(b.internalClient.DFSURL())
base = b.internalAccount.ApplySAS(base, b.Location(), opts...)
base = b.internalAccount.ApplySAS(base, b.Location(), common.EEntityType, opts...)

return base
}
Expand Down Expand Up @@ -175,7 +175,7 @@ func (b *BlobFSFileSystemResourceManager) Level() cmd.LocationLevel {

func (b *BlobFSFileSystemResourceManager) URI(opts ...GetURIOptions) string {
base := dfsStripSAS(b.internalClient.DFSURL())
base = b.internalAccount.ApplySAS(base, b.Location(), opts...)
base = b.internalAccount.ApplySAS(base, b.Location(), common.EEntityType, opts...)

return base
}
Expand Down Expand Up @@ -309,7 +309,7 @@ func (b *BlobFSPathResourceProvider) Level() cmd.LocationLevel {

func (b *BlobFSPathResourceProvider) URI(opts ...GetURIOptions) string {
base := dfsStripSAS(b.getFileClient().DFSURL()) // obj type doesn't matter here, URL is the same under the hood
base = b.internalAccount.ApplySAS(base, b.Location(), opts...)
base = b.internalAccount.ApplySAS(base, b.Location(), b.EntityType(), opts...)

return base
}
Expand Down
6 changes: 3 additions & 3 deletions e2etest/newe2e_resource_managers_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (s *FileServiceResourceManager) Level() cmd.LocationLevel {

func (s *FileServiceResourceManager) URI(opts ...GetURIOptions) string {
base := fileStripSAS(s.internalClient.URL())
base = s.internalAccount.ApplySAS(base, s.Location(), opts...)
base = s.internalAccount.ApplySAS(base, s.Location(), common.EEntityType, opts...)

return base
}
Expand Down Expand Up @@ -180,7 +180,7 @@ func (s *FileShareResourceManager) Level() cmd.LocationLevel {

func (s *FileShareResourceManager) URI(opts ...GetURIOptions) string {
base := fileStripSAS(s.internalClient.URL())
base = s.internalAccount.ApplySAS(base, s.Location(), opts...)
base = s.internalAccount.ApplySAS(base, s.Location(), common.EEntityType, opts...)

return base
}
Expand Down Expand Up @@ -397,7 +397,7 @@ func (f *FileObjectResourceManager) Level() cmd.LocationLevel {

func (f *FileObjectResourceManager) URI(opts ...GetURIOptions) string {
base := fileStripSAS(f.getFileClient().URL()) // restype doesn't matter here, same URL under the hood
base = f.internalAccount.ApplySAS(base, f.Location(), opts...)
base = f.internalAccount.ApplySAS(base, f.Location(), f.EntityType(), opts...)

return base
}
Expand Down
Loading