Browse Source

fixes incorrect versioning & lock config XML settings (#933)

* fixes incorrect versioning & lock config XML settings

* lint change

---------

Co-authored-by: Ersan Bozduman <ersanbozduman@gmail.com>
pull/934/head
ebozduman 2 years ago
committed by GitHub
parent
commit
313638a529
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      .editorconfig
  2. 22
      Minio.Functional.Tests/FunctionalTest.cs
  3. 6
      Minio/Credentials/AssumeRoleResponse.cs
  4. 8
      Minio/DataModel/Args/GetVersioningArgs.cs
  5. 18
      Minio/DataModel/ObjectLock/ObjectLockConfiguration.cs
  6. 5
      Minio/DataModel/Response/GetVersioningResponse.cs
  7. 26
      Minio/DataModel/VersioningConfiguration.cs
  8. 16
      Minio/Helper/Utils.cs

2
.editorconfig

@ -378,4 +378,4 @@ dotnet_separate_import_directive_groups = false
dotnet_style_prefer_foreach_explicit_cast_in_source = when_strongly_typed
MA0051.maximum_lines_per_method = 150
MA0051.maximum_statements_per_method = 60
MA0051.maximum_statements_per_method = 70

22
Minio.Functional.Tests/FunctionalTest.cs

@ -592,8 +592,10 @@ public static class FunctionalTest
ObjectLockConfiguration lockConfig = null;
try
{
var versioningConfig = await minio.GetVersioningAsync(new GetVersioningArgs()
.WithBucket(bucketName)).ConfigureAwait(false);
VersioningConfiguration versioningConfig = null;
versioningConfig = await minio.GetVersioningAsync(new GetVersioningArgs()
.WithBucket(bucketName)
.WithVersions(true)).ConfigureAwait(false);
if (versioningConfig is not null &&
(versioningConfig.Status.Contains("Enabled", StringComparison.Ordinal) ||
versioningConfig.Status.Contains("Suspended", StringComparison.Ordinal)))
@ -2216,18 +2218,18 @@ public static class FunctionalTest
}
catch (NotImplementedException ex)
{
await TearDown(minio, bucketName).ConfigureAwait(false);
new MintLogger(nameof(ObjectLockConfigurationAsync_Test1), setObjectLockConfigurationSignature,
"Tests whether SetObjectLockConfigurationAsync passes", TestStatus.NA, DateTime.Now - startTime,
ex.Message, ex.ToString(), args: args).Log();
await TearDown(minio, bucketName).ConfigureAwait(false);
return;
}
catch (Exception ex)
{
await TearDown(minio, bucketName).ConfigureAwait(false);
new MintLogger(nameof(ObjectLockConfigurationAsync_Test1), setObjectLockConfigurationSignature,
"Tests whether SetObjectLockConfigurationAsync passes", TestStatus.FAIL, DateTime.Now - startTime,
ex.Message, ex.ToString(), args: args).Log();
await TearDown(minio, bucketName).ConfigureAwait(false);
throw;
}
@ -2246,16 +2248,17 @@ public static class FunctionalTest
catch (NotImplementedException ex)
{
setLockNotImplemented = true;
await TearDown(minio, bucketName).ConfigureAwait(false);
new MintLogger(nameof(ObjectLockConfigurationAsync_Test1), setObjectLockConfigurationSignature,
"Tests whether SetObjectLockConfigurationAsync passes", TestStatus.NA, DateTime.Now - startTime,
ex.Message, ex.ToString(), args: args).Log();
}
catch (Exception ex)
{
await TearDown(minio, bucketName).ConfigureAwait(false);
new MintLogger(nameof(ObjectLockConfigurationAsync_Test1), setObjectLockConfigurationSignature,
"Tests whether SetObjectLockConfigurationAsync passes", TestStatus.FAIL, DateTime.Now - startTime,
ex.Message, ex.ToString(), args: args).Log();
await TearDown(minio, bucketName).ConfigureAwait(false);
throw;
}
@ -2276,6 +2279,7 @@ public static class FunctionalTest
}
catch (NotImplementedException ex)
{
await TearDown(minio, bucketName).ConfigureAwait(false);
getLockNotImplemented = true;
new MintLogger(nameof(ObjectLockConfigurationAsync_Test1), getObjectLockConfigurationSignature,
"Tests whether GetObjectLockConfigurationAsync passes", TestStatus.NA, DateTime.Now - startTime,
@ -2329,7 +2333,6 @@ public static class FunctionalTest
}
finally
{
await Task.Delay(1500).ConfigureAwait(false);
await TearDown(minio, bucketName).ConfigureAwait(false);
}
}
@ -2734,7 +2737,6 @@ public static class FunctionalTest
listenBucketNotificationsSignature,
"Tests whether ListenBucketNotifications passes for small object",
TestStatus.PASS, DateTime.Now - startTime, args: args).Log();
await TearDown(minio, bucketName).ConfigureAwait(false);
}
catch (NotImplementedException ex)
{
@ -2743,7 +2745,6 @@ public static class FunctionalTest
"Tests whether ListenBucketNotifications passes for small object",
TestStatus.NA, DateTime.Now - startTime, ex.Message,
ex.ToString(), args: args).Log();
await TearDown(minio, bucketName).ConfigureAwait(false);
}
catch (Exception ex)
{
@ -2775,10 +2776,13 @@ public static class FunctionalTest
"Tests whether ListenBucketNotifications passes for small object",
TestStatus.FAIL, DateTime.Now - startTime, ex.Message,
ex.ToString(), args: args).Log();
await TearDown(minio, bucketName).ConfigureAwait(false);
throw;
}
}
finally
{
await TearDown(minio, bucketName).ConfigureAwait(false);
}
}
internal static async Task ListenBucketNotificationsAsync_Test2(IMinioClient minio)

6
Minio/Credentials/AssumeRoleResponse.cs

@ -21,7 +21,7 @@ using System.Xml.Serialization;
namespace Minio.Credentials;
[Serializable]
[XmlRoot(ElementName = "AssumeRoleResponse", Namespace = "https://sts.amazonaws.com/doc/2011-06-15/")]
[XmlRoot(ElementName = "AssumeRoleResponse", Namespace = "http://s3.amazonaws.com/doc/2006-03-01/")]
public class AssumeRoleResponse
{
[XmlElement(ElementName = "AssumeRoleResult")]
@ -33,9 +33,9 @@ public class AssumeRoleResponse
using var ms = new MemoryStream();
using var xmlWriter = XmlWriter.Create(ms, settings);
var names = new XmlSerializerNamespaces();
names.Add(string.Empty, "https://sts.amazonaws.com/doc/2011-06-15/");
names.Add(string.Empty, "http://s3.amazonaws.com/doc/2006-03-01/");
var cs = new XmlSerializer(typeof(CertificateResponse));
var cs = new XmlSerializer(typeof(AssumeRoleResponse));
cs.Serialize(xmlWriter, this, names);
ms.Flush();

8
Minio/DataModel/Args/GetVersioningArgs.cs

@ -23,6 +23,14 @@ public class GetVersioningArgs : BucketArgs<GetVersioningArgs>
RequestMethod = HttpMethod.Get;
}
internal bool Versions { get; private set; }
public GetVersioningArgs WithVersions(bool ver)
{
Versions = ver;
return this;
}
internal override HttpRequestMessageBuilder BuildRequest(HttpRequestMessageBuilder requestMessageBuilder)
{
requestMessageBuilder.AddQueryParameter("versioning", "");

18
Minio/DataModel/ObjectLock/ObjectLockConfiguration.cs

@ -14,6 +14,7 @@
* limitations under the License.
*/
using System.Xml;
using System.Xml.Serialization;
namespace Minio.DataModel.ObjectLock;
@ -38,4 +39,21 @@ public class ObjectLockConfiguration
[XmlElement("ObjectLockEnabled")] public string ObjectLockEnabled { get; set; }
[XmlElement("Rule")] public ObjectLockRule Rule { get; set; }
public string ToXML()
{
var settings = new XmlWriterSettings { OmitXmlDeclaration = true };
using var ms = new MemoryStream();
using var xmlWriter = XmlWriter.Create(ms, settings);
var names = new XmlSerializerNamespaces();
names.Add(string.Empty, "http://s3.amazonaws.com/doc/2006-03-01/");
var cs = new XmlSerializer(typeof(ObjectLockConfiguration));
cs.Serialize(xmlWriter, this, names);
ms.Flush();
_ = ms.Seek(0, SeekOrigin.Begin);
using var streamReader = new StreamReader(ms);
return streamReader.ReadToEnd();
}
}

5
Minio/DataModel/Response/GetVersioningResponse.cs

@ -15,8 +15,6 @@
*/
using System.Net;
using System.Text;
using CommunityToolkit.HighPerformance;
using Minio.Helper;
namespace Minio.DataModel.Response;
@ -30,8 +28,7 @@ internal class GetVersioningResponse : GenericResponse
!HttpStatusCode.OK.Equals(statusCode))
return;
using var stream = Encoding.UTF8.GetBytes(responseContent).AsMemory().AsStream();
VersioningConfig = Utils.DeserializeXml<VersioningConfiguration>(stream);
VersioningConfig = Utils.DeserializeXml<VersioningConfiguration>(responseContent);
}
internal VersioningConfiguration VersioningConfig { get; set; }

26
Minio/DataModel/VersioningConfiguration.cs

@ -14,6 +14,7 @@
* limitations under the License.
*/
using System.Xml;
using System.Xml.Serialization;
namespace Minio.DataModel;
@ -30,10 +31,7 @@ public class VersioningConfiguration
public VersioningConfiguration(bool enableVersioning = true)
{
if (enableVersioning)
Status = "Enabled";
else
Status = "Suspended";
Status = enableVersioning ? "Enabled" : "Suspended";
}
public VersioningConfiguration(VersioningConfiguration vc)
@ -44,7 +42,25 @@ public class VersioningConfiguration
MfaDelete = vc.MfaDelete;
}
[XmlElement] public string Status { get; set; }
[XmlElement(ElementName = "Status")] public string Status { get; set; }
[XmlElement(ElementName = "MfaDelete")]
public string MfaDelete { get; set; }
public string ToXML()
{
var settings = new XmlWriterSettings { OmitXmlDeclaration = true };
using var ms = new MemoryStream();
using var xmlWriter = XmlWriter.Create(ms, settings);
var names = new XmlSerializerNamespaces();
names.Add(string.Empty, "http://s3.amazonaws.com/doc/2006-03-01/");
var cs = new XmlSerializer(typeof(VersioningConfiguration));
cs.Serialize(xmlWriter, this, names);
ms.Flush();
_ = ms.Seek(0, SeekOrigin.Begin);
using var streamReader = new StreamReader(ms);
return streamReader.ReadToEnd();
}
}

16
Minio/Helper/Utils.cs

@ -1065,23 +1065,15 @@ public static class Utils
using var stringReader = new StringReader(xml);
using var xmlReader = XmlReader.Create(stringReader, settings);
try
{
var serializer = new XmlSerializer(typeof(T));
return (T)serializer.Deserialize(xmlReader);
}
catch (InvalidOperationException)
{
return default;
}
}
private static string GetNamespace<T>()
{
if (typeof(T).GetCustomAttributes(typeof(XmlRootAttribute), true)
.FirstOrDefault() is XmlRootAttribute xmlRootAttribute)
return xmlRootAttribute.Namespace;
return null;
return typeof(T).GetCustomAttributes(typeof(XmlRootAttribute), true)
.FirstOrDefault() is XmlRootAttribute xmlRootAttribute
? xmlRootAttribute.Namespace
: null;
}
}
Loading…
Cancel
Save