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 all 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
6 changes: 3 additions & 3 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ jobs:
display_name: "Linux"
go_path: '$(go env GOPATH)/bin/'
suffix: ''
run_e2e: 'go test -timeout=1h -v ./e2etest | tee test.txt'
run_e2e: 'go test -timeout=2h -v ./e2etest | tee test.txt'
output_test_logs: ''
save_exit_code: 'exit_code=${PIPESTATUS[0]}'
return_exit_code: 'exit "$exit_code"'
Expand All @@ -138,7 +138,7 @@ jobs:
type: 'windows'
go_path: 'C:\Users\VssAdministrator\go\bin\'
suffix: '.exe'
run_e2e: 'go test -timeout=1h -v ./e2etest > test.txt'
run_e2e: 'go test -timeout=2h -v ./e2etest > test.txt'
output_test_logs: 'cat test.txt'
save_exit_code: 'set exit_code=%errorlevel%'
return_exit_code: 'exit %exit_code%'
Expand All @@ -148,7 +148,7 @@ jobs:
display_name: "MacOS"
go_path: '$(go env GOPATH)/bin/'
suffix: ''
run_e2e: 'go test -timeout=1h -v ./e2etest | tee test.txt'
run_e2e: 'go test -timeout=2h -v ./e2etest | tee test.txt'
output_test_logs: ''
save_exit_code: 'exit_code=${PIPESTATUS[0]}'
return_exit_code: 'exit "$exit_code"'
Expand Down
13 changes: 8 additions & 5 deletions e2etest/newe2e_resource_manager_azstorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
blobsas "github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/sas"
blobservice "github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/service"
blobfscommon "github.com/Azure/azure-sdk-for-go/sdk/storage/azdatalake"
datalakeSAS "github.com/Azure/azure-sdk-for-go/sdk/storage/azdatalake/sas"
datalakesas "github.com/Azure/azure-sdk-for-go/sdk/storage/azdatalake/sas"
blobfsservice "github.com/Azure/azure-sdk-for-go/sdk/storage/azdatalake/service"
filesas "github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/sas"
fileservice "github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/service"
Expand All @@ -30,10 +30,13 @@ func (acct *AzureAccountResourceManager) ApplySAS(URI string, loc common.Locatio
return URI
}

sasVals := opts.AzureOpts.SASValues
if sasVals == nil {
var sasVals GenericSignatureValues
if opts.AzureOpts.SASValues == nil {
// Default to account level SAS to cover all our bases
sasVals = GenericAccountSignatureValues{}
} else {
sasVals = opts.AzureOpts.SASValues

sasVals = GenericServiceSignatureValues{}
}

switch loc {
Expand Down Expand Up @@ -70,7 +73,7 @@ func (acct *AzureAccountResourceManager) ApplySAS(URI string, loc common.Locatio
p, err := sasVals.AsDatalake().SignWithSharedKey(skc)
common.PanicIfErr(err)

parts, err := datalakeSAS.ParseURL(URI)
parts, err := datalakesas.ParseURL(URI)
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 @@ -229,6 +229,8 @@ type ObjectResourceManager interface {
ResourceManager

EntityType() common.EntityType
ContainerName() string
ObjectName() string
// Create attempts to create an object. Should overwrite objects if they already exist. It is expected to attempt to track object creation.
Create(a Asserter, body ObjectContentContainer, properties ObjectProperties)
// Delete attempts to delete an object. NotFound type errors are ignored.
Expand Down
8 changes: 8 additions & 0 deletions e2etest/newe2e_resource_manager_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,14 @@ func (m *MockObjectResourceManager) EntityType() common.EntityType {
return m.entityType
}

func (m *MockObjectResourceManager) ContainerName() string {
return m.parent.ContainerName()
}

func (m *MockObjectResourceManager) ObjectName() string {
return m.path
}

func (m *MockObjectResourceManager) Create(a Asserter, body ObjectContentContainer, properties ObjectProperties) {
// no-op
}
Expand Down
8 changes: 8 additions & 0 deletions e2etest/newe2e_resource_managers_blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,14 @@ func (b *BlobObjectResourceManager) EntityType() common.EntityType {
return b.entityType
}

func (b *BlobObjectResourceManager) ContainerName() string {
return b.Container.ContainerName()
}

func (b *BlobObjectResourceManager) ObjectName() string {
return b.Path
}

// Create defaults to Block Blob. For implementation-specific options, GetTypeOrZero[T] / GetTypeOrAssert[T] to BlobObjectResourceManager and call CreateWithOptions
func (b *BlobObjectResourceManager) Create(a Asserter, body ObjectContentContainer, properties ObjectProperties) {
b.CreateWithOptions(a, body, properties, nil)
Expand Down
8 changes: 8 additions & 0 deletions e2etest/newe2e_resource_managers_blobfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,14 @@ func (b *BlobFSPathResourceProvider) EntityType() common.EntityType {
return b.entityType
}

func (b *BlobFSPathResourceProvider) ContainerName() string {
return b.Container.ContainerName()
}

func (b *BlobFSPathResourceProvider) ObjectName() string {
return b.objectPath
}

func (b *BlobFSPathResourceProvider) Create(a Asserter, body ObjectContentContainer, properties ObjectProperties) {
switch b.entityType {
case common.EEntityType.Folder():
Expand Down
8 changes: 8 additions & 0 deletions e2etest/newe2e_resource_managers_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,14 @@ func (f *FileObjectResourceManager) EntityType() common.EntityType {
return f.entityType
}

func (f *FileObjectResourceManager) ContainerName() string {
return f.Share.ContainerName()
}

func (f *FileObjectResourceManager) ObjectName() string {
return f.path
}

func (f *FileObjectResourceManager) PreparePermissions(a Asserter, p *string) *file.Permissions {
if p == nil {
return nil
Expand Down
24 changes: 12 additions & 12 deletions e2etest/newe2e_sas_generation.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package e2etest

import (
blobsas "github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/sas"
datalakeSAS "github.com/Azure/azure-sdk-for-go/sdk/storage/azdatalake/sas"
datalakesas "github.com/Azure/azure-sdk-for-go/sdk/storage/azdatalake/sas"
filesas "github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/sas"
"github.com/Azure/azure-storage-azcopy/v10/common"
"time"
Expand All @@ -20,10 +20,10 @@ type FileSignatureValues interface {

// DatalakeSignatureValues makes both account/service signature values generic for output from GenericSignatureValues
type DatalakeSignatureValues interface {
SignWithSharedKey(credential *datalakeSAS.SharedKeyCredential) (datalakeSAS.QueryParameters, error)
SignWithSharedKey(credential *datalakesas.SharedKeyCredential) (datalakesas.QueryParameters, error)
}

// GenericSignatureValues are a set of signature values that are portable to all 3 Azure storage services.
// GenericSignatureValues are a set of signature values that are portable to all 3 Azure storage services and both service and account level SAS.
// Distinct limitations of these generic values are documented in the struct.
type GenericSignatureValues interface {
AsBlob() BlobSignatureValues
Expand All @@ -50,7 +50,7 @@ type GenericServiceSignatureValues struct {
// Blob and Datalake overlap nicely
// blobsas.ContainerPermissions blobsas.BlobPermissions
// filesas.SharePermissions filesas.FilePermissions
// datalakeSAS.FileSystemPermissions datalakeSAS.FilePermissions datalakeSAS.DirectoryPermissions
// datalakesas.FileSystemPermissions datalakesas.FilePermissions datalakesas.DirectoryPermissions
// If zero, defaults to racwdl (read, add, create, write, delete, list
Permissions string
IPRange blobsas.IPRange
Expand Down Expand Up @@ -137,13 +137,13 @@ func (vals GenericServiceSignatureValues) AsFile() FileSignatureValues {
func (vals GenericServiceSignatureValues) AsDatalake() DatalakeSignatureValues {
s := vals.withDefaults()

return &datalakeSAS.DatalakeSignatureValues{
return &datalakesas.DatalakeSignatureValues{
Version: s.Version,
Protocol: datalakeSAS.Protocol(s.Protocol),
Protocol: datalakesas.Protocol(s.Protocol),
StartTime: s.StartTime,
ExpiryTime: s.ExpiryTime,
Permissions: s.Permissions,
IPRange: datalakeSAS.IPRange(s.IPRange),
IPRange: datalakesas.IPRange(s.IPRange),
Identifier: s.Identifier,
FileSystemName: s.ContainerName,
FilePath: s.ObjectName,
Expand All @@ -167,10 +167,10 @@ type GenericAccountSignatureValues struct {
StartTime time.Time
// Defaults to 24hr past StartTime
ExpiryTime time.Time
// Defaults to racwdl, uses blobsas.AccountPermissions, filesas.AccountPermissions, or datalakeSAS.AccountPermissions
// Defaults to racwdl, uses blobsas.AccountPermissions, filesas.AccountPermissions, or datalakesas.AccountPermissions
Permissions string
IPRange blobsas.IPRange
// defaults to sco, uses blobsas.AccountResourceTypes, filesas.AccountResourceTypes, or datalakeSAS.AccountResourceTypes
// defaults to sco, uses blobsas.AccountResourceTypes, filesas.AccountResourceTypes, or datalakesas.AccountResourceTypes
ResourceTypes string
}

Expand Down Expand Up @@ -219,13 +219,13 @@ func (vals GenericAccountSignatureValues) AsFile() FileSignatureValues {
func (vals GenericAccountSignatureValues) AsDatalake() DatalakeSignatureValues {
s := vals.withDefaults()

return datalakeSAS.AccountSignatureValues{
return datalakesas.AccountSignatureValues{
Version: s.Version,
Protocol: datalakeSAS.Protocol(s.Protocol),
Protocol: datalakesas.Protocol(s.Protocol),
StartTime: s.StartTime,
ExpiryTime: s.ExpiryTime,
Permissions: s.Permissions,
IPRange: datalakeSAS.IPRange(s.IPRange),
IPRange: datalakesas.IPRange(s.IPRange),
ResourceTypes: s.ResourceTypes,
}
}
16 changes: 11 additions & 5 deletions e2etest/zt_newe2e_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (s *ExampleSuite) Scenario_SingleFileCopySyncS2S(svm *ScenarioVariationMana
Body: body,
}) // todo: generic CreateResource is something to pursue in another branch, but it's an interesting thought.
// Scale up from service to container
dstObj := CreateResource[ContainerResourceManager](svm, dstService, ResourceDefinitionContainer{})
dstCont := CreateResource[ContainerResourceManager](svm, dstService, ResourceDefinitionContainer{})

RunAzCopy(
svm,
Expand All @@ -43,10 +43,11 @@ func (s *ExampleSuite) Scenario_SingleFileCopySyncS2S(svm *ScenarioVariationMana
Targets: []ResourceManager{
srcObj.Parent().(RemoteResourceManager).WithSpecificAuthType(EExplicitCredentialType.SASToken(), svm, CreateAzCopyTargetOptions{
SASTokenOptions: GenericServiceSignatureValues{
Permissions: (&blobsas.BlobPermissions{Read: true, List: true}).String(),
ContainerName: srcObj.ContainerName(),
Permissions: (&blobsas.BlobPermissions{Read: true, List: true}).String(),
},
}),
dstObj,
dstCont,
},
Flags: CopyFlags{
CopySyncCommonFlags: CopySyncCommonFlags{
Expand All @@ -57,7 +58,12 @@ func (s *ExampleSuite) Scenario_SingleFileCopySyncS2S(svm *ScenarioVariationMana
},
})

ValidateResource[ObjectResourceManager](svm, srcObj, ResourceDefinitionObject{
Body: body,
dstObjs := make(ObjectResourceMappingFlat)
dstObjs["test"] = ResourceDefinitionObject{
ObjectName: pointerTo("test"),
Body: body,
}
ValidateResource[ContainerResourceManager](svm, dstCont, ResourceDefinitionContainer{
Objects: dstObjs,
}, true)
}
Loading