Beispiel #1
0
        public void Upload_Symlinked_RootDir()
        {
#if DNXCORE50
            if (!CrossPlatformHelpers.IsLinux)
            {
                return;
            }
            DMLibDataInfo sourceDataInfo = new DMLibDataInfo("");
            DMLibDataInfo targetDataInfo = new DMLibDataInfo("target");
            UnicodeFileName = "TempTestName";

            DirNode dirNode = new DirNode($"{UnicodeFileName}{FolderSuffix}");
            dirNode.AddFileNode(new FileNode($"{UnicodeFileName}{FileSuffix}")
            {
                SizeInByte = 1024
            });

            targetDataInfo.RootNode.AddDirNode(dirNode);

            SourceAdaptor.CreateIfNotExists();
            DestAdaptor.CreateIfNotExists();

            SourceAdaptor.GenerateData(targetDataInfo);
            sourceDataInfo.RootNode = DirNode.SymlinkedDir($"{UnicodeFileName}{SymlinkSuffix}", "target", targetDataInfo.RootNode);
            SourceAdaptor.GenerateData(sourceDataInfo);

            TransferItem item = new TransferItem()
            {
                SourceObject        = Path.Combine(SourceAdaptor.GetTransferObject(sourceDataInfo.RootPath, sourceDataInfo.RootNode) as string, sourceDataInfo.RootNode.Name),
                DestObject          = DestAdaptor.GetTransferObject(sourceDataInfo.RootPath, sourceDataInfo.RootNode),
                IsDirectoryTransfer = true,
                SourceType          = DMLibTestContext.SourceType,
                DestType            = DMLibTestContext.DestType,
                CopyMethod          = DMLibTestContext.CopyMethod.ToCopyMethod(),
                TransferContext     = new DirectoryTransferContext(),
                Options             = DefaultTransferDirectoryOptions
            };

            (item.Options as UploadDirectoryOptions).Recursive = true;

            var result = this.RunTransferItems(new List <TransferItem>()
            {
                item
            }, new TestExecutionOptions <DMLibDataInfo>());

            Test.Assert(result.Exceptions.Count == 0, "Verify no exception is thrown.");
            Test.Assert(DMLibDataHelper.Equals(sourceDataInfo, result.DataInfo), "Verify transfer result.");
#endif
        }
        public TestResult <DMLibDataInfo> ExecuteTestCase(DMLibDataInfo sourceDataInfo, TestExecutionOptions <DMLibDataInfo> options)
        {
            this.CleanupData();
            SourceAdaptor.CreateIfNotExists();
            DestAdaptor.CreateIfNotExists();

            if (sourceDataInfo != null)
            {
                SourceAdaptor.GenerateData(sourceDataInfo);
            }

            if (options.DestTransferDataInfo != null)
            {
                DestAdaptor.GenerateData(options.DestTransferDataInfo);
            }

            if (options.AfterDataPrepared != null)
            {
                options.AfterDataPrepared();
            }

            List <TransferItem> allItems = new List <TransferItem>();

            foreach (var fileNode in sourceDataInfo.EnumerateFileNodes())
            {
                TransferItem item = new TransferItem()
                {
                    SourceObject  = SourceAdaptor.GetTransferObject(fileNode),
                    DestObject    = DestAdaptor.GetTransferObject(fileNode),
                    SourceType    = DMLibTestContext.SourceType,
                    DestType      = DMLibTestContext.DestType,
                    IsServiceCopy = DMLibTestContext.IsAsync,
                };

                if (options.TransferItemModifier != null)
                {
                    options.TransferItemModifier(fileNode, item);
                }

                allItems.Add(item);
            }

            return(this.RunTransferItems(allItems, options));
        }
        private void TestSASTokenOfEachVersion(string targetSASVersion, bool isDirectoryTransfer)
        {
            Test.Info("Testing version of {0}", targetSASVersion);
            DMLibDataInfo sourceDataInfo = new DMLibDataInfo(string.Empty);

            DMLibDataHelper.AddOneFileInBytes(sourceDataInfo.RootNode, DMLibTestBase.FileName, 1024);

            var options = new TestExecutionOptions <DMLibDataInfo>();

            options.IsDirectoryTransfer = isDirectoryTransfer;

            options.TransferItemModifier = (fileNode, transferItem) =>
            {
                dynamic transferOptions = isDirectoryTransfer ? DefaultTransferDirectoryOptions : DefaultTransferOptions;

                transferItem.Options = transferOptions;

                if (isDirectoryTransfer)
                {
                    transferItem.TransferContext = new DirectoryTransferContext();

                    transferItem.TransferContext.FileFailed += (source, e) =>
                    {
                        Test.Error(e.Exception.ToString());
                    };

                    DirectoryOptions dirOptions = transferItem.Options as DirectoryOptions;
                    dirOptions.Recursive = true;
                }
                else
                {
                    transferItem.TransferContext = new SingleTransferContext();
                }

                transferItem.TransferContext.ShouldOverwriteCallbackAsync = TransferContext.ForceOverwrite;
            };


            string sourceSAS = null;
            string destSAS   = null;

            switch (DMLibTestContext.SourceType)
            {
            case DMLibDataType.CloudBlob:
            case DMLibDataType.AppendBlob:
            case DMLibDataType.BlockBlob:
            case DMLibDataType.PageBlob:
                if ((DMLibTestContext.SourceType == DMLibDataType.AppendBlob) &&
                    (string.CompareOrdinal(targetSASVersion, "2015-04-05") < 0))
                {
                    break;
                }

                SourceAdaptor.CreateIfNotExists();
                CloudBlobDataAdaptor blobAdaptor = SourceAdaptor as CloudBlobDataAdaptor;
                sourceSAS = Util.SASGenerator.GetSharedAccessSignature(blobAdaptor.GetBaseContainer(),
                                                                       new SharedAccessBlobPolicy
                {
                    Permissions            = isDirectoryTransfer ? SharedAccessBlobPermissions.Read | SharedAccessBlobPermissions.List : SharedAccessBlobPermissions.Read,
                    SharedAccessExpiryTime = DateTimeOffset.UtcNow.AddHours(1)
                },
                                                                       null,
                                                                       null,
                                                                       null,
                                                                       targetSASVersion);
                break;

            case DMLibDataType.CloudFile:
                if (string.CompareOrdinal(targetSASVersion, "2015-02-21") < 0)
                {
                    break;
                }

                SourceAdaptor.CreateIfNotExists();
                CloudFileDataAdaptor fileAdaptor = SourceAdaptor as CloudFileDataAdaptor;
                sourceSAS = Util.SASGenerator.GetSharedAccessSignature(
                    fileAdaptor.GetBaseShare(),
                    new SharedAccessFilePolicy
                {
                    Permissions            = isDirectoryTransfer ? SharedAccessFilePermissions.List | SharedAccessFilePermissions.Read : SharedAccessFilePermissions.Read,
                    SharedAccessExpiryTime = DateTimeOffset.UtcNow.AddHours(1)
                },
                    null,
                    null,
                    null,
                    targetSASVersion);
                break;

            default:
                break;
            }

            if (!DMLibTestContext.IsAsync ||
                (string.CompareOrdinal(targetSASVersion, "2014-02-14") >= 0))
            {
                switch (DMLibTestContext.DestType)
                {
                case DMLibDataType.CloudBlob:
                case DMLibDataType.AppendBlob:
                case DMLibDataType.BlockBlob:
                case DMLibDataType.PageBlob:
                    if ((DMLibTestContext.DestType == DMLibDataType.AppendBlob) &&
                        (string.CompareOrdinal(targetSASVersion, "2015-04-05") < 0))
                    {
                        break;
                    }

                    DestAdaptor.CreateIfNotExists();
                    CloudBlobDataAdaptor blobAdaptor = DestAdaptor as CloudBlobDataAdaptor;
                    destSAS = Util.SASGenerator.GetSharedAccessSignature(blobAdaptor.GetBaseContainer(),
                                                                         new SharedAccessBlobPolicy
                    {
                        Permissions            = DMLibTestContext.IsAsync ? SharedAccessBlobPermissions.Write | SharedAccessBlobPermissions.Read : SharedAccessBlobPermissions.Write,
                        SharedAccessExpiryTime = DateTimeOffset.UtcNow.AddHours(1)
                    },
                                                                         null,
                                                                         null,
                                                                         null,
                                                                         targetSASVersion);
                    break;

                case DMLibDataType.CloudFile:
                    if (string.CompareOrdinal(targetSASVersion, "2015-02-21") < 0)
                    {
                        break;
                    }

                    DestAdaptor.CreateIfNotExists();
                    CloudFileDataAdaptor fileAdaptor = DestAdaptor as CloudFileDataAdaptor;
                    destSAS = Util.SASGenerator.GetSharedAccessSignature(
                        fileAdaptor.GetBaseShare(),
                        new SharedAccessFilePolicy
                    {
                        Permissions            = DMLibTestContext.IsAsync ? SharedAccessFilePermissions.Write | SharedAccessFilePermissions.Read : SharedAccessFilePermissions.Write,
                        SharedAccessExpiryTime = DateTimeOffset.UtcNow.AddHours(1)
                    },
                        null,
                        null,
                        null,
                        targetSASVersion);
                    break;

                default:
                    break;
                }
            }

            if (null != sourceSAS)
            {
                options.SourceCredentials = new StorageCredentials(sourceSAS);
            }

            if (null != destSAS)
            {
                options.DestCredentials = new StorageCredentials(destSAS);
            }

            var result = this.ExecuteTestCase(sourceDataInfo, options);

            VerificationHelper.VerifyTransferSucceed(result, sourceDataInfo);
        }
        public TestResult <DMLibDataInfo> ExecuteTestCase(DMLibDataInfo sourceDataInfo, TestExecutionOptions <DMLibDataInfo> options)
        {
            if (options.DisableSourceCleaner)
            {
                this.CleanupData(false, true);
            }
            else
            {
                this.CleanupData();
            }
            SourceAdaptor.CreateIfNotExists();
            DestAdaptor.CreateIfNotExists();

            string  sourceRootPath = string.Empty;
            DirNode sourceRootNode = new DirNode(string.Empty);

            if (sourceDataInfo != null)
            {
                sourceRootPath = sourceDataInfo.RootPath;
                sourceRootNode = sourceDataInfo.RootNode;
                if (!options.DisableSourceGenerator)
                {
                    SourceAdaptor.GenerateData(sourceDataInfo);
                }
            }

            string destRootPath = string.Empty;

            if (options.DestTransferDataInfo != null)
            {
                destRootPath = options.DestTransferDataInfo.RootPath;
                DestAdaptor.GenerateData(options.DestTransferDataInfo);
            }

            if (options.AfterDataPrepared != null)
            {
                options.AfterDataPrepared();
            }

            List <TransferItem> allItems = new List <TransferItem>();

            if (options.IsDirectoryTransfer)
            {
                TransferItem item = new TransferItem()
                {
                    SourceObject        = SourceAdaptor.GetTransferObject(sourceRootPath, sourceRootNode, options.SourceCredentials),
                    DestObject          = DestAdaptor.GetTransferObject(destRootPath, sourceRootNode, options.DestCredentials),
                    SourceType          = DMLibTestContext.SourceType,
                    DestType            = DMLibTestContext.DestType,
                    IsServiceCopy       = DMLibTestContext.IsAsync,
                    IsDirectoryTransfer = true,
                };

                if (options.TransferItemModifier != null)
                {
                    options.TransferItemModifier(null, item);
                }

                allItems.Add(item);
            }
            else
            {
                foreach (var fileNode in sourceDataInfo.EnumerateFileNodes())
                {
                    TransferItem item = new TransferItem()
                    {
                        SourceObject  = SourceAdaptor.GetTransferObject(sourceDataInfo.RootPath, fileNode, options.SourceCredentials),
                        DestObject    = DestAdaptor.GetTransferObject(destRootPath, fileNode, options.DestCredentials),
                        SourceType    = DMLibTestContext.SourceType,
                        DestType      = DMLibTestContext.DestType,
                        IsServiceCopy = DMLibTestContext.IsAsync,
                    };

                    if (options.TransferItemModifier != null)
                    {
                        options.TransferItemModifier(fileNode, item);
                    }

                    allItems.Add(item);
                }
            }

            return(this.RunTransferItems(allItems, options));
        }