private void ResumableUploadResumeTest_InitDelayTest() { var bucket = _fixture.SingleVersionBucket; var name = GenerateName(); var data = _fixture.SmallContent; string url = null; _fixture.RegisterDelayTest(_duration, beforeDelay: async duration => { url = _fixture.UrlSigner.Sign(bucket, name, duration, UrlSigner.ResumableHttpMethod); var sessionUri = await SignedUrlResumableUpload.InitiateSessionAsync(url); // Verify that the URL works initially. var uploader = ResumableUpload.CreateFromUploadUri(sessionUri, new MemoryStream(data)); var progress = await uploader.ResumeAsync(sessionUri); Assert.Null(progress.Exception); Assert.Equal(UploadStatus.Completed, progress.Status); var result = new MemoryStream(); await _fixture.Client.DownloadObjectAsync(bucket, name, result); Assert.Equal(result.ToArray(), data); // Reset the state. await _fixture.Client.DeleteObjectAsync(bucket, name); }, afterDelay: async() => { // Verify that the URL no longer works. await Assert.ThrowsAsync <GoogleApiException>(() => SignedUrlResumableUpload.InitiateSessionAsync(url)); var obj = await _fixture.Client.ListObjectsAsync(bucket, name).FirstOrDefault(o => o.Name == name); Assert.Null(obj); }); }
private static void ResumableUploadWithCustomerSuppliedEncryptionKeysTest_Common(StorageFixture fixture, SigningVersion signingVersion, [CallerMemberName] string caller = null) { var bucket = fixture.SingleVersionBucket; var name = IdGenerator.FromGuid(); var requestTemplate = RequestTemplate .FromBucket(bucket) .WithObjectName(name) .WithHttpMethod(ResumableHttpMethod) .WithRequestHeaders(new Dictionary <string, IEnumerable <string> > { { "x-goog-encryption-algorithm", new [] { "AES256" } } }); var content = fixture.SmallContent; string url = null; EncryptionKey key = EncryptionKey.Generate(); fixture.RegisterDelayTest( s_duration, beforeDelay: async duration => { url = fixture.UrlSigner.Sign(requestTemplate, Options.FromDuration(duration).WithSigningVersion(signingVersion)); // Verify that the URL works initially. var uploader = SignedUrlResumableUpload.Create( url, new MemoryStream(content), new ResumableUploadOptions { ModifySessionInitiationRequest = key.ModifyRequest }); var progress = await uploader.UploadAsync(); Assert.Null(progress.Exception); Assert.Equal(UploadStatus.Completed, progress.Status); // Make sure the encryption succeeded. var downloadedData = new MemoryStream(); await Assert.ThrowsAsync <GoogleApiException>( () => fixture.Client.DownloadObjectAsync(bucket, name, downloadedData)); await fixture.Client.DownloadObjectAsync(bucket, name, downloadedData, new DownloadObjectOptions { EncryptionKey = key }); AssertContentEqual(content, downloadedData.ToArray()); }, afterDelay: async() => { var uploader = SignedUrlResumableUpload.Create( url, new MemoryStream(content), new ResumableUploadOptions { ModifySessionInitiationRequest = key.ModifyRequest }); // Verify that the URL no longer works. var progress = await uploader.UploadAsync(); Assert.Equal(UploadStatus.Failed, progress.Status); Assert.IsType <GoogleApiException>(progress.Exception); }, caller); }
private void ResumableUploadWithCustomerSuppliedEncryptionKeysTest_InitDelayTest() { var bucket = _fixture.SingleVersionBucket; var name = GenerateName(); var data = _fixture.SmallContent; string url = null; EncryptionKey key = EncryptionKey.Generate(); _fixture.RegisterDelayTest(_duration, beforeDelay: async duration => { url = _fixture.UrlSigner.Sign( bucket, name, duration, UrlSigner.ResumableHttpMethod, requestHeaders: new Dictionary <string, IEnumerable <string> > { { "x-goog-encryption-algorithm", new [] { "AES256" } } }); // Verify that the URL works initially. var uploader = SignedUrlResumableUpload.Create( url, new MemoryStream(data), new ResumableUploadOptions { ModifySessionInitiationRequest = key.ModifyRequest }); var progress = await uploader.UploadAsync(); Assert.Null(progress.Exception); Assert.Equal(UploadStatus.Completed, progress.Status); // Make sure the encryption succeeded. var downloadedData = new MemoryStream(); await Assert.ThrowsAsync <GoogleApiException>( () => _fixture.Client.DownloadObjectAsync(bucket, name, downloadedData)); await _fixture.Client.DownloadObjectAsync(bucket, name, downloadedData, new DownloadObjectOptions { EncryptionKey = key }); Assert.Equal(data, downloadedData.ToArray()); }, afterDelay: async() => { var uploader = SignedUrlResumableUpload.Create( url, new MemoryStream(data), new ResumableUploadOptions { ModifySessionInitiationRequest = key.ModifyRequest }); // Verify that the URL no longer works. var progress = await uploader.UploadAsync(); Assert.Equal(UploadStatus.Failed, progress.Status); Assert.IsType(typeof(GoogleApiException), progress.Exception); }); }
private static void ResumableUploadTest_Common(StorageFixture fixture, SigningVersion signingVersion, [CallerMemberName] string caller = null) { var bucket = fixture.SingleVersionBucket; var name = IdGenerator.FromGuid(); var requestTemplate = RequestTemplate .FromBucket(bucket) .WithObjectName(name) .WithHttpMethod(ResumableHttpMethod); var content = fixture.SmallContent; string url = null; fixture.RegisterDelayTest( s_duration, beforeDelay: async duration => { url = fixture.UrlSigner.Sign(requestTemplate, Options.FromDuration(duration).WithSigningVersion(signingVersion)); // Verify that the URL works initially. var uploader = SignedUrlResumableUpload.Create(url, new MemoryStream(content)); var progress = await uploader.UploadAsync(); Assert.Equal(UploadStatus.Completed, progress.Status); var result = new MemoryStream(); await fixture.Client.DownloadObjectAsync(bucket, name, result); AssertContentEqual(content, result.ToArray()); // Reset the state. await fixture.Client.DeleteObjectAsync(bucket, name); }, afterDelay: async() => { var uploader = SignedUrlResumableUpload.Create(url, new MemoryStream(content)); // Verify that the URL no longer works. var progress = await uploader.UploadAsync(); Assert.Equal(UploadStatus.Failed, progress.Status); Assert.IsType <GoogleApiException>(progress.Exception); var obj = await fixture.Client.ListObjectsAsync(bucket, name).FirstOrDefaultAsync(o => o.Name == name); Assert.Null(obj); }, caller); }
private static void ResumableUploadResumeTest_Common(StorageFixture fixture, UrlSigner signer, [CallerMemberName] string caller = null) { var bucket = fixture.SingleVersionBucket; var name = IdGenerator.FromGuid(); var content = fixture.SmallContent; string url = null; fixture.RegisterDelayTest( s_duration, beforeDelay: async duration => { url = signer.Sign(bucket, name, duration, UrlSigner.ResumableHttpMethod); var sessionUri = await SignedUrlResumableUpload.InitiateSessionAsync(url); // Verify that the URL works initially. var uploader = ResumableUpload.CreateFromUploadUri(sessionUri, new MemoryStream(content)); var progress = await uploader.ResumeAsync(sessionUri); Assert.Null(progress.Exception); Assert.Equal(UploadStatus.Completed, progress.Status); var result = new MemoryStream(); await fixture.Client.DownloadObjectAsync(bucket, name, result); AssertContentEqual(content, result.ToArray()); // Reset the state. await fixture.Client.DeleteObjectAsync(bucket, name); }, afterDelay: async() => { // Verify that the URL no longer works. await Assert.ThrowsAsync <GoogleApiException>(() => SignedUrlResumableUpload.InitiateSessionAsync(url)); var obj = await fixture.Client.ListObjectsAsync(bucket, name).FirstOrDefault(o => o.Name == name); Assert.Null(obj); }, caller); }
private void ResumableUploadTest_InitDelayTest() { var bucket = _fixture.SingleVersionBucket; var name = IdGenerator.FromGuid(); var content = _fixture.SmallContent; string url = null; _fixture.RegisterDelayTest(_duration, beforeDelay: async duration => { url = _fixture.UrlSigner.Sign(bucket, name, duration, UrlSigner.ResumableHttpMethod); // Verify that the URL works initially. var uploader = SignedUrlResumableUpload.Create(url, new MemoryStream(content)); var progress = await uploader.UploadAsync(); Assert.Equal(UploadStatus.Completed, progress.Status); var result = new MemoryStream(); await _fixture.Client.DownloadObjectAsync(bucket, name, result); AssertContentEqual(content, result.ToArray()); // Reset the state. await _fixture.Client.DeleteObjectAsync(bucket, name); }, afterDelay: async() => { var uploader = SignedUrlResumableUpload.Create(url, new MemoryStream(content)); // Verify that the URL no longer works. var progress = await uploader.UploadAsync(); Assert.Equal(UploadStatus.Failed, progress.Status); Assert.IsType <GoogleApiException>(progress.Exception); var obj = await _fixture.Client.ListObjectsAsync(bucket, name).FirstOrDefault(o => o.Name == name); Assert.Null(obj); }); }