Make AccessPolicy::StartsOn and ExpiresOn nullable values. (#2829)

# Pull Request Checklist

Please leverage this checklist as a reminder to address commonly occurring feedback when submitting a pull request to make sure your PR can be reviewed quickly:

See the detailed list in the [contributing guide](https://github.com/Azure/azure-sdk-for-cpp/blob/main/CONTRIBUTING.md#pull-requests).

- [x] [C++ Guidelines](https://azure.github.io/azure-sdk/cpp_introduction.html)
- [x] Doxygen docs
- [x] Unit tests
- [x] No unwanted commits/changes
- [x] Descriptive title/description
  - [x] PR is single purpose
  - [x] Related issue listed
- [x] Comments in source
- [x] No typos
- [x] Update changelog
- [x] Not work-in-progress
- [x] External references or docs updated
- [x] Self review of PR done
- [] Any breaking changes?
This commit is contained in:
Kan Tang 2021-09-03 12:57:36 +08:00 committed by GitHub
parent 29659f9350
commit b2b1bdffd0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 63 additions and 18 deletions

View File

@ -6,6 +6,8 @@
### Breaking Changes
- `AccessPolicy::StartsOn` and `AccessPolicy::ExpiresOn` are now nullable values.
### Bugs Fixed
### Other Changes

View File

@ -178,12 +178,12 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
/**
* The date-time the policy is active.
*/
DateTime StartsOn;
Azure::Nullable<DateTime> StartsOn;
/**
* The date-time the policy expires.
*/
DateTime ExpiresOn;
Azure::Nullable<DateTime> 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});

View File

@ -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<Files::Shares::Models::SignedIdentifier> 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-"