diff --git a/sdk/storage/azure-storage-files-shares/CHANGELOG.md b/sdk/storage/azure-storage-files-shares/CHANGELOG.md index 1942e1f71..32d7fe44e 100644 --- a/sdk/storage/azure-storage-files-shares/CHANGELOG.md +++ b/sdk/storage/azure-storage-files-shares/CHANGELOG.md @@ -6,6 +6,8 @@ ### Breaking Changes +- `AccessPolicy::StartsOn` and `AccessPolicy::ExpiresOn` are now nullable values. + ### Bugs Fixed ### Other Changes diff --git a/sdk/storage/azure-storage-files-shares/inc/azure/storage/files/shares/protocol/share_rest_client.hpp b/sdk/storage/azure-storage-files-shares/inc/azure/storage/files/shares/protocol/share_rest_client.hpp index 0faad0334..177c7a9fc 100644 --- a/sdk/storage/azure-storage-files-shares/inc/azure/storage/files/shares/protocol/share_rest_client.hpp +++ b/sdk/storage/azure-storage-files-shares/inc/azure/storage/files/shares/protocol/share_rest_client.hpp @@ -178,12 +178,12 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares { /** * The date-time the policy is active. */ - DateTime StartsOn; + Azure::Nullable StartsOn; /** * The date-time the policy expires. */ - DateTime ExpiresOn; + Azure::Nullable ExpiresOn; /** * The permissions for the ACL policy. @@ -5007,20 +5007,28 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares { static void AccessPolicyToXml(_internal::XmlWriter& writer, const AccessPolicy& object) { writer.Write(_internal::XmlNode{_internal::XmlNodeType::StartTag, "AccessPolicy"}); - writer.Write(_internal::XmlNode{_internal::XmlNodeType::StartTag, "Start"}); - writer.Write(_internal::XmlNode{ - _internal::XmlNodeType::Text, - std::string(), - object.StartsOn.ToString( - Azure::DateTime::DateFormat::Rfc3339, DateTime::TimeFractionFormat::AllDigits)}); - writer.Write(_internal::XmlNode{_internal::XmlNodeType::EndTag}); - writer.Write(_internal::XmlNode{_internal::XmlNodeType::StartTag, "Expiry"}); - writer.Write(_internal::XmlNode{ - _internal::XmlNodeType::Text, - std::string(), - object.ExpiresOn.ToString( - Azure::DateTime::DateFormat::Rfc3339, DateTime::TimeFractionFormat::AllDigits)}); - writer.Write(_internal::XmlNode{_internal::XmlNodeType::EndTag}); + if (object.StartsOn.HasValue()) + { + writer.Write(_internal::XmlNode{_internal::XmlNodeType::StartTag, "Start"}); + writer.Write(_internal::XmlNode{ + _internal::XmlNodeType::Text, + std::string(), + object.StartsOn.Value().ToString( + Azure::DateTime::DateFormat::Rfc3339, + DateTime::TimeFractionFormat::AllDigits)}); + writer.Write(_internal::XmlNode{_internal::XmlNodeType::EndTag}); + } + if (object.ExpiresOn.HasValue()) + { + writer.Write(_internal::XmlNode{_internal::XmlNodeType::StartTag, "Expiry"}); + writer.Write(_internal::XmlNode{ + _internal::XmlNodeType::Text, + std::string(), + object.ExpiresOn.Value().ToString( + Azure::DateTime::DateFormat::Rfc3339, + DateTime::TimeFractionFormat::AllDigits)}); + writer.Write(_internal::XmlNode{_internal::XmlNodeType::EndTag}); + } writer.Write(_internal::XmlNode{_internal::XmlNodeType::StartTag, "Permission"}); writer.Write( _internal::XmlNode{_internal::XmlNodeType::Text, std::string(), object.Permission}); diff --git a/sdk/storage/azure-storage-files-shares/test/share_client_test.cpp b/sdk/storage/azure-storage-files-shares/test/share_client_test.cpp index a350321a0..f72dab390 100644 --- a/sdk/storage/azure-storage-files-shares/test/share_client_test.cpp +++ b/sdk/storage/azure-storage-files-shares/test/share_client_test.cpp @@ -14,8 +14,12 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares { names const Azure::Storage::Files::Shares::Models::SignedIdentifier& lhs, const Azure::Storage::Files::Shares::Models::SignedIdentifier& rhs) { - return lhs.Id == rhs.Id && lhs.Policy.StartsOn == rhs.Policy.StartsOn - && lhs.Policy.ExpiresOn == rhs.Policy.ExpiresOn + return lhs.Id == rhs.Id && lhs.Policy.StartsOn.HasValue() == rhs.Policy.StartsOn.HasValue() + && (!lhs.Policy.StartsOn.HasValue() + || lhs.Policy.StartsOn.Value() == rhs.Policy.StartsOn.Value()) + && lhs.Policy.ExpiresOn.HasValue() == rhs.Policy.ExpiresOn.HasValue() + && (!lhs.Policy.ExpiresOn.HasValue() + || lhs.Policy.ExpiresOn.Value() == rhs.Policy.ExpiresOn.Value()) && lhs.Policy.Permission == rhs.Policy.Permission; } @@ -213,6 +217,37 @@ namespace Azure { namespace Storage { namespace Test { EXPECT_EQ(ret2.Value.SignedIdentifiers, identifiers); } + TEST_F(FileShareClientTest, ShareAccessPolicyNullable) + { + std::vector identifiers; + { + Files::Shares::Models::SignedIdentifier identifier; + identifier.Id = RandomString(64); + identifier.Policy.Permission = "r"; + identifiers.emplace_back(identifier); + } + { + Files::Shares::Models::SignedIdentifier identifier; + identifier.Id = RandomString(64); + identifier.Policy.StartsOn = std::chrono::system_clock::now() - std::chrono::minutes(10); + identifier.Policy.Permission = "r"; + identifiers.emplace_back(identifier); + } + { + Files::Shares::Models::SignedIdentifier identifier; + identifier.Id = RandomString(64); + identifier.Policy.ExpiresOn = std::chrono::system_clock::now() + std::chrono::minutes(100); + identifier.Policy.Permission = "r"; + identifiers.emplace_back(identifier); + } + + auto ret = m_shareClient->SetAccessPolicy(identifiers); + EXPECT_TRUE(IsValidTime(ret.Value.LastModified)); + + auto ret2 = m_shareClient->GetAccessPolicy(); + EXPECT_EQ(ret2.Value.SignedIdentifiers, identifiers); + } + TEST_F(FileShareClientTest, SharePermissions) { std::string permission = "O:S-1-5-21-2127521184-1604012920-1887927527-21560751G:S-1-5-21-"