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

Next fixes #779

Merged
merged 13 commits into from
May 22, 2023
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
2 changes: 1 addition & 1 deletion .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"isRoot": true,
"tools": {
"jetbrains.resharper.globaltools": {
"version": "2023.1.0",
"version": "2023.1.1",
"commands": [
"jb"
]
Expand Down
6 changes: 2 additions & 4 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

<EnableNETAnalyzers>false</EnableNETAnalyzers>
<AnalysisLevel>latest</AnalysisLevel>
<AnalysisMode>AllEnabledByDefault</AnalysisMode>
<AnalysisMode>All</AnalysisMode>

<IsTestProject>$(MSBuildProjectName.Contains('Test'))</IsTestProject>
</PropertyGroup>
Expand All @@ -51,8 +51,6 @@
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DebugType>full</DebugType>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>

<ItemGroup>
Expand Down Expand Up @@ -80,7 +78,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Meziantou.Analyzer" Version="2.0.37">
<PackageReference Include="Meziantou.Analyzer" Version="2.0.48">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
Expand Down
2 changes: 1 addition & 1 deletion Minio.Examples/Cases/ChainedCredentialProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static class ChainedCredentialProvider
public static async Task Run()
{
var provider = new ChainedProvider()
.AddProviders(new ClientProvider[] { new AWSEnvironmentProvider(), new MinioEnvironmentProvider() });
.AddProviders(new IClientProvider[] { new AWSEnvironmentProvider(), new MinioEnvironmentProvider() });
//Chained provider definition here.
using var minioClient = new MinioClient()
.WithEndpoint("s3.amazonaws.com")
Expand Down
2 changes: 1 addition & 1 deletion Minio.Examples/Cases/GetPartialObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static async Task Run(IMinioClient minio,
.WithBucket(bucketName)
.WithObject(objectName)
.WithOffsetAndLength(1024L, 4096L)
.WithCallbackStream(async stream =>
.WithCallbackStream(async (stream, cancellationToken) =>
{
var fileStream = File.Create(fileName);
await stream.CopyToAsync(fileStream).ConfigureAwait(false);
Expand Down
4 changes: 2 additions & 2 deletions Minio.Functional.Tests/FunctionalTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5353,7 +5353,7 @@ internal static async Task PresignedGetObject_Test1(MinioClient minio)
var bucketName = GetRandomName(15);
var objectName = GetRandomObjectName(10);
var expiresInt = 1000;
var downloadFile = "downloadFileName";
var downloadFile = GetRandomObjectName(10);

var args = new Dictionary<string, string>
{
Expand Down Expand Up @@ -5481,7 +5481,7 @@ internal static async Task PresignedGetObject_Test3(MinioClient minio)
var objectName = GetRandomObjectName(10);
var expiresInt = 1000;
var reqDate = DateTime.UtcNow.AddSeconds(-50);
var downloadFile = "downloadFileName";
var downloadFile = GetRandomObjectName(10);
var args = new Dictionary<string, string>
{
{ "bucketName", bucketName },
Expand Down
2 changes: 1 addition & 1 deletion Minio.Tests/RegionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
namespace Minio.Tests;

[TestClass]
public class TestRegion
public class RegionTest
{
[DataTestMethod]
[DataRow("s3.us-east-2.amazonaws.com", "us-east-2")]
Expand Down
121 changes: 0 additions & 121 deletions Minio.Tests/UnitTest1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,125 +165,4 @@ public void TestEndpointFailure()
//

#endregion
}

/// <summary>
/// Summary description for UnitTest2
/// </summary>
[TestClass]
public class UnitTest2
{
public UnitTest2()
{
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
| SecurityProtocolType.Tls11
| SecurityProtocolType.Tls12;
using var minio = new MinioClient()
.WithEndpoint(TestHelper.Endpoint)
.WithCredentials(TestHelper.AccessKey, TestHelper.SecretKey)
.WithSSL()
.Build();
}

/// <summary>
/// Gets or sets the test context which provides
/// information about and functionality for the current test run.
/// </summary>
public TestContext TestContext { get; set; }

[TestMethod]
public void TestWithUrl()
{
using var client = new MinioClient()
.WithEndpoint("localhost", 9000)
.WithCredentials("minio", "minio")
.Build();
}

[TestMethod]
public void TestWithoutPort()
{
using var client = new MinioClient()
.WithEndpoint("localhost")
.WithCredentials("minio", "minio")
.Build();
}

[TestMethod]
public void TestWithTrailingSlash()
{
using var client = new MinioClient()
.WithEndpoint("localhost", 9000)
.WithCredentials("minio", "minio")
.Build();
}

[TestMethod]
[ExpectedException(typeof(InvalidEndpointException))]
public void TestUrlFailsWithMalformedScheme()
{
using var client = new MinioClient()
.WithEndpoint("htp://localhost", 9000)
.WithCredentials("minio", "minio")
.Build();
}

[TestMethod]
[ExpectedException(typeof(InvalidEndpointException))]
public void TestUrlFailsWithPath()
{
using var client = new MinioClient().WithEndpoint("localhost:9000/foo").WithCredentials("minio", "minio")
.Build();
}

[TestMethod]
[ExpectedException(typeof(InvalidEndpointException))]
public void TestUrlFailsWithQuery()
{
using var client = new MinioClient()
.WithEndpoint("localhost:9000/?foo=bar")
.WithCredentials("minio", "minio")
.Build();
}

[TestMethod]
[ExpectedException(typeof(ArgumentException))]
public void TestSetAppInfoFailsNullApp()
{
using var client = new MinioClient()
.WithEndpoint("localhost", 9000)
.WithCredentials("minio", "minio")
.Build();
client.SetAppInfo(null, "1.2.2");
}

[TestMethod]
[ExpectedException(typeof(ArgumentException))]
public void TestSetAppInfoFailsNullVersion()
{
using var client = new MinioClient()
.WithEndpoint("localhost", 9000)
.WithCredentials("minio", "minio")
.Build();
client.SetAppInfo("Hello-App", null);
}

[TestMethod]
public void TestSetAppInfoSuccess()
{
using var client = new MinioClient()
.WithEndpoint("localhost", 9000)
.WithCredentials("minio", "minio")
.Build();
client.SetAppInfo("Hello-App", "1.2.1");
}

[TestMethod]
public void TestEndpointSuccess()
{
using var client = new MinioClient()
.WithEndpoint("s3.amazonaws.com")
.WithCredentials("minio", "minio")
.Build();
}
}
142 changes: 142 additions & 0 deletions Minio.Tests/UnitTest2.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
/*
* MinIO .NET Library for Amazon S3 Compatible Cloud Storage, (C) 2017 MinIO, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

using System.Net;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Minio.Exceptions;

namespace Minio.Tests;

/// <summary>
/// Summary description for UnitTest2
/// </summary>
[TestClass]
public class UnitTest2
{
public UnitTest2()
{
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
| SecurityProtocolType.Tls11
| SecurityProtocolType.Tls12;
using var minio = new MinioClient()
.WithEndpoint(TestHelper.Endpoint)
.WithCredentials(TestHelper.AccessKey, TestHelper.SecretKey)
.WithSSL()
.Build();
}

/// <summary>
/// Gets or sets the test context which provides
/// information about and functionality for the current test run.
/// </summary>
public TestContext TestContext { get; set; }

[TestMethod]
public void TestWithUrl()
{
using var client = new MinioClient()
.WithEndpoint("localhost", 9000)
.WithCredentials("minio", "minio")
.Build();
}

[TestMethod]
public void TestWithoutPort()
{
using var client = new MinioClient()
.WithEndpoint("localhost")
.WithCredentials("minio", "minio")
.Build();
}

[TestMethod]
public void TestWithTrailingSlash()
{
using var client = new MinioClient()
.WithEndpoint("localhost", 9000)
.WithCredentials("minio", "minio")
.Build();
}

[TestMethod]
[ExpectedException(typeof(InvalidEndpointException))]
public void TestUrlFailsWithMalformedScheme()
{
using var client = new MinioClient()
.WithEndpoint("htp://localhost", 9000)
.WithCredentials("minio", "minio")
.Build();
}

[TestMethod]
[ExpectedException(typeof(InvalidEndpointException))]
public void TestUrlFailsWithPath()
{
using var client = new MinioClient().WithEndpoint("localhost:9000/foo").WithCredentials("minio", "minio")
.Build();
}

[TestMethod]
[ExpectedException(typeof(InvalidEndpointException))]
public void TestUrlFailsWithQuery()
{
using var client = new MinioClient()
.WithEndpoint("localhost:9000/?foo=bar")
.WithCredentials("minio", "minio")
.Build();
}

[TestMethod]
[ExpectedException(typeof(ArgumentException))]
public void TestSetAppInfoFailsNullApp()
{
using var client = new MinioClient()
.WithEndpoint("localhost", 9000)
.WithCredentials("minio", "minio")
.Build();
client.SetAppInfo(null, "1.2.2");
}

[TestMethod]
[ExpectedException(typeof(ArgumentException))]
public void TestSetAppInfoFailsNullVersion()
{
using var client = new MinioClient()
.WithEndpoint("localhost", 9000)
.WithCredentials("minio", "minio")
.Build();
client.SetAppInfo("Hello-App", null);
}

[TestMethod]
public void TestSetAppInfoSuccess()
{
using var client = new MinioClient()
.WithEndpoint("localhost", 9000)
.WithCredentials("minio", "minio")
.Build();
client.SetAppInfo("Hello-App", "1.2.1");
}

[TestMethod]
public void TestEndpointSuccess()
{
using var client = new MinioClient()
.WithEndpoint("s3.amazonaws.com")
.WithCredentials("minio", "minio")
.Build();
}
}
13 changes: 5 additions & 8 deletions Minio/Credentials/AWSEnvironmentProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,16 @@

namespace Minio.Credentials;

public class AWSEnvironmentProvider : EnvironmentProvider
public class AWSEnvironmentProvider : IClientProvider
{
public override AccessCredentials GetCredentials()
public AccessCredentials GetCredentials()
{
var credentials = new AccessCredentials(GetAccessKey(), GetSecretKey(), GetSessionToken(), default);
return credentials;
return new AccessCredentials(GetAccessKey(), GetSecretKey(), GetSessionToken(), default);
}

public override async Task<AccessCredentials> GetCredentialsAsync()
public ValueTask<AccessCredentials> GetCredentialsAsync()
{
var creds = GetCredentials();
await Task.Yield();
return creds;
return new ValueTask<AccessCredentials>(GetCredentials());
}

internal string GetAccessKey()
Expand Down
Loading