Exemplo n.º 1
0
        protected bool CheckUseS3()
        {
            Client.Executor.CheckApiServerVersion(ApiConfig.ApiS3DirectUploadPossible);
            IRestRequest       generalSettingsRequest = Client.Builder.GetGeneralSettings();
            ApiGeneralSettings apiGeneralSettings     =
                Client.Executor.DoSyncApiCall <ApiGeneralSettings>(generalSettingsRequest, RequestType.GetGeneralSettings);

            return(apiGeneralSettings.UseS3Storage);
        }
        public ServerGeneralSettings GetGeneral()
        {
            _client.Executor.CheckApiServerVersion();
            IRestRequest       request            = _client.Builder.GetGeneralSettings();
            ApiGeneralSettings apiGeneralSettings =
                _client.Executor.DoSyncApiCall <ApiGeneralSettings>(request, DracoonRequestExecutor.RequestType.GetGeneralSettings);

            return(SettingsMapper.FromApiGeneralSettings(apiGeneralSettings));
        }
Exemplo n.º 3
0
        public void FromApiGeneralSettings_Null()
        {
            // ARRANGE
            ServerGeneralSettings expected = null;
            ApiGeneralSettings    param    = null;

            // ACT
            ServerGeneralSettings actual = SettingsMapper.FromApiGeneralSettings(param);

            // ASSERT
            Assert.Equal(expected, actual, new ServerGeneralSettingsComparer());
        }
Exemplo n.º 4
0
        internal static ServerGeneralSettings FromApiGeneralSettings(ApiGeneralSettings apiGeneralConfig)
        {
            if (apiGeneralConfig == null)
            {
                return(null);
            }

            ServerGeneralSettings general = new ServerGeneralSettings {
                CryptoEnabled = apiGeneralConfig.CryptoEnabled,
                EmailNotificationButtonEnabled = apiGeneralConfig.EmailNotificationButtonEnabled,
                EulaEnabled             = apiGeneralConfig.EulaEnabled,
                MediaServerEnabled      = apiGeneralConfig.MediaServerEnabled,
                SharePasswordSmsEnabled = apiGeneralConfig.SharePasswordSmsEnabled,
                UseS3Storage            = apiGeneralConfig.UseS3Storage,
                WeakPasswordEnabled     = apiGeneralConfig.WeakPasswordEnabled
            };

            return(general);
        }
Exemplo n.º 5
0
        public void FromApiGeneralSettings()
        {
            // ARRANGE
            ServerGeneralSettings expected = FactoryServerSettings.ServerGeneralSettings;

            ApiGeneralSettings param = new ApiGeneralSettings {
                CryptoEnabled = expected.CryptoEnabled,
                EmailNotificationButtonEnabled = expected.EmailNotificationButtonEnabled,
                EulaEnabled             = expected.EulaEnabled,
                MediaServerEnabled      = expected.MediaServerEnabled,
                SharePasswordSmsEnabled = expected.SharePasswordSmsEnabled,
                UseS3Storage            = expected.UseS3Storage,
                WeakPasswordEnabled     = expected.WeakPasswordEnabled
            };

            // ACT
            ServerGeneralSettings actual = SettingsMapper.FromApiGeneralSettings(param);

            // ASSERT
            Assert.Equal(expected, actual, new ServerGeneralSettingsComparer());
        }
Exemplo n.º 6
0
        public void Encrypted_RunSync_S3_KnownFileSize_Success()
        {
            // ARRANGE
            byte[] fileMock = new byte[1564];
            new Random().NextBytes(fileMock);
            Stream s = new MemoryStream(fileMock);
            IInternalDracoonClient c        = FactoryClients.InternalDracoonClientMock(true);
            FileUploadCallbackMock callback = new FileUploadCallbackMock();
            EncFileUpload          f        = new EncFileUpload(c, "id1", FactoryFile.UploadFileRequest, s, FactoryUser.UserPublicKey, fileMock.Length);

            f.AddFileUploadCallback(callback);
            ApiGeneralSettings generalSettings = FactoryServerSettings.ApiGeneralSettings;

            generalSettings.UseS3Storage = true;
            ApiCreateFileUpload acfu = FactoryFile.ApiCreateFileUpload;

            acfu.Classification = null;
            Mock.Arrange(() => c.Builder.PostCreateFileUpload(Arg.IsAny <ApiCreateFileUpload>())).Returns(FactoryRestSharp.PostCreateFileUploadMock())
            .Occurs(1);
            Mock.Arrange(() => c.Executor.DoSyncApiCall <ApiUploadToken>(Arg.IsAny <IRestRequest>(), RequestType.PostUploadToken, 0))
            .Returns(FactoryFile.ApiUploadToken).Occurs(1);
            Mock.Arrange(() => c.Builder.PutCompleteS3FileUpload(Arg.AnyString, Arg.IsAny <ApiCompleteFileUpload>()))
            .Returns(FactoryRestSharp.PutCompleteFileUploadMock("path")).Occurs(1);
            Mock.Arrange(() => c.Executor.DoSyncApiCall <VoidResponse>(Arg.IsAny <IRestRequest>(), RequestType.PutCompleteS3Upload, 0)).DoNothing()
            .Occurs(1);
            Mock.Arrange(() => c.Builder.GetGeneralSettings())
            .Returns(FactoryRestSharp.RestRequestWithAuth(ApiConfig.ApiGetGeneralConfig, Method.GET)).Occurs(1);
            Mock.Arrange(() => c.Executor.DoSyncApiCall <ApiGeneralSettings>(Arg.IsAny <IRestRequest>(), RequestType.GetGeneralSettings, 0))
            .Returns(generalSettings).Occurs(1);
            Mock.Arrange(() => c.Builder.PostGetS3Urls(Arg.AnyString, Arg.IsAny <ApiGetS3Urls>())).Returns(FactoryRestSharp.PostGetS3UrlsMock())
            .OccursAtLeast(1);
            Mock.Arrange(() => c.Executor.DoSyncApiCall <ApiS3Urls>(Arg.IsAny <IRestRequest>(), RequestType.PostGetS3Urls, 0))
            .Returns(FactoryFile.ApiS3Urls).OccursAtLeast(1);
            Mock.Arrange(() => c.Builder.GetS3Status(Arg.AnyString)).Returns(FactoryRestSharp.GetS3StatusMock).OccursAtLeast(1);
            Mock.Arrange(() => c.Executor.DoSyncApiCall <ApiS3Status>(Arg.IsAny <IRestRequest>(), RequestType.GetS3Status, 0))
            .Returns(FactoryFile.ApiS3Status).OccursAtLeast(1);
            Mock.Arrange(() => FileMapper.ToApiCreateFileUpload(Arg.IsAny <FileUploadRequest>())).Returns(acfu).Occurs(1);
            Mock.Arrange(() => NodeMapper.FromApiNode(Arg.IsAny <ApiNode>())).Returns(FactoryNode.Node).Occurs(1);
            Mock.Arrange(() => FileMapper.ToApiCompleteFileUpload(Arg.IsAny <FileUploadRequest>())).Returns(FactoryFile.ApiCompleteFileUpload);
            DracoonWebClientExtension wc = Mock.Create <DracoonWebClientExtension>();

            Mock.Arrange(() => Mock.Create <UploadProgressChangedEventArgs>().BytesSent).IgnoreInstance();
            Mock.Arrange(() => c.Executor.ExecuteWebClientChunkUpload(Arg.IsAny <WebClient>(), Arg.IsAny <Uri>(), Arg.IsAny <byte[]>(),
                                                                      RequestType.PutUploadS3Chunk, Arg.IsAny <Thread>(), Arg.AnyInt)).DoInstead(() => Thread.Sleep(250))
            .Raises(() => wc.UploadProgressChanged += null, null, Mock.Create <UploadProgressChangedEventArgs>()).Returns(new byte[13]);
            Mock.Arrange(() => c.Builder.ProvideS3ChunkUploadWebClient()).Returns(wc);
            Mock.Arrange(() => JsonConvert.DeserializeObject <ApiUploadChunkResult>(Arg.AnyString)).Returns(FactoryFile.ApiUploadChunkResult);

            Mock.Arrange(() => Crypto.Sdk.Crypto.GenerateFileKey(Arg.AnyString)).Returns(FactoryFile.PlainFileKey).Occurs(1);
            FileEncryptionCipher cipher = Mock.Create <FileEncryptionCipher>();

            Mock.Arrange(() => Crypto.Sdk.Crypto.CreateFileEncryptionCipher(Arg.IsAny <PlainFileKey>())).Returns(cipher).Occurs(1);
            Mock.Arrange(() => cipher.ProcessBytes(Arg.IsAny <PlainDataContainer>())).Returns(new EncryptedDataContainer(fileMock, fileMock))
            .OccursAtLeast(1);
            Mock.Arrange(() => cipher.DoFinal()).Returns(new EncryptedDataContainer(fileMock, fileMock)).OccursAtLeast(1);
            Mock.Arrange(() => Crypto.Sdk.Crypto.EncryptFileKey(Arg.IsAny <PlainFileKey>(), Arg.IsAny <UserPublicKey>()))
            .Returns(FactoryFile.EncryptedFileKey).Occurs(1);
            Mock.Arrange(() => FileMapper.ToApiFileKey(Arg.IsAny <EncryptedFileKey>())).Returns(FactoryFile.ApiFileKey);

            Mock.Arrange(() => callback.OnStarted(Arg.AnyString)).Occurs(1);
            Mock.Arrange(() => callback.OnRunning(Arg.AnyString, Arg.AnyLong, Arg.AnyLong)).OccursAtLeast(1);
            Mock.Arrange(() => callback.OnFinished(Arg.AnyString, Arg.IsAny <Node>())).Occurs(1);

            // ACT
            Node actual = f.RunSync();

            s.Close();

            // ASSERT
            Assert.Equal(FactoryNode.Node, actual, new NodeComparer());
            Mock.Assert(callback);
            Mock.Assert(c.Builder);
            Mock.Assert(c.Executor);
        }
Exemplo n.º 7
0
        public void RunSync_S3_PollingError()
        {
            // ARRANGE
            ApiS3Status resultStatus = FactoryFile.ApiS3Status;

            resultStatus.Node      = null;
            resultStatus.Status    = "error";
            resultStatus.ErrorInfo = null;
            byte[] fileMock = new byte[1888];
            new Random().NextBytes(fileMock);
            Stream s = new MemoryStream(fileMock);
            IInternalDracoonClient c        = FactoryClients.InternalDracoonClientMock(true);
            FileUploadCallbackMock callback = new FileUploadCallbackMock();
            FileUpload             f        = new FileUpload(c, "id1", FactoryFile.UploadFileRequest, s, fileMock.Length);

            f.AddFileUploadCallback(callback);
            ApiGeneralSettings generalSettings = FactoryServerSettings.ApiGeneralSettings;

            generalSettings.UseS3Storage = true;
            ApiCreateFileUpload acfu = FactoryFile.ApiCreateFileUpload;

            acfu.Classification = null;
            Mock.Arrange(() => c.Builder.PostCreateFileUpload(Arg.IsAny <ApiCreateFileUpload>())).Returns(FactoryRestSharp.PostCreateFileUploadMock())
            .Occurs(1);
            Mock.Arrange(() => c.Executor.DoSyncApiCall <ApiUploadToken>(Arg.IsAny <IRestRequest>(), RequestType.PostUploadToken, 0))
            .Returns(FactoryFile.ApiUploadToken).Occurs(1);
            Mock.Arrange(() => c.Builder.PutCompleteS3FileUpload(Arg.AnyString, Arg.IsAny <ApiCompleteFileUpload>()))
            .Returns(FactoryRestSharp.PutCompleteFileUploadMock("path")).Occurs(1);
            Mock.Arrange(() => c.Executor.DoSyncApiCall <VoidResponse>(Arg.IsAny <IRestRequest>(), RequestType.PutCompleteS3Upload, 0)).DoNothing()
            .Occurs(1);
            Mock.Arrange(() => c.Builder.GetGeneralSettings())
            .Returns(FactoryRestSharp.RestRequestWithAuth(ApiConfig.ApiGetGeneralConfig, Method.GET)).Occurs(1);
            Mock.Arrange(() => c.Executor.DoSyncApiCall <ApiGeneralSettings>(Arg.IsAny <IRestRequest>(), RequestType.GetGeneralSettings, 0))
            .Returns(generalSettings).Occurs(1);
            Mock.Arrange(() => c.Builder.PostGetS3Urls(Arg.AnyString, Arg.IsAny <ApiGetS3Urls>())).Returns(FactoryRestSharp.PostGetS3UrlsMock())
            .OccursAtLeast(1);
            Mock.Arrange(() => c.Executor.DoSyncApiCall <ApiS3Urls>(Arg.IsAny <IRestRequest>(), RequestType.PostGetS3Urls, 0))
            .Returns(FactoryFile.ApiS3Urls).OccursAtLeast(1);
            Mock.Arrange(() => c.Builder.GetS3Status(Arg.AnyString)).Returns(FactoryRestSharp.GetS3StatusMock).OccursAtLeast(1);
            Mock.Arrange(() => c.Executor.DoSyncApiCall <ApiS3Status>(Arg.IsAny <IRestRequest>(), RequestType.GetS3Status, 0)).Returns(resultStatus)
            .OccursAtLeast(1);
            Mock.Arrange(() => FileMapper.ToApiCreateFileUpload(Arg.IsAny <FileUploadRequest>())).Returns(acfu).Occurs(1);
            Mock.Arrange(() => NodeMapper.FromApiNode(Arg.IsAny <ApiNode>())).Returns(FactoryNode.Node).Occurs(1);
            Mock.Arrange(() => FileMapper.ToApiCompleteFileUpload(Arg.IsAny <FileUploadRequest>())).Returns(FactoryFile.ApiCompleteFileUpload);
            DracoonWebClientExtension wc = Mock.Create <DracoonWebClientExtension>();

            Mock.Arrange(() => Mock.Create <UploadProgressChangedEventArgs>().BytesSent).IgnoreInstance();
            Mock.Arrange(() => c.Executor.ExecuteWebClientChunkUpload(Arg.IsAny <WebClient>(), Arg.IsAny <Uri>(), Arg.IsAny <byte[]>(),
                                                                      RequestType.PutUploadS3Chunk, Arg.IsAny <Thread>(), Arg.AnyInt)).DoInstead(() => Thread.Sleep(250))
            .Raises(() => wc.UploadProgressChanged += null, null, Mock.Create <UploadProgressChangedEventArgs>()).Returns(new byte[13]);
            Mock.Arrange(() => c.Builder.ProvideS3ChunkUploadWebClient()).Returns(wc);
            Mock.Arrange(() => JsonConvert.DeserializeObject <ApiUploadChunkResult>(Arg.AnyString)).Returns(FactoryFile.ApiUploadChunkResult);
            Mock.Arrange(() => DracoonErrorParser.ParseError(Arg.IsAny <ApiErrorResponse>(), RequestType.GetS3Status)).DoNothing();

            Mock.Arrange(() => callback.OnStarted(Arg.AnyString)).Occurs(1);
            Mock.Arrange(() => callback.OnRunning(Arg.AnyString, Arg.AnyLong, Arg.AnyLong)).OccursAtLeast(1);
            Mock.Arrange(() => callback.OnFailed(Arg.AnyString, Arg.IsAny <DracoonException>())).Occurs(1);

            // ACT
            Assert.Throws <DracoonApiException>(() => f.RunSync());
            s.Close();

            // ASSERT
            Mock.Assert(callback);
            Mock.Assert(c.Builder);
            Mock.Assert(c.Executor);
        }